I would like to specialize a function template such that the return type changes depending on the type of the template argument.
class ReturnTypeSpecializati
Since the specialization has to agree with the base template on the return type, you can make it so by adding a "return type trait", a struct you can specialize and draw the true return type from:
// in the normal case, just the identity
template
struct item_return{ typedef T type; };
template
typename item_return::type item();
template<>
struct item_return{ typedef int type; };
template<>
int item();
Live example.
Note that you might want to stick to the following, so you only need to update the return-type in the item_return specialization.
template<>
item_return::type foo(){ ... }
// note: No `typename` needed, because `float` is not a dependent type