Added user-defined literal for call to format()
This commit is contained in:
parent
3f46775b35
commit
7743c95631
14
inc/format.h
14
inc/format.h
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user