00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef METALIC_BOOL_HH
00029 # define METALIC_BOOL_HH
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 namespace mlc
00046 {
00047
00048 struct false_type;
00049
00050 struct true_type {
00051 static void is_true() {}
00052 typedef false_type not_type;
00053 typedef void is_true_type;
00054 };
00055
00056 struct false_type {
00057 static void is_false() {}
00058 typedef true_type not_type;
00059 typedef void is_false_type;
00060 };
00061
00062
00063
00064
00065
00066
00067 template <bool Cond, class if_true_type, class if_false_type>
00068 struct if_ {
00069 typedef if_true_type ret;
00070 };
00071
00072 template<class if_true_type, class if_false_type>
00073 struct if_<false, if_true_type, if_false_type>
00074 {
00075 typedef if_false_type ret;
00076 typedef false_type ensure_type;
00077 };
00078
00079
00080
00081
00082
00083 struct invalid {};
00084
00085 template<unsigned Cond, class Ret, class Cases = invalid>
00086 struct case_ {};
00087
00088 template<unsigned Cond, class Cases, class Default = invalid>
00089 struct switch_;
00090
00091 template<unsigned Cond, unsigned Compare, class Ret, class Default>
00092 struct switch_<Cond, case_<Compare, Ret>, Default >
00093 {
00094 typedef typename if_< (Cond == Compare), Ret, Default >::ret ret;
00095 };
00096
00097 template<unsigned Cond,
00098 unsigned Compare,
00099 class Ret,
00100 class Cases,
00101 class Default>
00102 struct switch_<Cond, case_<Compare, Ret, Cases>, Default >
00103 {
00104 typedef typename
00105 if_< (Cond == Compare),
00106 Ret,
00107 typename switch_<Cond, Cases, Default>::ret>::ret ret;
00108 };
00109
00110 template<bool Cond, class Ret, class Cases = invalid>
00111 struct bool_case_ {};
00112
00113 template<class Cases, class Default = invalid>
00114 struct bool_switch_;
00115
00116 template<bool Cond, class Ret, class Default>
00117 struct bool_switch_<bool_case_<Cond, Ret>, Default >
00118 {
00119 typedef typename if_< Cond, Ret, Default >::ret ret;
00120 };
00121
00122 template<bool Cond,class Ret, class Cases, class Default>
00123 struct bool_switch_<bool_case_<Cond, Ret, Cases>, Default >
00124 {
00125 typedef typename
00126 if_< Cond,
00127 Ret,
00128 typename bool_switch_<Cases, Default>::ret >::ret ret;
00129 };
00130
00131
00132
00133
00134
00135
00136 template<bool> struct is_true;
00137 template<> struct is_true<true>
00138 {
00139 static void ensure() {};
00140 typedef true_type ensure_type;
00141 };
00142
00143 template<bool> struct is_false;
00144 template<> struct is_false<false> { static void ensure() {}; };
00145
00146
00147
00148
00149
00150 template<bool> struct returns_bool_;
00151
00152 template<>
00153 struct returns_bool_<true> : public true_type
00154 {
00155 typedef void ensure_type;
00156 static const bool ret = true;
00157 static void ensure() {}
00158 };
00159
00160 template<>
00161 struct returns_bool_<false> : public false_type
00162 {
00163 static const bool ret = false;
00164 };
00165
00166 }
00167
00168
00169 #endif // METALIC_BOOL_HH