Created
October 1, 2024 01:29
-
-
Save ScatteredRay/a24a2c0f280129e95d447eceaf9850c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<t> struct Meta {}; | |
enum myEnum { | |
Success, | |
Failure | |
}; | |
template<> | |
struct Meta<myEnum> { | |
using type = Meta<myEnum>; | |
static const char* EnumValueToString(myEnum err) { | |
switch(err) { | |
case Success: return "Success"; | |
case Failure: return "Failure"; | |
} | |
} | |
}; | |
template <typename T> struct fmt::formatter<T>: formatter<fmt::string_view> { | |
fmt::format_context::iterator format(T value, fmt::format_context& ctx) const { | |
return fmt::format_to(ctx.out(), fmt::runtime("{}"), MetaType<T>::type::EnumValueToString(value)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment