20inline std::vector<std::string>
split(
const std::string& s,
char delimiter)
23 std::vector<std::string> tokens;
24 std::istringstream tokenStream(s);
25 while (std::getline(tokenStream, token, delimiter)) {
27 size_t first = token.find_first_not_of(
" \t\n\r");
28 if (std::string::npos != first) {
29 size_t last = token.find_last_not_of(
" \t\n\r");
30 tokens.push_back(token.substr(first, (last - first + 1)));
53template <
typename... Args>
54std::string
format_args(
const std::string& names,
const Args&... args)
58 std::vector<std::string> arg_names =
split(names,
',');
62 auto printer = [&](
const auto& arg_value) {
63 if (i < arg_names.size()) {
64 if (i > 0) ss <<
", ";
65 ss << arg_names[i] <<
" = " << arg_value;
76#if defined(__GNUC__) || defined(__clang__)
77#define FUNCTION_NAME __PRETTY_FUNCTION__
78#elif defined(_MSC_VER)
79#define FUNCTION_NAME __FUNCSIG__
81#define FUNCTION_NAME __func__
85#define THROW_ON_INVALID_ARG(condition, ...) \
88 std::stringstream ss; \
89 ss << "\n Condition '" << #condition << "' failed." \
90 << "\n With: " << format_args(#__VA_ARGS__, __VA_ARGS__) \
91 << "\n In function: " << FUNCTION_NAME \
92 << "\n At file: " << __FILE__ << "\n At line: " << __LINE__; \
93 throw std::invalid_argument(ss.str()); \
std::vector< std::string > split(const std::string &s, char delimiter)
Helper function to split a string by a delimiter.
std::string format_args(const std::string &names, const Args &... args)
The main variadic template function to log the arguments.