From 3a5cab9eaa32db9b47328dc891e6d9726d57aa02 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 10 Aug 2023 09:44:35 +0700 Subject: [PATCH] new way to bind metadata and arguments --- .../manuals/meta_manuals/metadata_manual.cpp | 30 +- develop/singles/headers/meta.hpp/meta_all.hpp | 839 ++++++++++-------- develop/untests/meta_base/type_list_tests.cpp | 49 + develop/untests/meta_states/dtor_tests.cpp | 6 +- .../untests/meta_states/function2_tests.cpp | 4 +- .../untests/meta_states/metadata_tests.cpp | 96 +- develop/untests/meta_states/method2_tests.cpp | 2 +- develop/untests/meta_states/scope_tests.cpp | 19 +- headers/meta.hpp/meta_base.hpp | 1 + headers/meta.hpp/meta_base/overloaded.hpp | 20 + headers/meta.hpp/meta_base/type_list.hpp | 34 + headers/meta.hpp/meta_binds.hpp | 141 +-- headers/meta.hpp/meta_binds/class_bind.hpp | 326 ++++--- headers/meta.hpp/meta_binds/enum_bind.hpp | 25 +- headers/meta.hpp/meta_binds/scope_bind.hpp | 110 ++- headers/meta.hpp/meta_states.hpp | 162 ++-- headers/meta.hpp/meta_states/constructor.hpp | 6 +- headers/meta.hpp/meta_states/function.hpp | 6 +- headers/meta.hpp/meta_states/member.hpp | 6 +- headers/meta.hpp/meta_states/method.hpp | 6 +- headers/meta.hpp/meta_states/variable.hpp | 6 +- 21 files changed, 1081 insertions(+), 813 deletions(-) create mode 100644 develop/untests/meta_base/type_list_tests.cpp create mode 100644 headers/meta.hpp/meta_base/overloaded.hpp diff --git a/develop/manuals/meta_manuals/metadata_manual.cpp b/develop/manuals/meta_manuals/metadata_manual.cpp index b57fd7a..0f81a82 100644 --- a/develop/manuals/meta_manuals/metadata_manual.cpp +++ b/develop/manuals/meta_manuals/metadata_manual.cpp @@ -36,29 +36,25 @@ TEST_CASE("meta/meta_manuals/metadata") { meta::class_(meta::metadata_() // for class type ("tooltip", "3D Vector"s) ) - .member_("x", &ivec3::x, { - .metadata = meta::metadata_() // for class members - ("tooltip", "X-Coordinate"s) - }) - .member_("y", &ivec3::y, { - .metadata = meta::metadata_() - ("tooltip", "Y-Coordinate"s) - }) - .member_("z", &ivec3::z, { - .metadata = meta::metadata_() - ("tooltip", "Z-Coordinate"s) - }); + .member_("x", &ivec3::x, meta::metadata_() // for class members + ("tooltip", "X-Coordinate"s) + ) + .member_("y", &ivec3::y, meta::metadata_() + ("tooltip", "Y-Coordinate"s) + ) + .member_("z", &ivec3::z, meta::metadata_() + ("tooltip", "Z-Coordinate"s) + ); const meta::scope math_scope = meta::local_scope_("math") .typedef_("ivec3") - .function_("cross", &cross, { - .arguments = meta::arguments_() + .function_("cross", &cross, + meta::arguments_() ("first vector") ("second vector", meta::metadata_() // even function arguments can have metadata ("tooltip", "The second cross product argument"s)), - .metadata = meta::metadata_() // for functions in a scope - ("tooltip", "Cross product of vectors"s), - }); + meta::metadata_() // for functions in a scope + ("tooltip", "Cross product of vectors"s)); // after binding, you can use it as you wish // in this example, I'm just going to print all of them to stdout diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index b27108e..c5033c2 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -1334,6 +1334,17 @@ namespace meta_hpp::detail }; } +namespace meta_hpp::detail +{ + template < typename... Ts > + struct overloaded : Ts... { + using Ts::operator()...; + }; + + template < typename... Ts > + overloaded(Ts...) -> overloaded; +} + namespace meta_hpp::detail { template < typename C, typename R, typename... Args > @@ -1480,6 +1491,40 @@ namespace meta_hpp::detail inline constexpr std::size_t type_list_arity_v = type_list_arity::value; } +namespace meta_hpp::detail +{ + template < template < typename > class Pred, typename TypeList > + struct type_list_count_of; + + template < template < typename > class Pred, typename... Types > + struct type_list_count_of> : size_constant<(0 + ... + Pred::value)> {}; + + template < template < typename > class Pred, typename TypeList > + inline constexpr std::size_t type_list_count_of_v = type_list_count_of::value; +} + +namespace meta_hpp::detail +{ + template < template < typename > class Pred, typename Default, typename TypeList > + struct type_list_first_of; + + template < template < typename > class Pred, typename Default > + struct type_list_first_of> { + using type = Default; + }; + + template < template < typename > class Pred, typename Default, typename Type, typename... Types > + struct type_list_first_of> { + using type = std::conditional_t< // + Pred::value, + Type, + typename type_list_first_of>::type>; + }; + + template < template < typename > class Pred, typename Default, typename TypeList > + using type_list_first_of_t = typename type_list_first_of::type; +} + namespace meta_hpp { using detail::error_code; @@ -3467,102 +3512,128 @@ namespace meta_hpp { namespace constructor_policy { - struct as_object_t final {}; + inline constexpr struct as_object_t final { + } as_object{}; - struct as_raw_pointer_t final {}; + inline constexpr struct as_raw_pointer_t final { + } as_raw_pointer{}; - struct as_shared_pointer_t final {}; + inline constexpr struct as_shared_pointer_t final { + } as_shared_pointer{}; - struct as_unique_pointer_t final {}; + inline constexpr struct as_unique_pointer_t final { + } as_unique_pointer{}; - inline constexpr as_object_t as_object{}; - inline constexpr as_raw_pointer_t as_raw_pointer{}; - inline constexpr as_shared_pointer_t as_shared_pointer{}; - inline constexpr as_unique_pointer_t as_unique_pointer{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } namespace function_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct discard_return_t final {}; + inline constexpr struct discard_return_t final { + } discard_return{}; - struct return_reference_as_pointer_t final {}; + inline constexpr struct return_reference_as_pointer_t final { + } return_reference_as_pointer{}; - inline constexpr as_copy_t as_copy{}; - inline constexpr discard_return_t discard_return{}; - inline constexpr return_reference_as_pointer_t return_reference_as_pointer{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } namespace member_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct as_pointer_t final {}; + inline constexpr struct as_pointer_t final { + } as_pointer{}; - struct as_reference_wrapper_t final {}; + inline constexpr struct as_reference_wrapper_t final { + } as_reference_wrapper{}; + + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; - inline constexpr as_copy_t as_copy{}; - inline constexpr as_pointer_t as_pointer{}; - inline constexpr as_reference_wrapper_t as_reference_wrapper{}; } namespace method_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct discard_return_t final {}; + inline constexpr struct discard_return_t final { + } discard_return{}; - struct return_reference_as_pointer_t final {}; + inline constexpr struct return_reference_as_pointer_t final { + } return_reference_as_pointer{}; - inline constexpr as_copy_t as_copy{}; - inline constexpr discard_return_t discard_return{}; - inline constexpr return_reference_as_pointer_t return_reference_as_pointer{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } namespace variable_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct as_pointer_t final {}; + inline constexpr struct as_pointer_t final { + } as_pointer{}; - struct as_reference_wrapper_t final {}; + inline constexpr struct as_reference_wrapper_t final { + } as_reference_wrapper{}; - inline constexpr as_copy_t as_copy{}; - inline constexpr as_pointer_t as_pointer{}; - inline constexpr as_reference_wrapper_t as_reference_wrapper{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } - - template < typename Policy > - concept constructor_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept function_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept member_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept method_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept variable_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // } namespace meta_hpp @@ -3946,7 +4017,7 @@ namespace meta_hpp::detail create_error_impl create_error{}; argument_list arguments{}; - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > [[nodiscard]] static constructor_state_ptr make(metadata_map metadata); explicit constructor_state(constructor_index index, metadata_map metadata); }; @@ -3991,7 +4062,7 @@ namespace meta_hpp::detail invoke_error_impl invoke_error{}; argument_list arguments{}; - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > [[nodiscard]] static function_state_ptr make(std::string name, Function function_ptr, metadata_map metadata); explicit function_state(function_index index, metadata_map metadata); }; @@ -4011,7 +4082,7 @@ namespace meta_hpp::detail getter_error_impl getter_error{}; setter_error_impl setter_error{}; - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > [[nodiscard]] static member_state_ptr make(std::string name, Member member_ptr, metadata_map metadata); explicit member_state(member_index index, metadata_map metadata); }; @@ -4027,7 +4098,7 @@ namespace meta_hpp::detail invoke_error_impl invoke_error{}; argument_list arguments{}; - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > [[nodiscard]] static method_state_ptr make(std::string name, Method method_ptr, metadata_map metadata); explicit method_state(method_index index, metadata_map metadata); }; @@ -4056,7 +4127,7 @@ namespace meta_hpp::detail setter_impl setter{}; setter_error_impl setter_error{}; - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > [[nodiscard]] static variable_state_ptr make(std::string name, Pointer variable_ptr, metadata_map metadata); explicit variable_state(variable_index index, metadata_map metadata); }; @@ -4489,40 +4560,6 @@ namespace meta_hpp using argument_info_list = std::vector; } -namespace meta_hpp -{ - struct constructor_opts final { - argument_info_list arguments; - metadata_map metadata; - }; - - struct destructor_opts final { - metadata_map metadata; - }; - - struct evalue_opts final { - metadata_map metadata; - }; - - struct function_opts final { - argument_info_list arguments; - metadata_map metadata; - }; - - struct member_opts final { - metadata_map metadata; - }; - - struct method_opts final { - argument_info_list arguments; - metadata_map metadata; - }; - - struct variable_opts final { - metadata_map metadata; - }; -} - namespace meta_hpp { template < type_family Type > @@ -4592,77 +4629,33 @@ namespace meta_hpp public: explicit class_bind(metadata_map metadata); - // base_ - template < detail::class_kind... Bases > requires(... && detail::class_bind_base_kind) class_bind& base_(); - // constructor_ - - template < typename... Args, constructor_policy_family Policy = constructor_policy::as_object_t > - class_bind& constructor_(Policy = {}) + template < typename... Args, typename... Opts > + class_bind& constructor_(Opts&&... opts) requires detail::class_bind_constructor_kind; - template < typename... Args, constructor_policy_family Policy = constructor_policy::as_object_t > - class_bind& constructor_(constructor_opts opts, Policy = {}) - requires detail::class_bind_constructor_kind; - - // destructor_ - - class_bind& destructor_() + template < typename... Opts > + class_bind& destructor_(Opts&&... opts) requires detail::class_bind_destructor_kind; - class_bind& destructor_(destructor_opts opts) - requires detail::class_bind_destructor_kind; + template < detail::function_pointer_kind Function, typename... Opts > + class_bind& function_(std::string name, Function function_ptr, Opts&&... opts); - // function_ + template < detail::member_pointer_kind Member, typename... Opts > + class_bind& member_(std::string name, Member member_ptr, Opts&&... opts); - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - class_bind& function_(std::string name, Function function_ptr, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - class_bind& function_(std::string name, Function function_ptr, function_opts opts, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - class_bind& function_(std::string name, Function function_ptr, string_ilist arguments, Policy = {}); - - // member_ - - template < detail::member_pointer_kind Member, member_policy_family Policy = member_policy::as_copy_t > - requires detail::class_bind_member_kind - class_bind& member_(std::string name, Member member_ptr, Policy = {}); - - template < detail::member_pointer_kind Member, member_policy_family Policy = member_policy::as_copy_t > - requires detail::class_bind_member_kind - class_bind& member_(std::string name, Member member_ptr, member_opts opts, Policy = {}); - - // method_ - - template < detail::method_pointer_kind Method, method_policy_family Policy = method_policy::as_copy_t > + template < detail::method_pointer_kind Method, typename... Opts > requires detail::class_bind_method_kind - class_bind& method_(std::string name, Method method_ptr, Policy = {}); - - template < detail::method_pointer_kind Method, method_policy_family Policy = method_policy::as_copy_t > - requires detail::class_bind_method_kind - class_bind& method_(std::string name, Method method_ptr, method_opts opts, Policy = {}); - - template < detail::method_pointer_kind Method, method_policy_family Policy = method_policy::as_copy_t > - requires detail::class_bind_method_kind - class_bind& method_(std::string name, Method method_ptr, string_ilist arguments, Policy = {}); - - // typdef_ + class_bind& method_(std::string name, Method method_ptr, Opts&&... opts); template < typename Type > class_bind& typedef_(std::string name); - // variable_ - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - class_bind& variable_(std::string name, Pointer variable_ptr, Policy = {}); - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - class_bind& variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy = {}); + template < detail::pointer_kind Pointer, typename... Opts > + class_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); }; } @@ -4673,8 +4666,8 @@ namespace meta_hpp public: explicit enum_bind(metadata_map metadata); - enum_bind& evalue_(std::string name, Enum value); - enum_bind& evalue_(std::string name, Enum value, evalue_opts opts); + template < typename... Opts > + enum_bind& evalue_(std::string name, Enum value, Opts&&... opts); }; } @@ -4756,29 +4749,14 @@ namespace meta_hpp public: explicit scope_bind(const scope& scope, metadata_map metadata); - // function_ - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - scope_bind& function_(std::string name, Function function_ptr, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - scope_bind& function_(std::string name, Function function_ptr, function_opts opts, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - scope_bind& function_(std::string name, Function function_ptr, string_ilist arguments, Policy = {}); - - // typedef_ + template < detail::function_pointer_kind Function, typename... Opts > + scope_bind& function_(std::string name, Function function_ptr, Opts&&... opts); template < typename Type > scope_bind& typedef_(std::string name); - // variable_ - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - scope_bind& variable_(std::string name, Pointer variable_ptr, Policy = {}); - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - scope_bind& variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy = {}); + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); }; } @@ -4901,6 +4879,14 @@ namespace meta_hpp inline arguments_bind arguments_() { return arguments_bind{}; } + + inline arguments_bind argument_(std::string name) { + return arguments_()(std::move(name)); + } + + inline arguments_bind argument_(std::string name, metadata_map metadata) { + return arguments_()(std::move(name), std::move(metadata)); + } } namespace meta_hpp @@ -4937,6 +4923,10 @@ namespace meta_hpp inline metadata_bind metadata_() { return metadata_bind{}; } + + inline metadata_bind metadata_(std::string name, uvalue value) { + return metadata_()(std::move(name), std::move(value)); + } } namespace meta_hpp @@ -5033,10 +5023,6 @@ namespace meta_hpp } } - // - // base_ - // - template < detail::class_kind Class > template < detail::class_kind... Bases > requires(... && detail::class_bind_base_kind) @@ -5081,167 +5067,227 @@ namespace meta_hpp return *this; } - // - // constructor_ - // - template < detail::class_kind Class > - template < typename... Args, constructor_policy_family Policy > - class_bind& class_bind::constructor_(Policy policy) + template < typename... Args, typename... Opts > + class_bind& class_bind::constructor_(Opts&&... opts) requires detail::class_bind_constructor_kind { - return constructor_({}, policy); - } + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < typename... Args, constructor_policy_family Policy > - class_bind& class_bind::constructor_(constructor_opts opts, Policy) - requires detail::class_bind_constructor_kind - { - auto state = detail::constructor_state::make(std::move(opts.metadata)); + static_assert( // + detail::type_list_count_of_v <= 1, + "constructor policy may be specified only once" + ); - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, constructor_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::constructor_state::make(std::move(metadata)); + + META_HPP_ASSERT( // + arguments.size() <= state->arguments.size() // && "provided argument names don't match constructor argument count" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { + for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_data().constructors, constructor{std::move(state)}); return *this; } - // - // destructor_ - // - template < detail::class_kind Class > - class_bind& class_bind::destructor_() + template < typename... Opts > + class_bind& class_bind::destructor_(Opts&&... opts) requires detail::class_bind_destructor_kind { - return destructor_({}); - } + metadata_map metadata; - template < detail::class_kind Class > - class_bind& class_bind::destructor_(destructor_opts opts) - requires detail::class_bind_destructor_kind - { - auto state = detail::destructor_state::make(std::move(opts.metadata)); + { + // clang-format off + const auto process_opt = detail::overloaded{ + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::destructor_state::make(std::move(metadata)); detail::insert_or_assign(get_data().destructors, destructor{std::move(state)}); return *this; } - // - // function_ - // - template < detail::class_kind Class > - template < detail::function_pointer_kind Function, function_policy_family Policy > - class_bind& class_bind::function_(std::string name, Function function_ptr, Policy policy) { - return function_(std::move(name), function_ptr, {}, policy); - } + template < detail::function_pointer_kind Function, typename... Opts > + class_bind& class_bind::function_(std::string name, Function function_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::function_pointer_kind Function, function_policy_family Policy > - class_bind& class_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // - && "provided arguments don't match function argument count" + static_assert( // + detail::type_list_count_of_v <= 1, + "function policy may be specified only once" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { - argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, function_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); } - detail::insert_or_assign(get_data().functions, function{std::move(state)}); - return *this; - } + auto state = detail::function_state::make(std::move(name), function_ptr, std::move(metadata)); - template < detail::class_kind Class > - template < detail::function_pointer_kind Function, function_policy_family Policy > - class_bind& class_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, {}); - - META_HPP_ASSERT( + META_HPP_ASSERT( // arguments.size() <= state->arguments.size() // && "provided argument names don't match function argument count" ); for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - // NOLINTNEXTLINE(*-pointer-arithmetic) - detail::state_access(arg)->name = std::data(arguments)[i]; + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_data().functions, function{std::move(state)}); return *this; } - // - // member_ - // - template < detail::class_kind Class > - template < detail::member_pointer_kind Member, member_policy_family Policy > - requires detail::class_bind_member_kind - class_bind& class_bind::member_(std::string name, Member member_ptr, Policy policy) { - return member_(std::move(name), member_ptr, {}, policy); - } + template < detail::member_pointer_kind Member, typename... Opts > + class_bind& class_bind::member_(std::string name, Member member_ptr, [[maybe_unused]] Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::member_pointer_kind Member, member_policy_family Policy > - requires detail::class_bind_member_kind - class_bind& class_bind::member_(std::string name, Member member_ptr, member_opts opts, Policy) { - auto state = detail::member_state::make(std::move(name), member_ptr, std::move(opts.metadata)); + static_assert( // + detail::type_list_count_of_v <= 1, + "member policy may be specified only once" + ); + + metadata_map metadata; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, member_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::member_state::make(std::move(name), member_ptr, std::move(metadata)); detail::insert_or_assign(get_data().members, member{std::move(state)}); return *this; } - // - // method_ - // - template < detail::class_kind Class > - template < detail::method_pointer_kind Method, method_policy_family Policy > + template < detail::method_pointer_kind Method, typename... Opts > requires detail::class_bind_method_kind - class_bind& class_bind::method_(std::string name, Method method_ptr, Policy policy) { - return method_(std::move(name), method_ptr, {}, policy); - } + class_bind& class_bind::method_(std::string name, Method method_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::method_pointer_kind Method, method_policy_family Policy > - requires detail::class_bind_method_kind - class_bind& class_bind::method_(std::string name, Method method_ptr, method_opts opts, Policy) { - auto state = detail::method_state::make(std::move(name), method_ptr, std::move(opts.metadata)); - - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // - && "provided arguments don't match method argument count" + static_assert( // + detail::type_list_count_of_v <= 1, + "method policy may be specified only once" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { - argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, method_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); } - detail::insert_or_assign(get_data().methods, method{std::move(state)}); - return *this; - } - - template < detail::class_kind Class > - template < detail::method_pointer_kind Method, method_policy_family Policy > - requires detail::class_bind_method_kind - class_bind& class_bind::method_(std::string name, Method method_ptr, string_ilist arguments, Policy) { - auto state = detail::method_state::make(std::move(name), method_ptr, {}); + auto state = detail::method_state::make(std::move(name), method_ptr, std::move(metadata)); META_HPP_ASSERT( // arguments.size() <= state->arguments.size() // @@ -5250,18 +5296,14 @@ namespace meta_hpp for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - // NOLINTNEXTLINE(*-pointer-arithmetic) - detail::state_access(arg)->name = std::data(arguments)[i]; + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_data().methods, method{std::move(state)}); return *this; } - // - // typedef_ - // - template < detail::class_kind Class > template < typename Type > class_bind& class_bind::typedef_(std::string name) { @@ -5269,20 +5311,38 @@ namespace meta_hpp return *this; } - // - // variable_ - // - template < detail::class_kind Class > - template < detail::pointer_kind Pointer, variable_policy_family Policy > - class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, Policy policy) { - return variable_(std::move(name), variable_ptr, {}, policy); - } + template < detail::pointer_kind Pointer, typename... Opts > + class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::pointer_kind Pointer, variable_policy_family Policy > - class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy) { - auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(opts.metadata)); + static_assert( // + detail::type_list_count_of_v <= 1, + "variable policy may be specified only once" + ); + + metadata_map metadata; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, variable_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(metadata)); detail::insert_or_assign(get_data().variables, variable{std::move(state)}); return *this; } @@ -5295,13 +5355,26 @@ namespace meta_hpp : type_bind_base{resolve_type(), std::move(metadata)} {} template < detail::enum_kind Enum > - enum_bind& enum_bind::evalue_(std::string name, Enum value) { - return evalue_(std::move(name), std::move(value), {}); - } + template < typename... Opts > + enum_bind& enum_bind::evalue_(std::string name, Enum value, Opts&&... opts) { + metadata_map metadata; - template < detail::enum_kind Enum > - enum_bind& enum_bind::evalue_(std::string name, Enum value, evalue_opts opts) { - auto state = detail::evalue_state::make(std::move(name), std::move(value), std::move(opts.metadata)); + { + // clang-format off + const auto process_opt = detail::overloaded{ + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::evalue_state::make(std::move(name), std::move(value), std::move(metadata)); detail::insert_or_assign(get_data().evalues, evalue{std::move(state)}); return *this; } @@ -5361,75 +5434,99 @@ namespace meta_hpp inline scope_bind::scope_bind(const scope& scope, metadata_map metadata) : state_bind_base{scope, std::move(metadata)} {} - // - // function_ - // + template < detail::function_pointer_kind Function, typename... Opts > + scope_bind& scope_bind::function_(std::string name, Function function_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::function_pointer_kind Function, function_policy_family Policy > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, Policy policy) { - return function_(std::move(name), function_ptr, {}, policy); - } - - template < detail::function_pointer_kind Function, function_policy_family Policy > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // - && "provided arguments don't match function argument count" + static_assert( // + detail::type_list_count_of_v <= 1, + "function policy may be specified only once" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { - argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, function_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); } - detail::insert_or_assign(get_state().functions, function{std::move(state)}); - return *this; - } - - template < detail::function_pointer_kind Function, function_policy_family Policy > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, {}); + auto state = detail::function_state::make(std::move(name), function_ptr, std::move(metadata)); META_HPP_ASSERT( // arguments.size() <= state->arguments.size() // - && "provided argument names don't match function argument count" + && "provided arguments don't match function argument count" ); for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - // NOLINTNEXTLINE(*-pointer-arithmetic) - detail::state_access(arg)->name = std::data(arguments)[i]; + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_state().functions, function{std::move(state)}); return *this; } - // - // typedef_ - // - template < typename Type > scope_bind& scope_bind::typedef_(std::string name) { get_state().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } - // - // variable_ - // + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::pointer_kind Pointer, variable_policy_family Policy > - scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, Policy policy) { - return variable_(std::move(name), variable_ptr, {}, policy); - } + static_assert( // + detail::type_list_count_of_v <= 1, + "variable policy may be specified only once" + ); - template < detail::pointer_kind Pointer, variable_policy_family Policy > - scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy) { - auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(opts.metadata)); + metadata_map metadata; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, variable_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(metadata)); detail::insert_or_assign(get_state().variables, variable{std::move(state)}); return *this; } @@ -6382,7 +6479,7 @@ namespace meta_hpp namespace meta_hpp::detail { - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > uvalue raw_function_invoke(type_registry& registry, Function function_ptr, std::span args) { using ft = function_traits>; using return_type = typename ft::return_type; @@ -6449,7 +6546,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > function_state::invoke_impl make_function_invoke(type_registry& registry, Function function_ptr) { return [®istry, function_ptr](std::span args) { // return raw_function_invoke(registry, function_ptr, args); @@ -6484,7 +6581,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > function_state_ptr function_state::make(std::string name, Function function_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; @@ -6839,7 +6936,7 @@ namespace meta_hpp namespace meta_hpp::detail { - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > uvalue raw_member_getter(type_registry& registry, Member member_ptr, const uinst& inst) { using mt = member_traits; using class_type = typename mt::class_type; @@ -6982,7 +7079,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > member_state::getter_impl make_member_getter(type_registry& registry, Member member_ptr) { return [®istry, member_ptr](const uinst& inst) { // return raw_member_getter(registry, member_ptr, inst); @@ -7017,7 +7114,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > member_state_ptr member_state::make(std::string name, Member member_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; @@ -7204,7 +7301,7 @@ namespace meta_hpp namespace meta_hpp::detail { - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > uvalue raw_method_invoke(type_registry& registry, Method method_ptr, const uinst& inst, std::span args) { using mt = method_traits; using return_type = typename mt::return_type; @@ -7282,7 +7379,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > method_state::invoke_impl make_method_invoke(type_registry& registry, Method method_ptr) { return [®istry, method_ptr](const uinst& inst, std::span args) { return raw_method_invoke(registry, method_ptr, inst, args); @@ -7317,7 +7414,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > method_state_ptr method_state::make(std::string name, Method method_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; @@ -7749,7 +7846,7 @@ namespace meta_hpp namespace meta_hpp::detail { - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > uvalue raw_constructor_create(type_registry& registry, std::span args) { using ct = constructor_traits; using class_type = typename ct::class_type; @@ -7838,7 +7935,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > constructor_state::create_impl make_constructor_create(type_registry& registry) { return [®istry](std::span args) { // return raw_constructor_create(registry, args); @@ -7880,7 +7977,7 @@ namespace meta_hpp::detail : index{nindex} , metadata{std::move(nmetadata)} {} - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > constructor_state_ptr constructor_state::make(metadata_map metadata) { type_registry& registry{type_registry::instance()}; @@ -8276,7 +8373,7 @@ namespace meta_hpp namespace meta_hpp::detail { - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > uvalue raw_variable_getter(type_registry&, Pointer variable_ptr) { using pt = pointer_traits; using data_type = typename pt::data_type; @@ -8348,7 +8445,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > variable_state::getter_impl make_variable_getter(type_registry& registry, Pointer variable_ptr) { return [®istry, variable_ptr]() { // return raw_variable_getter(registry, variable_ptr); @@ -8376,7 +8473,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > variable_state_ptr variable_state::make(std::string name, Pointer variable_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; diff --git a/develop/untests/meta_base/type_list_tests.cpp b/develop/untests/meta_base/type_list_tests.cpp new file mode 100644 index 0000000..157d334 --- /dev/null +++ b/develop/untests/meta_base/type_list_tests.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include +#include + +TEST_CASE("meta/meta_base/type_list") { + namespace meta = meta_hpp; + using meta::detail::type_list; + + SUBCASE("type_list_at_t") { + using meta::detail::type_list_at_t; + + static_assert(std::is_same_v>, int>); + static_assert(std::is_same_v>, float>); + } + + SUBCASE("type_list_arity_v") { + using meta::detail::type_list_arity_v; + + static_assert(type_list_arity_v> == 0); + static_assert(type_list_arity_v> == 1); + static_assert(type_list_arity_v> == 2); + } + + SUBCASE("type_list_count_of_v") { + using meta::detail::type_list_count_of_v; + + static_assert(type_list_count_of_v> == 0); + static_assert(type_list_count_of_v> == 0); + static_assert(type_list_count_of_v> == 1); + static_assert(type_list_count_of_v> == 2); + static_assert(type_list_count_of_v> == 3); + } + + SUBCASE("type_list_first_of_t") { + using meta::detail::type_list_first_of_t; + + static_assert(std::is_same_v>, int>); + static_assert(std::is_same_v>, int>); + static_assert(std::is_same_v>, int>); + static_assert(std::is_same_v>, long>); + + static_assert(std::is_same_v>, long>); + } +} diff --git a/develop/untests/meta_states/dtor_tests.cpp b/develop/untests/meta_states/dtor_tests.cpp index 7ea775b..3375386 100644 --- a/develop/untests/meta_states/dtor_tests.cpp +++ b/develop/untests/meta_states/dtor_tests.cpp @@ -37,10 +37,8 @@ TEST_CASE("meta/meta_states/dtor") { meta::class_(); meta::class_() - .destructor_({ - .metadata = meta::metadata_() - ("desc", "virtual dtor"s) - }); + .destructor_(meta::metadata_() + ("desc", "virtual dtor"s)); SUBCASE("closed_dtor") { const meta::class_type clazz_type = meta::resolve_type(); diff --git a/develop/untests/meta_states/function2_tests.cpp b/develop/untests/meta_states/function2_tests.cpp index 2a34d78..01a307a 100644 --- a/develop/untests/meta_states/function2_tests.cpp +++ b/develop/untests/meta_states/function2_tests.cpp @@ -27,8 +27,8 @@ TEST_CASE("meta/meta_states/function2") { namespace meta = meta_hpp; meta::class_() - .function_("iadd", &ivec2::iadd, { "l" }) - .function_("isub", &ivec2::isub, { "l", "r" }); + .function_("iadd", &ivec2::iadd, meta::arguments_()("l")) + .function_("isub", &ivec2::isub, meta::arguments_()("l")("r")); const meta::class_type ivec2_type = meta::resolve_type(); REQUIRE(ivec2_type); diff --git a/develop/untests/meta_states/metadata_tests.cpp b/develop/untests/meta_states/metadata_tests.cpp index bcad0d2..8ef92d8 100644 --- a/develop/untests/meta_states/metadata_tests.cpp +++ b/develop/untests/meta_states/metadata_tests.cpp @@ -31,7 +31,13 @@ namespace static ivec2 iadd(const ivec2& l, const ivec2& r) noexcept { return {l.x + r.x, l.y + r.y}; } + + static const ivec2 zero; + static const ivec2 unit; }; + + const ivec2 ivec2::zero{0, 0}; + const ivec2 ivec2::unit{1, 1}; } TEST_CASE("meta/meta_states/metadata/enum") { @@ -41,15 +47,12 @@ TEST_CASE("meta/meta_states/metadata/enum") { meta::enum_(meta::metadata_() ("desc1", "enum-desc1"s) ("desc2", "enum-desc2"s)) - .evalue_("red", color::red, { - .metadata{meta::metadata_()("desc1", "red-color"s)} - }) - .evalue_("green", color::green, { - .metadata{meta::metadata_()("desc1", "green-color"s)} - }) - .evalue_("blue", color::blue, { - .metadata{meta::metadata_()("desc1", "blue-color"s)} - }); + .evalue_("red", color::red, + meta::metadata_()("desc1", "red-color"s)) + .evalue_("green", color::green, + meta::metadata_()("desc1", "green-color"s)) + .evalue_("blue", color::blue, + meta::metadata_()("desc1", "blue-color"s)); // metadata override @@ -58,10 +61,9 @@ TEST_CASE("meta/meta_states/metadata/enum") { ("desc3", "new-enum-desc3"s)); meta::enum_() - .evalue_("red", color::red, { - .metadata = meta::metadata_() - ("desc2", "new-red-color"s) - }); + .evalue_("red", color::red, + meta::metadata_() + ("desc2", "new-red-color"s)); // @@ -89,36 +91,28 @@ TEST_CASE("meta/meta_states/metadata/class") { meta::class_(meta::metadata_() ("desc1", "class-desc1"s) ("desc2", "class-desc2"s)) - .constructor_({ - .arguments{meta::arguments_() - ("v", meta::metadata_()("desc", "the ctor arg"s))}, - .metadata{meta::metadata_()("desc", "one arg 2d vector ctor"s)}, - }) - .constructor_({ - .arguments{meta::arguments_() - ("x", meta::metadata_()("desc", "the 1st ctor arg"s)) - ("y", meta::metadata_()("desc", "the 2nd ctor arg"s)) - }, - .metadata{meta::metadata_()("desc", "two args 2d vector ctor"s)} - }) - .member_("x", &ivec2::x, { - .metadata{meta::metadata_()("desc", "x-member"s)} - }) - .member_("y", &ivec2::y, { - .metadata{meta::metadata_()("desc", "y-member"s)} - }) - .method_("add", &ivec2::add, { - .arguments{meta::arguments_() - ("other", meta::metadata_()("desc", "other-arg"s))}, - .metadata{meta::metadata_()("desc", "add-method"s)} - }) - .function_("iadd", &ivec2::iadd, { - .arguments{meta::arguments_() - ("l", meta::metadata_()("desc", "l-arg"s)) - ("r", meta::metadata_()("desc", "r-arg"s)) - }, - .metadata{meta::metadata_()("desc", "iadd-function"s)} - }); + .constructor_( + meta::arguments_() + ("v", meta::metadata_()("desc", "the ctor arg"s)), + meta::metadata_()("desc", "one arg 2d vector ctor"s)) + .constructor_( + meta::argument_("x", meta::metadata_("desc", "the 1st ctor arg"s)), + meta::argument_("y", meta::metadata_("desc", "the 2nd ctor arg"s)), + meta::metadata_()("desc", "two args 2d vector ctor"s)) + .member_("x", &ivec2::x, meta::metadata_()("desc", "x-member"s)) + .member_("y", &ivec2::y, meta::metadata_()("desc", "y-member"s)) + .method_("add", &ivec2::add, + meta::arguments_() + ("other", meta::metadata_()("desc", "other-arg"s)), + meta::metadata_()("desc", "add-method"s)) + .function_("iadd", &ivec2::iadd, + meta::arguments_() + ("l", meta::metadata_()("desc", "l-arg"s)), + meta::arguments_() + ("r", meta::metadata_()("desc", "r-arg"s)), + meta::metadata_()("desc", "iadd-function"s)) + .variable_("zero", &ivec2::zero, meta::metadata_("desc", "{0,0} vector"s)) + .variable_("unit", &ivec2::unit, meta::metadata_("desc", "{1,1} vector"s)); // metadata override @@ -221,6 +215,22 @@ TEST_CASE("meta/meta_states/metadata/class") { REQUIRE(ivec2_iadd.get_argument(1).get_metadata().contains("desc")); CHECK(ivec2_iadd.get_argument(1).get_metadata().at("desc").as() == "r-arg"s); } + + SUBCASE("ivec2::zero") { + const meta::variable ivec2_zero = ivec2_type.get_variable("zero"); + REQUIRE(ivec2_zero); + + REQUIRE(ivec2_zero.get_metadata().contains("desc")); + CHECK(ivec2_zero.get_metadata().at("desc").as() == "{0,0} vector"s); + } + + SUBCASE("ivec2::unit") { + const meta::variable ivec2_unit = ivec2_type.get_variable("unit"); + REQUIRE(ivec2_unit); + + REQUIRE(ivec2_unit.get_metadata().contains("desc")); + CHECK(ivec2_unit.get_metadata().at("desc").as() == "{1,1} vector"s); + } } TEST_CASE("meta/meta_states/metadata/scope") { diff --git a/develop/untests/meta_states/method2_tests.cpp b/develop/untests/meta_states/method2_tests.cpp index c03b92f..bce3666 100644 --- a/develop/untests/meta_states/method2_tests.cpp +++ b/develop/untests/meta_states/method2_tests.cpp @@ -25,7 +25,7 @@ TEST_CASE("meta/meta_states/method2") { namespace meta = meta_hpp; meta::class_() - .method_("add", &ivec2::add, {"other"}); + .method_("add", &ivec2::add, meta::argument_("other")); const meta::class_type ivec2_type = meta::resolve_type(); REQUIRE(ivec2_type); diff --git a/develop/untests/meta_states/scope_tests.cpp b/develop/untests/meta_states/scope_tests.cpp index 8be6265..dac268a 100644 --- a/develop/untests/meta_states/scope_tests.cpp +++ b/develop/untests/meta_states/scope_tests.cpp @@ -43,17 +43,18 @@ namespace TEST_CASE("meta/meta_states/scope") { namespace meta = meta_hpp; + using namespace std::string_literals; meta::static_scope_("meta/meta_states/scope/math") .typedef_("color") .typedef_("ivec2") .typedef_("ivec3") - .function_("iadd2", &iadd2, {"l", "r"}) - .function_("iadd3", &iadd3, {"l"}) + .function_("iadd2", &iadd2, meta::arguments_()("l")("r"), meta::metadata_()("desc", "iadd2"s)) + .function_("iadd3", &iadd3, meta::arguments_()("l"), meta::metadata_()("desc", "iadd3"s)) .function_("function_overloaded", meta::select_overload(&function_overloaded)) .function_("function_overloaded", meta::select_overload(&function_overloaded)) - .variable_("static_ivec2", &static_ivec2) - .variable_("static_const_ivec3", &static_const_ivec3); + .variable_("static_ivec2", &static_ivec2, meta::metadata_()("desc", "static_ivec2"s)) + .variable_("static_const_ivec3", &static_const_ivec3, meta::metadata_()("desc", "static_const_ivec3"s)); const meta::scope math_scope = meta::resolve_scope("meta/meta_states/scope/math"); REQUIRE(math_scope); @@ -114,6 +115,9 @@ TEST_CASE("meta/meta_states/scope") { CHECK(iadd2_func.get_argument(1).get_name() == "r"); CHECK_FALSE(iadd2_func.get_argument(2)); + + REQUIRE(iadd2_func.get_metadata().contains("desc")); + CHECK(iadd2_func.get_metadata().at("desc").as() == "iadd2"s); } const meta::function iadd3_func = math_scope.get_function("iadd3"); @@ -133,6 +137,9 @@ TEST_CASE("meta/meta_states/scope") { CHECK(iadd3_func.get_argument(1).get_name() == ""); CHECK_FALSE(iadd3_func.get_argument(2)); + + REQUIRE(iadd3_func.get_metadata().contains("desc")); + CHECK(iadd3_func.get_metadata().at("desc").as() == "iadd3"s); } } @@ -199,10 +206,14 @@ TEST_CASE("meta/meta_states/scope") { const meta::variable static_ivec2_var = math_scope.get_variable("static_ivec2"); REQUIRE(static_ivec2_var); CHECK(static_ivec2_var.get_type().get_data_type() == meta::resolve_type()); + REQUIRE(static_ivec2_var.get_metadata().contains("desc")); + CHECK(static_ivec2_var.get_metadata().at("desc").as() == "static_ivec2"s); const meta::variable static_const_ivec3_var = math_scope.get_variable("static_const_ivec3"); REQUIRE(static_const_ivec3_var); CHECK(static_const_ivec3_var.get_type().get_data_type() == meta::resolve_type()); + REQUIRE(static_const_ivec3_var.get_metadata().contains("desc")); + CHECK(static_const_ivec3_var.get_metadata().at("desc").as() == "static_const_ivec3"s); } } diff --git a/headers/meta.hpp/meta_base.hpp b/headers/meta.hpp/meta_base.hpp index e84aebb..593f5d0 100644 --- a/headers/meta.hpp/meta_base.hpp +++ b/headers/meta.hpp/meta_base.hpp @@ -23,6 +23,7 @@ #include "meta_base/memory_buffer.hpp" #include "meta_base/noncopyable.hpp" #include "meta_base/nonesuch.hpp" +#include "meta_base/overloaded.hpp" #include "meta_base/select_overload.hpp" #include "meta_base/to_underlying.hpp" #include "meta_base/type_kinds.hpp" diff --git a/headers/meta.hpp/meta_base/overloaded.hpp b/headers/meta.hpp/meta_base/overloaded.hpp new file mode 100644 index 0000000..9574afc --- /dev/null +++ b/headers/meta.hpp/meta_base/overloaded.hpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "base.hpp" + +namespace meta_hpp::detail +{ + template < typename... Ts > + struct overloaded : Ts... { + using Ts::operator()...; + }; + + template < typename... Ts > + overloaded(Ts...) -> overloaded; +} diff --git a/headers/meta.hpp/meta_base/type_list.hpp b/headers/meta.hpp/meta_base/type_list.hpp index a0058f1..fd0e813 100644 --- a/headers/meta.hpp/meta_base/type_list.hpp +++ b/headers/meta.hpp/meta_base/type_list.hpp @@ -45,3 +45,37 @@ namespace meta_hpp::detail template < typename TypeList > inline constexpr std::size_t type_list_arity_v = type_list_arity::value; } + +namespace meta_hpp::detail +{ + template < template < typename > class Pred, typename TypeList > + struct type_list_count_of; + + template < template < typename > class Pred, typename... Types > + struct type_list_count_of> : size_constant<(0 + ... + Pred::value)> {}; + + template < template < typename > class Pred, typename TypeList > + inline constexpr std::size_t type_list_count_of_v = type_list_count_of::value; +} + +namespace meta_hpp::detail +{ + template < template < typename > class Pred, typename Default, typename TypeList > + struct type_list_first_of; + + template < template < typename > class Pred, typename Default > + struct type_list_first_of> { + using type = Default; + }; + + template < template < typename > class Pred, typename Default, typename Type, typename... Types > + struct type_list_first_of> { + using type = std::conditional_t< // + Pred::value, + Type, + typename type_list_first_of>::type>; + }; + + template < template < typename > class Pred, typename Default, typename TypeList > + using type_list_first_of_t = typename type_list_first_of::type; +} diff --git a/headers/meta.hpp/meta_binds.hpp b/headers/meta.hpp/meta_binds.hpp index 9c62ef3..c16790a 100644 --- a/headers/meta.hpp/meta_binds.hpp +++ b/headers/meta.hpp/meta_binds.hpp @@ -82,40 +82,6 @@ namespace meta_hpp using argument_info_list = std::vector; } -namespace meta_hpp -{ - struct constructor_opts final { - argument_info_list arguments; - metadata_map metadata; - }; - - struct destructor_opts final { - metadata_map metadata; - }; - - struct evalue_opts final { - metadata_map metadata; - }; - - struct function_opts final { - argument_info_list arguments; - metadata_map metadata; - }; - - struct member_opts final { - metadata_map metadata; - }; - - struct method_opts final { - argument_info_list arguments; - metadata_map metadata; - }; - - struct variable_opts final { - metadata_map metadata; - }; -} - namespace meta_hpp { template < type_family Type > @@ -185,77 +151,33 @@ namespace meta_hpp public: explicit class_bind(metadata_map metadata); - // base_ - template < detail::class_kind... Bases > requires(... && detail::class_bind_base_kind) class_bind& base_(); - // constructor_ - - template < typename... Args, constructor_policy_family Policy = constructor_policy::as_object_t > - class_bind& constructor_(Policy = {}) + template < typename... Args, typename... Opts > + class_bind& constructor_(Opts&&... opts) requires detail::class_bind_constructor_kind; - template < typename... Args, constructor_policy_family Policy = constructor_policy::as_object_t > - class_bind& constructor_(constructor_opts opts, Policy = {}) - requires detail::class_bind_constructor_kind; - - // destructor_ - - class_bind& destructor_() + template < typename... Opts > + class_bind& destructor_(Opts&&... opts) requires detail::class_bind_destructor_kind; - class_bind& destructor_(destructor_opts opts) - requires detail::class_bind_destructor_kind; + template < detail::function_pointer_kind Function, typename... Opts > + class_bind& function_(std::string name, Function function_ptr, Opts&&... opts); - // function_ + template < detail::member_pointer_kind Member, typename... Opts > + class_bind& member_(std::string name, Member member_ptr, Opts&&... opts); - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - class_bind& function_(std::string name, Function function_ptr, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - class_bind& function_(std::string name, Function function_ptr, function_opts opts, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - class_bind& function_(std::string name, Function function_ptr, string_ilist arguments, Policy = {}); - - // member_ - - template < detail::member_pointer_kind Member, member_policy_family Policy = member_policy::as_copy_t > - requires detail::class_bind_member_kind - class_bind& member_(std::string name, Member member_ptr, Policy = {}); - - template < detail::member_pointer_kind Member, member_policy_family Policy = member_policy::as_copy_t > - requires detail::class_bind_member_kind - class_bind& member_(std::string name, Member member_ptr, member_opts opts, Policy = {}); - - // method_ - - template < detail::method_pointer_kind Method, method_policy_family Policy = method_policy::as_copy_t > + template < detail::method_pointer_kind Method, typename... Opts > requires detail::class_bind_method_kind - class_bind& method_(std::string name, Method method_ptr, Policy = {}); - - template < detail::method_pointer_kind Method, method_policy_family Policy = method_policy::as_copy_t > - requires detail::class_bind_method_kind - class_bind& method_(std::string name, Method method_ptr, method_opts opts, Policy = {}); - - template < detail::method_pointer_kind Method, method_policy_family Policy = method_policy::as_copy_t > - requires detail::class_bind_method_kind - class_bind& method_(std::string name, Method method_ptr, string_ilist arguments, Policy = {}); - - // typdef_ + class_bind& method_(std::string name, Method method_ptr, Opts&&... opts); template < typename Type > class_bind& typedef_(std::string name); - // variable_ - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - class_bind& variable_(std::string name, Pointer variable_ptr, Policy = {}); - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - class_bind& variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy = {}); + template < detail::pointer_kind Pointer, typename... Opts > + class_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); }; } @@ -266,8 +188,8 @@ namespace meta_hpp public: explicit enum_bind(metadata_map metadata); - enum_bind& evalue_(std::string name, Enum value); - enum_bind& evalue_(std::string name, Enum value, evalue_opts opts); + template < typename... Opts > + enum_bind& evalue_(std::string name, Enum value, Opts&&... opts); }; } @@ -349,29 +271,14 @@ namespace meta_hpp public: explicit scope_bind(const scope& scope, metadata_map metadata); - // function_ - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - scope_bind& function_(std::string name, Function function_ptr, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - scope_bind& function_(std::string name, Function function_ptr, function_opts opts, Policy = {}); - - template < detail::function_pointer_kind Function, function_policy_family Policy = function_policy::as_copy_t > - scope_bind& function_(std::string name, Function function_ptr, string_ilist arguments, Policy = {}); - - // typedef_ + template < detail::function_pointer_kind Function, typename... Opts > + scope_bind& function_(std::string name, Function function_ptr, Opts&&... opts); template < typename Type > scope_bind& typedef_(std::string name); - // variable_ - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - scope_bind& variable_(std::string name, Pointer variable_ptr, Policy = {}); - - template < detail::pointer_kind Pointer, variable_policy_family Policy = variable_policy::as_copy_t > - scope_bind& variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy = {}); + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); }; } @@ -494,6 +401,14 @@ namespace meta_hpp inline arguments_bind arguments_() { return arguments_bind{}; } + + inline arguments_bind argument_(std::string name) { + return arguments_()(std::move(name)); + } + + inline arguments_bind argument_(std::string name, metadata_map metadata) { + return arguments_()(std::move(name), std::move(metadata)); + } } namespace meta_hpp @@ -530,4 +445,8 @@ namespace meta_hpp inline metadata_bind metadata_() { return metadata_bind{}; } + + inline metadata_bind metadata_(std::string name, uvalue value) { + return metadata_()(std::move(name), std::move(value)); + } } diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index 77f7b2a..d6294dc 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -97,10 +97,6 @@ namespace meta_hpp } } - // - // base_ - // - template < detail::class_kind Class > template < detail::class_kind... Bases > requires(... && detail::class_bind_base_kind) @@ -145,167 +141,227 @@ namespace meta_hpp return *this; } - // - // constructor_ - // - template < detail::class_kind Class > - template < typename... Args, constructor_policy_family Policy > - class_bind& class_bind::constructor_(Policy policy) + template < typename... Args, typename... Opts > + class_bind& class_bind::constructor_(Opts&&... opts) requires detail::class_bind_constructor_kind { - return constructor_({}, policy); - } + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < typename... Args, constructor_policy_family Policy > - class_bind& class_bind::constructor_(constructor_opts opts, Policy) - requires detail::class_bind_constructor_kind - { - auto state = detail::constructor_state::make(std::move(opts.metadata)); + static_assert( // + detail::type_list_count_of_v <= 1, + "constructor policy may be specified only once" + ); - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, constructor_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::constructor_state::make(std::move(metadata)); + + META_HPP_ASSERT( // + arguments.size() <= state->arguments.size() // && "provided argument names don't match constructor argument count" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { + for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_data().constructors, constructor{std::move(state)}); return *this; } - // - // destructor_ - // - template < detail::class_kind Class > - class_bind& class_bind::destructor_() + template < typename... Opts > + class_bind& class_bind::destructor_(Opts&&... opts) requires detail::class_bind_destructor_kind { - return destructor_({}); - } + metadata_map metadata; - template < detail::class_kind Class > - class_bind& class_bind::destructor_(destructor_opts opts) - requires detail::class_bind_destructor_kind - { - auto state = detail::destructor_state::make(std::move(opts.metadata)); + { + // clang-format off + const auto process_opt = detail::overloaded{ + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::destructor_state::make(std::move(metadata)); detail::insert_or_assign(get_data().destructors, destructor{std::move(state)}); return *this; } - // - // function_ - // - template < detail::class_kind Class > - template < detail::function_pointer_kind Function, function_policy_family Policy > - class_bind& class_bind::function_(std::string name, Function function_ptr, Policy policy) { - return function_(std::move(name), function_ptr, {}, policy); - } + template < detail::function_pointer_kind Function, typename... Opts > + class_bind& class_bind::function_(std::string name, Function function_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::function_pointer_kind Function, function_policy_family Policy > - class_bind& class_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // - && "provided arguments don't match function argument count" + static_assert( // + detail::type_list_count_of_v <= 1, + "function policy may be specified only once" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { - argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, function_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); } - detail::insert_or_assign(get_data().functions, function{std::move(state)}); - return *this; - } + auto state = detail::function_state::make(std::move(name), function_ptr, std::move(metadata)); - template < detail::class_kind Class > - template < detail::function_pointer_kind Function, function_policy_family Policy > - class_bind& class_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, {}); - - META_HPP_ASSERT( + META_HPP_ASSERT( // arguments.size() <= state->arguments.size() // && "provided argument names don't match function argument count" ); for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - // NOLINTNEXTLINE(*-pointer-arithmetic) - detail::state_access(arg)->name = std::data(arguments)[i]; + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_data().functions, function{std::move(state)}); return *this; } - // - // member_ - // - template < detail::class_kind Class > - template < detail::member_pointer_kind Member, member_policy_family Policy > - requires detail::class_bind_member_kind - class_bind& class_bind::member_(std::string name, Member member_ptr, Policy policy) { - return member_(std::move(name), member_ptr, {}, policy); - } + template < detail::member_pointer_kind Member, typename... Opts > + class_bind& class_bind::member_(std::string name, Member member_ptr, [[maybe_unused]] Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::member_pointer_kind Member, member_policy_family Policy > - requires detail::class_bind_member_kind - class_bind& class_bind::member_(std::string name, Member member_ptr, member_opts opts, Policy) { - auto state = detail::member_state::make(std::move(name), member_ptr, std::move(opts.metadata)); + static_assert( // + detail::type_list_count_of_v <= 1, + "member policy may be specified only once" + ); + + metadata_map metadata; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, member_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::member_state::make(std::move(name), member_ptr, std::move(metadata)); detail::insert_or_assign(get_data().members, member{std::move(state)}); return *this; } - // - // method_ - // - template < detail::class_kind Class > - template < detail::method_pointer_kind Method, method_policy_family Policy > + template < detail::method_pointer_kind Method, typename... Opts > requires detail::class_bind_method_kind - class_bind& class_bind::method_(std::string name, Method method_ptr, Policy policy) { - return method_(std::move(name), method_ptr, {}, policy); - } + class_bind& class_bind::method_(std::string name, Method method_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::method_pointer_kind Method, method_policy_family Policy > - requires detail::class_bind_method_kind - class_bind& class_bind::method_(std::string name, Method method_ptr, method_opts opts, Policy) { - auto state = detail::method_state::make(std::move(name), method_ptr, std::move(opts.metadata)); - - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // - && "provided arguments don't match method argument count" + static_assert( // + detail::type_list_count_of_v <= 1, + "method policy may be specified only once" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { - argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, method_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); } - detail::insert_or_assign(get_data().methods, method{std::move(state)}); - return *this; - } - - template < detail::class_kind Class > - template < detail::method_pointer_kind Method, method_policy_family Policy > - requires detail::class_bind_method_kind - class_bind& class_bind::method_(std::string name, Method method_ptr, string_ilist arguments, Policy) { - auto state = detail::method_state::make(std::move(name), method_ptr, {}); + auto state = detail::method_state::make(std::move(name), method_ptr, std::move(metadata)); META_HPP_ASSERT( // arguments.size() <= state->arguments.size() // @@ -314,18 +370,14 @@ namespace meta_hpp for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - // NOLINTNEXTLINE(*-pointer-arithmetic) - detail::state_access(arg)->name = std::data(arguments)[i]; + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_data().methods, method{std::move(state)}); return *this; } - // - // typedef_ - // - template < detail::class_kind Class > template < typename Type > class_bind& class_bind::typedef_(std::string name) { @@ -333,20 +385,38 @@ namespace meta_hpp return *this; } - // - // variable_ - // - template < detail::class_kind Class > - template < detail::pointer_kind Pointer, variable_policy_family Policy > - class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, Policy policy) { - return variable_(std::move(name), variable_ptr, {}, policy); - } + template < detail::pointer_kind Pointer, typename... Opts > + class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::class_kind Class > - template < detail::pointer_kind Pointer, variable_policy_family Policy > - class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy) { - auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(opts.metadata)); + static_assert( // + detail::type_list_count_of_v <= 1, + "variable policy may be specified only once" + ); + + metadata_map metadata; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, variable_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(metadata)); detail::insert_or_assign(get_data().variables, variable{std::move(state)}); return *this; } diff --git a/headers/meta.hpp/meta_binds/enum_bind.hpp b/headers/meta.hpp/meta_binds/enum_bind.hpp index b095afd..8da4093 100644 --- a/headers/meta.hpp/meta_binds/enum_bind.hpp +++ b/headers/meta.hpp/meta_binds/enum_bind.hpp @@ -17,13 +17,26 @@ namespace meta_hpp : type_bind_base{resolve_type(), std::move(metadata)} {} template < detail::enum_kind Enum > - enum_bind& enum_bind::evalue_(std::string name, Enum value) { - return evalue_(std::move(name), std::move(value), {}); - } + template < typename... Opts > + enum_bind& enum_bind::evalue_(std::string name, Enum value, Opts&&... opts) { + metadata_map metadata; - template < detail::enum_kind Enum > - enum_bind& enum_bind::evalue_(std::string name, Enum value, evalue_opts opts) { - auto state = detail::evalue_state::make(std::move(name), std::move(value), std::move(opts.metadata)); + { + // clang-format off + const auto process_opt = detail::overloaded{ + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::evalue_state::make(std::move(name), std::move(value), std::move(metadata)); detail::insert_or_assign(get_data().evalues, evalue{std::move(state)}); return *this; } diff --git a/headers/meta.hpp/meta_binds/scope_bind.hpp b/headers/meta.hpp/meta_binds/scope_bind.hpp index a04ba2c..b459fbf 100644 --- a/headers/meta.hpp/meta_binds/scope_bind.hpp +++ b/headers/meta.hpp/meta_binds/scope_bind.hpp @@ -15,75 +15,99 @@ namespace meta_hpp inline scope_bind::scope_bind(const scope& scope, metadata_map metadata) : state_bind_base{scope, std::move(metadata)} {} - // - // function_ - // + template < detail::function_pointer_kind Function, typename... Opts > + scope_bind& scope_bind::function_(std::string name, Function function_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::function_pointer_kind Function, function_policy_family Policy > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, Policy policy) { - return function_(std::move(name), function_ptr, {}, policy); - } - - template < detail::function_pointer_kind Function, function_policy_family Policy > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - - META_HPP_ASSERT( // - opts.arguments.size() <= state->arguments.size() // - && "provided arguments don't match function argument count" + static_assert( // + detail::type_list_count_of_v <= 1, + "function policy may be specified only once" ); - for ( std::size_t i{}, e{std::min(opts.arguments.size(), state->arguments.size())}; i < e; ++i ) { - argument& arg = state->arguments[i]; - detail::state_access(arg)->name = std::move(opts.arguments[i].get_name()); - detail::state_access(arg)->metadata = std::move(opts.arguments[i].get_metadata()); + metadata_map metadata; + argument_info_list arguments; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, function_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + [&arguments](auto&&, argument_info_list l) { + arguments.insert(arguments.end(), + std::make_move_iterator(l.begin()), + std::make_move_iterator(l.end())); + }, + [](auto&& self, arguments_bind b) { + self(self, argument_info_list{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); } - detail::insert_or_assign(get_state().functions, function{std::move(state)}); - return *this; - } - - template < detail::function_pointer_kind Function, function_policy_family Policy > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { - auto state = detail::function_state::make(std::move(name), function_ptr, {}); + auto state = detail::function_state::make(std::move(name), function_ptr, std::move(metadata)); META_HPP_ASSERT( // arguments.size() <= state->arguments.size() // - && "provided argument names don't match function argument count" + && "provided arguments don't match function argument count" ); for ( std::size_t i{}, e{std::min(arguments.size(), state->arguments.size())}; i < e; ++i ) { argument& arg = state->arguments[i]; - // NOLINTNEXTLINE(*-pointer-arithmetic) - detail::state_access(arg)->name = std::data(arguments)[i]; + detail::state_access(arg)->name = std::move(arguments[i].get_name()); + detail::state_access(arg)->metadata = std::move(arguments[i].get_metadata()); } detail::insert_or_assign(get_state().functions, function{std::move(state)}); return *this; } - // - // typedef_ - // - template < typename Type > scope_bind& scope_bind::typedef_(std::string name) { get_state().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } - // - // variable_ - // + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) { + using opts_t = detail::type_list...>; + using policy_t = detail::type_list_first_of_t; - template < detail::pointer_kind Pointer, variable_policy_family Policy > - scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, Policy policy) { - return variable_(std::move(name), variable_ptr, {}, policy); - } + static_assert( // + detail::type_list_count_of_v <= 1, + "variable policy may be specified only once" + ); - template < detail::pointer_kind Pointer, variable_policy_family Policy > - scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy) { - auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(opts.metadata)); + metadata_map metadata; + + { + // clang-format off + const auto process_opt = detail::overloaded{ + [](auto&&, variable_policy::family auto) { + // nothing + }, + [&metadata](auto&&, metadata_map m) { + detail::insert_or_assign(metadata, std::move(m)); + }, + [](auto&& self, metadata_bind b) { + self(self, metadata_map{std::move(b)}); + }, + }; + // clang-format on + + (process_opt(process_opt, std::forward(opts)), ...); + } + + auto state = detail::variable_state::make(std::move(name), variable_ptr, std::move(metadata)); detail::insert_or_assign(get_state().variables, variable{std::move(state)}); return *this; } diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index 4d43a0a..8e82c38 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -18,102 +18,128 @@ namespace meta_hpp { namespace constructor_policy { - struct as_object_t final {}; + inline constexpr struct as_object_t final { + } as_object{}; - struct as_raw_pointer_t final {}; + inline constexpr struct as_raw_pointer_t final { + } as_raw_pointer{}; - struct as_shared_pointer_t final {}; + inline constexpr struct as_shared_pointer_t final { + } as_shared_pointer{}; - struct as_unique_pointer_t final {}; + inline constexpr struct as_unique_pointer_t final { + } as_unique_pointer{}; - inline constexpr as_object_t as_object{}; - inline constexpr as_raw_pointer_t as_raw_pointer{}; - inline constexpr as_shared_pointer_t as_shared_pointer{}; - inline constexpr as_unique_pointer_t as_unique_pointer{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } namespace function_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct discard_return_t final {}; + inline constexpr struct discard_return_t final { + } discard_return{}; - struct return_reference_as_pointer_t final {}; + inline constexpr struct return_reference_as_pointer_t final { + } return_reference_as_pointer{}; - inline constexpr as_copy_t as_copy{}; - inline constexpr discard_return_t discard_return{}; - inline constexpr return_reference_as_pointer_t return_reference_as_pointer{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } namespace member_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct as_pointer_t final {}; + inline constexpr struct as_pointer_t final { + } as_pointer{}; - struct as_reference_wrapper_t final {}; + inline constexpr struct as_reference_wrapper_t final { + } as_reference_wrapper{}; + + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; - inline constexpr as_copy_t as_copy{}; - inline constexpr as_pointer_t as_pointer{}; - inline constexpr as_reference_wrapper_t as_reference_wrapper{}; } namespace method_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct discard_return_t final {}; + inline constexpr struct discard_return_t final { + } discard_return{}; - struct return_reference_as_pointer_t final {}; + inline constexpr struct return_reference_as_pointer_t final { + } return_reference_as_pointer{}; - inline constexpr as_copy_t as_copy{}; - inline constexpr discard_return_t discard_return{}; - inline constexpr return_reference_as_pointer_t return_reference_as_pointer{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } namespace variable_policy { - struct as_copy_t final {}; + inline constexpr struct as_copy_t final { + } as_copy{}; - struct as_pointer_t final {}; + inline constexpr struct as_pointer_t final { + } as_pointer{}; - struct as_reference_wrapper_t final {}; + inline constexpr struct as_reference_wrapper_t final { + } as_reference_wrapper{}; - inline constexpr as_copy_t as_copy{}; - inline constexpr as_pointer_t as_pointer{}; - inline constexpr as_reference_wrapper_t as_reference_wrapper{}; + template < typename Policy > + concept family // + = std::is_same_v // + || std::is_same_v // + || std::is_same_v; // + + template < typename T > + using is_family = std::bool_constant>; + + template < typename T > + inline constexpr bool is_family_v = is_family::value; } - - template < typename Policy > - concept constructor_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept function_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept member_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept method_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // - - template < typename Policy > - concept variable_policy_family // - = std::is_same_v // - || std::is_same_v // - || std::is_same_v; // } namespace meta_hpp @@ -497,7 +523,7 @@ namespace meta_hpp::detail create_error_impl create_error{}; argument_list arguments{}; - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > [[nodiscard]] static constructor_state_ptr make(metadata_map metadata); explicit constructor_state(constructor_index index, metadata_map metadata); }; @@ -542,7 +568,7 @@ namespace meta_hpp::detail invoke_error_impl invoke_error{}; argument_list arguments{}; - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > [[nodiscard]] static function_state_ptr make(std::string name, Function function_ptr, metadata_map metadata); explicit function_state(function_index index, metadata_map metadata); }; @@ -562,7 +588,7 @@ namespace meta_hpp::detail getter_error_impl getter_error{}; setter_error_impl setter_error{}; - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > [[nodiscard]] static member_state_ptr make(std::string name, Member member_ptr, metadata_map metadata); explicit member_state(member_index index, metadata_map metadata); }; @@ -578,7 +604,7 @@ namespace meta_hpp::detail invoke_error_impl invoke_error{}; argument_list arguments{}; - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > [[nodiscard]] static method_state_ptr make(std::string name, Method method_ptr, metadata_map metadata); explicit method_state(method_index index, metadata_map metadata); }; @@ -607,7 +633,7 @@ namespace meta_hpp::detail setter_impl setter{}; setter_error_impl setter_error{}; - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > [[nodiscard]] static variable_state_ptr make(std::string name, Pointer variable_ptr, metadata_map metadata); explicit variable_state(variable_index index, metadata_map metadata); }; diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 0ac7ebd..3e5abcc 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -15,7 +15,7 @@ namespace meta_hpp::detail { - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > uvalue raw_constructor_create(type_registry& registry, std::span args) { using ct = constructor_traits; using class_type = typename ct::class_type; @@ -104,7 +104,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > constructor_state::create_impl make_constructor_create(type_registry& registry) { return [®istry](std::span args) { // return raw_constructor_create(registry, args); @@ -146,7 +146,7 @@ namespace meta_hpp::detail : index{nindex} , metadata{std::move(nmetadata)} {} - template < constructor_policy_family Policy, class_kind Class, typename... Args > + template < constructor_policy::family Policy, class_kind Class, typename... Args > constructor_state_ptr constructor_state::make(metadata_map metadata) { type_registry& registry{type_registry::instance()}; diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index ef91c22..aae5632 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -15,7 +15,7 @@ namespace meta_hpp::detail { - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > uvalue raw_function_invoke(type_registry& registry, Function function_ptr, std::span args) { using ft = function_traits>; using return_type = typename ft::return_type; @@ -82,7 +82,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > function_state::invoke_impl make_function_invoke(type_registry& registry, Function function_ptr) { return [®istry, function_ptr](std::span args) { // return raw_function_invoke(registry, function_ptr, args); @@ -117,7 +117,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < function_policy_family Policy, function_pointer_kind Function > + template < function_policy::family Policy, function_pointer_kind Function > function_state_ptr function_state::make(std::string name, Function function_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index 1ad4c0d..baf145a 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -16,7 +16,7 @@ namespace meta_hpp::detail { - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > uvalue raw_member_getter(type_registry& registry, Member member_ptr, const uinst& inst) { using mt = member_traits; using class_type = typename mt::class_type; @@ -159,7 +159,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > member_state::getter_impl make_member_getter(type_registry& registry, Member member_ptr) { return [®istry, member_ptr](const uinst& inst) { // return raw_member_getter(registry, member_ptr, inst); @@ -194,7 +194,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < member_policy_family Policy, member_pointer_kind Member > + template < member_policy::family Policy, member_pointer_kind Member > member_state_ptr member_state::make(std::string name, Member member_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index d04214e..bd5ff6a 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -16,7 +16,7 @@ namespace meta_hpp::detail { - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > uvalue raw_method_invoke(type_registry& registry, Method method_ptr, const uinst& inst, std::span args) { using mt = method_traits; using return_type = typename mt::return_type; @@ -94,7 +94,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > method_state::invoke_impl make_method_invoke(type_registry& registry, Method method_ptr) { return [®istry, method_ptr](const uinst& inst, std::span args) { return raw_method_invoke(registry, method_ptr, inst, args); @@ -129,7 +129,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < method_policy_family Policy, method_pointer_kind Method > + template < method_policy::family Policy, method_pointer_kind Method > method_state_ptr method_state::make(std::string name, Method method_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 8c567d9..c05a9eb 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -15,7 +15,7 @@ namespace meta_hpp::detail { - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > uvalue raw_variable_getter(type_registry&, Pointer variable_ptr) { using pt = pointer_traits; using data_type = typename pt::data_type; @@ -87,7 +87,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > variable_state::getter_impl make_variable_getter(type_registry& registry, Pointer variable_ptr) { return [®istry, variable_ptr]() { // return raw_variable_getter(registry, variable_ptr); @@ -115,7 +115,7 @@ namespace meta_hpp::detail : index{std::move(nindex)} , metadata{std::move(nmetadata)} {} - template < variable_policy_family Policy, pointer_kind Pointer > + template < variable_policy::family Policy, pointer_kind Pointer > variable_state_ptr variable_state::make(std::string name, Pointer variable_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()};