PPL  1.2
meta_programming.hh
Go to the documentation of this file.
1 /* Metaprogramming utilities.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_meta_programming_hh
25 #define PPL_meta_programming_hh 1
26 
27 #include <gmpxx.h>
28 
29 namespace Parma_Polyhedra_Library {
30 
31 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
32 
41 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
42 #define const_bool_nodef(name, value) \
43  enum const_bool_value_ ## name { PPL_U(name) = (value) }
44 
45 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
46 
55 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
56 #define const_int_nodef(name, value) \
57  enum anonymous_enum_ ## name { PPL_U(name) = (value) }
58 
59 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
60 
70 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
71 #define const_value_nodef(type, name, value) \
72  static type PPL_U(name)() { \
73  return (value); \
74  }
75 
76 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
77 
87 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
88 #define const_ref_nodef(type, name, value) \
89  static const type& PPL_U(name)() { \
90  static type PPL_U(name) = (value); \
91  return (name); \
92  }
93 
94 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
95 
101 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
102 template <bool b>
104 
105 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
106 
113 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
114 template <>
115 struct Compile_Time_Check<true> {
116 };
117 
118 #define PPL_COMPILE_TIME_CHECK_NAME(suffix) compile_time_check_ ## suffix
119 #define PPL_COMPILE_TIME_CHECK_AUX(e, suffix) \
120  enum anonymous_enum_compile_time_check_ ## suffix { \
121  /* If e evaluates to false, then the sizeof cannot be compiled. */ \
122  PPL_COMPILE_TIME_CHECK_NAME(suffix) \
123  = sizeof(Parma_Polyhedra_Library::Compile_Time_Check<(e)>) \
124  }
125 
126 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
127 
132 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
133 #define PPL_COMPILE_TIME_CHECK(e, msg) PPL_COMPILE_TIME_CHECK_AUX(e, __LINE__)
134 
135 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
136 
141 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
142 template <bool b>
143 struct Bool {
145  value = b
146  };
147 };
148 
149 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
150 
155 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
156 struct True : public Bool<true> {
157 };
158 
159 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
160 
165 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
166 struct False : public Bool<false> {
167 };
168 
169 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
170 
177 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
178 template <typename T1, typename T2>
179 struct Is_Same : public False {
180 };
181 
182 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
183 
190 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
191 template <typename T>
192 struct Is_Same<T, T> : public True {
193 };
194 
195 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
196 
221 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
222 template <typename Base, typename Derived>
224 
225 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
226 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
228  struct Any {
230  template <typename T>
231  Any(const T&);
232  };
233 
235  static char func(const Base&);
236 
238  static double func(Any);
239 
241  static const Derived& derived_object();
242 
243  PPL_COMPILE_TIME_CHECK(sizeof(char) != sizeof(double),
244  "architecture with sizeof(char) == sizeof(double)"
245  " (!?)");
246 
255  value = (sizeof(func(derived_object())) == sizeof(char))
256  };
257 };
258 
259 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
260 
268 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
269 template <bool b, typename T = void>
270 struct Enable_If {
271 };
272 
273 template <typename Type, Type, typename T = void>
274 struct Enable_If_Is {
275  typedef T type;
276 };
277 
278 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
279 
303 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
304 template <typename T>
305 struct Enable_If<true, T> {
306  typedef T type;
307 };
308 
309 template <typename T>
310 struct Is_Native : public False {
311 };
312 
313 template <> struct Is_Native<char> : public True { };
314 template <> struct Is_Native<signed char> : public True { };
315 template <> struct Is_Native<signed short> : public True { };
316 template <> struct Is_Native<signed int> : public True { };
317 template <> struct Is_Native<signed long> : public True { };
318 template <> struct Is_Native<signed long long> : public True { };
319 template <> struct Is_Native<unsigned char> : public True { };
320 template <> struct Is_Native<unsigned short> : public True { };
321 template <> struct Is_Native<unsigned int> : public True { };
322 template <> struct Is_Native<unsigned long> : public True { };
323 template <> struct Is_Native<unsigned long long> : public True { };
324 
325 #if PPL_SUPPORTED_FLOAT
326 template <> struct Is_Native<float> : public True { };
327 #endif
328 #if PPL_SUPPORTED_DOUBLE
329 template <> struct Is_Native<double> : public True { };
330 #endif
331 #if PPL_SUPPORTED_LONG_DOUBLE
332 template <> struct Is_Native<long double> : public True { };
333 #endif
334 
335 template <> struct Is_Native<mpz_class> : public True { };
336 
337 template <> struct Is_Native<mpq_class> : public True { };
338 
339 } // namespace Parma_Polyhedra_Library
340 
341 #endif // !defined(PPL_meta_programming_hh)
A class holding a constant called value that evaluates to true if and only if T1 is the same type as ...
static const Derived & derived_object()
A function obtaining a const reference to a Derived object.
A class that is only defined if b evaluates to true.
PPL_COMPILE_TIME_CHECK(sizeof(char)!=sizeof(double),"architecture with sizeof(char) == sizeof(double)"" (!?)")
signed signed signed signed signed char signed signed signed signed signed int signed long long
A class that is constructible from just anything.
signed signed signed signed signed char signed signed signed signed signed int signed long signed long signed long signed long signed long long unsigned short
A class holding a constant called value that evaluates to true if and only if Base is the same type a...
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned int
A class holding a constant called value that evaluates to true.
The entire library is confined to this namespace.
Definition: version.hh:61
static char func(const Base &)
Overloading with Base.
A class that provides a type member called type equivalent to T if and only if b is true...
A class holding a constant called value that evaluates to false.
A class holding a constant called value that evaluates to b.
Any(const T &)
The universal constructor.