Questions tagged [template-argument-deduction]

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

692 questions
8
votes
2 answers

Why can't I create a template function with an optional UnaryPredicate argument?

I'm trying to create a templated function with an optional argument and I'm having trouble understanding why the compile fails. This is my test (contrived) code: #include #include template int…
kshenoy
  • 1,726
  • 17
  • 31
8
votes
1 answer

Clang claims that `member reference base type 'X' is not a structure or union`, but X is a structure template with deduced parameters

Consider following code: template struct X { X(T) {} void foo() {} }; template struct Y { int object = 0; void bar() { X(object).foo(); } }; Live on gcc.godbold.org GCC 8.2 compiles it,…
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
8
votes
1 answer

Variadic template type deduction crashes compilers if there is a substitution on deducible type

I think I hit a template type deduction bug in all the compilers, but before reporting it I want to be sure I did not miss something. Consider an example: #include template void…
8
votes
2 answers

Template non-type parameter deduction

Is it possible to deduce template value (not type) for a c++17 function? The function foo: template int foo() { return (I); } Can be called via: foo<5>(); And will return 5. Template types can be deduced through the type of a function…
user7119460
  • 1,451
  • 10
  • 20
8
votes
1 answer

Template argument deduction failure with new expression

I'm working on a variadic class template but I cannot use it with a new expression without specifying the template arguments (I don't want to). I reduced the problem to the following code sample: template struct Foo { Foo(T p) …
Zejj
  • 83
  • 5
8
votes
1 answer

Is it abuse to deduce parameters of parent template when passing pointer to constexpr function in the scope of a class

Minimal example I got is a bit complicated: struct A { }; template struct Parent { }; template constexpr int operator*(A, Parent*) { return N; } template using ptr = T*; template struct Other { }; template
8
votes
1 answer