Skip to content

Commit

Permalink
mod: trying to fix AppleClang 14 error
Browse files Browse the repository at this point in the history
````
error: sorry, non-type template argument of type 'float' is not yet supported
    static_limiter<float, .0001f, .1f> time_step              = .01f;
````
  • Loading branch information
quesnel committed Mar 21, 2024
1 parent 72c13af commit eeacb63
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
35 changes: 34 additions & 1 deletion lib/include/irritator/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef ORG_VLEPROJECT_IRRITATOR_HELPERS_2023
#define ORG_VLEPROJECT_IRRITATOR_HELPERS_2023

#include <concepts>
#include <irritator/core.hpp>
#include <irritator/error.hpp>

Expand All @@ -31,9 +32,9 @@ struct limiter {
};

template<typename T, T Lower, T Upper>
requires std::integral<T>
class static_limiter
{
static_assert(std::is_arithmetic_v<T>);
static_assert(Lower < Upper);

T m_value;
Expand All @@ -58,6 +59,38 @@ class static_limiter
operator T() const noexcept { return m_value; }
};

template<typename T, int LowerNum, int LowerDenom, int UpperNum, int UpperDenom>
requires std::floating_point<T>
class floating_point_limiter
{
static inline constexpr T lower =
static_cast<T>(LowerNum) / static_cast<T>(LowerDenom);
static inline constexpr T upper =
static_cast<T>(UpperNum) / static_cast<T>(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<typename>
struct is_result : std::false_type {};

Expand Down
6 changes: 3 additions & 3 deletions lib/include/irritator/modeling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ class variable_simulation_observer

vector<observer_id> observers;

static_limiter<i32, 8, 512> raw_buffer_size = 64;
static_limiter<i32, 1024, 65536> linearized_buffer_size = 32768;
static_limiter<float, .0001f, .1f> time_step = .01f;
static_limiter<i32, 8, 512> raw_buffer_size = 64;
static_limiter<i32, 1024, 65536> linearized_buffer_size = 32768;
floating_point_limiter<float, 1, 10000, 1, 10> time_step = .01f;

variable_observer_id id = undefined<variable_observer_id>();
};
Expand Down

0 comments on commit eeacb63

Please sign in to comment.