rewrite global is_invocable_with to dynamic version

This commit is contained in:
BlackMATov
2023-02-19 02:59:52 +07:00
parent cda2035321
commit 704aef878d
4 changed files with 57 additions and 60 deletions

View File

@@ -5306,11 +5306,11 @@ namespace meta_hpp
template < typename... Args > template < typename... Args >
bool is_invocable_with(const function& function, Args&&... args); bool is_invocable_with(const function& function, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(); bool is_invocable_with(Function);
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Args&&... args); bool is_invocable_with(Function, Args&&... args);
} }
namespace meta_hpp namespace meta_hpp
@@ -5321,11 +5321,11 @@ namespace meta_hpp
template < typename Instance > template < typename Instance >
bool is_invocable_with(const member& member, Instance&& instance); bool is_invocable_with(const member& member, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(); bool is_invocable_with(Member);
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Instance&& instance); bool is_invocable_with(Member, Instance&& instance);
} }
namespace meta_hpp namespace meta_hpp
@@ -5336,11 +5336,11 @@ namespace meta_hpp
template < typename Instance, typename... Args > template < typename Instance, typename... Args >
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args); bool is_invocable_with(const method& method, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(); bool is_invocable_with(Method);
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Instance&& instance, Args&&... args); bool is_invocable_with(Method, Instance&& instance, Args&&... args);
} }
namespace meta_hpp::detail namespace meta_hpp::detail
@@ -6931,16 +6931,16 @@ namespace meta_hpp
return function.is_invocable_with(std::forward<Args>(args)...); return function.is_invocable_with(std::forward<Args>(args)...);
} }
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with() { bool is_invocable_with(Function) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, type_list<Args>{}}...}; const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, type_list<Args>{}}...};
return !raw_function_invoke_error<Function>(registry, vargs); return !raw_function_invoke_error<Function>(registry, vargs);
} }
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Args&&... args) { bool is_invocable_with(Function, Args&&... args) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, std::forward<Args>(args)}...}; const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, std::forward<Args>(args)}...};
@@ -6960,16 +6960,16 @@ namespace meta_hpp
return member.is_gettable_with(std::forward<Instance>(instance)); return member.is_gettable_with(std::forward<Instance>(instance));
} }
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with() { bool is_invocable_with(Member) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}}; const uinst_base vinst{registry, type_list<Instance>{}};
return !raw_member_getter_error<Member>(registry, vinst); return !raw_member_getter_error<Member>(registry, vinst);
} }
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Instance&& instance) { bool is_invocable_with(Member, Instance&& instance) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)}; const uinst_base vinst{registry, std::forward<Instance>(instance)};
@@ -6989,8 +6989,8 @@ namespace meta_hpp
return method.is_invocable_with(std::forward<Instance>(instance), std::forward<Args>(args)...); return method.is_invocable_with(std::forward<Instance>(instance), std::forward<Args>(args)...);
} }
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with() { bool is_invocable_with(Method) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}}; const uinst_base vinst{registry, type_list<Instance>{}};
@@ -6998,8 +6998,8 @@ namespace meta_hpp
return !raw_method_invoke_error<Method>(registry, vinst, vargs); return !raw_method_invoke_error<Method>(registry, vinst, vargs);
} }
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Instance&& instance, Args&&... args) { bool is_invocable_with(Method, Instance&& instance, Args&&... args) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)}; const uinst_base vinst{registry, std::forward<Instance>(instance)};

View File

