From 8036fdf2a95bc59ba67cd9ee280dddd654a7fd60 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 2 Dec 2022 00:59:09 +0100 Subject: [PATCH] constexpr range --- framework/std_utils/src/mm/scalar_range2.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/std_utils/src/mm/scalar_range2.hpp b/framework/std_utils/src/mm/scalar_range2.hpp index bc230f1..79d16c6 100644 --- a/framework/std_utils/src/mm/scalar_range2.hpp +++ b/framework/std_utils/src/mm/scalar_range2.hpp @@ -7,14 +7,14 @@ struct ScalarRange2 { T v_min {}; T v_max {}; - ScalarRange2(void) = default; + constexpr ScalarRange2(void) = default; - ScalarRange2(const T& both) noexcept { + constexpr ScalarRange2(const T& both) noexcept { v_min = both; v_max = both; } - ScalarRange2(const T& min, const T& max) noexcept { + constexpr ScalarRange2(const T& min, const T& max) noexcept { if (min <= max) { v_min = min; v_max = max; @@ -24,19 +24,19 @@ struct ScalarRange2 { } } - bool operator==(const ScalarRange2& rhs) const { + constexpr bool operator==(const ScalarRange2& rhs) const { return min() == rhs.min() && max() == rhs.max(); } - bool operator!=(const ScalarRange2& rhs) const { + constexpr bool operator!=(const ScalarRange2& rhs) const { return !(*this == rhs); } - [[nodiscard]] T& min(void) { return v_min; } - [[nodiscard]] T& max(void) { return v_max; } + [[nodiscard]] constexpr T& min(void) { return v_min; } + [[nodiscard]] constexpr T& max(void) { return v_max; } - [[nodiscard]] const T& min(void) const { return v_min; } - [[nodiscard]] const T& max(void) const { return v_max; } + [[nodiscard]] constexpr const T& min(void) const { return v_min; } + [[nodiscard]] constexpr const T& max(void) const { return v_max; } void setMin(const T& new_min) { min() = new_min; @@ -57,7 +57,7 @@ struct ScalarRange2 { } } - [[nodiscard]] bool inRange(T&& value) const { + [[nodiscard]] constexpr bool inRange(T&& value) const { return value >= min() && value <= max(); } };