Complete code in
http://download.csdn.net/detail/zhuyingqingfen/8457091
#ifndef Typetraits_h_#define typetraits_h_//is only declared and not defined, it can only be used to denote "I am not an interesting type". Class nulltype;//This is a legitimate type that can be inherited, and you can pass Emptytype objects. Class EMPTYTYPE{};//1. Constant integer mapping to type/* generates different types based on different values. Generally, int2type1 can be used if the following conditions are met. It is necessary to call one or several different function 2 according to a compile-time constant. It is necessary to implement "dispatch" (dispatch) at compile time (if else dispatch requires that each condition be compiled through, and Int2type does not produce a similar problem, because the compile time does not compile a template function that is not used, if a template The member function was never actually used, and C + + would not have it present. */template<int v>struct int2type{enum{value = v};};/ The only effect of/type2type is to eliminate the ambiguity (ambiguity) of overloaded functions. Class Template type2type// Converts each type to a unique, insipid type//invocation type2type<t> where T is a type//defines the type Origin Altype which maps back to T////////////////////////////////////////////////////////////////////////////////template <typename t>struct type2type{typedef T originaltype;};/ /type selection, judging by the first argument is the second parameter or the third parameter Template<bool flag,typename t,typename u>struct select{typedef T Result;}; Template<typenameT,typename u>struct select<false,t,u>{typedef U result;};/ /type traitstemplate <class t>class typetraints{private:template<class U>struct PointerTraints{enum{ result = False};typedef nulltype pointertype;}; Template<class u>struct Pointertraints<u*>{enum{result = true;}; typedef U PointerType;}; Template<class u>struct Ptomtraits{enum{result = false};}; Template<class u,class v>struct ptomtraits<u V::* >{enum{result = true};}; Public:enum{ispointer = Pointertraints<t>::result,ismemberpointer = Ptomtraits<t>::result};typedef TypeName Pointertraints<t>::P ointertype pointertype;}; #endif
Typetraints of C + + generics