Template Metafunction Identity

The identity metafunction stores the type provided in value. The is_same metafunction uses partial template specialization to determine at compile time if two object types are the same.

 namespace framework {
 namespace meta
 {
    template <typename T> struct identity { typedef T value; };
    template <typename T0, typename T1> struct is_same { enum { value = false }; };
    template <typename T> struct is_same<T, T> { enum { value = true }; };

} // namespace meta } // namespace framework

Examples:

 identity<float>::value f = 3.14159f;
 true == is_same<identity<int>::value, int>::value;


TemplateMetaprogrammingTechniques CategoryCppTemplates


EditText of this page (last edited May 29, 2006) or FindPage with title or text search