tom_usenet wrote in
1 Template argument deduction is done by comparing each function
template parameter type (call it P) with the type of the
corresponding argument of the call (call it A) as described below.
2 If P is not a reference type:
Oops, I missed the "If P is not a reference type". In this case, P is
a reference type of course, so the paragraph below doesn't apply.
...
— If A is a function type, the pointer type produced by the
function-to-pointer standard conversion (4.3) is used in
place of A for type deduction; otherwise,
...
I quoted (1) as it describes P.
Given:
struct S
{
template <class F>
void method(const F& f)
{
f();
}
};
You seem to think "template parameter type (call it P)" is F where as
I think it is F const &.
I just missed the "If P is not a reference type". So in fact, the
reverse is true; rather than choosing the function pointer type for
the template parameter, template argument deduction deduces F=void():
S::method<void()>
Still, as I said before, there is nothing ambiguous about it and
overload resolution doesn't come into it, since 1 function is chosen
by TAD (S::method<void()>) and there is only 1 valid conversion
sequence for the parameter to reach that type (void() ->
void(const&)() (direct reference binding).
The original example compiles fine with Comeau C++:
#include <iostream>
void func()
{ std::cout << "success!\n"; }
struct S
{
template <class F>
void method(const F& f)
{ f(); }
};
int main()
{
S s;
s.method(func);
}
Tom