Questions tagged [template-argument-deduction]

Template argument deduction is a compiler attempt to deduce template arguments when some are omitted.

692 questions
15
votes
1 answer

Partial template function specification in C++ works, but why?

I'm trying to find out whether partial specification of templated functions is part of the C++ standard, or whether this is something compiler specific. By partial specification, I mean specifying only the types the compiler can't deduce. So if I…
14
votes
1 answer

C++20 designated initializers with templated types

How are designated initializers (C++20) supposed to work with CTAD? This code works fine in gcc9.2, but fails with clang8 template struct my_pair { int_t first; float_t…
14
votes
3 answers

Can template deduction guides call constexpr functions?

I have my own fixed-size array type I want to be constexpr constructible from an std::initializer_list without having to explicitly define the size template argument. I thought I'd be able to use a template deduction guide but it looks like it's not…
14
votes
4 answers

Why didn't the C++17 standard bring partial class template argument deductions?

One of the places I hoped I would be able to use the new template argument deduction, was in construction of std::set's / std::maps / any other containers with custom comparators - my goal is to create a one-line statement, that will create an…
Kaznov
  • 1,035
  • 10
  • 17
14
votes
1 answer

Class template argument deduction and default template parameters

The following stripped down code doesn't work with the latest clang++5 but is accepted by g++7: template struct wrapper; template struct wrapper { wrapper() = default; //…
Morwenn
  • 21,684
  • 12
  • 93
  • 152
14
votes
2 answers

Why does deduction fail for std::set in GCC?

I have a std::set which allows deduction from an iterator range. #include #include int main() { std::set s1 = {1,2,3,4}; std::set s2(s1.begin(), s1.end()); } The above program failed to compile in GCC. Why does deduction…
msc
  • 33,420
  • 29
  • 119
  • 214
14
votes
2 answers