Namespaces
Variants
Actions

Talk:cpp/language/template argument deduction

From cppreference.com

The section on deduction from a function call is somewhat confusing because the use of symbols like A, P, etc. is inconsistent throughout the section. For example, in the first few paragraphs, A denotes the value of an argument to a function, "deduced A" denotes the type of the argument A, and P denotes a template. Later, A is used to denote a type. 154.21.216.76 22:46, 14 January 2021 (PST) (a.k.a. kp8080)

[edit] Possibly incorrect example

When I run the example

template<int I>
class A {};
 
template<short s>
void f(A<s>) {} // the type of the non-type template param is short
 
void k1()
{
  A<1> a;  // the type of the non-type template param of a is int
 
  f(a);    // P = A<(short)s>, A = A<(int)1>
           // error: deduced non-type template argument does not have the same
           // type as its corresponding template argument
 
  f<1>(a); // OK: the template argument is not deduced, 
           // this calls f<(short)1>(A<(short)1>)
}

with the gnu c++20 compiler, I receive the following error message:

error: no matching function for call to ‘f(A<1>&)’
note:   template argument deduction/substitution failed:
note:   mismatched types ‘short int’ and ‘int’
Works here https://godbolt.org/z/86EzEKPhM --Ybab321 (talk) 02:47, 18 June 2022 (PDT)
the example is right out of https://eel.is/c++draft/temp.deduct#type-example-12 so if it fails, it's a bug --Cubbi (talk) 19:00, 18 June 2022 (PDT)