Home > Mobile >  How alternative deductions can yield more than one possible "deduced A"?
How alternative deductions can yield more than one possible "deduced A"?

Time:08-13

Per [temp.deduct.call]/5

These alternatives ([temp.deduct.call]/4) are considered only if type deduction would otherwise fail. If they yield more than one possible deduced A, the type deduction fails. [ Note: If a template-parameter is not used in any of the function parameters of a function template, or is used only in a non-deduced context, its corresponding template-argument cannot be deduced from a function call and the template-argument must be explicitly specified. — end note ]

My question:

  • How these alternative deductions can yield more than one possible "deduced A"?

Please, support the answer with an example that triggers this case.

CodePudding user response:

How these alternative deductions can yield more than one possible "deduced A"? Please, support the answer with an example that triggers this case.

An example of this can be:

template<typename T> 
void f(T a, T b)
{
    
}
int main()
{
    f(3, 5.5); //deduced A as int from first deduction while double from second deduction
    return 0;
}

Here we have more than one possible "deduced A". From the first argument we've int and from the second argument b we have double.

  • Related