diff options
-rw-r--r-- | entity/metadata.hpp | 4 | ||||
-rw-r--r-- | test/entity.cpp | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/entity/metadata.hpp b/entity/metadata.hpp index a35e0cc6..dc7d9f1d 100644 --- a/entity/metadata.hpp +++ b/entity/metadata.hpp @@ -211,10 +211,10 @@ constexpr erased_accessor entity_field<Obj, Type, R, W, P>::erased() const return erased_accessor { (void*)&reader, writer ? (void*)&writer : nullptr, - std::is_same_v<P, std::nullptr_t> ? (const void*)&predicate : nullptr, + !std::is_same_v<P, std::nullptr_t> ? (const void*)&predicate : nullptr, name, obj_name, field_name, reader_fn, writer ? writer_fn : writer_stub_fn, - std::is_same_v<P, std::nullptr_t> ? predicate_fn : predicate_stub_fn, + !std::is_same_v<P, std::nullptr_t> ? predicate_fn : predicate_stub_fn, }; } diff --git a/test/entity.cpp b/test/entity.cpp index 858c5a11..5db83974 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -155,6 +155,22 @@ constexpr bool test_null_writer() return true; } +void test_predicate() +{ + constexpr TestAccessors x{0, 0, 0}; + constexpr auto m_foo = entity::type<int>::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo, + [](const TestAccessors&) { return false; }}; + static_assert(!m_foo.is_enabled(m_foo.predicate, x)); + fm_assert(!m_foo.erased().is_enabled(x)); + constexpr auto m_foo2 = entity::type<int>::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo, + [](const TestAccessors&) { return true; }}; + static_assert(m_foo2.is_enabled(m_foo2.predicate, x)); + fm_assert(m_foo2.erased().is_enabled(x)); + constexpr auto m_foo3 = entity::type<int>::field{"foo"_s, &TestAccessors::foo, &TestAccessors::foo}; + static_assert(m_foo3.is_enabled(m_foo3.predicate, x)); + fm_assert(m_foo3.erased().is_enabled(x)); +} + } // namespace static constexpr bool test_names() @@ -179,6 +195,7 @@ void test_app::test_entity() static_assert(test_visitor()); static_assert(test_null_writer()); static_assert(test_names()); + test_predicate(); test_fun2(); test_erasure(); test_type_name(); |