You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, the formatting crashes when the format string contains more placeholders than the number of arguments passed to the formatting operator():
std::cout << "Hello %!\n"_fmt();
However, it is perfectly possible to test at compile time if a given list of parameters would cause problems:
constexprauto f = "Hello, %! How is % feeling today?"_fmt;
constexprauto cnt_1 = f.check("Paul", "Chani");
static_assert(cnt_1.first == cnt.second,
"Wrong number of arguments."); // Ok!constexprauto cnt_2 = f.check("Paul");
static_assert(cnt_2.first == cnt_2.second,
"Wrong number of arguments."); // Compile-time ERROR!
The check() method returns a pair of numbers, one representing the number of placeholders '%' in the format string and another representing the number of parameters passed. Both are computed in a constexpr context.
Unfortunately, the static_assert cannot be performed inside the formatting operator() of the format string due to the c++14 rules for constexpr. Within the member operator, the object cannot be aware of its own "constexpr"-ness, so it is unable to compute the number of placeholders '%' in a constexpr context.
The text was updated successfully, but these errors were encountered:
At the moment, the formatting crashes when the format string contains more placeholders than the number of arguments passed to the formatting operator():
std::cout << "Hello %!\n"_fmt();
However, it is perfectly possible to test at compile time if a given list of parameters would cause problems:
The check() method returns a pair of numbers, one representing the number of placeholders '%' in the format string and another representing the number of parameters passed. Both are computed in a constexpr context.
Unfortunately, the static_assert cannot be performed inside the formatting operator() of the format string due to the c++14 rules for constexpr. Within the member operator, the object cannot be aware of its own "constexpr"-ness, so it is unable to compute the number of placeholders '%' in a constexpr context.
The text was updated successfully, but these errors were encountered: