Value:template <> struct std::formatter<CLASS_NAME> : std::formatter<std::string_view> \
{ \
template <typename FormatContext> \
auto format(const CLASS_NAME& item, FormatContext& ctx) const \
{ \
return std::formatter<std::string_view>::format(item.to_string(), ctx); \
} \
}; \
\
template <> \
struct std::formatter<CLASS_NAME, wchar_t> : std::formatter<std::wstring_view, wchar_t> \
{ \
template <typename FormatContext> \
auto format(const CLASS_NAME& item, FormatContext& ctx) const \
{ \
auto str = item.to_string(); \
return std::formatter<std::wstring_view, wchar_t>::format(wstr, ctx); \
} \
};
static auto to_wstring(const std::string &value) -> std::tuple< std::optional< std::wstring >, std::optional< std::string > >
Converts a std::string (system-encoded) to a std::wstring.
Generates std::formatter specializations for narrow and wide characters.
This macro creates two formatter specializations:
- std::formatter<CLASS_NAME> for narrow character formatting
- std::formatter<CLASS_NAME, wchar_t> for wide character formatting
Requirements:
- The class must have a to_string() method that returns std::string
- The convert_string::to_wstring function must be available
- Parameters
-
| CLASS_NAME | The fully qualified class name (including namespace if any) |
Definition at line 43 of file formatter_macros.h.
43#define DECLARE_FORMATTER(CLASS_NAME) \
44template <> struct std::formatter<CLASS_NAME> : std::formatter<std::string_view> \
45{ \
46 template <typename FormatContext> \
47 auto format(const CLASS_NAME& item, FormatContext& ctx) const \
48 { \
49 return std::formatter<std::string_view>::format(item.to_string(), ctx); \
50 } \
51}; \
52 \
53template <> \
54struct std::formatter<CLASS_NAME, wchar_t> : std::formatter<std::wstring_view, wchar_t> \
55{ \
56 template <typename FormatContext> \
57 auto format(const CLASS_NAME& item, FormatContext& ctx) const \
58 { \
59 auto str = item.to_string(); \
60 auto wstr = utility_module::convert_string::to_wstring(str); \
61 return std::formatter<std::wstring_view, wchar_t>::format(wstr, ctx); \
62 } \
63};