summaryrefslogtreecommitdiffhomepage
path: root/entity
diff options
context:
space:
mode:
Diffstat (limited to 'entity')
-rw-r--r--entity/accessor.hpp1
-rw-r--r--entity/entity.hpp9
2 files changed, 9 insertions, 1 deletions
diff --git a/entity/accessor.hpp b/entity/accessor.hpp
index 9b836420..a097afd4 100644
--- a/entity/accessor.hpp
+++ b/entity/accessor.hpp
@@ -40,6 +40,7 @@ struct erased_accessor final {
template<typename Obj, typename FieldType> requires std::is_default_constructible_v<FieldType> FieldType read(const Obj& x) const noexcept;
template<typename Obj, typename FieldType> void read(const Obj& x, FieldType& value) const noexcept;
template<typename Obj, typename FieldType> void write(Obj& x, move_qualified<FieldType> value) const noexcept;
+ constexpr bool can_write() const noexcept { return writer != nullptr; }
};
template<typename T, typename FieldType>
diff --git a/entity/entity.hpp b/entity/entity.hpp
index 4eca858e..30c75c15 100644
--- a/entity/entity.hpp
+++ b/entity/entity.hpp
@@ -56,7 +56,8 @@ template<typename F, typename T, typename FieldType>
concept FieldWriter = requires {
requires FieldWriter_memfn<F, T, FieldType> ||
FieldWriter_ptr<F, T, FieldType> ||
- FieldWriter_function<F, T, FieldType>;
+ FieldWriter_function<F, T, FieldType> ||
+ std::same_as<F, std::nullptr_t>;
};
namespace detail {
@@ -100,6 +101,11 @@ struct write_field<Obj, Type, fu2::function_base<IsOwning, IsCopyable, Capacity,
template<typename F> static constexpr void write(Obj& x, F&& fun, move_qualified<Type> value) { fun(x, value); }
};
+template<typename Obj, typename FieldType>
+struct write_field<Obj, FieldType, std::nullptr_t> {
+ static constexpr void write(Obj&, std::nullptr_t, move_qualified<FieldType>) { fm_abort("no writing for this accessor"); }
+};
+
template<typename F, typename Tuple, std::size_t N>
requires std::invocable<F, decltype(std::get<N>(std::declval<Tuple>()))>
constexpr CORRADE_ALWAYS_INLINE void visit_tuple(F&& fun, Tuple&& tuple)
@@ -152,6 +158,7 @@ struct entity_field : entity_field_base<Obj, Type> {
static constexpr void write(const W& writer, Obj& x, move_qualified<Type> v) { detail::write_field<Obj, Type, W>::write(x, writer, v); }
constexpr decltype(auto) read(const Obj& x) const { return read(reader, x); }
constexpr void write(Obj& x, move_qualified<Type> value) const { write(writer, x, value); }
+ static constexpr bool can_write = !std::is_same_v<std::nullptr_t, decltype(entity_field<Obj, Type, R, W>::writer)>;
constexpr entity_field(StringView name, R r, W w) noexcept : name{name}, reader{r}, writer{w} {}
constexpr erased_accessor erased() const;
};