56#include "../microfmt.hpp"
59#if RELOCO_HAS_REFLECTION
67template <
typename E>
inline constexpr bool is_reflect_formattable_enum_v = std::is_enum_v<E>;
70inline constexpr bool is_reflect_formattable_struct_v = std::is_class_v<T> && enable_reflect_format<T>::value;
79template <
typename E>
struct formatter<E, std::enable_if_t<detail::is_reflect_formattable_enum_v<E>>> {
80 constexpr void parse(format_parse_context &ctx)
noexcept { (void)ctx; }
82 void format(E val,
const sink &out)
const noexcept {
83 template for (
constexpr auto e : define_static_array(std::meta::enumerators_of(^^E))) {
84 constexpr auto enumerator_value = [:e:];
85 if (val == enumerator_value) {
86 constexpr std::string_view name = std::meta::identifier_of(e);
87 out.write(microfmt::string_view(name.data(), name.size()));
93 format_to(out,
"{}",
static_cast<std::underlying_type_t<E>
>(val));
100template <
typename T>
struct formatter<T, std::enable_if_t<detail::is_reflect_formattable_struct_v<T>>> {
101 constexpr void parse(format_parse_context &ctx)
noexcept { (void)ctx; }
103 void format(
const T &val,
const sink &out)
const noexcept {
107 template for (
constexpr auto member : define_static_array(
108 std::meta::nonstatic_data_members_of(^^T, std::meta::access_context::current()))) {
114 constexpr std::string_view name = std::meta::identifier_of(member);
115 out.write(microfmt::string_view(name.data(), name.size()));
Definition bintime.hpp:22
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
RELOCO_CONSTEXPR20 void format_to(const sink &out, microfmt::string_view fmt, const Args &...args) noexcept
Definition microfmt.hpp:1766
RELOCO_CONSTEXPR20 buffer_sink< N > format(microfmt::string_view fmt, const Args &...args) noexcept
Definition microfmt.hpp:1786
Always-safe reflection opt-in markers: MICROFMT_REFLECT_FORMAT, MICROFMT_REFLECT_DUMP_ENUM,...