Does template argument deduction takes return type into account?

Viewed 225

I am going through "C++ Templates: The Complete Guide (Second Edition)", page 10.

As per the book, template argument deduction doesn't take return type into account.

Template Deduction can be seen as part of overload resolution. A process that is not based on selection of return types. The sole exception is the return type of conversion operator members

Any example will be helpful in which return type is taken into account in deduction.

2 Answers
struct A {
    int value; 

    //conversion operator
    template<class T>
    operator T() {return static_cast<T>(value);}
};

A a{4};
float f = a; //conversion from A to float

I could think of one more case:

template <typename A, typename B>
A foo(B)
{
    cout << "Am I being instantiated? " << __PRETTY_FUNCTION__ << endl;
    return A();
}

int main ( )
{        
    int(*fp)(int) = foo; // Instantiates "int foo(int) [A = int, B = int]"
    fp(1);      
}
Related