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