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_TypeDecorate.h"
15 #include "SYS_Inline.h"
16 #include <type_traits>
17 
18 /// @file
19 
20 // In C++17, this could be std::bool_constant
21 template< bool v >
22 struct SYS_BoolConstant : std::integral_constant< bool, v > {};
23 
26 
27 /// Alternative for C++17's std::void that can be used in C++14:
28 template< typename ... >
29 using SYS_Void_t = void;
30 
31 /// SYS_IsIntegral is true if std::is_integral
32 /// but is also true for additional types,
33 /// which may be declared using SYS_DECLARE_IS_INTEGRAL
34 template< typename T >
36  std::is_integral< T >::value ||
37  AddIntegralNoCV< std::remove_cv_t< T > >::value
38 > {};
39 
40 template< typename T >
42 
43 /// SYS_IsFloatingPoint is true if std::is_floating_point,
44 /// but is also true for additional types,
45 /// which may be declared using SYS_DECLARE_IS_FLOATING_POINT
46 template< typename T >
48  std::is_floating_point< T >::value ||
49  AddFloatingPointNoCV< std::remove_cv_t< T > >::value
50 > {};
51 
52 template< typename T >
54 
55 /// SYS_IsPod is true if std::is_pod,
56 /// but is also true for additional types,
57 /// which may be declared using SYS_DECLARE_IS_POD
58 template< typename T >
60  std::is_pod< T >::value ||
61  AddPodNoCV< std::remove_cv_t< T > >::value
62 > {};
63 
64 template< typename T >
66 
67 /// Check whether a given type is plain-old-data (POD)
68 template <typename T>
69 static constexpr SYS_FORCE_INLINE bool SYSisPOD()
70 {
71  return SYS_IsPod_v< T >;
72 }
73 
74 /// If SYS_IsTriviallyRelocatable is true, then it should be safe
75 /// to bitwise copy an object of type T to a different memory location.
76 /// This can be declared using the macro SYS_DECLARE_IS_TR
77 template< typename T >
79  SafeTrivialRelocationNoCV< std::remove_cv_t< T > >::value
80 > {};
81 
82 template< typename T >
84 
85 /// Check whether a type is arithmetic (integer or floating-point type),
86 /// which means SYS_IsIntegral or SYS_IsFloatingPoint
87 /// This struct should not be specialized; instead use
88 /// SYS_DECLARE_IS_INTEGRAL and SYS_DECLARE_IS_FLOATING_POINT
89 template <typename T>
91  ( SYS_IsIntegral< T >::value || SYS_IsFloatingPoint< T >::value )
92 > {};
93 
94 template< typename T >
96 
97 /// Check whether an arithmetic type is signed.
98 template <typename T>
99 struct SYS_IsSigned : public std::is_signed<T> {};
100 
101 template <typename T>
103 
104 /// Check whether two types are the same
105 /// @{
106 
107 // Primary: assume not the same by default
108 template< typename T, typename U >
110 
111 // Partial specialization for two the same types
112 template< typename T >
113 struct SYS_IsSame< T, T > : SYS_TrueType {};
114 
115 template< typename T, typename U >
117 
118 template <typename T1, typename T2>
119 static constexpr SYS_FORCE_INLINE bool SYSisSame()
120 {
121  return SYS_IsSame_v< T1, T2 >;
122 }
123 
124 /// @}
125 
126 /// Check whether a given type is a pointer
127 /// @{
128 
129 template <typename T>
130 struct SYS_IsPointer : SYS_BoolConstant< false > {};
131 
132 template <typename U>
134 
135 template <typename T>
137 
138 /// @}
139 
140 /// Map a type to itself.
141 /// Useful for specifying the result of a type metafunction;
142 /// simply inherit from SYS_TypeIdentity<ResultType>
143 /// @{
144 
145 template< typename T >
146 struct SYS_TypeIdentity { using type = T; };
147 
148 template< typename T >
150 
151 /// @}
152 
153 /// Remove reference, if T is a reference type.
154 /// After that, remove the topmost cv-qualifiers.
155 /// @{
156 
157 template< typename T >
159  SYS_RemoveCV_t< std::remove_reference_t< T > >
160 > {};
161 
162 template< typename T >
164 
165 /// @}
166 
167 /// Evaluates to true if
168 /// T is not a reference and
169 /// T has no const/volatile qualifiers.
170 /// Otherwise evaluates to false.
171 /// @{
172 
173 template< typename T >
175  std::is_same< T, SYS_RemoveCVRef_t< T > >::value
176 > {};
177 
178 template< typename T >
180 
181 /// @}
182 
183 /// Choose whether to make a type const or not with a template bool.
184 /// This allows a set of types to be made const or not with a single
185 /// bool template, instead of having a separate template parameter for
186 /// each type.
187 /// @{
188 
189 template<typename T,bool MAKE_CONST>
191 
192 template<typename T>
193 struct SYS_ConstType< T, true > : SYS_TypeIdentity< const T > {};
194 
195 template<typename T,bool MAKE_CONST>
197 
198 /// @}
199 
200 /// Choose a type from two alternatives based on a bool.
201 /// It choses the first type if false, and the second type if true.
202 /// @{
203 
204 template<typename T0,typename T1,bool IST1>
206 
207 template<typename T0,typename T1>
208 struct SYS_SelectType< T0, T1, true > : SYS_TypeIdentity< T1 > {};
209 
210 template<typename T0,typename T1,bool IST1>
212 
213 /// @}
214 
215 /// Hides a function overload or template specialization based on a
216 /// compile-time boolean.
217 /// {@
218 template <bool B, typename T = void>
219 struct SYS_EnableIf : public std::enable_if<B, T> {};
220 
221 template <bool B, typename T = void>
223 
224 template <bool B, typename T = void>
225 struct SYS_DisableIf : public SYS_EnableIf<!B, T> {};
226 
227 template <bool B, typename T = void>
229 /// @}
230 
231 /// Return the number of elements of a static array
232 template <typename T, std::size_t N>
233 static SYS_FORCE_INLINE constexpr auto
234 SYSarraySize(const T (&)[N]) noexcept
235 {
236  return N; // same as std::extent<T>::value
237 }
238 
239 ///
240 /// Determine whether a type is designated as a fixed-array-like type;
241 /// its must have a compile-time size and support square-bracket indexing.
242 ///
243 /// Examples of such types include a built-in bounded array and std::array< T, N >.
244 ///
245 /// Specialize SYS_IsFixedArrayNoCVRef to add support to additional types.
246 /// {@
247 
248 template< typename T >
249 struct SYS_IsFixedArray : SYS_IsFixedArrayNoCVRef< SYS_RemoveCVRef_t< T > > {};
250 
251 template< typename T >
253 
254 /// @}
255 
256 /// Extracts the element type of a fixed-array-like type.
257 /// Specialize SYS_FixedArrayElementNoCVRef to add support to additional types.
258 /// {@
259 
260 template< typename T >
261 struct SYS_FixedArrayElement : SYS_FixedArrayElementNoCVRef< SYS_RemoveCVRef_t< T > > {};
262 
263 template< typename T >
265 
266 /// @}
267 
268 ///
269 /// Obtain the size of a fixed-array-like type.
270 /// Specialize SYS_FixedArraySizeNoCVRef to add support to additional types.
271 /// {@
272 
273 template< typename T >
274 struct SYS_FixedArraySize : SYS_FixedArraySizeNoCVRef< SYS_RemoveCVRef_t< T > > {};
275 
276 template< typename T >
278 
279 /// @}
280 
281 ///
282 /// Determine whether T is a fixed-array-like type of element type E and size N.
283 /// This ignores const and volatile qualifiers of the element type.
284 /// {@
285 ///
286 
287 template< typename T, typename E, std::size_t N >
289  SYS_IsFixedArray_v< T > &&
290  ( std::is_same< SYS_FixedArrayElement_t< std::remove_cv_t< T > >, E >::value ) &&
291  ( SYS_FixedArraySize_v< T > == N )
292  > {};
293 
294 template< typename T, typename E, std::size_t N >
296 
297 /// @}
298 
299 // Specialize FixedArray traits for built-in bounded arrays
300 
301 template< typename T, std::size_t N >
302 struct SYS_IsFixedArrayNoCVRef< T[N] > : SYS_BoolConstant< true > {};
303 
304 template< typename T, std::size_t N >
306 
307 template< typename T, std::size_t N >
308 struct SYS_FixedArraySizeNoCVRef< T[N] > : std::integral_constant< std::size_t, N > {};
309 
310 #endif // __SYS_TYPETRAITS_H_INCLUDED__
constexpr auto SYS_IsIntegral_v
constexpr auto SYS_IsPod_v
void
Definition: png.h:1083
typename SYS_TypeIdentity< T >::type SYS_TypeIdentity_t
void SYS_Void_t
Alternative for C++17's std::void that can be used in C++14:
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
constexpr auto SYS_IsSame_v
typename SYS_DisableIf< B, T >::type SYS_DisableIf_t
typename SYS_RemoveCVRef< T >::type SYS_RemoveCVRef_t
std::integral_constant< bool, std::numeric_limits< T >::is_signed||std::is_same< T, int128_t >::value > is_signed
Definition: format.h:821
constexpr bool SYS_IsFixedArray_v
typename SYS_EnableIf< B, T >::type SYS_EnableIf_t
constexpr auto SYS_IsFloatingPoint_v
typename SYS_ConstType< T, MAKE_CONST >::type SYS_ConstType_t
constexpr auto SYS_HasNoCVRef_v
Check whether an arithmetic type is signed.
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_RemoveCV_t< std::remove_reference_t< T > > type
typename SYS_SelectType< T0, T1, IST1 >::type SYS_SelectType_t
constexpr auto SYS_IsPointer_v
constexpr bool SYS_IsFixedArrayOf_v
constexpr auto SYS_IsTriviallyRelocatable_v
constexpr auto SYS_IsArithmetic_v
GA_API const UT_StringHolder N
constexpr std::size_t SYS_FixedArraySize_v
constexpr auto SYS_IsSigned_v