From 3e2f0199cf4ae6343bcda40ffa3ae06335626615 Mon Sep 17 00:00:00 2001 From: Nikita Kniazev Date: Mon, 8 Mar 2021 01:28:05 +0300 Subject: [PATCH] Use variadic templates in result_of --- .../utility/detail/result_of_variadic.hpp | 190 ++++++++++++++++++ include/boost/utility/result_of.hpp | 29 ++- 2 files changed, 210 insertions(+), 9 deletions(-) create mode 100644 include/boost/utility/detail/result_of_variadic.hpp diff --git a/include/boost/utility/detail/result_of_variadic.hpp b/include/boost/utility/detail/result_of_variadic.hpp new file mode 100644 index 0000000..f6929f8 --- /dev/null +++ b/include/boost/utility/detail/result_of_variadic.hpp @@ -0,0 +1,190 @@ +// Boost result_of library + +// Copyright Douglas Gregor 2004. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Copyright Daniel Walker, Eric Niebler, Michel Morin 2008-2012. +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or +// copy at http://www.boost.org/LICENSE_1_0.txt) + +// For more information, see http://www.boost.org/libs/utility + +#ifndef BOOST_RESULT_OF_HPP +# error Boost result_of - do not include this file! +#endif + +template +struct tr1_result_of + : conditional< + is_pointer::value || is_member_function_pointer::value + , boost::detail::tr1_result_of_impl< + typename remove_cv::type, + typename remove_cv::type(Args...), + (boost::detail::result_of_has_result_type::value)> + , boost::detail::tr1_result_of_impl< + F, + F(Args...), + (boost::detail::result_of_has_result_type::value)> >::type { }; + +#ifdef BOOST_RESULT_OF_USE_DECLTYPE +template +struct result_of + : detail::cpp0x_result_of { }; +#endif // BOOST_RESULT_OF_USE_DECLTYPE + +#ifdef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK +template +struct result_of + : conditional::value || detail::result_of_has_result::value, + tr1_result_of, + detail::cpp0x_result_of >::type { }; +#endif // BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK + +#if defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK) + +namespace detail { + +template +struct cpp0x_result_of + : conditional< + is_member_function_pointer::value + , detail::tr1_result_of_impl< + typename remove_cv::type, + typename remove_cv::type(Args...), false + > + , detail::cpp0x_result_of_impl< + F(Args...) + > + >::type +{}; + +#ifdef BOOST_NO_SFINAE_EXPR + +template +struct result_of_callable_fun_2; + +template +struct result_of_callable_fun_2 { + R operator()(Args...) const; + typedef result_of_private_type const &(*pfn_t)(...); + operator pfn_t() const volatile; +}; + +template +struct result_of_callable_fun + : result_of_callable_fun_2 +{}; + +template +struct result_of_callable_fun + : result_of_callable_fun_2 +{}; + +template +struct result_of_select_call_wrapper_type + : conditional< + is_class::type>::value, + result_of_wrap_callable_class, + type_identity::type>::type> > + >::type +{}; + +template +struct result_of_is_callable { + typedef typename result_of_select_call_wrapper_type::type wrapper_t; + static const bool value = ( + sizeof(result_of_no_type) == sizeof(detail::result_of_is_private_type( + (boost::declval()(boost::declval()...), result_of_weird_type()) + )) + ); + typedef integral_constant type; +}; + +template +struct cpp0x_result_of_impl + : lazy_enable_if< + result_of_is_callable + , cpp0x_result_of_impl + > +{}; + +template +struct cpp0x_result_of_impl +{ + typedef decltype( + boost::declval()( + boost::declval()... + ) + ) type; +}; + +#else // BOOST_NO_SFINAE_EXPR + +template +struct cpp0x_result_of_impl()( + boost::declval()... + ) + )>::type> { + typedef decltype( + boost::declval()( + boost::declval()... + ) + ) type; +}; + +#endif // BOOST_NO_SFINAE_EXPR + +} // namespace detail + +#else // defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK) + +template +struct result_of + : tr1_result_of { }; + +#endif // defined(BOOST_RESULT_OF_USE_DECLTYPE) + +namespace detail { + +template +struct tr1_result_of_impl +{ + typedef R type; +}; + +template +struct tr1_result_of_impl +{ + typedef R type; +}; + +template +struct tr1_result_of_impl +{ + typedef R type; +}; + +template +struct tr1_result_of_impl +{ + typedef R type; +}; + +template +struct tr1_result_of_impl +{ + typedef R type; +}; + +template +struct tr1_result_of_impl +{ + typedef R type; +}; + +} diff --git a/include/boost/utility/result_of.hpp b/include/boost/utility/result_of.hpp index 2b652ba..9d444f9 100644 --- a/include/boost/utility/result_of.hpp +++ b/include/boost/utility/result_of.hpp @@ -10,13 +10,6 @@ #define BOOST_RESULT_OF_HPP #include -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -29,6 +22,20 @@ #include #include +#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES +# undef BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES +# define BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES +#endif +#ifdef BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES +# include +# include +# include +# include +# include +# include +# include +#endif + #ifndef BOOST_RESULT_OF_NUM_ARGS # define BOOST_RESULT_OF_NUM_ARGS 16 #endif @@ -217,8 +224,12 @@ struct tr1_result_of_impl } // end namespace detail -#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,)) -#include BOOST_PP_ITERATE() +#ifndef BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES +# include +#else +# define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,)) +# include BOOST_PP_ITERATE() +#endif #if 0 // inform dependency trackers, as they can't see through macro includes