HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SYS_TypeTraits.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_TypeTraits.h (SYS Library, C++)
7  *
8  * COMMENTS: Wrapper for Boost.TypeTraits
9  */
10 
11 #ifndef __SYS_TYPETRAITS_H_INCLUDED__
12 #define __SYS_TYPETRAITS_H_INCLUDED__
13 
14 #include "SYS_API.h"
15 #include "SYS_Inline.h"
16 #include <type_traits>
17 
18 /// @file
19 
20 /// Check whether a given type is plain-old-data (POD)
21 template <typename T>
22 static constexpr SYS_FORCE_INLINE bool SYSisPOD()
23 {
24  return std::is_pod<T>::value;
25 }
26 
27 /// Check whether a type is arithmetic (integer or floating-point type).
28 template <typename T>
29 class SYS_IsArithmetic : public std::is_arithmetic<T>
30 {
31 };
32 
33 /// Check whether a type is an integral type.
34 template <typename T>
35 class SYS_IsIntegral : public std::is_integral<T>
36 {
37 };
38 
39 /// Check whether a type is a floating point type.
40 template <typename T>
41 class SYS_IsFloatingPoint : public std::is_floating_point<T>
42 {
43 };
44 
45 /// Check whether an arithmetic type is signed.
46 template <typename T>
47 class SYS_IsSigned : public std::is_signed<T>
48 {
49 };
50 
51 /// Check whether two types are the same
52 /// @{
53 template <typename T1, typename T2>
54 class SYS_IsSame : public std::is_same<T1, T2>
55 {
56 };
57 
58 template <typename T1, typename T2>
59 static constexpr SYS_FORCE_INLINE bool SYSisSame()
60 {
62 }
63 /// @}
64 
65 /// Check whether a given type is a pointer
66 /// @{
67 
68 template <typename T> class SYS_IsPointer
69 { public: static const bool value = false; };
70 
71 template <typename U> class SYS_IsPointer<U*>
72 { public: static const bool value = true; };
73 
74 template <typename T>
75 static constexpr SYS_FORCE_INLINE bool SYSisPointer()
76 {
78 }
79 
80 /// @}
81 
82 /// Choose whether to make a type const or not with a template bool.
83 /// This allows a set of types to be made const or not with a single
84 /// bool template, instead of having a separate template parameter for
85 /// each type.
86 /// @{
87 
88 template<typename T,bool CONST> class SYS_ConstType
89 { public: typedef T type; };
90 
91 template<typename T> class SYS_ConstType<T,true>
92 { public: typedef const T type; };
93 
94 /// @}
95 
96 /// Choose a type from two alternatives based on a bool.
97 /// It choses the first type if false, and the second type if true.
98 /// @{
99 
100 template<typename T0,typename T1,bool IST1> class SYS_SelectType
101 { public: typedef T0 type; };
102 
103 template<typename T0,typename T1> class SYS_SelectType<T0,T1,true>
104 { public: typedef T1 type; };
105 
106 /// @}
107 
108 /// Hides a function overload or template specialization based on a
109 /// compile-time boolean.
110 /// {@
111 template <bool B, class T = void>
112 class SYS_EnableIf : public std::enable_if<B, T>
113 {
114 };
115 
116 template <bool B, class T = void>
117 class SYS_DisableIf : public SYS_EnableIf<!B, T>
118 {
119 };
120 /// @}
121 
122 // For consistency, include this for all platforms even though we're only using
123 // stdlib.h for _countof()
124 #include <stdlib.h>
125 
126 
127 /// Return the number of elements of a static array
128 /// @{
129 
130 #ifdef _MSC_VER
131 
132 #define SYScountof(array) (_countof(array))
133 
134 #else
135 
136 template <typename T, size_t N>
137 char (*SYScountOfHelper(T(&array_arg)[N]))[N];
138 
139 #define SYScountof(array) sizeof(*SYScountOfHelper(array))
140 
141 #endif
142 
143 /// @}
144 
145 /// This function is for use with lambdas to force the compiler to
146 /// not even try compiling or inlining function calls when a compile-time
147 /// condition is false.
148 /// @{
149 template<bool CONDITION>
151 {
152  template<typename FUNCTOR>
153  static SYS_FORCE_INLINE void call(FUNCTOR functor)
154  {
155  // No call at all if CONDITION is false
156  }
157 };
158 
159 template<>
160 struct SYS_CallIf<true>
161 {
162  template<typename FUNCTOR>
163  static SYS_FORCE_INLINE void call(FUNCTOR functor)
164  {
165  functor();
166  }
167 };
168 /// @}
169 
170 #endif // __SYS_TYPETRAITS_H_INCLUDED__
static SYS_FORCE_INLINE void call(FUNCTOR functor)
static SYS_FORCE_INLINE void call(FUNCTOR functor)
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Check whether a type is arithmetic (integer or floating-point type).
GLsizei const GLfloat * value
Definition: glcorearb.h:823
Check whether an arithmetic type is signed.
char(* SYScountOfHelper(T(&array_arg)[N]))[N]
Check whether a type is an integral type.
GA_API const UT_StringHolder N
Check whether a type is a floating point type.