From 154e1b53d650923b31e34deddbbc95c0d7d8d709 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 13 Feb 2022 22:32:08 +0700 Subject: [PATCH] remove all unnecessary std::invoke calls --- headers/meta.hpp/meta_states/constructor.hpp | 10 ++++------ headers/meta.hpp/meta_states/function.hpp | 16 ++++++---------- headers/meta.hpp/meta_states/member.hpp | 6 +++--- headers/meta.hpp/meta_states/method.hpp | 17 ++++++----------- untests/meta_utilities/arg6_tests.cpp | 4 ++-- untests/meta_utilities/value_tests.cpp | 12 ++++++------ 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 927ec5a..fee31b3 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -36,10 +36,8 @@ namespace meta_hpp::detail throw_exception_with("an attempt to call a constructor with an incorrect arity"); } - return std::invoke([ - args // NOLINTNEXTLINE(readability-named-parameter) - ](std::index_sequence) -> uvalue { + return [args](std::index_sequence) -> uvalue { if ( !(... && args[Is].can_cast_to>()) ) { throw_exception_with("an attempt to call a constructor with incorrect argument types"); } @@ -58,7 +56,7 @@ namespace meta_hpp::detail auto return_value{std::make_shared(args[Is].cast>()...)}; return uvalue{std::move(return_value)}; } - }, std::make_index_sequence()); + }(std::make_index_sequence()); } template < class_kind Class, typename... Args > @@ -71,9 +69,9 @@ namespace meta_hpp::detail } // NOLINTNEXTLINE(readability-named-parameter) - return std::invoke([args](std::index_sequence){ + return [args](std::index_sequence){ return (... && args[Is].can_cast_to>()); - }, std::make_index_sequence()); + }(std::make_index_sequence()); } } diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 287c71b..a6cc5ce 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -38,22 +38,18 @@ namespace meta_hpp::detail throw_exception_with("an attempt to call a function with an incorrect arity"); } - return std::invoke([ - &function, args // NOLINTNEXTLINE(readability-named-parameter) - ](std::index_sequence) -> uvalue { + return [&function, args](std::index_sequence) -> uvalue { if ( !(... && args[Is].can_cast_to>()) ) { throw_exception_with("an attempt to call a function with incorrect argument types"); } if constexpr ( as_void ) { - std::ignore = std::invoke( - function, + std::ignore = function( args[Is].cast>()...); return uvalue{}; } else { - return_type&& return_value = std::invoke( - function, + return_type&& return_value = function( args[Is].cast>()...); if constexpr ( ref_as_ptr ) { @@ -62,7 +58,7 @@ namespace meta_hpp::detail return uvalue{std::forward(return_value)}; } } - }, std::make_index_sequence()); + }(std::make_index_sequence()); } template < function_kind Function > @@ -75,9 +71,9 @@ namespace meta_hpp::detail } // NOLINTNEXTLINE(readability-named-parameter) - return std::invoke([args](std::index_sequence){ + return [args](std::index_sequence){ return (... && args[Is].can_cast_to>()); - }, std::make_index_sequence()); + }(std::make_index_sequence()); } } diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index f6a4e78..56e0093 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -38,7 +38,7 @@ namespace meta_hpp::detail } if ( inst.is_const() ) { - auto&& return_value = std::invoke(member, inst.cast()); + auto&& return_value = inst.cast().*member; if constexpr ( as_copy ) { return uvalue{std::forward(return_value)}; @@ -52,7 +52,7 @@ namespace meta_hpp::detail return uvalue{std::ref(return_value)}; } } else { - auto&& return_value = std::invoke(member, inst.cast()); + auto&& return_value = inst.cast().*member; if constexpr ( as_copy ) { return uvalue{std::forward(return_value)}; @@ -100,7 +100,7 @@ namespace meta_hpp::detail throw_exception_with("an attempt to set a member with an incorrect argument type"); } - std::invoke(member, inst.cast()) = arg.cast(); + inst.cast().*member = arg.cast(); } } diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index 890d663..f0984ca 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -44,24 +44,19 @@ namespace meta_hpp::detail throw_exception_with("an attempt to call a method with an incorrect instance type"); } - return std::invoke([ - &method, &inst, args // NOLINTNEXTLINE(readability-named-parameter) - ](std::index_sequence) -> uvalue { + return [&method, &inst, args](std::index_sequence) -> uvalue { if ( !(... && args[Is].can_cast_to>()) ) { throw_exception_with("an attempt to call a method with incorrect argument types"); } if constexpr ( as_void ) { - std::ignore = std::invoke( - method, + std::ignore = (inst.cast().*method)( inst.cast(), args[Is].cast>()...); return uvalue{}; } else { - return_type&& return_value = std::invoke( - method, - inst.cast(), + return_type&& return_value = (inst.cast().*method)( args[Is].cast>()...); if constexpr ( ref_as_ptr ) { @@ -70,7 +65,7 @@ namespace meta_hpp::detail return uvalue{std::forward(return_value)}; } } - }, std::make_index_sequence()); + }(std::make_index_sequence()); } template < method_kind Method > @@ -88,9 +83,9 @@ namespace meta_hpp::detail } // NOLINTNEXTLINE(readability-named-parameter) - return std::invoke([args](std::index_sequence){ + return [args](std::index_sequence){ return (... && args[Is].can_cast_to>()); - }, std::make_index_sequence()); + }(std::make_index_sequence()); } } diff --git a/untests/meta_utilities/arg6_tests.cpp b/untests/meta_utilities/arg6_tests.cpp index 65dba9e..b9f8535 100644 --- a/untests/meta_utilities/arg6_tests.cpp +++ b/untests/meta_utilities/arg6_tests.cpp @@ -24,11 +24,11 @@ namespace using int_method_t = int (clazz::*)() const; int func_with_member(const clazz& cl, int_member_t m) { - return std::invoke(m, cl); + return cl.*m; } int func_with_method(const clazz& cl, int_method_t m) { - return std::invoke(m, cl); + return (cl.*m)(); } } diff --git a/untests/meta_utilities/value_tests.cpp b/untests/meta_utilities/value_tests.cpp index 4b0d388..febc5a7 100644 --- a/untests/meta_utilities/value_tests.cpp +++ b/untests/meta_utilities/value_tests.cpp @@ -582,8 +582,8 @@ TEST_CASE("meta/meta_utilities/value/functions") { { const meta::uvalue v{&ivec2::add}; CHECK(v.get_type() == meta::resolve_type()); - CHECK(std::invoke(v.cast(), ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); - CHECK(std::invoke(*v.try_cast(), ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); + CHECK((ivec2{1,2}.*(v.cast()))(ivec2{3,4}) == ivec2(4,6)); + CHECK((ivec2{1,2}.*(*v.try_cast()))(ivec2{3,4}) == ivec2(4,6)); } } @@ -591,14 +591,14 @@ TEST_CASE("meta/meta_utilities/value/functions") { { const meta::uvalue v{iadd2}; CHECK(v.get_type() == meta::resolve_type()); - CHECK(std::invoke(v.cast(), ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); - CHECK(std::invoke(*v.try_cast(), ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); + CHECK((v.cast())(ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); + CHECK((*v.try_cast())(ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); } { const meta::uvalue v{&iadd2}; CHECK(v.get_type() == meta::resolve_type()); - CHECK(std::invoke(v.cast(), ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); - CHECK(std::invoke(*v.try_cast(), ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); + CHECK((v.cast())(ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); + CHECK((*v.try_cast())(ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); } } }