3#include <boost/describe.hpp>
8template <wren::DescribedStruct T>
9struct std::formatter<T, char> {
10 constexpr auto parse(std::format_parse_context& ctx) {
11 auto it = ctx.begin(), end = ctx.end();
13 if (it != end && *it !=
'}') {
14 throw std::runtime_error(
"invalid format");
20 auto format(
const T& t, format_context& ctx)
const {
21 using namespace boost::describe;
23 using Bd = describe_bases<T, mod_any_access>;
24 using Md = describe_members<T, mod_any_access>;
32 boost::mp11::mp_for_each<Bd>([&](
auto d) {
39 out = std::format_to(out,
" {}", t);
42 boost::mp11::mp_for_each<Md>([&](
auto d) {
49 out = std::format_to(out,
" .{}={}", d.name, t.*d.pointer);
62template <wren::DescribedEnum T>
63struct std::formatter<T, char> {
65 using U = std::underlying_type_t<T>;
67 std::formatter<std::string_view, char>
sf_;
68 std::formatter<U, char>
nf_;
71 constexpr auto parse(format_parse_context& ctx) {
72 auto i1 =
sf_.parse(ctx);
73 auto i2 =
nf_.parse(ctx);
76 throw std::runtime_error(
"invalid format");
82 auto format(
const T& t, format_context& ctx)
const {
83 const char* s = boost::describe::enum_to_string(t, 0);
86 return sf_.format(s, ctx);
88 return nf_.format(
static_cast<U>(t), ctx);