HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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: Type trait utilities
9  */
10 
11 #ifndef __SYS_TYPETRAITS_H_INCLUDED__
12 #define __SYS_TYPETRAITS_H_INCLUDED__
13 
14 #include "SYS_Inline.h"
15 #include <type_traits>
16 
17 /// @file
18 
19 /// Check whether a given type is plain-old-data (POD)
20 template <typename T>
21 static constexpr SYS_FORCE_INLINE bool SYSisPOD()
22 {
23  return std::is_pod<T>::value;
24 }
25 
26 /// Check whether a type is arithmetic (integer or floating-point type).
27 template <typename T>
28 class SYS_IsArithmetic : public std::is_arithmetic<T>
29 {
30 };
31 
32 /// Check whether a type is an integral type.
33 template <typename T>
34 class SYS_IsIntegral : public std::is_integral<T>
35 {
36 };
37 
38 /// Check whether a type is a floating point type.
39 template <typename T>
40 class SYS_IsFloatingPoint : public std::is_floating_point<T>
41 {
42 };
43 
44 /// Check whether an arithmetic type is signed.
45 template <typename T>
46 class SYS_IsSigned : public std::is_signed<T>
47 {
48 };
49 
50 /// Check whether two types are the same
51 /// @{
52 template <typename T1, typename T2>
53 class SYS_IsSame : public std::is_same<T1, T2>
54 {
55 };
56 
57 template <typename T1, typename T2>
58 static constexpr SYS_FORCE_INLINE bool SYSisSame()
59 {
61 }
62 /// @}
63 
64 /// Check whether a given type is a pointer
65 /// @{
66 
67 template <typename T> class SYS_IsPointer
68 { public: static const bool value = false; };
69 
70 template <typename U> class SYS_IsPointer<U*>
71 { public: static const bool value = true; };
72 
73 template <typename T>
74 static constexpr SYS_FORCE_INLINE bool SYSisPointer()
75 {
77 }
78 
79 /// @}
80 
81 /// Choose whether to make a type const or not with a template bool.
82 /// This allows a set of types to be made const or not with a single
83 /// bool template, instead of having a separate template parameter for
84 /// each type.
85 /// @{
86 
87 template<typename T,bool CONST> class SYS_ConstType
88 { public: typedef T type; };
89 
90 template<typename T> class SYS_ConstType<T,true>
91 { public: typedef const T type; };
92 
93 /// @}
94 
95 /// Choose a type from two alternatives based on a bool.
96 /// It choses the first type if false, and the second type if true.
97 /// @{
98 
99 template<typename T0,typename T1,bool IST1> class SYS_SelectType
100 { public: typedef T0 type; };
101 
102 template<typename T0,typename T1> class SYS_SelectType<T0,T1,true>
103 { public: typedef T1 type; };
104 
105 /// @}
106 
107 /// Hides a function overload or template specialization based on a
108 /// compile-time boolean.
109 /// {@
110 template <bool B, class T = void>
111 class SYS_EnableIf : public std::enable_if<B, T>
112 {
113 };
114 
115 template <bool B, class T = void>
116 class SYS_DisableIf : public SYS_EnableIf<!B, T>
117 {
118 };
119 /// @}
120 
121 // For consistency, include this for all platforms even though we're only using
122 // stdlib.h for _countof()
123 #include <stdlib.h>
124 
125 
126 /// Return the number of elements of a static array
127 /// @{
128 
129 #ifdef _MSC_VER
130 
131 #define SYScountof(array) (_countof(array))
132 
133 #else
134 
135 template <typename T, size_t N>
136 char (*SYScountOfHelper(T(&array_arg)[N]))[N];
137 
138 #define SYScountof(array) sizeof(*SYScountOfHelper(array))
139 
140 #endif
141 
142 /// @}
143 
144 #endif // __SYS_TYPETRAITS_H_INCLUDED__
#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.