From eeacb63f0c93e5cb4d039d9f0cc9ff47b946ddf8 Mon Sep 17 00:00:00 2001 From: Gauthier Quesnel Date: Thu, 21 Mar 2024 15:40:01 +0100 Subject: [PATCH] mod: trying to fix AppleClang 14 error ```` error: sorry, non-type template argument of type 'float' is not yet supported static_limiter time_step = .01f; ```` --- lib/include/irritator/helpers.hpp | 35 +++++++++++++++++++++++++++++- lib/include/irritator/modeling.hpp | 6 ++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/include/irritator/helpers.hpp b/lib/include/irritator/helpers.hpp index 59017211..00045387 100644 --- a/lib/include/irritator/helpers.hpp +++ b/lib/include/irritator/helpers.hpp @@ -5,6 +5,7 @@ #ifndef ORG_VLEPROJECT_IRRITATOR_HELPERS_2023 #define ORG_VLEPROJECT_IRRITATOR_HELPERS_2023 +#include #include #include @@ -31,9 +32,9 @@ struct limiter { }; template + requires std::integral class static_limiter { - static_assert(std::is_arithmetic_v); static_assert(Lower < Upper); T m_value; @@ -58,6 +59,38 @@ class static_limiter operator T() const noexcept { return m_value; } }; +template + requires std::floating_point +class floating_point_limiter +{ + static inline constexpr T lower = + static_cast(LowerNum) / static_cast(LowerDenom); + static inline constexpr T upper = + static_cast(UpperNum) / static_cast(UpperDenom); + static_assert(lower < upper); + + T m_value; + +public: + constexpr floating_point_limiter(const T value) noexcept + : m_value(std::clamp(value, lower, upper)) + {} + + static constexpr bool is_valid(const T value) noexcept + { + return lower <= value && value <= upper; + } + + void set(const T value) noexcept + { + m_value = std::clamp(value, lower, upper); + } + + T value() const noexcept { return m_value; } + operator T() noexcept { return m_value; } + operator T() const noexcept { return m_value; } +}; + template struct is_result : std::false_type {}; diff --git a/lib/include/irritator/modeling.hpp b/lib/include/irritator/modeling.hpp index c115c733..68a1710b 100644 --- a/lib/include/irritator/modeling.hpp +++ b/lib/include/irritator/modeling.hpp @@ -705,9 +705,9 @@ class variable_simulation_observer vector observers; - static_limiter raw_buffer_size = 64; - static_limiter linearized_buffer_size = 32768; - static_limiter time_step = .01f; + static_limiter raw_buffer_size = 64; + static_limiter linearized_buffer_size = 32768; + floating_point_limiter time_step = .01f; variable_observer_id id = undefined(); };