17template <
typename ... Args>
19 if constexpr (
sizeof...(Args) not_eq 0) {
20 std::ostringstream os;
21 ((os << std::forward<Args>(args)), ...);
28#if __cpp_lib_source_location >= 201907L
30#include <source_location>
32#define CURRENT_SOURCE_LOCATION \
33 var_string("Filename: ", \
34 std::quoted(std::source_location::current().file_name()), '\n', \
36 std::quoted(std::source_location::current().function_name()), \
37 '\n', "Line Number: ", std::source_location::current().line(), \
39 "Column Number: ", std::source_location::current().column())
43#define CURRENT_SOURCE_LOCATION var_string("\t", __FILE__, ":", __LINE__)
53#define DEBUG_ONLY(...) __VA_ARGS__
57#define DEBUG_COUNTER(n) \
60 std::cerr << "DBG: " << #n << ": " << ++n << std::endl; \
64#define DEBUG_PRINT(e) \
65 { std::cerr << "DBG: " << (e) << std::endl; }
69 { std::cerr << "DBG: " << #e << ": " << (e) << std::endl; }
72#define DEBUG_VAR_FLT(p, e) \
74 std::streamsize old_p = std::cerr.precision(); \
75 std::cerr << "DBG: " << #e << ": " << std::setprecision(p) << (e) \
77 << std::setprecision(old_p); \
81#define ARTS_NOEXCEPT noexcept(false)
84#define ARTS_ASSERT(condition, ...) \
86 if (not(condition)) { \
87 throw std::runtime_error( \
88 var_string("Failed Internal Assert: " #condition "\n" \
89 "This is a bug! Bug is found at:\n", \
90 CURRENT_SOURCE_LOCATION, \
92 " ARTS developers so we can fix " \
93 "our error(s) via:\n\t" \
94 "github.com/atmtools/arts\n" __VA_OPT__(, __VA_ARGS__))); \
100#define DEBUG_ONLY(...)
102#define DEBUG_COUNTER(n)
104#define DEBUG_PRINT(e)
108#define DEBUG_VAR_FLT(p, e)
111#define ARTS_NOEXCEPT noexcept(true)
114#define ARTS_ASSERT(condition, ...) {}
118#ifdef NO_ARTS_USER_ERRORS
121#define ARTS_USER_NOEXCEPT noexcept(true)
124#define ARTS_USER_ERROR_IF(condition, ...) {}
127#define ARTS_USER_ERROR(...) {}
132#define ARTS_USER_NOEXCEPT noexcept(false)
135#define ARTS_USER_ERROR_IF(condition, ...) \
137 static_assert(false __VA_OPT__(or true), \
138 "Must have an error message in user-" \
139 "facing code in " __FILE__); \
141 throw std::runtime_error( \
142 var_string("User Error: " #condition "\nError is found at:\n", \
143 CURRENT_SOURCE_LOCATION, \
145 "these instructions to correct your " \
146 "error:\n" __VA_OPT__(, __VA_ARGS__))); \
151#define ARTS_USER_ERROR(...) \
153 static_assert(false __VA_OPT__(or true), \
154 "Must have an error message in user-" \
155 "facing code in " __FILE__); \
156 throw std::runtime_error( \
157 var_string("User Error:\n" \
158 "Error is found at:\n", \
159 CURRENT_SOURCE_LOCATION, \
161 "these instructions to correct your " \
162 "error:\n" __VA_OPT__(, __VA_ARGS__))); \
std::string var_string(Args &&... args)