Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
type_structs.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_TYPE_STRUCTS_H_
19 #define ION_BASE_TYPE_STRUCTS_H_
20 
29 
30 namespace ion {
31 namespace base {
32 
34 template <bool b> struct BoolType { static const bool value = b; };
35 template <bool b> const bool BoolType<b>::value;
36 
39 template<typename T, typename U> struct IsSameType : public BoolType<false> {};
40 template<typename T> struct IsSameType<T, T> : public BoolType<true> {};
41 
45 template <typename Base, typename Derived> struct IsBaseOf {
48  struct Helper {
49  operator Base*() const;
50  operator Derived*();
51  };
55  template <typename T> static char Test(Derived*, T);
56  static int Test(Base*, int);
57  static const bool value = sizeof(Test(Helper(), 0)) == 1;
58 };
59 template <typename Base, typename Derived>
61 
66 template <typename From, typename To>
67 struct IsConvertible : public BoolType<IsSameType<To, From>::value ||
68  IsBaseOf<To, From>::value> {};
69 
73 template<bool condition, typename A, typename B>
74 struct ConditionalType { typedef A Type; };
75 template<typename A, typename B>
76 struct ConditionalType<false, A, B> { typedef B Type; };
77 
83 template <typename T> struct HasTrivialDestructor {
84  static const bool value = __has_trivial_destructor(T);
85 };
86 template <typename T>
88 
89 } // namespace base
90 } // namespace ion
91 
92 #endif // ION_BASE_TYPE_STRUCTS_H_
IsBaseOf is similar to std::is_base_of.
Definition: type_structs.h:45
static char Test(Derived *, T)
Overloaded function that chooses the Derived version iff Derived is actually derived from Base...
Because the Derived type-cast operator is non-const, it is preferred over the Base operator when call...
Definition: type_structs.h:48
BoolType is a struct whose value member is either true or false.
Definition: type_structs.h:34
ConditionalType is similar to std::conditional.
Definition: type_structs.h:74
IsSameType is similar to std::is_same.
Definition: type_structs.h:39
static const bool value
Definition: type_structs.h:34
static const bool value
Definition: type_structs.h:57
IsConvertible is similar to std::is_convertible, except that it only looks at direct inheritance rela...
Definition: type_structs.h:67
HasTrivialDestructor is similar to std::has_trivial_destructor or std::is_trivially_destructible.
Definition: type_structs.h:83