00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PPL_meta_programming_hh
00024 #define PPL_meta_programming_hh 1
00025
00026 #include <gmpxx.h>
00027
00028 namespace Parma_Polyhedra_Library {
00029
00030 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00031
00040 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00041 #define const_bool_nodef(name, value) \
00042 enum { name = (value) }
00043
00044 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00045
00054 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00055 #define const_int_nodef(name, value) \
00056 enum { name = (value) }
00057
00058 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00059
00069 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00070 #define const_value_nodef(type, name, value) \
00071 static type name() { \
00072 return value; \
00073 }
00074
00075 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00076
00086 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00087 #define const_ref_nodef(type, name, value) \
00088 static const type& name() { \
00089 static type name(value); \
00090 return name; \
00091 }
00092
00093 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00094
00100 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00101 template <bool b>
00102 struct Compile_Time_Check;
00103
00104 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00105
00112 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00113 template <>
00114 struct Compile_Time_Check<true> {
00115 };
00116
00117 #define COMPILE_TIME_CHECK_NAME(suffix) compile_time_check_ ## suffix
00118 #define COMPILE_TIME_CHECK_AUX(e, suffix) \
00119 enum { \
00120 \
00121 COMPILE_TIME_CHECK_NAME(suffix) \
00122 = sizeof(Parma_Polyhedra_Library:: \
00123 Compile_Time_Check<static_cast<bool>(e)>) \
00124 }
00125
00126 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00127
00132 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00133 #define COMPILE_TIME_CHECK(e, msg) COMPILE_TIME_CHECK_AUX(e, __LINE__)
00134
00135 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00136
00141 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00142 template <bool b>
00143 struct Bool {
00144 enum {
00145 value = b
00146 };
00147 };
00148
00149 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00150
00155 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00156 struct True : public Bool<true> {
00157 };
00158
00159 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00160
00165 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00166 struct False : public Bool<false> {
00167 };
00168
00169 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00170
00177 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00178 template <typename T1, typename T2>
00179 struct Is_Same : public False {
00180 };
00181
00182 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00183
00190 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00191 template <typename T>
00192 struct Is_Same<T, T> : public True {
00193 };
00194
00195 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00196
00221 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00222 template <typename Base, typename Derived>
00223 struct Is_Same_Or_Derived {
00224
00225 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00227 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00228 struct Any {
00230 template <typename T>
00231 Any(const T&);
00232 };
00233
00235 static char func(const Base&);
00236
00238 static double func(Any);
00239
00241 static const Derived& derived_object();
00242
00243 COMPILE_TIME_CHECK(sizeof(char) != sizeof(double),
00244 "architecture with sizeof(char) == sizeof(double) (!?)");
00245
00246 enum {
00253 value = (sizeof(func(derived_object())) == sizeof(char))
00254 };
00255 };
00256
00257 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00258
00266 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00267 template <bool b, typename T = void>
00268 struct Enable_If {
00269 };
00270
00271 template <typename Type, Type, typename T = void>
00272 struct Enable_If_Is {
00273 typedef T type;
00274 };
00275
00276 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00277
00301 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00302 template <typename T>
00303 struct Enable_If<true, T> {
00304 typedef T type;
00305 };
00306
00307 template <typename T>
00308 struct Is_Native : public False {
00309 };
00310
00311 template <> struct Is_Native<signed char> : public True { };
00312 template <> struct Is_Native<signed short> : public True { };
00313 template <> struct Is_Native<signed int> : public True { };
00314 template <> struct Is_Native<signed long> : public True { };
00315 template <> struct Is_Native<signed long long> : public True { };
00316 template <> struct Is_Native<unsigned char> : public True { };
00317 template <> struct Is_Native<unsigned short> : public True { };
00318 template <> struct Is_Native<unsigned int> : public True { };
00319 template <> struct Is_Native<unsigned long> : public True { };
00320 template <> struct Is_Native<unsigned long long> : public True { };
00321
00322 #if PPL_SUPPORTED_FLOAT
00323 template <> struct Is_Native<float> : public True { };
00324 #endif
00325 #if PPL_SUPPORTED_DOUBLE
00326 template <> struct Is_Native<double> : public True { };
00327 #endif
00328 #if PPL_SUPPORTED_LONG_DOUBLE
00329 template <> struct Is_Native<long double> : public True { };
00330 #endif
00331
00332 template <> struct Is_Native<mpz_class> : public True { };
00333
00334 template <> struct Is_Native<mpq_class> : public True { };
00335
00336 }
00337
00338 #endif // !defined(PPL_meta_programming_hh)