From c5b5756b4d65202d1252619d3e181ea6867c2add Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 29 Mar 2023 16:47:39 +0200 Subject: [PATCH] refactor(example): constraints added to `ranged_representation` --- example/include/ranged_representation.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/example/include/ranged_representation.h b/example/include/ranged_representation.h index 3d7b2a88..2aebf72b 100644 --- a/example/include/ranged_representation.h +++ b/example/include/ranged_representation.h @@ -25,21 +25,26 @@ #include "validated_type.h" #include #include +#include #include -template +template auto Min, std::convertible_to auto Max> inline constexpr auto is_in_range = [](const auto& v) { return std::clamp(v, T{Min}, T{Max}) == v; }; -template +template auto Min, std::convertible_to auto Max> using is_in_range_t = decltype(is_in_range); -template +template auto Min, std::convertible_to auto Max> class ranged_representation : public validated_type> { public: using validated_type>::validated_type; constexpr ranged_representation() : validated_type>(T{}) {} - [[nodiscard]] constexpr ranged_representation operator-() const { return ranged_representation(-this->value()); } + [[nodiscard]] constexpr ranged_representation operator-() const + requires requires(T t) { -t; } + { + return ranged_representation(-this->value()); + } }; template