From 0bb7d39ccc93b8ba0c0da3ffc5210759c6a5685b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 19 Nov 2022 12:46:03 +0100 Subject: entity: move concepts out to another file --- entity/metadata.hpp | 92 +---------------------------------------------------- 1 file changed, 1 insertion(+), 91 deletions(-) (limited to 'entity/metadata.hpp') diff --git a/entity/metadata.hpp b/entity/metadata.hpp index cbfcd38a..d1ecfa71 100644 --- a/entity/metadata.hpp +++ b/entity/metadata.hpp @@ -3,8 +3,8 @@ #include "accessor.hpp" #include "constraints.hpp" #include "util.hpp" +#include "concepts.hpp" #include -#include #include #include #include @@ -15,98 +15,8 @@ namespace floormat::entities { -template -concept FieldReader_memfn = requires(const T x, F f) { - { (x.*f)() } -> std::convertible_to; -}; - -template -concept FieldReader_ptr = requires(const T x, F f) { - { x.*f } -> std::convertible_to; -}; - -template -concept FieldReader_function = requires(const T x, F f) { - { f(x) } -> std::convertible_to; -}; - -template -concept FieldReader = requires { - requires FieldReader_memfn || - FieldReader_ptr || - FieldReader_function; -}; - -template -concept FieldWriter_memfn = requires(T x, move_qualified value, F f) { - { (x.*f)(value) } -> std::same_as; -}; - -template -concept FieldWriter_ptr = requires(T x, move_qualified value, F f) { - { x.*f = value }; -}; - -template -concept FieldWriter_function = requires(T x, move_qualified value, F f) { - { f(x, value) } -> std::same_as; -}; - -template -concept FieldWriter = requires { - requires FieldWriter_memfn || - FieldWriter_ptr || - FieldWriter_function || - std::same_as; -}; - namespace detail { -template R> -struct read_field { - static constexpr Type read(const Obj& x, R r) { return r(x); } -}; - -template -struct read_field { - static constexpr Type read(const Obj& x, Type (Obj::*r)() const) { return (x.*r)(); } -}; - -template -struct read_field { - static constexpr Type read(const Obj& x, Type Obj::*r) { return x.*r; } -}; - -template -struct read_field) const>> -{ - template static constexpr Type read(const Obj& x, F&& fun) { return fun(x); } -}; - -template W> struct write_field { - static constexpr void write(Obj& x, W w, move_qualified value) { w(x, value); } -}; - -template -struct write_field)> { - static constexpr void write(Obj& x, void(Obj::*w)(move_qualified), move_qualified value) { (x.*w)(value); } -}; - -template -struct write_field { - static constexpr void write(Obj& x, FieldType Obj::* w, move_qualified value) { x.*w = value; } -}; - -template -struct write_field) const>> { - template static constexpr void write(Obj& x, F&& fun, move_qualified value) { fun(x, value); } -}; - -template -struct write_field { - static constexpr void write(Obj&, std::nullptr_t, move_qualified) { fm_abort("no writing for this accessor"); } -}; - template requires std::invocable(std::declval()))> constexpr CORRADE_ALWAYS_INLINE void visit_tuple(F&& fun, Tuple&& tuple) -- cgit v1.2.3