编译期的类型测试
一、使用模板特化机制
如比较两个类型是否一致:
VC8及以后版本支持了type traits机制:
add_const Class // Makes const type from type. add_cv Class // Makes const/volatile type from type. add_pointer Class // Makes pointer to type from type. add_reference Class // Makes reference to type from type. add_volatile Class // Makes volatile type from type. aligned_storage Class // Makes suitably aligned type. alignment_of Class // Gets alignment of type. common_type Class conditional Class decay Class enable_if Class extent Class // Gets an array dimension. has_nothrow_assign Class // Tests whether the type does not throw on assign. has_nothrow_constructor Class // Tests whether the type does not throw on default construction. has_nothrow_copy Class // Tests whether the type does not throw on copy construction. has_nothrow_copy_constructor Class has_nothrow_default_constructor Class has_trivial_assign Class // Tests whether the type has trivial assign. has_trivial_constructor Class // Tests whether the type has trivial default constructor. has_trivial_copy Class // Tests whether the type has trivial copy constructor. has_trivial_copy_constructor Class has_trivial_default_constructor Class has_trivial_destructor Class // Tests whether the type has trivial destructor. has_virtual_destructor Class // Tests whether the type has virtual destructor. is_abstract Class // Tests whether the type is abstract class. is_arithmetic Class // Tests whether the type is arithmetic. is_array Class |