@@ -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, meta::uvalue{3}));
CHECK(meta::is_invocable_with<int>(clazz_function)); CHECK(meta::is_invocable_with<int>(clazz_function));
using function_t = decltype(&clazz::function); CHECK(meta::is_invocable_with(&clazz::function, 3));
CHECK(meta::is_invocable_with<function_t>(3)); CHECK(meta::is_invocable_with(&clazz::function, meta::uvalue{3}));
CHECK(meta::is_invocable_with<function_t>(meta::uvalue{3})); CHECK(meta::is_invocable_with<int>(&clazz::function));
CHECK(meta::is_invocable_with<function_t, int>());
} }
{ {
@@ -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, meta::uvalue{cl}));
CHECK(meta::is_invocable_with<const clazz&>(clazz_member)); CHECK(meta::is_invocable_with<const clazz&>(clazz_member));
using member_t = decltype(&clazz::member); CHECK(meta::is_invocable_with(&clazz::member, cl));
CHECK(meta::is_invocable_with<member_t>(cl)); CHECK(meta::is_invocable_with(&clazz::member, meta::uvalue{cl}));
CHECK(meta::is_invocable_with<member_t>(meta::uvalue{cl})); CHECK(meta::is_invocable_with<const clazz&>(&clazz::member));
CHECK(meta::is_invocable_with<member_t, const clazz&>());
} }
{ {
@@ -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, meta::uvalue{cl}, meta::uvalue{2}));
CHECK(meta::is_invocable_with<const clazz&, int>(clazz_method)); CHECK(meta::is_invocable_with<const clazz&, int>(clazz_method));
using method_t = decltype(&clazz::method); CHECK(meta::is_invocable_with(&clazz::method, cl, 2));
CHECK(meta::is_invocable_with<method_t>(cl, 2)); CHECK(meta::is_invocable_with(&clazz::method, meta::uvalue{cl}, meta::uvalue{2}));
CHECK(meta::is_invocable_with<method_t>(meta::uvalue{cl}, meta::uvalue{2})); CHECK(meta::is_invocable_with<const clazz&, int>(&clazz::method));
CHECK(meta::is_invocable_with<method_t, const clazz&, int>());
} }
} }

View File

@@ -45,11 +45,11 @@ namespace meta_hpp
template < typename... Args > template < typename... Args >
bool is_invocable_with(const function& function, Args&&... args); bool is_invocable_with(const function& function, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(); bool is_invocable_with(Function);
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Args&&... args); bool is_invocable_with(Function, Args&&... args);
} }
namespace meta_hpp namespace meta_hpp
@@ -60,11 +60,11 @@ namespace meta_hpp
template < typename Instance > template < typename Instance >
bool is_invocable_with(const member& member, Instance&& instance); bool is_invocable_with(const member& member, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(); bool is_invocable_with(Member);
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Instance&& instance); bool is_invocable_with(Member, Instance&& instance);
} }
namespace meta_hpp namespace meta_hpp
@@ -75,9 +75,9 @@ namespace meta_hpp
template < typename Instance, typename... Args > template < typename Instance, typename... Args >
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args); bool is_invocable_with(const method& method, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(); bool is_invocable_with(Method);
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Instance&& instance, Args&&... args); bool is_invocable_with(Method, Instance&& instance, Args&&... args);
} }

View File

@@ -78,16 +78,16 @@ namespace meta_hpp
return function.is_invocable_with(std::forward<Args>(args)...); return function.is_invocable_with(std::forward<Args>(args)...);
} }
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with() { bool is_invocable_with(Function) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, type_list<Args>{}}...}; const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, type_list<Args>{}}...};
return !raw_function_invoke_error<Function>(registry, vargs); return !raw_function_invoke_error<Function>(registry, vargs);
} }
template < detail::function_pointer_kind Function, typename... Args > template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Args&&... args) { bool is_invocable_with(Function, Args&&... args) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, std::forward<Args>(args)}...}; const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, std::forward<Args>(args)}...};
@@ -107,16 +107,16 @@ namespace meta_hpp
return member.is_gettable_with(std::forward<Instance>(instance)); return member.is_gettable_with(std::forward<Instance>(instance));
} }
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with() { bool is_invocable_with(Member) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}}; const uinst_base vinst{registry, type_list<Instance>{}};
return !raw_member_getter_error<Member>(registry, vinst); return !raw_member_getter_error<Member>(registry, vinst);
} }
template < detail::member_pointer_kind Member, typename Instance > template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Instance&& instance) { bool is_invocable_with(Member, Instance&& instance) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)}; const uinst_base vinst{registry, std::forward<Instance>(instance)};
@@ -136,8 +136,8 @@ namespace meta_hpp
return method.is_invocable_with(std::forward<Instance>(instance), std::forward<Args>(args)...); return method.is_invocable_with(std::forward<Instance>(instance), std::forward<Args>(args)...);
} }
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with() { bool is_invocable_with(Method) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}}; const uinst_base vinst{registry, type_list<Instance>{}};
@@ -145,8 +145,8 @@ namespace meta_hpp
return !raw_method_invoke_error<Method>(registry, vinst, vargs); return !raw_method_invoke_error<Method>(registry, vinst, vargs);
} }
template < detail::method_pointer_kind Method, typename Instance, typename... Args > template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Instance&& instance, Args&&... args) { bool is_invocable_with(Method, Instance&& instance, Args&&... args) {
using namespace detail; using namespace detail;
type_registry& registry{type_registry::instance()}; type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)}; const uinst_base vinst{registry, std::forward<Instance>(instance)};