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
00029
00030
00031
00032
00033 #ifndef LEMON_UTILITY_H
00034 #define LEMON_UTILITY_H
00035
00041
00042
00043 namespace lemon
00044 {
00045
00047
00054 struct True {
00056 static const bool value = true;
00057 };
00058
00060
00064 struct False {
00066 static const bool value = false;
00067 };
00068
00069 template <typename T>
00070 struct Wrap {
00071 const T &value;
00072 Wrap(const T &t) : value(t) {}
00073 };
00074
00075
00076
00077 template<int T> struct dummy { dummy(int) {} };
00078
00079
00080
00081 template <bool B, class T = void>
00082 struct enable_if_c {
00083 typedef T type;
00084 };
00085
00086 template <class T>
00087 struct enable_if_c<false, T> {};
00088
00089 template <class Cond, class T = void>
00090 struct enable_if : public enable_if_c<Cond::value, T> {};
00091
00092 template <bool B, class T>
00093 struct lazy_enable_if_c {
00094 typedef typename T::type type;
00095 };
00096
00097 template <class T>
00098 struct lazy_enable_if_c<false, T> {};
00099
00100 template <class Cond, class T>
00101 struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
00102
00103
00104 template <bool B, class T = void>
00105 struct disable_if_c {
00106 typedef T type;
00107 };
00108
00109 template <class T>
00110 struct disable_if_c<true, T> {};
00111
00112 template <class Cond, class T = void>
00113 struct disable_if : public disable_if_c<Cond::value, T> {};
00114
00115 template <bool B, class T>
00116 struct lazy_disable_if_c {
00117 typedef typename T::type type;
00118 };
00119
00120 template <class T>
00121 struct lazy_disable_if_c<true, T> {};
00122
00123 template <class Cond, class T>
00124 struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
00125
00126
00127
00128 template <typename _Type, typename Enable = void>
00129 struct SmartReference {
00130 typedef _Type& Type;
00131 };
00132
00133 template <typename _Type>
00134 struct SmartReference<
00135 _Type,
00136 typename enable_if<typename _Type::NeedCopy, void>::type
00137 > {
00138 typedef _Type Type;
00139 };
00140
00141 template <typename _Type, typename Enable = void>
00142 struct SmartConstReference {
00143 typedef const _Type& Type;
00144 };
00145
00146 template <typename _Type>
00147 struct SmartConstReference<
00148 _Type,
00149 typename enable_if<typename _Type::NeedCopy, void>::type
00150 > {
00151 typedef const _Type Type;
00152 };
00153
00154 template <typename _Type, typename Enable = void>
00155 struct SmartParameter {
00156 typedef _Type& Type;
00157 };
00158
00159 template <typename _Type>
00160 struct SmartParameter<
00161 _Type,
00162 typename enable_if<typename _Type::NeedCopy, void>::type
00163 > {
00164 typedef const _Type& Type;
00165 };
00166
00167 }
00168
00169 #endif