forked from msinilo/rdestl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_traits.h
97 lines (82 loc) · 1.92 KB
/
type_traits.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef RDESTL_TYPETRAITS_H
#define RDESTL_TYPETRAITS_H
namespace rde
{
template<typename T> struct is_integral
{
enum { value = false };
};
template<typename T> struct is_floating_point
{
enum { value = false };
};
#define RDE_INTEGRAL(TYPE) template<> struct is_integral<TYPE> { enum { value = true }; }
RDE_INTEGRAL(char);
RDE_INTEGRAL(unsigned char);
RDE_INTEGRAL(bool);
RDE_INTEGRAL(short);
RDE_INTEGRAL(unsigned short);
RDE_INTEGRAL(int);
RDE_INTEGRAL(unsigned int);
RDE_INTEGRAL(long);
RDE_INTEGRAL(unsigned long);
RDE_INTEGRAL(wchar_t);
template<> struct is_floating_point<float> { enum { value = true }; };
template<> struct is_floating_point<double> { enum { value = true }; };
template<typename T> struct is_pointer
{
enum { value = false };
};
template<typename T> struct is_pointer<T*>
{
enum { value = true };
};
template<typename T> struct is_pod
{
enum { value = false };
};
template<typename T> struct is_fundamental
{
enum
{
value = is_integral<T>::value || is_floating_point<T>::value
};
};
template<typename T> struct has_trivial_constructor
{
enum
{
value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
};
};
template<typename T> struct has_trivial_copy
{
enum
{
value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
};
};
template<typename T> struct has_trivial_assign
{
enum
{
value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
};
};
template<typename T> struct has_trivial_destructor
{
enum
{
value = is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value
};
};
template<typename T> struct has_cheap_compare
{
enum
{
value = has_trivial_copy<T>::value && sizeof(T) <= 4
};
};
} // namespace rde
//-----------------------------------------------------------------------------
#endif // #ifndef RDESTL_TYPETRAITS_H