27 #ifndef TOMOGRAPHER_TOOLS_UTILS_H
28 #define TOMOGRAPHER_TOOLS_UTILS_H
36 #include <type_traits>
72 #define PRINTF1_ARGS_SAFE __attribute__ ((__format__ (__printf__, 1, 2)))
75 #define PRINTF2_ARGS_SAFE __attribute__ ((__format__ (__printf__, 2, 3)))
78 #define PRINTF3_ARGS_SAFE __attribute__ ((__format__ (__printf__, 3, 4)))
81 #define PRINTF4_ARGS_SAFE __attribute__ ((__format__ (__printf__, 4, 5)))
96 namespace tomo_internal {
99 FinalAction(F f) : clean_{f} {}
100 ~FinalAction() { clean_(); }
116 template <
typename F>
117 inline tomo_internal::FinalAction<F>
finally(F f)
119 return tomo_internal::FinalAction<F>(f);
144 template<
typename T_,
int Value>
161 assert(val == ValueAtCTime);
182 template<
typename T_>
200 inline T
value()
const {
return _dyn_value; }
220 template<
typename T_,
bool enabled>
229 template<
typename... Args>
236 template<
typename T_>
248 template<
typename... ArgTypes>
257 inline std::ostream & operator<<(std::ostream & str, store_if_enabled<T, false> )
266 inline std::ostream & operator<<(std::ostream & str, store_if_enabled<T, true> val)
268 return str << val.value;
280 return N && !(N & (N - 1));
294 #define TOMO_FUNCTION __PRETTY_FUNCTION__
298 namespace tomo_internal {
300 struct extractFuncName_helper {
304 constexpr extracted(
std::size_t dp,
const conststr& s) : decl_pos(dp), extr(s) { }
306 static constexpr conststr alltofirstparen(
const conststr& s)
308 return s.substr(0, s.find(conststr(
"("), 0, s.size()));
312 return found_pos == std::string::npos ? 0 : found_pos + 1;
314 static constexpr
std::size_t pos_decl(
const conststr& s)
316 return ((s.size() > 2)
317 ? declpos_from_found_spc(s.rfind(conststr(
" "), std::string::npos))
320 static constexpr extracted allfromfirstspace(
const conststr& s)
322 return extracted(pos_decl(s),
323 s.substr_e(pos_decl(s),
326 static constexpr extracted do_extract(
const conststr& funcname)
328 return allfromfirstspace(alltofirstparen(funcname));
330 static constexpr conststr extract_choose(
const extracted& do_extracted,
331 const conststr& funcname)
333 return (do_extracted.extr.substr(0,8) == conststr(
"operator")
334 ? funcname.substr(do_extracted.decl_pos)
335 : do_extracted.extr);
337 static constexpr conststr extract(
const conststr& funcname)
339 return extract_choose(do_extract(funcname), funcname);
352 return tomo_internal::extractFuncName_helper::extract(funcname);
363 #define TOMO_STATIC_ASSERT_EXPR(...) \
364 static_assert(__VA_ARGS__, #__VA_ARGS__)
370 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN
373 #define TOMOGRAPHER_ENABLED_IF(...) \
374 template<bool _dummy__enabledif = false, \
375 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \
376 _dummy__enabledif2 = false>
377 #define TOMOGRAPHER_ENABLED_IF_TMPL(...) \
378 bool _dummy__enabledif = false, \
379 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \
380 _dummy__enabledif2 = true
Base namespace for the Tomographer project.
A constexpr string type, suitable for basic compile-time string processing.