27 #ifndef TOMOGRAPHER_TOOLS_UTILS_H 28 #define TOMOGRAPHER_TOOLS_UTILS_H 40 #include <type_traits> 59 #define TOMO_STATIC_ASSERT_EXPR(...) \ 60 static_assert(__VA_ARGS__, #__VA_ARGS__) 63 #ifndef tomographer_assert 64 #define tomographer_assert(...) eigen_assert((__VA_ARGS__) && "assert: " #__VA_ARGS__) 69 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 72 #define TOMOGRAPHER_ENABLED_IF(...) \ 73 template<bool _dummy__enabledif = false, \ 74 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \ 75 _dummy__enabledif2 = false> 76 #define TOMOGRAPHER_ENABLED_IF_TMPL(...) \ 77 bool _dummy__enabledif = false, \ 78 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \ 79 _dummy__enabledif2 = true 87 #define TOMOGRAPHER_ENABLED_IF_TMPL_REPEAT(...) \ 88 bool _dummy__enabledif, \ 89 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \ 90 _dummy__enabledifAlt2 = true 105 namespace tomo_internal {
106 template <
typename F>
108 FinalAction(F f) : clean_{f} {}
109 ~FinalAction() { clean_(); }
125 template <
typename F>
126 inline tomo_internal::FinalAction<F>
finally(F f)
128 return tomo_internal::FinalAction<F>(f);
155 template<
typename T_,
bool IsDynamic_, T_ StaticValue_ = T_()>
166 static constexpr
bool IsDynamic = IsDynamic_;
168 static constexpr T StaticValue = StaticValue_;
178 tomographer_assert(val == StaticValue);
186 inline T
value()
const {
return StaticValue; }
195 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
197 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
204 template<
typename T_, T_ StaticValue_>
212 static constexpr
bool IsDynamic =
true;
225 inline T
value()
const {
return _dyn_value; }
236 template<
typename T_, T_ StaticValue_>
252 template<
typename T_,
bool enabled>
258 static constexpr
bool IsEnabled =
false;
261 template<
typename... Args>
265 template<
typename T_,
bool enabled>
271 template<
typename T_>
277 static constexpr
bool IsEnabled =
true;
283 template<
typename... ArgTypes>
287 template<
typename T_>
298 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, false>& )
311 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, true>& val)
324 template<
typename IntType =
int>
328 return N && !(N & (N - 1));
340 template<
typename Scalar>
355 template<
typename Scalar>
361 template<
typename RealScalar>
364 typedef RealScalar type;
402 #if defined(__GNUC__) || defined(__clang__) || defined(TOMOGRAPHER_PARSED_BY_DOXGEN) 422 # define PRINTF1_ARGS_SAFE __attribute__ ((__format__ (__printf__, 1, 2))) 423 # define PRINTF2_ARGS_SAFE __attribute__ ((__format__ (__printf__, 2, 3))) 425 # define PRINTF3_ARGS_SAFE __attribute__ ((__format__ (__printf__, 3, 4))) 427 # define PRINTF4_ARGS_SAFE __attribute__ ((__format__ (__printf__, 4, 5))) 430 # define PRINTF1_ARGS_SAFE 431 # define PRINTF2_ARGS_SAFE 432 # define PRINTF3_ARGS_SAFE 433 # define PRINTF4_ARGS_SAFE 439 #if TOMOGRAPHER_PARSED_BY_DOXYGEN 448 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 449 #else // TOMOGRAPHER_PARSED_BY_DOXYGEN 451 #if defined(__GNUC__) || defined(__clang__) 452 # if defined(__MINGW32__) || defined(__MINGW64__) 453 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN __attribute__((force_align_arg_pointer,noinline)) 455 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 459 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 461 # warning "You are using an unknown compiler. You may run into memory alignment problems... Good luck!" 462 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 465 #endif // TOMOGRAPHER_PARSED_BY_DOXYGEN 472 namespace tomo_internal {
473 template<
typename Enabledtype =
void>
struct sfinae_no {
typedef int no[1]; };
474 template<
typename EnabledType =
void>
struct sfinae_yes {
typedef int yes[2]; };
495 const int offset = max_width;
497 #if defined(__MINGW32__) || defined(__MINGW64__) 506 if (cols_s != NULL) {
528 #define TOMO_FUNCTION __PRETTY_FUNCTION__ 532 namespace tomo_internal {
534 struct extractFuncName_helper {
538 constexpr extracted(
std::size_t dp,
const conststr& s) : decl_pos(dp), extr(s) { }
540 static constexpr conststr alltofirstparen(
const conststr& s)
542 return s.substr(0, s.find(conststr(
"("), 0, s.size()));
546 return found_pos == std::string::npos ? 0 : found_pos + 1;
548 static constexpr
std::size_t pos_decl(
const conststr& s)
550 return ((s.size() > 2)
551 ? declpos_from_found_spc(s.rfind(conststr(
" "), std::string::npos))
554 static constexpr extracted allfromfirstspace(
const conststr& s)
556 return extracted(pos_decl(s),
557 s.substr_e(pos_decl(s),
560 static constexpr extracted do_extract(
const conststr& funcname)
562 return allfromfirstspace(alltofirstparen(funcname));
564 static constexpr conststr extract_choose(
const extracted& do_extracted,
565 const conststr& funcname)
567 return (do_extracted.extr.substr(0,8) == conststr(
"operator")
568 ? funcname.substr(do_extracted.decl_pos)
569 : do_extracted.extr);
571 static constexpr conststr extract(
const conststr& funcname)
573 return extract_choose(do_extract(funcname), funcname);
586 return tomo_internal::extractFuncName_helper::extract(funcname);
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
Base namespace for the Tomographer project.
A constexpr string type, suitable for basic compile-time string processing.
VarValueDecoder< T >::RetType value(const Var &var)
Access the value of the given variable, as a C++ type.