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 namespace SYS_TypeTraitsImpl
18 {
19 
20 // Primary templates for additional types that are considered,
21 // integral, floating-point, POD:
22 template <typename T> struct AddIntegralNoCV : std::integral_constant< bool, false > {};
23 template <typename T> struct AddFloatingPointNoCV : std::integral_constant< bool, false > {};
24 template <typename T> struct AddPodNoCV : std::integral_constant< bool, false > {};
25 
26 }
27 
28 /// @file
29 
30 /// SYS_IsIntegral is true if std::is_integral
31 /// but is also true for additional types,
32 /// which may be declared using SYS_DECLARE_IS_INTEGRAL
33 template< typename T >
34 struct SYS_IsIntegral : std::integral_constant< bool,
35  std::is_integral< T >::value ||
36  SYS_TypeTraitsImpl::AddIntegralNoCV< std::remove_cv_t< T > >::value
37 > {};
38 
39 template< typename T >
41 
42 /// SYS_IsFloatingPoint is true if std::is_floating_point,
43 /// but is also true for additional types,
44 /// which may be declared using SYS_DECLARE_IS_FLOATING_POINT
45 template< typename T >
46 struct SYS_IsFloatingPoint : std::integral_constant< bool,
47  std::is_floating_point< T >::value ||
48  SYS_TypeTraitsImpl::AddFloatingPointNoCV< std::remove_cv_t< T > >::value
49 > {};
50 
51 template< typename T >
53 
54 /// SYS_IsPod is true if std::is_pod,
55 /// but is also true for additional types,
56 /// which may be declared using SYS_DECLARE_IS_POD
57 template< typename T >
58 struct SYS_IsPod : std::integral_constant< bool,
59  std::is_pod< T >::value ||
60  SYS_TypeTraitsImpl::AddPodNoCV< std::remove_cv_t< T > >::value
61 > {};
62 
63 template< typename T >
65 
66 /// Check whether a given type is plain-old-data (POD)
67 template <typename T>
68 static constexpr SYS_FORCE_INLINE bool SYSisPOD()
69 {
70  return SYS_IsPod_v< T >;
71 }
72 
73 /// Check whether a type is arithmetic (integer or floating-point type),
74 /// which means SYS_IsIntegral or SYS_IsFloatingPoint
75 /// This struct should not be specialized; instead use
76 /// SYS_DECLARE_IS_INTEGRAL and SYS_DECLARE_IS_FLOATING_POINT
77 template <typename T>
78 struct SYS_IsArithmetic : std::integral_constant< bool,
79  ( SYS_IsIntegral< T >::value || SYS_IsFloatingPoint< T >::value )
80 > {};
81 
82 template< typename T >
84 
85 /// Check whether an arithmetic type is signed.
86 template <typename T>
87 struct SYS_IsSigned : public std::is_signed<T> {};
88 
89 template <typename T>
91 
92 /// Check whether two types are the same
93 /// @{
94 template <typename T1, typename T2>
95 struct SYS_IsSame : public std::is_same<T1, T2> {};
96 
97 template <typename T1, typename T2>
99 
100 template <typename T1, typename T2>
101 static constexpr SYS_FORCE_INLINE bool SYSisSame()
102 {
103  return SYS_IsSame_v< T1, T2 >;
104 }
105 
106 /// @}
107 
108 /// Check whether a given type is a pointer
109 /// @{
110 
111 template <typename T>
112 struct SYS_IsPointer : std::integral_constant< bool, false > {};
113 
114 template <typename U>
115 struct SYS_IsPointer< U* > : std::integral_constant< bool, true > {};
116 
117 template <typename T>
119 
120 /// @}
121 
122 /// Map a type to itself.
123 /// Useful for specifying the result of a type metafunction;
124 /// simply inherit from SYS_TypeIdentity<ResultType>
125 /// @{
126 
127 template< typename T >
128 struct SYS_TypeIdentity { using type = T; };
129 
130 template< typename T >
132 
133 /// @}
134 
135 /// Remove reference, if T is a reference type.
136 /// After that, remove the topmost cv-qualifiers.
137 /// @{
138 
139 template< typename T >
141  std::remove_cv_t< std::remove_reference_t< T > >
142 > {};
143 
144 template< typename T >
146 
147 /// @}
148 
149 /// Evaluates to true if
150 /// T is not a reference and
151 /// T has no const/volatile qualifiers.
152 /// Otherwise evaluates to false.
153 /// @{
154 
155 template< typename T >
156 struct SYS_HasNoCVRef : std::integral_constant< bool,
157  std::is_same< T, SYS_RemoveCVRef_t< T > >::value
158 > {};
159 
160 template< typename T >
162 
163 /// @}
164 
165 /// Choose whether to make a type const or not with a template bool.
166 /// This allows a set of types to be made const or not with a single
167 /// bool template, instead of having a separate template parameter for
168 /// each type.
169 /// @{
170 
171 template<typename T,bool MAKE_CONST>
173 
174 template<typename T>
175 struct SYS_ConstType< T, true > : SYS_TypeIdentity< const T > {};
176 
177 template<typename T,bool MAKE_CONST>
179 
180 /// @}
181 
182 /// Choose a type from two alternatives based on a bool.
183 /// It choses the first type if false, and the second type if true.
184 /// @{
185 
186 template<typename T0,typename T1,bool IST1>
188 
189 template<typename T0,typename T1>
190 struct SYS_SelectType< T0, T1, true > : SYS_TypeIdentity< T1 > {};
191 
192 template<typename T0,typename T1,bool IST1>
194 
195 /// @}
196 
197 /// Hides a function overload or template specialization based on a
198 /// compile-time boolean.
199 /// {@
200 template <bool B, typename T = void>
201 struct SYS_EnableIf : public std::enable_if<B, T> {};
202 
203 template <bool B, typename T = void>
204 struct SYS_DisableIf : public SYS_EnableIf<!B, T> {};
205 /// @}
206 
207 /// Return the number of elements of a static array
208 template <typename T, std::size_t N>
209 static SYS_FORCE_INLINE constexpr auto
210 SYSarraySize(const T (&)[N]) noexcept
211 {
212  return N; // same as std::extent<T>::value
213 }
214 
215 #endif // __SYS_TYPETRAITS_H_INCLUDED__
constexpr auto SYS_IsIntegral_v
constexpr auto SYS_IsPod_v
typename SYS_TypeIdentity< T >::type SYS_TypeIdentity_t
constexpr auto SYS_IsSame_v
std::integral_constant< bool, std::numeric_limits< T >::is_signed||std::is_same< T, int128_t >::value > is_signed
Definition: format.h:787
typename SYS_RemoveCVRef< T >::type SYS_RemoveCVRef_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
std::remove_cv_t< std::remove_reference_t< T > > type
typename SYS_SelectType< T0, T1, IST1 >::type SYS_SelectType_t
constexpr auto SYS_IsPointer_v
constexpr auto SYS_IsArithmetic_v
GA_API const UT_StringHolder N
constexpr auto SYS_IsSigned_v