template struct integral_constant { typedef T value_type; static const value_type value = v; typedef integral_constant type; }; template const typename integral_constant::value_type integral_constant:: value; typedef integral_constant true_type; typedef integral_constant false_type; template struct remove_const { typedef T type; }; template struct remove_const { typedef T type; }; template struct remove_volatile { typedef T type; }; template struct remove_volatile { typedef T type; }; template struct remove_cv: remove_const::type> { }; template struct is_same: false_type { }; template struct is_same: true_type { }; // is T a standard signed/unsigned integer type? template struct __is_std_signed: false_type { }; template struct __is_std_unsigned: false_type { }; // __is_std_signed specializations for each standard signed // integer type (T must not be cv-qualified) template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; // __is_std_unsigned specializations for each standard unsigned // integer type (T must not be cv-qualified) template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; template <> struct __is_std_signed: true_type { }; // __is_ext_signed and __is_ext_unsigned traits for implementation // defined extended signed and extended unsigned integer types template struct __is_ext_signed: false_type { }; template struct __is_ext_unsigned: false_type { }; template struct is_signed: integral_constant::type>::value || __is_ext_signed::type>::value> { }; template struct is_unsigned: integral_constant::type>::value || __is_ext_unsigned::type>::value> { }; template struct is_integral: integral_constant< bool, is_signed::value || is_unsigned::value || is_same::type, bool>::value || is_same::type, char>::value || is_same::type, wchar_t>::value> { }; #include template void test () { // verify that is_integral is publicly (directly or otherwise) // derived from integral_constant and that the base // has a static const data member of type bool named value with // the expected value (and if the same member exists in the // derived class it has the same value as well) #define TEST(T) \ do { \ const is_integral trait = is_integral(); \ typedef integral_constant Base; \ const Base &base = trait; \ const bool &base_result = Base::value; \ const bool &derived_result = is_integral::value; \ assert (Expect == base_result); \ assert (base_result == derived_result); \ } while (0) TEST (T); TEST (const T); TEST (volatile T); TEST (const volatile T); } typedef int Array []; struct Incomplete; enum Enumeration { }; typedef void Function (); typedef void (*FunctionPointer)(); typedef int Incomplete::*MemberPointer; typedef void (Incomplete::*MemberFunctionPointer)(); int main () { // exercise signed intergral types test(); test(); test(); test(); test(); // exercise unsigned intergral types test(); test(); test(); test(); test(); // exercise bool, char, and wchar_t test(); test(); test(); // references to integral types are not themselves integral types test(); test(); test(); test(); test(); test(); test(); test(); // exercise floating point types test(); test(); test(); // exercise other types test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); }