Public Types | |
| typedef T | type |
f(1, 3.141) because the type T of the template can not be deduced in a unique way from the types of the arguments. However, if the template is written as template <typename T> void f(T, typename identity<T>::type);
T is not deducible from the second argument to the function, so only the first argument participates in template type resolution.The context for this feature is as follows: consider
template <typename RT, typename A> void forward_call(RT (*p) (A), A a) { p(a); } void h (double); void g() { forward_call(&h, 1); }
A should be double (from the signature of the function given as first argument to forward_call, or int because the expression 1 has that type. Of course, what we would like the compiler to do is simply cast the 1 to double. We can achieve this by writing the code as follows: template <typename RT, typename A> void forward_call(RT (*p) (A), typename identity<A>::type a) { p(a); } void h (double); void g() { forward_call(&h, 1); }
documentation generated on Thu Mar 11 23:10:24 2010 by
doxygen
1.5.9