添加TypeTraits机制
This commit is contained in:
242
TinySTL/TypeTraits.h
Normal file
242
TinySTL/TypeTraits.h
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
#ifndef _TYPE_TRAITS_H_
|
||||||
|
#define _TYPE_TRAITS_H_
|
||||||
|
|
||||||
|
namespace TinySTL{
|
||||||
|
namespace zstd
|
||||||
|
{
|
||||||
|
struct _true_type { };
|
||||||
|
struct _false_type { };
|
||||||
|
|
||||||
|
/*
|
||||||
|
** <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>T<EFBFBD><54><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
struct _type_traits
|
||||||
|
{
|
||||||
|
typedef _false_type has_trivial_default_constructor;
|
||||||
|
typedef _false_type has_trivial_copy_constructor;
|
||||||
|
typedef _false_type has_trivial_assignment_operator;
|
||||||
|
typedef _false_type has_trivial_destructor;
|
||||||
|
typedef _false_type is_POD_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct _type_traits<bool>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<char>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<unsigned char>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<signed char>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<wchar_t>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<short>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<unsigned short>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<int>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<unsigned int>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<long>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<unsigned long>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<long long>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<unsigned long long>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<float>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<double>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<long double>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct _type_traits<T*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<class T>
|
||||||
|
struct _type_traits<const T*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<char*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<unsigned char*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<signed char*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<const char*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<const unsigned char*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
struct _type_traits<const signed char*>
|
||||||
|
{
|
||||||
|
typedef _true_type has_trivial_default_constructor;
|
||||||
|
typedef _true_type has_trivial_copy_constructor;
|
||||||
|
typedef _true_type has_trivial_assignment_operator;
|
||||||
|
typedef _true_type has_trivial_destructor;
|
||||||
|
typedef _true_type is_POD_type;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user