wibble  1.1
sfinae.h
Go to the documentation of this file.
1 // -*- C++ -*- Substitution Failure Is Not An Error
2 
3 #ifndef WIBBLE_SFINAE_H
4 #define WIBBLE_SFINAE_H
5 
6 namespace wibble {
7 
8 struct Unit {
9  bool operator<( Unit ) const { return false; }
10  bool operator==( Unit ) const { return true; }
11 };
12 
13 struct TTrue {
14  static const bool value = true;
15 };
16 
17 struct TFalse {
18  static const bool value = false;
19 };
20 
21 // small SFINAE utilities, we probably prefer to avoid full weight of boost here
22 template< typename A, typename B >
23 struct TSame {
24  static const bool value = false;
25 };
26 
27 template< typename A >
28 struct TSame< A, A > {
29  static const bool value = true;
30 };
31 
32 template< bool, bool, bool = true, bool = true, bool = true >
33 struct TAndC {
34  static const bool value = false;
35 };
36 
37 template<>
38 struct TAndC< true, true, true, true, true > {
39  static const bool value = true;
40 };
41 
42 template< typename A, typename B,
43  typename C = TTrue, typename D = TTrue, typename E = TTrue >
44 struct TAnd : TAndC< A::value, B::value, C::value, D::value, E::value > {};
45 
46 template< bool, bool, bool = false, bool = false, bool = false >
47 struct TOrC {
48  static const bool value = true;
49 };
50 
51 template<>
52 struct TOrC< false, false, false, false, false > {
53  static const bool value = false;
54 };
55 
56 template< typename A, typename B,
57  typename C = TFalse, typename D = TFalse, typename E = TFalse >
58 struct TOr : TOrC< A::value, B::value, C::value, D::value, E::value > {};
59 
60 /* template< typename T >
61 struct IsT {
62  static const bool value = true;
63  }; */
64 
65 template< bool a > struct TNotC {
66  static const bool value = !a;
67 };
68 
69 template< typename T > struct TNot : TNotC< T::value > {};
70 
71 template< bool a, bool b >
72 struct TImplyC : TNot< TAndC< a, TNotC< b >::value > > {};
73 
74 template< typename A, typename B >
75 struct TImply : TImplyC< A::value, B::value > {};
76 
77 template< bool, typename T = Unit >
78 struct EnableIfC {};
79 
80 template< typename Type >
81 struct EnableIfC< true, Type > { typedef Type T; };
82 
83 template< bool, typename T = Unit >
84 struct DisableIfC {};
85 
86 template< typename Type >
87 struct DisableIfC< false, Type > { typedef Type T; };
88 
89 template< typename X, typename T = Unit >
90 struct EnableIf : EnableIfC< X::value, T > {};
91 
92 template< typename X, typename T = Unit >
93 struct DisableIf : DisableIfC< X::value, T > {};
94 
95 template< typename A, typename B >
96 struct TPair {
97  typedef A First;
98  typedef B Second;
99 };
100 
101 struct Preferred {};
103 
104 
105 }
106 
107 #endif
Definition: amorph.h:17
Type T
Definition: sfinae.h:87
Definition: sfinae.h:84
Definition: sfinae.h:93
Type T
Definition: sfinae.h:81
Definition: sfinae.h:78
Definition: sfinae.h:90
Definition: sfinae.h:102
NotPreferred(Preferred)
Definition: sfinae.h:102
Definition: sfinae.h:101
Definition: sfinae.h:33
static const bool value
Definition: sfinae.h:34
Definition: sfinae.h:44
Definition: sfinae.h:17
static const bool value
Definition: sfinae.h:18
Definition: sfinae.h:72
Definition: sfinae.h:75
Definition: sfinae.h:65
static const bool value
Definition: sfinae.h:66
Definition: sfinae.h:69
Definition: sfinae.h:47
static const bool value
Definition: sfinae.h:48
Definition: sfinae.h:58
Definition: sfinae.h:96
A First
Definition: sfinae.h:97
B Second
Definition: sfinae.h:98
Definition: sfinae.h:23
static const bool value
Definition: sfinae.h:24
Definition: sfinae.h:13
static const bool value
Definition: sfinae.h:14
Definition: sfinae.h:8
bool operator==(Unit) const
Definition: sfinae.h:10
bool operator<(Unit) const
Definition: sfinae.h:9