You.i Engine
YiTypeTraits.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_TYPE_TRAITS_H_
3 #define _YI_TYPE_TRAITS_H_
4 
5 #include <cstddef>
6 
12 #if defined(DOXY)
13 
28 template<class YI_TYPE>
30 {
34  typedef YI_TYPE type;
35 };
36 #else
37 template<class YI_TYPE>
39 {
40  typedef YI_TYPE type;
41 };
42 template<class YI_TYPE>
43 struct YI_REMOVE_REFERENCE<YI_TYPE &>
44 {
45  typedef YI_TYPE type;
46 };
47 #endif
48 
49 #if defined(DOXY)
50 
63 template<class YI_TYPE>
65 {
69  typedef YI_TYPE type;
70 };
71 #else
72 template<class YI_TYPE>
73 struct YI_REMOVE_CONST
74 {
75  typedef YI_TYPE type;
76 };
77 template<class YI_TYPE>
78 struct YI_REMOVE_CONST<const YI_TYPE>
79 {
80  typedef YI_TYPE type;
81 };
82 #endif
83 
84 #if defined(DOXY)
85 
98 template<class YI_TYPE>
100 {
104  typedef YI_TYPE type;
105 };
106 #else
107 template<class YI_TYPE>
108 struct YI_REMOVE_VOLATILE
109 {
110  typedef YI_TYPE type;
111 };
112 template<class YI_TYPE>
113 struct YI_REMOVE_VOLATILE<volatile YI_TYPE>
114 {
115  typedef YI_TYPE type;
116 };
117 #endif
118 
119 #if defined(DOXY)
120 
133 template<class YI_TYPE>
135 {
139  typedef YI_TYPE type;
140 };
141 #else
142 template<class YI_TYPE>
144 {
146 };
147 #endif
148 
149 #if defined(DOXY)
150 
170 template<class YI_TYPE>
172 {
176  typedef YI_TYPE type;
177 };
178 #else
179 template<class YI_TYPE>
180 struct YI_REMOVE_POINTER
181 {
182  typedef YI_TYPE type;
183 };
184 template<class YI_TYPE>
185 struct YI_REMOVE_POINTER<YI_TYPE *>
186 {
187  typedef YI_TYPE type;
188 };
189 template<class YI_TYPE>
190 struct YI_REMOVE_POINTER<YI_TYPE *const>
191 {
192  typedef YI_TYPE type;
193 };
194 template<class YI_TYPE>
195 struct YI_REMOVE_POINTER<YI_TYPE *volatile>
196 {
197  typedef YI_TYPE type;
198 };
199 template<class YI_TYPE>
200 struct YI_REMOVE_POINTER<YI_TYPE *const volatile>
201 {
202  typedef YI_TYPE type;
203 };
204 #endif
205 
206 #if defined(DOXY)
207 
222 template<class FIRST, class SECOND>
224 {
228  static const bool value;
229 };
230 #else
231 template<class FIRST, class SECOND>
232 struct YiIsSameType
233 {
234  static const bool value = false;
235 };
236 template<class FIRST>
237 struct YiIsSameType<FIRST, FIRST>
238 {
239  static const bool value = true;
240 };
241 #endif
242 
251 template<typename Type, Type templateValue>
253 {
254  typedef Type value_type;
256 
258  static const Type value = templateValue;
259 
263  operator value_type() const
264  {
265  return value;
266  }
267 
274  value_type operator()() const
275  {
276  return value;
277  }
278 };
279 
287 
295 
296 #if defined(DOXY)
297 
314 template<typename Type>
315 struct YiIsVoid
316 {
320  static const bool value;
321 };
322 #else
323 template<typename Type>
324 struct YiIsVoid : YiFalseType
325 {
326 };
327 
328 template<>
329 struct YiIsVoid<void> : YiTrueType
330 {
331 };
332 template<>
333 struct YiIsVoid<const void> : YiTrueType
334 {
335 };
336 template<>
337 struct YiIsVoid<volatile void> : YiTrueType
338 {
339 };
340 template<>
341 struct YiIsVoid<const volatile void> : YiTrueType
342 {
343 };
344 #endif
345 
346 #if defined(DOXY)
347 
355 template<typename Type>
357 {
358 };
359 #else
360 # undef YI_DEFINE_IS_INTEGRAL
361 # undef YI_DEFINE_BASIC_TRUETYPE_IS_INTEGRAL
362 
363 template<typename Type>
364 struct YiIsIntegral : YiFalseType
365 {
366 };
367 
368 # define YI_DEFINE_IS_INTEGRAL(Type) \
369  template<> \
370  struct YiIsIntegral<Type> : YiTrueType \
371  { \
372  }; \
373  template<> \
374  struct YiIsIntegral<const Type> : YiTrueType \
375  { \
376  }; \
377  template<> \
378  struct YiIsIntegral<volatile Type> : YiTrueType \
379  { \
380  }; \
381  template<> \
382  struct YiIsIntegral<const volatile Type> : YiTrueType \
383  { \
384  };
385 
386 # define YI_DEFINE_SIGNED_UNSIGNED_TRUETYPE_IS_INTEGRAL(Type) \
387  YI_DEFINE_IS_INTEGRAL(signed Type) \
388  YI_DEFINE_IS_INTEGRAL(unsigned Type)
389 
390 YI_DEFINE_IS_INTEGRAL(bool)
391 YI_DEFINE_IS_INTEGRAL(wchar_t)
392 YI_DEFINE_SIGNED_UNSIGNED_TRUETYPE_IS_INTEGRAL(char)
393 YI_DEFINE_SIGNED_UNSIGNED_TRUETYPE_IS_INTEGRAL(short)
394 YI_DEFINE_SIGNED_UNSIGNED_TRUETYPE_IS_INTEGRAL(int)
395 YI_DEFINE_SIGNED_UNSIGNED_TRUETYPE_IS_INTEGRAL(long)
396 YI_DEFINE_SIGNED_UNSIGNED_TRUETYPE_IS_INTEGRAL(long long)
397 
398 //Disallowing users from inventing seemingly valid integral types that aren't standard
399 # undef YI_DEFINE_IS_INTEGRAL
400 # undef YI_DEFINE_BASIC_TRUETYPE_IS_INTEGRAL
401 #endif
402 
403 #if defined(DOXY)
404 
412 template<typename Type>
414 {
415 };
416 #else
417 # undef YI_DEFINE_IS_FLOATING_POINT
418 
419 template<typename Type>
421 {
422 };
423 
424 # define YI_DEFINE_IS_FLOATING_POINT(Type) \
425  template<> \
426  struct YiIsFloatingPoint<Type> : YiTrueType \
427  { \
428  }; \
429  template<> \
430  struct YiIsFloatingPoint<const Type> : YiTrueType \
431  { \
432  }; \
433  template<> \
434  struct YiIsFloatingPoint<volatile Type> : YiTrueType \
435  { \
436  }; \
437  template<> \
438  struct YiIsFloatingPoint<const volatile Type> : YiTrueType \
439  { \
440  };
441 
442 YI_DEFINE_IS_FLOATING_POINT(float)
443 YI_DEFINE_IS_FLOATING_POINT(double)
444 YI_DEFINE_IS_FLOATING_POINT(long double)
445 
446 //Disallowing users from inventing seemingly valid floating-point types that aren't standard
447 # undef YI_DEFINE_IS_FLOATING_POINT
448 #endif
449 
450 #if defined(DOXY)
451 
472 template<typename BASE, typename DERIVED>
474 {
475 public:
479  static const bool value;
480 };
481 #else
482 template<typename BASE, typename DERIVED>
483 class YiIsBaseOf
484 {
485  typedef typename YI_REMOVE_CONST_VOLATILE<BASE>::type BASE_NOCV;
486  typedef typename YI_REMOVE_CONST_VOLATILE<DERIVED>::type DERIVED_NOCV;
487 
488  template<typename T>
489  static char Check(DERIVED_NOCV *, T);
490 
491  static int Check(BASE_NOCV *, int);
492 
493 public:
494  struct YiIsBaseOfTester
495  {
496  operator BASE_NOCV *() const;
497  operator DERIVED_NOCV *();
498  };
499 
501 };
502 #endif
503 
504 #if defined(DOXY)
505 
518 template<typename STREAM, typename TYPE>
520 {
524  static const bool value;
525 };
526 #else
527 namespace youi_private
528 {
529 struct AnyType
530 {
531  template<class T>
532  AnyType(const T &);
533 };
534 
535 template<class T>
536 char Check(T const &);
537 int Check(int);
538 
539 int operator<<(const AnyType &, const AnyType &);
540 
541 template<typename S, typename T>
542 struct HasOutputStreamOperator
543 {
544  static S &stream;
545  static T &x;
546  static const bool value = (sizeof(Check(stream << x)) == sizeof(char));
547 };
548 
549 template<typename S>
550 struct HasOutputStreamOperator<S, std::nullptr_t>
551 {
552  static const bool value = false;
553 };
554 } // namespace youi_private
555 template<typename STREAM, typename TYPE>
557 {
558  static const bool value = youi_private::HasOutputStreamOperator<STREAM, TYPE>::value;
559 };
560 #endif
561 
562 #if defined(DOXY)
563 
577 template<bool CONDITION, class TYPE = void>
578 struct YiEnableIf;
579 #else
580 template<bool CONDITION, class TYPE = void>
581 struct YiEnableIf
582 {
583 };
584 template<class TYPE>
585 struct YiEnableIf<true, TYPE>
586 {
587  typedef TYPE type;
588 };
589 #endif
590 
591 #if defined(DOXY)
592 
601 template<int... S>
603 {
604  typedef YiIndexSequence<S...> type;
605 };
606 
616 template<int...>
618 {
619 };
620 #else
621 template<int...>
622 struct YiIndexSequence
623 {
624 };
625 
626 template<int N, int... S>
627 struct YiMakeIndexSequence : YiMakeIndexSequence<N - 1, N - 1, S...>
628 {
629 };
630 
631 template<int... S>
632 struct YiMakeIndexSequence<0, S...>
633 {
634  typedef YiIndexSequence<S...> type;
635 };
636 #endif
637 
650 template<typename... T>
652 {
653  static const bool value = false;
654 };
655 
656 #if defined(DOXY)
657 
668 template<typename F>
670 {
671  static const size_t value;
672 };
673 #else
674 template<typename F>
675 struct YiFunctionArity;
676 
677 template<typename R, typename C, typename... Args>
678 struct YiFunctionArity<R (C::*)(Args...)>
679 {
680  static const size_t value = sizeof...(Args);
681 };
682 
683 template<typename R, typename C, typename... Args>
684 struct YiFunctionArity<R (C::*)(Args...) const>
685 {
686  static const size_t value = sizeof...(Args);
687 };
688 
689 template<typename R, typename... Args>
690 struct YiFunctionArity<R (*)(Args...)>
691 {
692  static const size_t value = sizeof...(Args);
693 };
694 
695 template<typename F>
696 struct YiFunctionArity : YiFunctionArity<decltype(&F::operator())>
697 {
698 };
699 #endif
700 
703 #endif // _YI_TYPE_TRAITS_H_
Definition: YiTypeTraits.h:473
Definition: YiTypeTraits.h:651
Definition: YiTypeTraits.h:519
YI_TYPE type
Definition: YiTypeTraits.h:176
Definition: YiTypeTraits.h:171
Definition: YiTypeTraits.h:64
Definition: YiTypeTraits.h:134
Definition: YiTypeTraits.h:315
YI_TYPE type
Definition: YiTypeTraits.h:139
static const bool value
Definition: YiTypeTraits.h:320
Definition: YiTypeTraits.h:602
YiIndexSequence< S... > type
Definition: YiTypeTraits.h:604
YiIntegralConstant< bool, true > YiTrueType
Definition: YiTypeTraits.h:286
Definition: YiTypeTraits.h:223
YI_TYPE type
Definition: YiTypeTraits.h:34
value_type operator()() const
Definition: YiTypeTraits.h:274
static const bool value
Definition: YiTypeTraits.h:479
static const bool value
Definition: YiTypeTraits.h:228
std::ostream & operator<<(std::ostream &stream, const CYIUrl &val)
Definition: YiTypeTraits.h:578
YiIntegralConstant< bool, false > YiFalseType
Definition: YiTypeTraits.h:294
Definition: YiTypeTraits.h:617
YI_TYPE type
Definition: YiTypeTraits.h:69
Type value_type
Definition: YiTypeTraits.h:254
Definition: YiTypeTraits.h:413
Definition: YiTypeTraits.h:99
Definition: YiTypeTraits.h:29
Definition: YiKeyEventUtilities.h:7
static const bool value
Definition: YiTypeTraits.h:524
Definition: YiTypeTraits.h:356
Definition: YiTypeTraits.h:252
static const size_t value
Definition: YiTypeTraits.h:671
YI_TYPE type
Definition: YiTypeTraits.h:104
YiIntegralConstant< Type, templateValue > type
Definition: YiTypeTraits.h:255
Definition: YiTypeTraits.h:669