From 437794834f64a2ef2111f9e9437ab876eff4df88 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 3 Apr 2024 23:56:57 +0200 Subject: entity: fix getting enum min/max --- entity/constraints.hpp | 8 ++++++++ test/entity.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/entity/constraints.hpp b/entity/constraints.hpp index c807fddc..6a5587d5 100644 --- a/entity/constraints.hpp +++ b/entity/constraints.hpp @@ -25,6 +25,14 @@ struct limit_traits static constexpr auto max() { return limits::max; } }; +template +requires std::is_enum_v +struct limit_traits +{ + static constexpr T min() { return T(limits>::min); } + static constexpr T max() { return T(limits>::max); } +}; + template struct limit_traits { diff --git a/test/entity.cpp b/test/entity.cpp index 36302662..783721f1 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -281,6 +281,17 @@ void test_range4() fm_assert(r.second == rʹ.max); } +constexpr bool test_enum_range() +{ + enum class E { foo, bar }; + constexpr auto x = TestAccessors{}; + constexpr auto f = entity::type::field("vec"_s, constantly(E::bar), [](auto&&, auto&&) {}); + static_assert(f.read(x) == E::bar); + constexpr auto r = f.get_range(x); + static_assert(r.max != E{0}); + return true; +} + } // namespace void test_app::test_entity() @@ -300,6 +311,7 @@ void test_app::test_entity() test_range2(); static_assert(test_range3()); test_range4(); + static_assert(test_enum_range()); } } // namespace floormat -- cgit v1.2.3