mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-07 14:14:27 +02:00
feat(example): text output added to validated_type
and ranged_representation
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "validated_type.h"
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
#include <mp-units/bits/fmt.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#include <algorithm>
|
||||
#include <concepts>
|
||||
@@ -53,3 +54,12 @@ public:
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
inline constexpr bool mp_units::is_scalar<ranged_representation<T, Min, Max>> = mp_units::is_scalar<T>;
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
struct MP_UNITS_STD_FMT::formatter<ranged_representation<T, Min, Max>> : formatter<T> {
|
||||
template<typename FormatContext>
|
||||
auto format(const ranged_representation<T, Min, Max>& v, FormatContext& ctx)
|
||||
{
|
||||
return formatter<T>::format(v.value(), ctx);
|
||||
}
|
||||
};
|
||||
|
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <gsl/gsl-lite.hpp>
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
#include <mp-units/bits/fmt.h>
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
inline constexpr struct validated_tag {
|
||||
@@ -97,3 +99,22 @@ public:
|
||||
requires std::three_way_comparable<T>
|
||||
= default;
|
||||
};
|
||||
|
||||
|
||||
template<typename CharT, typename Traits, typename T, typename Validator>
|
||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
|
||||
const validated_type<T, Validator>& v)
|
||||
requires requires { os << v.value(); }
|
||||
{
|
||||
return os << v.value();
|
||||
}
|
||||
|
||||
|
||||
template<typename T, typename Validator>
|
||||
struct MP_UNITS_STD_FMT::formatter<validated_type<T, Validator>> : formatter<T> {
|
||||
template<typename FormatContext>
|
||||
auto format(const validated_type<T, Validator>& v, FormatContext& ctx)
|
||||
{
|
||||
return formatter<T>::format(v.value(), ctx);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user