From 8822eb5ff883bf267f55d24e1791d99a00ab31b5 Mon Sep 17 00:00:00 2001 From: Dmytro <33125344+smay1613@users.noreply.github.com> Date: Tue, 19 May 2020 16:05:34 +0300 Subject: [PATCH 1/2] Implement with c++11 --- headers/invoke.hpp/invoke.hpp | 77 +++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/headers/invoke.hpp/invoke.hpp b/headers/invoke.hpp/invoke.hpp index 8dfb861..4c6a646 100644 --- a/headers/invoke.hpp/invoke.hpp +++ b/headers/invoke.hpp/invoke.hpp @@ -54,7 +54,7 @@ namespace invoke_hpp template < typename T > struct is_reference_wrapper - : impl::is_reference_wrapper_impl> {}; + : impl::is_reference_wrapper_impl::type> {}; } // @@ -72,7 +72,7 @@ namespace invoke_hpp template < typename Base, typename F, typename Derived, - typename std::enable_if_t>::value, int> = 0 + typename std::enable_if::type>::value, int>::type = 0 > constexpr auto invoke_member_object_impl(F Base::* f, Derived&& ref) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -81,7 +81,7 @@ namespace invoke_hpp template < typename Base, typename F, typename RefWrap, - typename std::enable_if_t>::value, int> = 0 + typename std::enable_if::type>::value, int>::type = 0 > constexpr auto invoke_member_object_impl(F Base::* f, RefWrap&& ref) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -90,10 +90,10 @@ namespace invoke_hpp template < typename Base, typename F, typename Pointer, - typename std::enable_if_t< - !std::is_base_of>::value && - !is_reference_wrapper>::value - , int> = 0 + typename std::enable_if< + !std::is_base_of::type>::value && + !is_reference_wrapper::type>::value + , int>::type = 0 > constexpr auto invoke_member_object_impl(F Base::* f, Pointer&& ptr) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -106,7 +106,7 @@ namespace invoke_hpp template < typename Base, typename F, typename Derived, typename... Args, - typename std::enable_if_t>::value, int> = 0 + typename std::enable_if::type>::value, int>::type = 0 > constexpr auto invoke_member_function_impl(F Base::* f, Derived&& ref, Args&&... args) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -115,7 +115,7 @@ namespace invoke_hpp template < typename Base, typename F, typename RefWrap, typename... Args, - typename std::enable_if_t>::value, int> = 0 + typename std::enable_if::type>::value, int>::type = 0 > constexpr auto invoke_member_function_impl(F Base::* f, RefWrap&& ref, Args&&... args) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -124,10 +124,10 @@ namespace invoke_hpp template < typename Base, typename F, typename Pointer, typename... Args, - typename std::enable_if_t< - !std::is_base_of>::value && - !is_reference_wrapper>::value - , int> = 0 + typename std::enable_if< + !std::is_base_of::type>::value && + !is_reference_wrapper::type>::value + , int>::type = 0 > constexpr auto invoke_member_function_impl(F Base::* f, Pointer&& ptr, Args&&... args) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -137,7 +137,7 @@ namespace invoke_hpp template < typename F, typename... Args, - typename std::enable_if_t>::value, int> = 0 + typename std::enable_if::type>::value, int>::type = 0 > constexpr auto invoke(F&& f, Args&&... args) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -146,7 +146,7 @@ namespace invoke_hpp template < typename F, typename T, - typename std::enable_if_t>::value, int> = 0 + typename std::enable_if::type>::value, int>::type = 0 > constexpr auto invoke(F&& f, T&& t) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -155,7 +155,7 @@ namespace invoke_hpp template < typename F, typename... Args, - typename std::enable_if_t>::value, int> = 0 + typename std::enable_if::type>::value, int>::type = 0 > constexpr auto invoke(F&& f, Args&&... args) INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( @@ -205,10 +205,10 @@ namespace invoke_hpp template < typename R, typename F, typename... Args > struct is_invocable_r_impl>, R, F, Args...> - : std::conditional_t< + : std::conditional< std::is_void::value, std::true_type, - std::is_convertible, R>> {}; + std::is_convertible, R>>::type {}; } template < typename R, typename F, typename... Args > @@ -223,26 +223,51 @@ namespace invoke_hpp // apply // +namespace invoke_hpp +{ + namespace impl + { + template + struct integer_sequence + { + typedef T value_type; + static constexpr std::size_t size() { return sizeof...(Ints); } + }; + + template + using index_sequence = integer_sequence; + + template + struct make_integer_sequence : make_integer_sequence {}; + + template + struct make_integer_sequence : integer_sequence {}; + + template + using make_index_sequence = make_integer_sequence; + + template + using index_sequence_for = make_index_sequence; + } +} + namespace invoke_hpp { namespace impl { template < typename F, typename Tuple, std::size_t... I > - constexpr decltype(auto) apply_impl(F&& f, Tuple&& args, std::index_sequence) - INVOKE_HPP_NOEXCEPT_RETURN( + constexpr auto apply_impl(F&& f, Tuple&& args, impl::index_sequence) + INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( invoke_hpp::invoke( std::forward(f), std::get(std::forward(args))...)) } template < typename F, typename Tuple > - constexpr decltype(auto) apply(F&& f, Tuple&& args) - INVOKE_HPP_NOEXCEPT_RETURN( + constexpr auto apply(F&& f, Tuple&& args) + INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN( impl::apply_impl( std::forward(f), std::forward(args), - std::make_index_sequence>::value>())) + impl::make_index_sequence::type>::value>())) } - -#undef INVOKE_HPP_NOEXCEPT_RETURN -#undef INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN From 4ca21a07a61f1de4a5c579a2b2c58b2a0515a6a0 Mon Sep 17 00:00:00 2001 From: Dmytro <33125344+smay1613@users.noreply.github.com> Date: Tue, 19 May 2020 16:25:25 +0300 Subject: [PATCH 2/2] Update invoke.hpp --- headers/invoke.hpp/invoke.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/headers/invoke.hpp/invoke.hpp b/headers/invoke.hpp/invoke.hpp index 4c6a646..47c027b 100644 --- a/headers/invoke.hpp/invoke.hpp +++ b/headers/invoke.hpp/invoke.hpp @@ -271,3 +271,7 @@ namespace invoke_hpp std::forward(args), impl::make_index_sequence::type>::value>())) } + + +#undef INVOKE_HPP_NOEXCEPT_RETURN +#undef INVOKE_HPP_NOEXCEPT_DECLTYPE_RETURN