function objects Polymorphic wrappers for function objects are similar to function pointers in semantics and syntax, but are less tightly bound and can indiscriminately refer to anything which can be called (function pointers, member function pointers, or functors) whose arguments are compatible with those of the wrapper. An example can clarify its characteristics: std::function<int (int, int)> func; // Wrapper creation using // template class 'function'. std::plus<int> add; // 'plus' is declared as 'template<class T> T plus( T, T ) ;' // then 'add' is type 'int add( int x, int y )'. func = add; // OK - Parameters and return types are the same. int a = func (1, 2); // NOTE: if the wrapper 'func' does not refer to any function, // the exception 'std::bad_function_call' is thrown. std::function<bool (short, short)> func2 ; if (!func2) { // True because 'func2' has not yet been assigned a function. bool adjacent(long x, long y); func2 = &adjacent; // OK - Parameters and return types are convertible. struct Test { bool operator()(short x, short y); }; Test car; func = std::ref(car); // 'std::ref' is a template function that returns the wrapper // of member function 'operator()' of struct 'car'. } func = func2; // OK - Parameters and return types are convertible. The template class function was defined inside the header <functional>, without needing any change to the C++ language. Type traits for metaprogramming Metaprogramming consists of creating a program that creates or modifies another program (or itself). This can happen during compilation or during execution. The C++ Standards Committee has decided to introduce a library for metaprogramming during compiling via templates. Here is an example of a meta-program using the C++03 standard: a recursion of template instances for calculating integer exponents: template<int B, int N> struct Pow { // recursive call and recombination. enum{ value = B*Pow<B, N-1>::value }; }; template< int B > struct Pow<B, 0> { // ''N == 0'' condition of termination. enum{ value = 1 }; }; int quartic_of_three = Pow<3, 4>::value; Many algorithms can operate on different types of data; C++'s templates support generic programming and make code more compact and useful. Nevertheless, it is common for algorithms to need information on the data types being used. This information can be extracted during instantiation of a template class using type traits. Type traits can identify the category of an object and all the characteristics of a