From d94d56bb395f64a819c72fe5d09228ec31e0dd93 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 19 Nov 2022 13:34:39 +0100 Subject: entity: wip constraints --- entity/constraints.hpp | 2 +- entity/metadata.hpp | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'entity') diff --git a/entity/constraints.hpp b/entity/constraints.hpp index f629b149..f8434bd7 100644 --- a/entity/constraints.hpp +++ b/entity/constraints.hpp @@ -50,7 +50,7 @@ template constexpr std::pair range::convert() const } struct length final { - std::size_t value = (std::size_t)-1; + std::size_t value = std::numeric_limits::max(); }; struct group final { diff --git a/entity/metadata.hpp b/entity/metadata.hpp index a402a2a3..8bd36cb8 100644 --- a/entity/metadata.hpp +++ b/entity/metadata.hpp @@ -65,6 +65,9 @@ template struct find_reader { using type = F; static constexpr std::size_t index = I; }; +template +using find_reader2 = find_reader; + template constexpr auto constantly = [](const Obj&) constexpr { return constant; }; @@ -80,9 +83,9 @@ private: static constexpr auto default_predicate = detail::constantly; using default_predicate_t = std::decay_t; using c_predicate = detail::find_reader; - using c_range = detail::find_reader, constraints::range, 0, Ts...>; - using c_length = detail::find_reader; - using c_group = detail::find_reader; + using c_range = detail::find_reader2, Ts...>; + using c_length = detail::find_reader2; + using c_group = detail::find_reader2; static constexpr std::size_t good_arguments = unsigned(c_predicate::index != sizeof...(Ts)) + unsigned(c_range::index != sizeof...(Ts)) + @@ -96,14 +99,17 @@ public: using Reader = R; using Writer = W; using Predicate = typename c_predicate::type; + using Range = typename c_range::type; + using Length = typename c_length::type; + using Group = typename c_group::type; StringView name; [[no_unique_address]] R reader; [[no_unique_address]] W writer; [[no_unique_address]] Predicate predicate; - [[no_unique_address]] c_range range; - [[no_unique_address]] c_length length; - [[no_unique_address]] c_group group; + [[no_unique_address]] Range range; + [[no_unique_address]] Length length; + [[no_unique_address]] Group group; constexpr entity_field(const entity_field&) = default; constexpr entity_field& operator=(const entity_field&) = default; @@ -115,7 +121,10 @@ public: static constexpr field_status is_enabled(const Predicate & p, const Obj& x); constexpr entity_field(StringView name, R r, W w, Ts&&... ts) noexcept : name{name}, reader{r}, writer{w}, - predicate{std::get(std::forward_as_tuple(ts..., default_predicate))} + predicate{std::get(std::forward_as_tuple(ts..., default_predicate))}, + range{std::get(std::forward_as_tuple(ts..., constraints::range{}))}, + length{std::get(std::forward_as_tuple(ts..., constraints::length{}))}, + group{std::get(std::forward_as_tuple(ts..., constraints::group{}))} {} constexpr erased_accessor erased() const; }; -- cgit v1.2.3