class (or of a struct). They are defined in the new header <type_traits>. In the next example there is the template function ‘elaborate’ which, depending on the given data types, will instantiate one of the two proposed algorithms (algorithm.do_it). // First way of operating. template< bool B > struct Algorithm { template<class T1, class T2> static int do_it (T1 &, T2 &) { /*...*/ } }; // Second way of operating. template<> struct Algorithm<true> { template<class T1, class T2> static int do_it (T1, T2) { /*...*/ } }; // Instantiating 'elaborate' will automatically instantiate the correct way to operate. template<class T1, class T2> int elaborate (T1 A, T2 B) { // Use the second way only if 'T1' is an integer and if 'T2' is // in floating point, otherwise use the first way. return Algorithm<std::is_integral<T1>::value && std::is_floating_point<T2>::value>::do_it( A, B ) ; } Via type traits, defined in header <type_traits>, it's also possible to create type transformation operations (static_cast and const_cast are insufficient inside a template). This type of programming produces elegant and concise code; however, the weak point of these techniques is the debugging: it's uncomfortable during compilation and very difficult during program execution. Uniform method for computing the return type of function objects Determining the return type of a template function object at compile-time is not intuitive, particularly if the return value depends on the parameters of the function. As an example: struct Clear { int operator()(int) const; // The parameter type is double operator()(double) const; // equal to the return type. }; template <class Obj> class Calculus { public: template<class Arg> Arg operator()(Arg& a) const { return member(a); } private: Obj member; }; Instantiating the class template Calculus<Clear>, the function object of calculus will have always the same return type as the function object of Clear. However, given class Confused below: struct Confused { double operator()(int) const; // The parameter type is not int operator()(double) const; // equal to the return type. }; Attempting to instantiate Calculus<Confused> will cause the return type of Calculus to not be the same as that of class Confused. The compiler may generate warnings about the conversion from int to double and vice versa. TR1 introduces, and C++11 adopts, the template class std::result_of that allows one to determine and use the return type of a function object for every declaration. The object CalculusVer2 uses the std::result_of object to derive the return type