Tomographer  v5.4
Tomographer C++ Framework Documentation
cxxdefs.h
Go to the documentation of this file.
1 /* This file is part of the Tomographer project, which is distributed under the
2  * terms of the MIT license.
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2016 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  * Copyright (c) 2017 Caltech, Institute for Quantum Information and Matter, Philippe Faist
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 
28 #ifndef TOMOGRAPHER_TOOLS_DEFS_H
29 #define TOMOGRAPHER_TOOLS_DEFS_H
30 
39 #include <cassert>
40 #include <cstddef>
41 #include <cstdlib>
42 
43 #include <boost/predef.h>
44 
45 // NOTE: DO NOT INCLUDE EIGEN HEADERS IN THIS FILE! For instance eigen_assert_exception.h
46 // depends on cxxdefs.h not including any Eigen headers.
47 
48 
49 
50 
51 // -----------------------------------------------------------------------------
52 // Some general useful definitions
53 // -----------------------------------------------------------------------------
54 
55 
56 //
57 // Included in front of all public symbols. If you need, you may define this to
58 // e.g. "__attribute__((visibility("default")))" or "__declspec(dllexport)" to export the
59 // definition in the library
60 //
61 #ifndef TOMOGRAPHER_EXPORT
62 #define TOMOGRAPHER_EXPORT
63 #endif
64 
65 
66 // -----------------------------------------------------------------------------
67 // Some C++ helpers
68 // -----------------------------------------------------------------------------
69 
70 
71 
77 #define TOMO_STATIC_ASSERT_EXPR(...) \
78  static_assert(__VA_ARGS__, #__VA_ARGS__)
79 
80 
81 #ifndef tomographer_assert
82 
84 #define tomographer_assert(...) eigen_assert((__VA_ARGS__) && "assert: " #__VA_ARGS__)
85 #endif
86 
87 
88 
89 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN
90 // WARNING!!! CHECK OUT http://stackoverflow.com/q/29363532/1694896
91 // FOR VERY SUBTLE BUGS :( :( -- TEST WITH INTEL ICC!!
92 #define TOMOGRAPHER_ENABLED_IF(...) \
93  template<bool _dummy__enabledif = false, \
94  typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \
95  _dummy__enabledif2 = false>
96 #define TOMOGRAPHER_ENABLED_IF_TMPL(...) \
97  bool _dummy__enabledif = false, \
98  typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \
99  _dummy__enabledif2 = true
100 
107 #define TOMOGRAPHER_ENABLED_IF_TMPL_REPEAT(...) \
108  bool _dummy__enabledif, \
109  typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \
110  _dummy__enabledifAlt2 = true
111 #endif
112 
113 
114 
115 
116 // -----------------------------------------------------------------------------
117 // Mark stuff as deprecated
118 // -----------------------------------------------------------------------------
119 
120 //
121 // This is giving me headaches with different compilers & compatibility ... just document
122 // stuff as being deprecated.
123 //
124 
125 // #ifdef TOMOGRAPHER_PARSED_BY_DOXYGEN
126 
127 // /** \brief Mark a class declaration as deprecated
128 // *
129 // * Use for instance as:
130 // * \code
131 // * template<typename CountType>
132 // * TOMOGRAPHER_DEPRECATED_CLASS(MyObject) : public Base<CountType> { ... }
133 // * \endcode
134 // */
135 // # define TOMOGRAPHER_DEPRECATED_CLASS(X) class X
136 
137 // /** \brief Mark a class declaration as deprecated
138 // *
139 // * Use for instance as:
140 // * \code
141 // * template<typename CountType>
142 // * TOMOGRAPHER_DEPRECATED_STRUCT(MyObject) : public Base<CountType> { ... }
143 // * \endcode
144 // */
145 // # define TOMOGRAPHER_DEPRECATED_STRUCT(X) struct X
146 
147 // /** \brief Mark a function declaration as deprecated
148 // *
149 // * Use as:
150 // * \code
151 // * TOMOGRAPHER_DEPRECATED_FUNC(double f(int x, int y)) {
152 // * return (double)x / y;
153 // * }
154 // * \endcode
155 // */
156 // # define TOMOGRAPHER_DEPRECATED_FUNC(FuncDecl) FuncDecl
157 
158 // /** \brief Mark a "using x = y" declaration as deprecated
159 // *
160 // * Use as:
161 // * \code
162 // * // using MyAlias = OriginalType
163 // * TOMOGRAPHER_DEPRECATED_USING(MyAlias, OriginalType);
164 // * \endcode
165 // */
166 // # define TOMOGRAPHER_DEPRECATED_USING(X, Y) using X = Y
167 
168 // #else
169 // // implementation:
170 
171 // #if defined(__has_cpp_attribute)
172 // # if __has_cpp_attribute(deprecated)
173 // # define _tomographer_has_cxx_deprecated_attribute
174 // # endif
175 // #endif
176 
177 // # if defined(_tomographer_has_cxx_deprecated_attribute)
178 // # define TOMOGRAPHER_DEPRECATED [[deprecated]]
179 // # define TOMOGRAPHER_DEPRECATED_FUNC(...) TOMOGRAPHER_DEPRECATED __VA_ARGS__
180 // # define TOMOGRAPHER_DEPRECATED_CLASS(...) class TOMOGRAPHER_DEPRECATED __VA_ARGS__
181 // # define TOMOGRAPHER_DEPRECATED_STRUCT(...) struct TOMOGRAPHER_DEPRECATED __VA_ARGS__
182 // # define TOMOGRAPHER_DEPRECATED_USING(X, ...) using X TOMOGRAPHER_DEPRECATED = __VA_ARGS__
183 // # elif defined(__GNUC__)
184 // # define TOMOGRAPHER_DEPRECATED __attribute__((deprecated))
185 // # define TOMOGRAPHER_DEPRECATED_FUNC(...) __VA_ARGS__ TOMOGRAPHER_DEPRECATED
186 // # define TOMOGRAPHER_DEPRECATED_CLASS(...) class TOMOGRAPHER_DEPRECATED __VA_ARGS__
187 // # define TOMOGRAPHER_DEPRECATED_STRUCT(...) struct TOMOGRAPHER_DEPRECATED __VA_ARGS__
188 // # define TOMOGRAPHER_DEPRECATED_USING(X, ...) using TOMOGRAPHER_DEPRECATED X = __VA_ARGS__
189 // # elif defined(_MSC_VER)
190 // # define TOMOGRAPHER_DEPRECATED __declspec(deprecated)
191 // # define TOMOGRAPHER_DEPRECATED_FUNC(...) __VA_ARGS__ TOMOGRAPHER_DEPRECATED
192 // # define TOMOGRAPHER_DEPRECATED_CLASS(...) class TOMOGRAPHER_DEPRECATED __VA_ARGS__
193 // # define TOMOGRAPHER_DEPRECATED_STRUCT(...) struct TOMOGRAPHER_DEPRECATED __VA_ARGS__
194 // # define TOMOGRAPHER_DEPRECATED_USING(X, ...) TOMOGRAPHER_DEPRECATED using X = __VA_ARGS__
195 // # else
196 // # define TOMOGRAPHER_DEPRECATED_FUNC(...) __VA_ARGS__
197 // # define TOMOGRAPHER_DEPRECATED_CLASS(...) class __VA_ARGS__
198 // # define TOMOGRAPHER_DEPRECATED_STRUCT(...) struct __VA_ARGS__
199 // # define TOMOGRAPHER_DEPRECATED_USING(X, ...) using X = __VA_ARGS__
200 // # endif
201 
202 // #endif
203 
204 
205 
206 
207 // -----------------------------------------------------------------------------
208 // Compiler information
209 // -----------------------------------------------------------------------------
210 
211 // see http://www.boost.org/doc/libs/1_62_0/doc/html/predef/reference.html#predef.reference.boost_comp_compiler_macros
212 
213 #ifdef TOMOGRAPHER_PARSED_BY_DOXYGEN
214 
217 #define TOMOGRAPHER_COMPILER_INFO_STR /* ... */
218 #else
219 // implementation of TOMOGRAPHER_COMPILER_INFO_STR:
220 #if BOOST_COMP_BORLAND
221 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Borland C++ %x", __BORLANDC__)
222 #elif BOOST_COMP_CLANG
223 # ifdef __apple_build_version__
224 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Apple LLVM/clang++ %s", __clang_version__)
225 # else
226 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("LLVM/clang++ %s", __clang_version__)
227 # endif
228 #elif BOOST_COMP_COMO
229 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Comeau C++ %d", __COMO_VERSION__)
230 #elif BOOST_COMP_DEC
231 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Compaq C/C++ %d", __DECCXX_VER)
232 #elif BOOST_COMP_DIAB
233 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Diab C/C++ %d", __VERSION_NUMBER__)
234 #elif BOOST_COMP_DMC
235 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Digital Mars %x", __DMC__)
236 #elif BOOST_COMP_SYSC
237 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Dignus Systems/C++ %d", __SYSC_VER__)
238 #elif BOOST_COMP_EDG
239 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("EDG C++ Frontend %d", __EDG_VERSION__)
240 #elif BOOST_COMP_PATH
241 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("EKOpath %d.%d.%d", __PATHCC__, __PATHCC_MINOR__, __PATHCC_PATCHLEVEL__)
242 #elif BOOST_COMP_GNUC
243 # ifdef __MINGW32__
244 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("MinGW GCC %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
245 # else
246 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Gnu GCC %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
247 # endif
248 #elif BOOST_COMP_GCCXML
249 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("GCC XML")
250 #elif BOOST_COMP_GHS
251 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Green Hills C/C++ %d", __GHS_VERSION_NUMBER__)
252 #elif BOOST_COMP_HPACC
253 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("HP aC++ %d", __HP_aCC)
254 #elif BOOST_COMP_IAR
255 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("IAR C/C++ %d", __VER__)
256 #elif BOOST_COMP_IBM
257 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("IBM XL C/C++ %d", __IBMCPP__)
258 #elif BOOST_COMP_INTEL
259 # ifdef __INTEL_COMPILER_BUILD_DATE
260 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Intel C/C++ %d (%d)", __INTEL_COMPILER, __INTEL_COMPILER_BUILD_DATE)
261 # else
262 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Intel C/C++ %d", __INTEL_COMPILER)
263 # endif
264 #elif BOOST_COMP_KCC
265 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Kai C++ %d", __KCC_VERSION)
266 #elif BOOST_COMP_LLVM // not covered by BOOST_COMP_CLANG???
267 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("<LLVM>")
268 #elif BOOST_COMP_HIGHC
269 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("MetaWare High C/C++")
270 #elif BOOST_COMP_MWERKS
271 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Metrowerks CodeWarrior %x", __MWERKS__)
272 #elif BOOST_COMP_MRI
273 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Microtec C/C++")
274 #elif BOOST_COMP_MPW
275 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("MPW C++ %x", __MRC__)
276 #elif BOOST_COMP_PALM
277 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Palm C/C++ %x", _PACC_VER)
278 #elif BOOST_COMP_PGI
279 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Portland Group C/C++ %d.%d.%d", __PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
280 #elif BOOST_COMP_SGI
281 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("SGI MIPSpro %d", _SGI_COMPILER_VERSION)
282 #elif BOOST_COMP_SUNPRO
283 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Oracle Solaris Studio %x", __SUNPRO_CC)
284 #elif BOOST_COMP_TENDRA
285 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("TenDRA C/C++")
286 #elif BOOST_COMP_MSVC
287 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Microsoft Visual C/C++ %d", _MSC_FULL_VER)
288 #elif BOOST_COMP_WATCOM
289 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("Watcom C++ %d", __WATCOMC__)
290 #elif defined(__VERSION__)
291 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("<unknown compiler, version %s>", __VERSION__)
292 #else
293 # define TOMOGRAPHER_COMPILER_INFO_STR Tomographer::Tools::fmts("<unknown compiler>")
294 #endif
295 // end implementation of TOMOGRAPHER_COMPILER_INFO_STR:
296 #endif
297 
298 
299 
300 
301 
302 
303 #endif