From 704aef878d99b9cb67407960dc0c7b2380e74767 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 19 Feb 2023 02:59:52 +0700 Subject: [PATCH] rewrite global is_invocable_with to dynamic version --- develop/singles/headers/meta.hpp/meta_all.hpp | 48 +++++++++---------- .../untests/meta_utilities/invoke_tests.cpp | 21 ++++---- headers/meta.hpp/meta_invoke.hpp | 24 +++++----- headers/meta.hpp/meta_invoke/invoke.hpp | 24 +++++----- 4 files changed, 57 insertions(+), 60 deletions(-) diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 836d96c..bde6136 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -5306,11 +5306,11 @@ namespace meta_hpp template < typename... Args > bool is_invocable_with(const function& function, Args&&... args); - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with(); + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function); - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with(Args&&... args); + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function, Args&&... args); } namespace meta_hpp @@ -5321,11 +5321,11 @@ namespace meta_hpp template < typename Instance > bool is_invocable_with(const member& member, Instance&& instance); - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with(); + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member); - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with(Instance&& instance); + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member, Instance&& instance); } namespace meta_hpp @@ -5336,11 +5336,11 @@ namespace meta_hpp template < typename Instance, typename... Args > bool is_invocable_with(const method& method, Instance&& instance, Args&&... args); - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with(); + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method); - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with(Instance&& instance, Args&&... args); + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method, Instance&& instance, Args&&... args); } namespace meta_hpp::detail @@ -6931,16 +6931,16 @@ namespace meta_hpp return function.is_invocable_with(std::forward(args)...); } - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with() { + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function) { using namespace detail; type_registry& registry{type_registry::instance()}; const std::array vargs{uarg_base{registry, type_list{}}...}; return !raw_function_invoke_error(registry, vargs); } - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with(Args&&... args) { + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function, Args&&... args) { using namespace detail; type_registry& registry{type_registry::instance()}; const std::array vargs{uarg_base{registry, std::forward(args)}...}; @@ -6960,16 +6960,16 @@ namespace meta_hpp return member.is_gettable_with(std::forward(instance)); } - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with() { + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, type_list{}}; return !raw_member_getter_error(registry, vinst); } - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with(Instance&& instance) { + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member, Instance&& instance) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, std::forward(instance)}; @@ -6989,8 +6989,8 @@ namespace meta_hpp return method.is_invocable_with(std::forward(instance), std::forward(args)...); } - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with() { + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, type_list{}}; @@ -6998,8 +6998,8 @@ namespace meta_hpp return !raw_method_invoke_error(registry, vinst, vargs); } - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with(Instance&& instance, Args&&... args) { + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method, Instance&& instance, Args&&... args) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, std::forward(instance)}; diff --git a/develop/untests/meta_utilities/invoke_tests.cpp b/develop/untests/meta_utilities/invoke_tests.cpp index dedd570..b6b0fdf 100644 --- a/develop/untests/meta_utilities/invoke_tests.cpp +++ b/develop/untests/meta_utilities/invoke_tests.cpp @@ -42,10 +42,9 @@ TEST_CASE("meta/meta_utilities/invoke") { CHECK(meta::is_invocable_with(clazz_function, meta::uvalue{3})); CHECK(meta::is_invocable_with(clazz_function)); - using function_t = decltype(&clazz::function); - CHECK(meta::is_invocable_with(3)); - CHECK(meta::is_invocable_with(meta::uvalue{3})); - CHECK(meta::is_invocable_with()); + CHECK(meta::is_invocable_with(&clazz::function, 3)); + CHECK(meta::is_invocable_with(&clazz::function, meta::uvalue{3})); + CHECK(meta::is_invocable_with(&clazz::function)); } { @@ -60,10 +59,9 @@ TEST_CASE("meta/meta_utilities/invoke") { CHECK(meta::is_invocable_with(clazz_member, meta::uvalue{cl})); CHECK(meta::is_invocable_with(clazz_member)); - using member_t = decltype(&clazz::member); - CHECK(meta::is_invocable_with(cl)); - CHECK(meta::is_invocable_with(meta::uvalue{cl})); - CHECK(meta::is_invocable_with()); + CHECK(meta::is_invocable_with(&clazz::member, cl)); + CHECK(meta::is_invocable_with(&clazz::member, meta::uvalue{cl})); + CHECK(meta::is_invocable_with(&clazz::member)); } { @@ -78,9 +76,8 @@ TEST_CASE("meta/meta_utilities/invoke") { CHECK(meta::is_invocable_with(clazz_method, meta::uvalue{cl}, meta::uvalue{2})); CHECK(meta::is_invocable_with(clazz_method)); - using method_t = decltype(&clazz::method); - CHECK(meta::is_invocable_with(cl, 2)); - CHECK(meta::is_invocable_with(meta::uvalue{cl}, meta::uvalue{2})); - CHECK(meta::is_invocable_with()); + CHECK(meta::is_invocable_with(&clazz::method, cl, 2)); + CHECK(meta::is_invocable_with(&clazz::method, meta::uvalue{cl}, meta::uvalue{2})); + CHECK(meta::is_invocable_with(&clazz::method)); } } diff --git a/headers/meta.hpp/meta_invoke.hpp b/headers/meta.hpp/meta_invoke.hpp index e3b207d..01eb38b 100644 --- a/headers/meta.hpp/meta_invoke.hpp +++ b/headers/meta.hpp/meta_invoke.hpp @@ -45,11 +45,11 @@ namespace meta_hpp template < typename... Args > bool is_invocable_with(const function& function, Args&&... args); - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with(); + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function); - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with(Args&&... args); + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function, Args&&... args); } namespace meta_hpp @@ -60,11 +60,11 @@ namespace meta_hpp template < typename Instance > bool is_invocable_with(const member& member, Instance&& instance); - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with(); + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member); - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with(Instance&& instance); + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member, Instance&& instance); } namespace meta_hpp @@ -75,9 +75,9 @@ namespace meta_hpp template < typename Instance, typename... Args > bool is_invocable_with(const method& method, Instance&& instance, Args&&... args); - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with(); + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method); - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with(Instance&& instance, Args&&... args); + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method, Instance&& instance, Args&&... args); } diff --git a/headers/meta.hpp/meta_invoke/invoke.hpp b/headers/meta.hpp/meta_invoke/invoke.hpp index ba1e3e7..cefa5c2 100644 --- a/headers/meta.hpp/meta_invoke/invoke.hpp +++ b/headers/meta.hpp/meta_invoke/invoke.hpp @@ -78,16 +78,16 @@ namespace meta_hpp return function.is_invocable_with(std::forward(args)...); } - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with() { + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function) { using namespace detail; type_registry& registry{type_registry::instance()}; const std::array vargs{uarg_base{registry, type_list{}}...}; return !raw_function_invoke_error(registry, vargs); } - template < detail::function_pointer_kind Function, typename... Args > - bool is_invocable_with(Args&&... args) { + template < typename... Args, detail::function_pointer_kind Function > + bool is_invocable_with(Function, Args&&... args) { using namespace detail; type_registry& registry{type_registry::instance()}; const std::array vargs{uarg_base{registry, std::forward(args)}...}; @@ -107,16 +107,16 @@ namespace meta_hpp return member.is_gettable_with(std::forward(instance)); } - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with() { + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, type_list{}}; return !raw_member_getter_error(registry, vinst); } - template < detail::member_pointer_kind Member, typename Instance > - bool is_invocable_with(Instance&& instance) { + template < typename Instance, detail::member_pointer_kind Member > + bool is_invocable_with(Member, Instance&& instance) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, std::forward(instance)}; @@ -136,8 +136,8 @@ namespace meta_hpp return method.is_invocable_with(std::forward(instance), std::forward(args)...); } - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with() { + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, type_list{}}; @@ -145,8 +145,8 @@ namespace meta_hpp return !raw_method_invoke_error(registry, vinst, vargs); } - template < detail::method_pointer_kind Method, typename Instance, typename... Args > - bool is_invocable_with(Instance&& instance, Args&&... args) { + template < typename Instance, typename... Args, detail::method_pointer_kind Method > + bool is_invocable_with(Method, Instance&& instance, Args&&... args) { using namespace detail; type_registry& registry{type_registry::instance()}; const uinst_base vinst{registry, std::forward(instance)};