From b3fb025053bb06ee1d044690dc5f268042231f9d Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 4 Sep 2023 11:15:33 +0200 Subject: [PATCH] feat(example): text output added to `validated_type` and `ranged_representation` --- example/include/ranged_representation.h | 10 ++++++++++ example/include/validated_type.h | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/example/include/ranged_representation.h b/example/include/ranged_representation.h index 60bab6fe..d0a725a9 100644 --- a/example/include/ranged_representation.h +++ b/example/include/ranged_representation.h @@ -24,6 +24,7 @@ #include "validated_type.h" #include +#include #include #include #include @@ -53,3 +54,12 @@ public: template inline constexpr bool mp_units::is_scalar> = mp_units::is_scalar; + +template +struct MP_UNITS_STD_FMT::formatter> : formatter { + template + auto format(const ranged_representation& v, FormatContext& ctx) + { + return formatter::format(v.value(), ctx); + } +}; diff --git a/example/include/validated_type.h b/example/include/validated_type.h index 8692a9b3..2cf8cc71 100644 --- a/example/include/validated_type.h +++ b/example/include/validated_type.h @@ -24,6 +24,8 @@ #include #include +#include +#include #include inline constexpr struct validated_tag { @@ -97,3 +99,22 @@ public: requires std::three_way_comparable = default; }; + + +template +std::basic_ostream& operator<<(std::basic_ostream& os, + const validated_type& v) + requires requires { os << v.value(); } +{ + return os << v.value(); +} + + +template +struct MP_UNITS_STD_FMT::formatter> : formatter { + template + auto format(const validated_type& v, FormatContext& ctx) + { + return formatter::format(v.value(), ctx); + } +};