Added user-defined literal for call to format()

This commit is contained in:
Andreas Tsouchlos 2021-11-25 14:03:50 +01:00
parent 3f46775b35
commit 7743c95631
2 changed files with 15 additions and 1 deletions

View File

@ -128,5 +128,19 @@ constexpr std::array<char, detail::get_output_len<s>()> format(args_t... args) {
return result;
}
template<detail::ConstString t_s>
class fmt_literal_obj_t {
public:
template<typename... args_t>
constexpr auto operator()(args_t... args) {
return format<t_s>(args...);
}
};
template <detail::ConstString t_s>
constexpr auto operator""_const_fmt() {
return fmt_literal_obj_t<t_s>{};
}
#endif // LOGGER_FORMAT_H

View File

@ -4,7 +4,7 @@
int main() {
constexpr auto formatted = format<"Test: {:012.5} {} {:8}">(142.4334, "abcdef", -1234);
constexpr auto formatted = "Test: {:012.5} {:6} {:8}"_const_fmt(142.4334, "abcdef", -1234);
for (const auto& c : formatted)
std::cout << c;