73 template <comppare::
internal::concepts::Streamable T>
102 std::ios saved(
nullptr);
105 std::ostringstream tmp;
110 tmp << comppare::internal::ansi::RED(mv.
value_);
112 tmp << comppare::internal::ansi::RED(mv.
err_msg_);
113 std::string body = std::move(tmp).str();
134 template <
typename U>
148 template <
typename M>
156 template <
typename M>
191 template <
typename Val,
typename EP>
195 { EP::metric_count() } -> std::convertible_to<std::size_t>;
196 { EP::metric_name(std::size_t{}) } -> std::convertible_to<std::string_view>;
199 (
requires(EP ep,
const Val &a,
const Val &b) { ep.compute_error(a, b); }) &&
201 (
requires(EP ep, std::size_t i) {
202 { ep.metric(i) } -> IsMetricValue; } ||
requires(EP ep, std::size_t i) {
203 { ep.metric(i) } -> std::convertible_to<double>; } ||
requires(EP ep, std::size_t i) {
204 { ep.metric(i) } -> std::same_as<std::string>; }) &&
207 { ep.is_fail() } -> std::convertible_to<bool>; });
218 template <
class EP,
class V>
221 ep.compute_error(a, b);
253 template <
typename T>
271 template <
typename T>
281 static constexpr std::array
names{
"Total|err|"};
286 if constexpr (!std::is_floating_point_v<T>)
289 tolerance_ =
static_cast<T
>(comppare::config::fp_tolerance<double>());
294 tolerance_ = comppare::config::fp_tolerance<T>();
312 if constexpr (std::is_floating_point_v<T>)
314 if (!std::isfinite(a) || !std::isfinite(b))
316 error_ = std::numeric_limits<T>::quiet_NaN();
323 T e = std::abs(a - b);
340 static constexpr std::array
names{
"Equal?"};
366 template <
typename R>
370 using T = std::remove_cvref_t<std::ranges::range_value_t<R>>;
382 static constexpr std::array
names{
"Max|err|",
"Mean|err|",
"Total|err|"};
405 if constexpr (!std::is_floating_point_v<T>)
408 tolerance_ =
static_cast<T>(comppare::config::fp_tolerance<double>());
413 tolerance_ = comppare::config::fp_tolerance<T>();
433 throw std::out_of_range(
"Invalid metric index");
453 if (std::ranges::size(a) != std::ranges::size(b))
462 auto ia = std::ranges::begin(a);
463 auto ib = std::ranges::begin(b);
464 for (; ia != std::ranges::end(a) && ib != std::ranges::end(b); ++ia, ++ib)
466 if constexpr (std::is_floating_point_v<T>)
468 if (!std::isfinite(*ia) || !std::isfinite(*ib))
470 max_error_ = std::numeric_limits<T>::quiet_NaN();
481 T e = std::abs(*ia - *ib);
500 template <
typename T>
508 template <
typename T>
520 template <
typename T>
532 template <
typename T>
544 template <
typename T>
This file contains utilities for applying ANSI styles and colors to console output.
Wrapper for a value that can be streamed to an output stream.
Definition policy.hpp:75
T value_
Definition policy.hpp:76
MetricValue(T v, bool is_fail, bool valid, std::string_view msg)
Definition policy.hpp:85
MetricValue(T v)
Definition policy.hpp:83
bool is_fail_
Definition policy.hpp:77
bool valid_
Definition policy.hpp:79
MetricValue(T v, bool is_fail)
Definition policy.hpp:84
friend std::ostream & operator<<(std::ostream &os, MetricValue< T > const &mv)
Overloaded operator<< to stream the value or error message.
Definition policy.hpp:100
std::string_view err_msg_
Definition policy.hpp:80
Concept for types supported by automatic error policy selection.
Definition policy.hpp:274
std::string err_msg_
Definition policy.hpp:276
bool valid_
Definition policy.hpp:278
MetricValue< T > metric(std::size_t) const
Definition policy.hpp:303
T error_
Definition policy.hpp:275
bool is_fail() const
Definition policy.hpp:308
T tolerance_
Definition policy.hpp:279
ArithmeticErrorPolicy()
Definition policy.hpp:284
bool fail_
Definition policy.hpp:277
static constexpr std::size_t metric_count()
Definition policy.hpp:300
void compute_error(const T &a, const T &b)
Definition policy.hpp:310
static constexpr std::array names
Definition policy.hpp:281
~ArithmeticErrorPolicy()=default
static constexpr std::string_view metric_name(std::size_t)
Definition policy.hpp:301
Error policy for ranges of arithmetic types.
Definition policy.hpp:369
T max_error_
Definition policy.hpp:372
T tolerance_
Definition policy.hpp:380
std::size_t elem_cnt_
Definition policy.hpp:374
std::remove_cvref_t< std::ranges::range_value_t< R > > T
Definition policy.hpp:370
MetricValue< T > metric(std::size_t i) const
Definition policy.hpp:422
static constexpr std::size_t metric_count()
Definition policy.hpp:419
MetricValue< T > get_mean() const
Definition policy.hpp:389
bool valid_
Indicates if the current error state is a failure.
Definition policy.hpp:377
MetricValue< T > get_max() const
Definition policy.hpp:384
RangeErrorPolicy()
Definition policy.hpp:403
std::string err_msg_
Indicates if the current error state is valid.
Definition policy.hpp:378
void compute_error(const R &a, const R &b)
Definition policy.hpp:451
T total_error_
Definition policy.hpp:373
MetricValue< T > get_total() const
Definition policy.hpp:397
bool is_fail() const
Checks if the current error state is a failure.
Definition policy.hpp:443
~RangeErrorPolicy()=default
static constexpr std::string_view metric_name(std::size_t i)
Definition policy.hpp:420
static constexpr std::array names
Definition policy.hpp:382
bool fail_
Definition policy.hpp:376
Error policy for std::string. Compares two strings for equality.
Definition policy.hpp:337
static constexpr std::size_t metric_count()
Definition policy.hpp:346
StringEqualPolicy()=default
~StringEqualPolicy()=default
bool eq_
Definition policy.hpp:338
void compute_error(const std::string &a, const std::string &b)
Definition policy.hpp:356
static constexpr std::string_view metric_name(std::size_t)
Definition policy.hpp:347
static constexpr std::array names
Definition policy.hpp:340
bool is_fail() const
Definition policy.hpp:354
MetricValue< std::string > metric(std::size_t) const
Definition policy.hpp:349
Concept for an arithmetic type (either floating-point or integral).
Definition concepts.hpp:78
Concept for a range of arithmetic types, excluding strings.
Definition concepts.hpp:103
Concept for a string type.
Definition concepts.hpp:87
Concept for a valid Error Policy.
Definition policy.hpp:192
Concept for a MetricValue.
Definition policy.hpp:157
Concept for types supported by automatic error policy selection.
Definition policy.hpp:254
This file contains commonly used concepts internally within the ComPPare library.
typename AutoPolicy< T >::type AutoPolicy_t
Helper alias to get the automatic error policy type for a given type T.
Definition policy.hpp:545
bool is_fail(const EP &ep)
Wrapper function to check if the error policy indicates a failure.
Definition policy.hpp:232
constexpr bool is_metric_value_v
Checks if a type is a MetricValue.
Definition policy.hpp:149
void compute_error(EP &ep, const V &a, const V &b)
Wrapper function to compute the error using the given instance of the error policy.
Definition policy.hpp:219
AutoPolicy is a empty struct with alias type to deduce the appropriate error policy.
Definition policy.hpp:501
Partial specialisation for not a MetricValue.
Definition policy.hpp:128