From 03fbc7240099d7007b99761d6510910627e8119c Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 11 Aug 2023 02:07:09 +0700 Subject: [PATCH] ref-qualifiers for binds --- ROADMAP.md | 6 +- develop/singles/headers/meta.hpp/meta_all.hpp | 161 +++++++++++++++--- headers/meta.hpp/meta_binds.hpp | 61 +++++-- headers/meta.hpp/meta_binds/class_bind.hpp | 76 +++++++-- headers/meta.hpp/meta_binds/scope_bind.hpp | 24 ++- 5 files changed, 273 insertions(+), 55 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index b775ffa..78c1df0 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -7,12 +7,12 @@ - register base types by `META_HPP_ENABLE_POLY_INFO` - fix all includes to work with the library more flexible - test and support shared libraries +- remove `resolve_poly_type`, use `resolve_type(T&&)` instead +- add `match` function to `any_type` class ## Thoughts -- should `uvalue` dereference operators return `reference_wrapper`? -- `array_view`/`pointer_view` instead `unmap`/`operator[]`/`operator*`? -- can we add move-only uvalue analog to return move-only values? +- store only `hashed_string` in indices instead `string` ## Version 1.0 diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 1ec96d9..86bc569 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -4586,30 +4586,56 @@ namespace meta_hpp explicit class_bind(metadata_map metadata); template < detail::class_bind_base_kind... Bases > - class_bind& base_(); + class_bind& base_() &; + + template < detail::class_bind_base_kind... Bases > + class_bind base_() &&; template < typename... Args, typename... Opts > - class_bind& constructor_(Opts&&... opts) - requires detail::class_bind_constructor_kind; + requires detail::class_bind_constructor_kind + class_bind& constructor_(Opts&&... opts) &; + + template < typename... Args, typename... Opts > + requires detail::class_bind_constructor_kind + class_bind constructor_(Opts&&... opts) &&; template < typename... Opts > - class_bind& destructor_(Opts&&... opts) - requires detail::class_bind_destructor_kind; + requires detail::class_bind_destructor_kind + class_bind& destructor_(Opts&&... opts) &; + + template < typename... Opts > + requires detail::class_bind_destructor_kind + class_bind destructor_(Opts&&... opts) &&; template < detail::function_pointer_kind Function, typename... Opts > - class_bind& function_(std::string name, Function function_ptr, Opts&&... opts); + class_bind& function_(std::string name, Function function_ptr, Opts&&... opts) &; + + template < detail::function_pointer_kind Function, typename... Opts > + class_bind function_(std::string name, Function function_ptr, Opts&&... opts) &&; template < detail::class_bind_member_kind Member, typename... Opts > - class_bind& member_(std::string name, Member member_ptr, Opts&&... opts); + class_bind& member_(std::string name, Member member_ptr, Opts&&... opts) &; + + template < detail::class_bind_member_kind Member, typename... Opts > + class_bind member_(std::string name, Member member_ptr, Opts&&... opts) &&; template < detail::class_bind_method_kind Method, typename... Opts > - class_bind& method_(std::string name, Method method_ptr, Opts&&... opts); + class_bind& method_(std::string name, Method method_ptr, Opts&&... opts) &; + + template < detail::class_bind_method_kind Method, typename... Opts > + class_bind method_(std::string name, Method method_ptr, Opts&&... opts) &&; template < typename Type > - class_bind& typedef_(std::string name); + class_bind& typedef_(std::string name) &; + + template < typename Type > + class_bind typedef_(std::string name) &&; template < detail::pointer_kind Pointer, typename... Opts > - class_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); + class_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &; + + template < detail::pointer_kind Pointer, typename... Opts > + class_bind variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &&; }; } @@ -4704,13 +4730,22 @@ namespace meta_hpp explicit scope_bind(const scope& scope, metadata_map metadata); template < detail::function_pointer_kind Function, typename... Opts > - scope_bind& function_(std::string name, Function function_ptr, Opts&&... opts); + scope_bind& function_(std::string name, Function function_ptr, Opts&&... opts) &; + + 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); + scope_bind& typedef_(std::string name) &; + + template < typename Type > + scope_bind typedef_(std::string name) &&; template < detail::pointer_kind Pointer, typename... Opts > - scope_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); + scope_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &; + + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &&; }; } @@ -5089,7 +5124,7 @@ namespace meta_hpp template < detail::class_kind Class > template < detail::class_bind_base_kind... Bases > - class_bind& class_bind::base_() { + class_bind& class_bind::base_() & { using namespace detail; using namespace detail::class_bind_impl; @@ -5130,11 +5165,17 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::class_bind_base_kind... Bases > + class_bind class_bind::base_() && { + base_(); + return std::move(*this); + } + template < detail::class_kind Class > template < typename... Args, typename... Opts > - class_bind& class_bind::constructor_(Opts&&... opts) requires detail::class_bind_constructor_kind - { + class_bind& class_bind::constructor_(Opts&&... opts) & { using opts_t = detail::type_list...>; using policy_t = detail::type_list_first_of_t; @@ -5175,11 +5216,18 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < typename... Args, typename... Opts > + requires detail::class_bind_constructor_kind + class_bind class_bind::constructor_(Opts&&... opts) && { + constructor_(std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < typename... Opts > - class_bind& class_bind::destructor_(Opts&&... opts) requires detail::class_bind_destructor_kind - { + class_bind& class_bind::destructor_(Opts&&... opts) & { metadata_bind metadata; { @@ -5196,9 +5244,17 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < typename... Opts > + requires detail::class_bind_destructor_kind + class_bind class_bind::destructor_(Opts&&... opts) && { + destructor_(std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::function_pointer_kind Function, typename... Opts > - class_bind& class_bind::function_(std::string name, Function function_ptr, Opts&&... 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; @@ -5239,9 +5295,16 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::function_pointer_kind Function, typename... Opts > + class_bind class_bind::function_(std::string name, Function function_ptr, Opts&&... opts) && { + function_(std::move(name), function_ptr, std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::class_bind_member_kind Member, typename... Opts > - class_bind& class_bind::member_(std::string name, Member member_ptr, [[maybe_unused]] Opts&&... opts) { + class_bind& class_bind::member_(std::string name, Member member_ptr, Opts&&... opts) & { using opts_t = detail::type_list...>; using policy_t = detail::type_list_first_of_t; @@ -5267,9 +5330,16 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::class_bind_member_kind Member, typename... Opts > + class_bind class_bind::member_(std::string name, Member member_ptr, Opts&&... opts) && { + member_(std::move(name), member_ptr, std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::class_bind_method_kind Method, typename... Opts > - class_bind& class_bind::method_(std::string name, Method method_ptr, Opts&&... opts) { + 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; @@ -5310,16 +5380,30 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::class_bind_method_kind Method, typename... Opts > + class_bind class_bind::method_(std::string name, Method method_ptr, Opts&&... opts) && { + method_(std::move(name), method_ptr, std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < typename Type > - class_bind& class_bind::typedef_(std::string name) { + class_bind& class_bind::typedef_(std::string name) & { get_data().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } + template < detail::class_kind Class > + template < typename Type > + class_bind class_bind::typedef_(std::string name) && { + typedef_(std::move(name)); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::pointer_kind Pointer, typename... Opts > - class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... 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; @@ -5344,6 +5428,13 @@ namespace meta_hpp detail::insert_or_assign(get_data().variables, variable{std::move(state)}); return *this; } + + template < detail::class_kind Class > + template < detail::pointer_kind Pointer, typename... Opts > + class_bind class_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) && { + variable_(std::move(name), variable_ptr, std::forward(opts)...); + return std::move(*this); + } } namespace meta_hpp @@ -5433,7 +5524,7 @@ namespace meta_hpp : state_bind_base{scope, std::move(metadata)} {} template < detail::function_pointer_kind Function, typename... Opts > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, Opts&&... 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; @@ -5474,14 +5565,26 @@ namespace meta_hpp return *this; } + template < detail::function_pointer_kind Function, typename... Opts > + scope_bind scope_bind::function_(std::string name, Function function_ptr, Opts&&... opts) && { + function_(std::move(name), function_ptr, std::forward(opts)...); + return std::move(*this); + } + template < typename Type > - scope_bind& scope_bind::typedef_(std::string name) { + scope_bind& scope_bind::typedef_(std::string name) & { get_state().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } + template < typename Type > + scope_bind scope_bind::typedef_(std::string name) && { + typedef_(std::move(name)); + return std::move(*this); + } + template < detail::pointer_kind Pointer, typename... Opts > - scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... 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; @@ -5506,6 +5609,12 @@ namespace meta_hpp detail::insert_or_assign(get_state().variables, variable{std::move(state)}); return *this; } + + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind scope_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) && { + variable_(std::move(name), variable_ptr, std::forward(opts)...); + return std::move(*this); + } } namespace meta_hpp diff --git a/headers/meta.hpp/meta_binds.hpp b/headers/meta.hpp/meta_binds.hpp index 9df76f0..182d627 100644 --- a/headers/meta.hpp/meta_binds.hpp +++ b/headers/meta.hpp/meta_binds.hpp @@ -108,30 +108,56 @@ namespace meta_hpp explicit class_bind(metadata_map metadata); template < detail::class_bind_base_kind... Bases > - class_bind& base_(); + class_bind& base_() &; + + template < detail::class_bind_base_kind... Bases > + class_bind base_() &&; template < typename... Args, typename... Opts > - class_bind& constructor_(Opts&&... opts) - requires detail::class_bind_constructor_kind; + requires detail::class_bind_constructor_kind + class_bind& constructor_(Opts&&... opts) &; + + template < typename... Args, typename... Opts > + requires detail::class_bind_constructor_kind + class_bind constructor_(Opts&&... opts) &&; template < typename... Opts > - class_bind& destructor_(Opts&&... opts) - requires detail::class_bind_destructor_kind; + requires detail::class_bind_destructor_kind + class_bind& destructor_(Opts&&... opts) &; + + template < typename... Opts > + requires detail::class_bind_destructor_kind + class_bind destructor_(Opts&&... opts) &&; template < detail::function_pointer_kind Function, typename... Opts > - class_bind& function_(std::string name, Function function_ptr, Opts&&... opts); + class_bind& function_(std::string name, Function function_ptr, Opts&&... opts) &; + + template < detail::function_pointer_kind Function, typename... Opts > + class_bind function_(std::string name, Function function_ptr, Opts&&... opts) &&; template < detail::class_bind_member_kind Member, typename... Opts > - class_bind& member_(std::string name, Member member_ptr, Opts&&... opts); + class_bind& member_(std::string name, Member member_ptr, Opts&&... opts) &; + + template < detail::class_bind_member_kind Member, typename... Opts > + class_bind member_(std::string name, Member member_ptr, Opts&&... opts) &&; template < detail::class_bind_method_kind Method, typename... Opts > - class_bind& method_(std::string name, Method method_ptr, Opts&&... opts); + class_bind& method_(std::string name, Method method_ptr, Opts&&... opts) &; + + template < detail::class_bind_method_kind Method, typename... Opts > + class_bind method_(std::string name, Method method_ptr, Opts&&... opts) &&; template < typename Type > - class_bind& typedef_(std::string name); + class_bind& typedef_(std::string name) &; + + template < typename Type > + class_bind typedef_(std::string name) &&; template < detail::pointer_kind Pointer, typename... Opts > - class_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); + class_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &; + + template < detail::pointer_kind Pointer, typename... Opts > + class_bind variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &&; }; } @@ -226,13 +252,22 @@ namespace meta_hpp explicit scope_bind(const scope& scope, metadata_map metadata); template < detail::function_pointer_kind Function, typename... Opts > - scope_bind& function_(std::string name, Function function_ptr, Opts&&... opts); + scope_bind& function_(std::string name, Function function_ptr, Opts&&... opts) &; + + 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); + scope_bind& typedef_(std::string name) &; + + template < typename Type > + scope_bind typedef_(std::string name) &&; template < detail::pointer_kind Pointer, typename... Opts > - scope_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts); + scope_bind& variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &; + + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind variable_(std::string name, Pointer variable_ptr, Opts&&... opts) &&; }; } diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index 5047cf0..376dd37 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -99,7 +99,7 @@ namespace meta_hpp template < detail::class_kind Class > template < detail::class_bind_base_kind... Bases > - class_bind& class_bind::base_() { + class_bind& class_bind::base_() & { using namespace detail; using namespace detail::class_bind_impl; @@ -140,11 +140,17 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::class_bind_base_kind... Bases > + class_bind class_bind::base_() && { + base_(); + return std::move(*this); + } + template < detail::class_kind Class > template < typename... Args, typename... Opts > - class_bind& class_bind::constructor_(Opts&&... opts) requires detail::class_bind_constructor_kind - { + class_bind& class_bind::constructor_(Opts&&... opts) & { using opts_t = detail::type_list...>; using policy_t = detail::type_list_first_of_t; @@ -185,11 +191,18 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < typename... Args, typename... Opts > + requires detail::class_bind_constructor_kind + class_bind class_bind::constructor_(Opts&&... opts) && { + constructor_(std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < typename... Opts > - class_bind& class_bind::destructor_(Opts&&... opts) requires detail::class_bind_destructor_kind - { + class_bind& class_bind::destructor_(Opts&&... opts) & { metadata_bind metadata; { @@ -206,9 +219,17 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < typename... Opts > + requires detail::class_bind_destructor_kind + class_bind class_bind::destructor_(Opts&&... opts) && { + destructor_(std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::function_pointer_kind Function, typename... Opts > - class_bind& class_bind::function_(std::string name, Function function_ptr, Opts&&... 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; @@ -249,9 +270,16 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::function_pointer_kind Function, typename... Opts > + class_bind class_bind::function_(std::string name, Function function_ptr, Opts&&... opts) && { + function_(std::move(name), function_ptr, std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::class_bind_member_kind Member, typename... Opts > - class_bind& class_bind::member_(std::string name, Member member_ptr, [[maybe_unused]] Opts&&... opts) { + class_bind& class_bind::member_(std::string name, Member member_ptr, Opts&&... opts) & { using opts_t = detail::type_list...>; using policy_t = detail::type_list_first_of_t; @@ -277,9 +305,16 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::class_bind_member_kind Member, typename... Opts > + class_bind class_bind::member_(std::string name, Member member_ptr, Opts&&... opts) && { + member_(std::move(name), member_ptr, std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::class_bind_method_kind Method, typename... Opts > - class_bind& class_bind::method_(std::string name, Method method_ptr, Opts&&... opts) { + 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; @@ -320,16 +355,30 @@ namespace meta_hpp return *this; } + template < detail::class_kind Class > + template < detail::class_bind_method_kind Method, typename... Opts > + class_bind class_bind::method_(std::string name, Method method_ptr, Opts&&... opts) && { + method_(std::move(name), method_ptr, std::forward(opts)...); + return std::move(*this); + } + template < detail::class_kind Class > template < typename Type > - class_bind& class_bind::typedef_(std::string name) { + class_bind& class_bind::typedef_(std::string name) & { get_data().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } + template < detail::class_kind Class > + template < typename Type > + class_bind class_bind::typedef_(std::string name) && { + typedef_(std::move(name)); + return std::move(*this); + } + template < detail::class_kind Class > template < detail::pointer_kind Pointer, typename... Opts > - class_bind& class_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... 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; @@ -354,4 +403,11 @@ namespace meta_hpp detail::insert_or_assign(get_data().variables, variable{std::move(state)}); return *this; } + + template < detail::class_kind Class > + template < detail::pointer_kind Pointer, typename... Opts > + class_bind class_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) && { + variable_(std::move(name), variable_ptr, std::forward(opts)...); + return std::move(*this); + } } diff --git a/headers/meta.hpp/meta_binds/scope_bind.hpp b/headers/meta.hpp/meta_binds/scope_bind.hpp index 760a9b4..f8c9e06 100644 --- a/headers/meta.hpp/meta_binds/scope_bind.hpp +++ b/headers/meta.hpp/meta_binds/scope_bind.hpp @@ -16,7 +16,7 @@ namespace meta_hpp : state_bind_base{scope, std::move(metadata)} {} template < detail::function_pointer_kind Function, typename... Opts > - scope_bind& scope_bind::function_(std::string name, Function function_ptr, Opts&&... 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; @@ -57,14 +57,26 @@ namespace meta_hpp return *this; } + template < detail::function_pointer_kind Function, typename... Opts > + scope_bind scope_bind::function_(std::string name, Function function_ptr, Opts&&... opts) && { + function_(std::move(name), function_ptr, std::forward(opts)...); + return std::move(*this); + } + template < typename Type > - scope_bind& scope_bind::typedef_(std::string name) { + scope_bind& scope_bind::typedef_(std::string name) & { get_state().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } + template < typename Type > + scope_bind scope_bind::typedef_(std::string name) && { + typedef_(std::move(name)); + return std::move(*this); + } + template < detail::pointer_kind Pointer, typename... Opts > - scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... 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; @@ -89,4 +101,10 @@ namespace meta_hpp detail::insert_or_assign(get_state().variables, variable{std::move(state)}); return *this; } + + template < detail::pointer_kind Pointer, typename... Opts > + scope_bind scope_bind::variable_(std::string name, Pointer variable_ptr, Opts&&... opts) && { + variable_(std::move(name), variable_ptr, std::forward(opts)...); + return std::move(*this); + } }