9#include "../microfmt.hpp"
10#include <boost/optional.hpp>
11#include <boost/outcome/result.hpp>
12#include <boost/variant2/variant.hpp>
17template <
typename T>
struct formatter<boost::optional<T>> {
18 microfmt::string_view forwarded_spec{};
22 void format(
const boost::optional<T> &value,
const sink &out)
const noexcept {
31 inner.parse(inner_context);
32 inner.format(*value, out);
37template <
typename... Ts>
struct formatter<boost::variant2::variant<Ts...>> {
38 microfmt::string_view forwarded_spec{};
39 bool show_index{
false};
42 auto spec = ctx.spec();
43 if (!spec.empty() && (spec.front() ==
'i' || spec.front() ==
'#')) {
45 spec.remove_prefix(1);
47 forwarded_spec = spec;
50 void format(
const boost::variant2::variant<Ts...> &value,
const sink &out)
const noexcept {
55 boost::variant2::visit(
56 [
this, &out](
const auto &active)
noexcept {
57 using active_type = std::decay_t<
decltype(active)>;
60 inner.parse(inner_context);
61 inner.format(active, out);
71template <
typename R,
typename S,
typename NoValuePolicy>
72struct formatter<boost::outcome_v2::basic_result<R, S, NoValuePolicy>> {
73 microfmt::string_view forwarded_spec{};
77 void format(
const boost::outcome_v2::basic_result<R, S, NoValuePolicy> &result,
const sink &out)
const noexcept {
78 if (result.has_value()) {
80 if constexpr (!std::is_void_v<R>) {
83 inner.parse(inner_context);
84 inner.format(result.assume_value(), out);
90 if (result.has_error()) {
94 inner.parse(inner_context);
95 inner.format(result.assume_error(), out);
100 out.write(
"NoValue");
Definition microfmt.hpp:881
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