/*---------------------------------------------------------------------------* Project: Horizon File: util_TypeTraits.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 12449 $ *---------------------------------------------------------------------------*/ #ifndef NN_UTIL_UTIL_TYPETRAITS_H_ #define NN_UTIL_UTIL_TYPETRAITS_H_ #ifdef __cplusplus #include #include // C++0x の の先取り。 // 必要になったものから順次実装してゆく。 // コメントアウトされているものは未実装。 // 一部はコンパイラサポートが必要だったり、C++0xでないと定義されないものもある。 // なお、このヘッダには、互換性を保つため、 // 以外の要素を加えないこと。 namespace nn { namespace util { // 宣言部 // 実装したものは、ここでコメントからはずすこと。 // ここに実装は書かないこと。 // [20.4.3] helper class: template struct integral_constant; typedef integral_constant true_type; typedef integral_constant false_type; // [20.4.4.1] primary type categories: template struct is_void; //template struct is_integral; //template struct is_floating_point; //template struct is_array; //template struct is_pointer; //template struct is_lvalue_reference; //template struct is_rvalue_reference; //template struct is_member_object_pointer; //template struct is_member_function_pointer; //template struct is_enum; //template struct is_union; //template struct is_class; //template struct is_function; // [20.4.4.2] composite type categories: //template struct is_reference; //template struct is_arithmetic; //template struct is_fundamental; //template struct is_object; //template struct is_scalar; //template struct is_compound; //template struct is_member_pointer; // [20.4.4.3] type properties: //template struct is_const; //template struct is_volatile; //template struct is_trivial; //template struct is_standard_layout; //template struct is_pod; //template struct is_empty; //template struct is_polymorphic; //template struct is_abstract; //template struct has_trivial_default_constructor; //template struct has_trivial_copy_constructor; //template struct has_trivial_assign; //template struct has_trivial_destructor; //template struct has_nothrow_default_constructor; //template struct has_nothrow_copy_constructor; //template struct has_nothrow_assign; //template struct has_virtual_destructor; //template struct is_signed; //template struct is_unsigned; template struct alignment_of; //template struct rank; //template struct extent; // [20.4.5] type relations: template struct is_same; template struct is_base_of; template struct is_convertible; // [20.4.6.1] const-volatile modifications: //template struct remove_const; //template struct remove_volatile; //template struct remove_cv; //template struct add_const; //template struct add_volatile; //template struct add_cv; // [20.4.6.2] reference modifications: //template struct remove_reference; //template struct add_lvalue_reference; //template struct add_rvalue_reference; // [20.4.6.3] sign modifications: //template struct make_signed; //template struct make_unsigned; // [20.4.6.4] array modifications: //template struct remove_extent; //template struct remove_all_extents; // [20.4.6.5] pointer modifications: //template struct remove_pointer; //template struct add_pointer; // [20.4.7] other transformations: template struct aligned_storage; //template struct aligned_union; //template struct decay; template struct enable_if; //template struct conditional; // ここから実装部 // template struct integral_constant; 実装 template struct integral_constant { typedef integral_constant type; typedef T value_type; static const value_type value = v; }; // template struct is_void; 実装 template struct is_void : public false_type {}; template <> struct is_void : public true_type {}; //template struct alignment_of; 実装 #ifdef NN_COMPILER_RVCT template struct alignment_of : public integral_constant {}; #else namespace detail { template class AlignmentHack { char c; T x; }; } template struct alignment_of : public integral_constant) - sizeof(T)> {}; #endif //template struct aligned_storage; 実装 namespace detail { template struct AlignmentType {}; template <> struct AlignmentType<1> { typedef u8 type; }; template <> struct AlignmentType<2> { typedef u16 type; }; template <> struct AlignmentType<4> { typedef u32 type; }; template <> struct AlignmentType<8> { typedef u64 type; }; } template struct aligned_storage { private: union UnionType { char c[Size]; typename detail::AlignmentType::type a; }; public: typedef UnionType type; }; // template struct enable_if; 実装 template struct enable_if {}; template struct enable_if { typedef T type; }; // template struct is_convertible; 実装 template struct is_convertible { private: typedef char T1; struct T2 { char dummy[2]; }; static T1 IsConvertibleTest(To); static T2 IsConvertibleTest(...); static From MakeFrom(); public: typedef bool value_type; static const bool value = sizeof(IsConvertibleTest(MakeFrom())) == sizeof(T1); }; // template struct is_same; 実装 template struct is_same : public false_type {}; template struct is_same : public true_type {}; // template struct is_base_of; 実装 template struct is_base_of : public integral_constant::value && !is_same::value> {}; }} #endif // __cplusplus #endif /* NN_UTIL_STATICASSERT_H_ */