Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Created October 1, 2024 01:29
Show Gist options
  • Save ScatteredRay/a24a2c0f280129e95d447eceaf9850c9 to your computer and use it in GitHub Desktop.
Save ScatteredRay/a24a2c0f280129e95d447eceaf9850c9 to your computer and use it in GitHub Desktop.
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