diff --git a/inc/format.h b/inc/format.h index a012e4b..ac3f0a1 100644 --- a/inc/format.h +++ b/inc/format.h @@ -128,5 +128,19 @@ constexpr std::array()> format(args_t... args) { return result; } +template +class fmt_literal_obj_t { + public: + template + constexpr auto operator()(args_t... args) { + return format(args...); + } +}; + +template +constexpr auto operator""_const_fmt() { + return fmt_literal_obj_t{}; +} + #endif // LOGGER_FORMAT_H diff --git a/src/main.cpp b/src/main.cpp index aa2f8fc..b37273d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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;