]> git.tdb.fi Git - libs/core.git/blob - source/core/meta.h
Add move semantics to Variant
[libs/core.git] / source / core / meta.h
1 #ifndef MSP_CORE_META_H_
2 #define MSP_CORE_META_H_
3
4 #include <cstddef>
5 #include "attributes.h"
6
7 namespace Msp {
8
9 #pragma GCC diagnostic push
10 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
11 template<typename T>
12 struct DEPRECATED RemoveConst
13 { typedef T Type; };
14
15 template<typename T>
16 struct DEPRECATED RemoveConst<const T>
17 { typedef T Type; };
18
19
20 template<typename T>
21 struct DEPRECATED RemoveReference
22 { typedef T Type; };
23
24 template<typename T>
25 struct DEPRECATED RemoveReference<T &>
26 { typedef T Type; };
27
28
29 template<typename T>
30 struct DEPRECATED RemoveConstReference
31 { typedef typename RemoveConst<typename RemoveReference<T>::Type>::Type Type; };
32
33
34 template<bool c, typename R>
35 struct DEPRECATED EnableIf;
36
37 template<typename R>
38 struct DEPRECATED EnableIf<true, R>
39 { typedef R Yes; };
40
41 template<typename R>
42 struct DEPRECATED EnableIf<false, R>
43 { typedef R No; };
44 #pragma GCC diagnostic pop
45
46
47 /**
48 Common fragments used in SFINAE-based decider constructs.
49 */
50 struct Sfinae
51 {
52         struct Yes { char c[2]; };
53         struct No { char c; };
54
55         template<typename T>
56         static No f(...);
57
58         template<typename C, typename T>
59         struct Evaluate
60         {
61                 enum { value = (sizeof(C::template f<T>(0))==sizeof(Yes)) };
62         };
63 };
64
65
66 struct CheckEqualityComparable: Sfinae
67 {
68         static int &v;
69         template<typename T>
70         static Yes f(int (*)[sizeof(reinterpret_cast<const T &>(v)==reinterpret_cast<const T &>(v))]);
71         using Sfinae::f;
72 };
73
74 template<typename T>
75 struct IsEqualityComparable: Sfinae::Evaluate<CheckEqualityComparable, T> { };
76
77 } // namespace Msp
78
79 #endif