diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-05 08:08:24 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-05 08:08:24 +0100 |
commit | b29f30b6d1fe1e4fc366d094dd6072321ea0ae38 (patch) | |
tree | 39bbef83ab4914b9d1408b6c4cc7f4df5e733386 /entity | |
parent | 98da53beb78d9a617a1c66b404e9a7d8469a443a (diff) |
entity: workaround clion + gcc-14 clangd bug
Diffstat (limited to 'entity')
-rw-r--r-- | entity/constraints.hpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/entity/constraints.hpp b/entity/constraints.hpp index 6ebf2d90..c90353ac 100644 --- a/entity/constraints.hpp +++ b/entity/constraints.hpp @@ -19,18 +19,27 @@ template<typename T> struct range template<typename T> range(T min, T max) -> range<T>; +template<typename T> constexpr erased_constraints::range erased_range_from_range(T, T) +{ return { {}, {}, erased_constraints::range::type_none }; } + +template<typename T> +requires (std::is_floating_point_v<T> && !std::is_integral_v<T>) +constexpr erased_constraints::range erased_range_from_range(T min, T max) +{ return { { .f = min }, { .f = max }, erased_constraints::range::type_::type_float }; } + +template<typename T> +requires (std::is_integral_v<T> && std::is_unsigned_v<T> && !std::is_floating_point_v<T>) +constexpr erased_constraints::range erased_range_from_range(T min, T max) +{ return { { .u = min }, { .u = max }, erased_constraints::range::type_::type_uint }; } + +template<typename T> +requires (std::is_integral_v<T> && std::is_signed_v<T> && !std::is_floating_point_v<T>) +constexpr erased_constraints::range erased_range_from_range(T min, T max) +{ return { { .i = min }, { .i = max }, erased_constraints::range::type_::type_int }; } + template<typename T> constexpr range<T>::operator erased_constraints::range() const noexcept -{ - using enum erased_constraints::range::type_; - if constexpr (std::is_floating_point_v<T>) - return { { .f = min }, { .f = max }, type_float }; - if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) - return { {.u = min}, {.u = max}, type_uint }; - if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) - return { {.i = min}, {.i = max}, type_int }; - return { {}, {}, type_none }; -} +{ return erased_range_from_range(min, max); } template<typename T> constexpr range<T>::operator std::pair<T, T>() const noexcept { return { min, max }; } |