31 #ifndef Pt_TypeTraits_h
32 #define Pt_TypeTraits_h
39 template <
typename T, T V>
40 struct IntegralConstant
42 static const T value = V;
44 typedef IntegralConstant<T, V> Type;
46 operator ValueType()
const
52 using BoolConstant = IntegralConstant<bool, V>;
54 typedef BoolConstant<false> FalseType;
55 typedef BoolConstant<true> TrueType;
58 template<
class T,
class U>
59 struct IsSame : FalseType
64 struct IsSame<T, T> : TrueType
68 template <
bool Condition,
typename TrueT,
typename FalseT>
75 template <
typename TrueT,
typename FalseT>
76 struct IfElse<false, TrueT, FalseT>
82 template <std::size_t Index,
typename T,
typename... Ts>
85 typedef typename NthType<Index - 1, Ts...>::type type;
89 template <
typename T,
typename... Ts>
90 struct NthType<0, T, Ts...>
100 typedef const T ConstValue;
101 typedef T& Reference;
102 typedef const T& ConstReference;
104 typedef const T* ConstPointer;
109 template <
typename T>
110 struct TypeTraits :
public TypeTraitsBase<T>
112 static const unsigned int isConst = 0;
120 template <
typename T>
121 struct TypeTraits<const T> :
public TypeTraitsBase<T>
123 static const unsigned int isConst = 1;
129 template <
typename T>
130 struct TypeTraits<volatile T> :
public TypeTraitsBase<T>
132 static const unsigned int isConst = 0;
138 template <
typename T>
139 struct TypeTraits<const volatile T> :
public TypeTraitsBase<T>
141 static const unsigned int isConst = 1;
148 template <
typename T>
149 struct TypeTraits<T&> :
public TypeTraitsBase<T>
151 static const unsigned int isConst = 0;
152 static const unsigned int isVolatile = 0;
153 static const unsigned int isPointer = 0;
154 static const unsigned int isReference = 1;
158 template <
typename T>
159 struct TypeTraits<const T&> :
public TypeTraitsBase<T>
161 static const unsigned int isConst = 1;
162 static const unsigned int isVolatile = 0;
163 static const unsigned int isPointer = 0;
164 static const unsigned int isReference = 1;
168 template <
typename T>
169 struct TypeTraits<volatile T&> :
public TypeTraitsBase<T>
171 static const unsigned int isConst = 0;
172 static const unsigned int isVolatile = 1;
173 static const unsigned int isPointer = 0;
174 static const unsigned int isReference = 1;
178 template <
typename T>
179 struct TypeTraits<const volatile T&> :
public TypeTraitsBase<T>
181 static const unsigned int isConst = 1;
182 static const unsigned int isVolatile = 1;
183 static const unsigned int isPointer = 0;
184 static const unsigned int isReference = 1;
188 template <
typename T>
189 struct TypeTraits<T*> :
public TypeTraitsBase<T>
191 static const unsigned int isConst = 0;
192 static const unsigned int isVolatile = 0;
193 static const unsigned int isPointer = 1;
194 static const unsigned int isReference = 0;
198 template <
typename T>
199 struct TypeTraits<const T*> :
public TypeTraitsBase<T>
201 static const unsigned int isConst = 1;
202 static const unsigned int isVolatile = 0;
203 static const unsigned int isPointer = 1;
204 static const unsigned int isReference = 0;
208 template <
typename T>
209 struct TypeTraits<volatile T*> :
public TypeTraitsBase<T>
211 static const unsigned int isConst = 0;
212 static const unsigned int isVolatile = 1;
213 static const unsigned int isPointer = 1;
214 static const unsigned int isReference = 0;
218 template <
typename T>
219 struct TypeTraits<const volatile T*> :
public TypeTraitsBase<T>
221 static const unsigned int isConst = 1;
222 static const unsigned int isVolatile = 1;
223 static const unsigned int isPointer = 1;
224 static const unsigned int isReference = 0;
228 template <
typename T, std::
size_t N>
229 struct TypeTraits<T[N]> :
public TypeTraitsBase<T*>
231 static const unsigned int isConst = 0;
238 template <
typename T, std::
size_t N>
239 struct TypeTraits<const T[N]> :
public TypeTraitsBase<const T*>
241 static const unsigned int isConst = 1;
248 template <
typename T, std::
size_t N>
249 struct TypeTraits<volatile T[N]> :
public TypeTraitsBase<volatile T*>
251 static const unsigned int isConst = 0;
258 template <
typename T, std::
size_t N>
259 struct TypeTraits<const volatile T[N]> :
public TypeTraitsBase<const volatile T*>
261 static const unsigned int isConst = 1;
268 template <
typename T>
269 struct TypeTraits<T[]> :
public TypeTraitsBase<T*>
271 static const unsigned int isConst = 0;
278 template <
typename T>
279 struct TypeTraits<const T[]> :
public TypeTraitsBase<const T*>
281 static const unsigned int isConst = 1;
288 template <
typename T>
289 struct TypeTraits<volatile T[]> :
public TypeTraitsBase<volatile T*>
291 static const unsigned int isConst = 0;
298 template <
typename T>
299 struct TypeTraits<const volatile T[]> :
public TypeTraitsBase<const volatile T*>
301 static const unsigned int isConst = 1;
308 template <
typename R,
typename... Args>
309 struct TypeTraits<R(*)(Args...)> :
public TypeTraitsBase<R(*)(Args...)>
311 static const unsigned int isConst = 0;
312 static const unsigned int isVolatile = 0;
313 static const unsigned int isPointer = 1;
314 static const unsigned int isReference = 0;
318 template <
typename R,
typename... Args>
319 struct TypeTraits<R(Args...)> :
public TypeTraitsBase<R(*)(Args...)>
321 static const unsigned int isConst = 0;
328 template <
typename R,
typename... Args>
329 struct TypeTraits<R(&)(Args...)> :
public TypeTraitsBase<R(*)(Args...)>
331 static const unsigned int isConst = 0;
332 static const unsigned int isVolatile = 0;
333 static const unsigned int isPointer = 0;
334 static const unsigned int isReference = 1;
339 struct TypeTraits<void>
342 typedef void ConstType;
348 static const unsigned int isConst = 0;
355 template <
typename Base,
typename Derived>
356 class IsCompatibleImpl
372 static YesType test(BaseType*);
373 static NoType test(...);
378 value =
sizeof(test(
static_cast<DerivedType*
>(0))) ==
sizeof(YesType)
383 template <
typename Base,
typename Derived>
385 :
public BoolConstant< IsCompatibleImpl<Base, Derived>::value >
389 template <
typename T>
394 struct IntTraits<signed char>
396 typedef unsigned char Unsigned;
397 typedef signed char Signed;
399 static const unsigned int isSigned = 1;
403 struct IntTraits<unsigned char>
405 typedef unsigned char Unsigned;
406 typedef signed char Signed;
408 static const unsigned int isSigned = 0;
412 struct IntTraits<short>
414 typedef unsigned short Unsigned;
415 typedef signed short Signed;
417 static const unsigned int isSigned = 1;
421 struct IntTraits<unsigned short>
423 typedef unsigned short Unsigned;
424 typedef signed short Signed;
426 static const unsigned int isSigned = 0;
430 struct IntTraits<int>
432 typedef unsigned int Unsigned;
433 typedef signed int Signed;
435 static const unsigned int isSigned = 1;
439 struct IntTraits<unsigned int>
441 typedef unsigned int Unsigned;
442 typedef signed int Signed;
444 static const unsigned int isSigned = 0;
448 struct IntTraits<long>
450 typedef unsigned long Unsigned;
451 typedef signed long Signed;
453 static const unsigned int isSigned = 1;
457 struct IntTraits<unsigned long>
459 typedef unsigned long Unsigned;
460 typedef signed long Signed;
462 static const unsigned int isSigned = 0;
466 struct IntTraits<long long>
468 typedef unsigned long long Unsigned;
469 typedef signed long long Signed;
471 static const unsigned int isSigned = 1;
475 struct IntTraits<unsigned long long>
477 typedef unsigned long long Unsigned;
478 typedef signed long long Signed;
480 static const unsigned int isSigned = 0;
485 #endif // Pt_TypeTraits_h