diff --git a/include/boost/utility/detail/result_of_iterate.hpp b/include/boost/utility/detail/result_of_iterate.hpp index 5192172cf..31588066e 100644 --- a/include/boost/utility/detail/result_of_iterate.hpp +++ b/include/boost/utility/detail/result_of_iterate.hpp @@ -6,15 +6,18 @@ // http://www.boost.org/LICENSE_1_0.txt) // Copyright Daniel Walker, Eric Niebler, Michel Morin 2008-2012. +// Copyright Kohei Takahashi 2016. // 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 -#if !defined(BOOST_PP_IS_ITERATING) +#if !defined(BOOST_PP_IS_ITERATING) && !defined(BOOST_RESULT_OF_USE_VARIADICS) # error Boost result_of - do not include this file! #endif +#if !defined(BOOST_RESULT_OF_USE_VARIADICS) + // CWPro8 requires an argument in a function type specialization #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0 # define BOOST_RESULT_OF_ARGS void @@ -22,8 +25,37 @@ # define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T) #endif +#define BOOST_RESULT_OF_typename_T BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T) +#define BOOST_RESULT_OF_typename_T1 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_DEC(BOOST_PP_ITERATION()),typename T) +#define BOOST_RESULT_OF_enum_T BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T) +#define BOOST_RESULT_OF_enum_T1 BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_PP_ITERATION()),T) +#define BOOST_RESULT_OF_trailing_T BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),T) +#define BOOST_RESULT_OF_declval_T BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval() BOOST_PP_INTERCEPT) + +#define BOOST_RESULT_OF_callable2 BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION()) +#define BOOST_RESULT_OF_callable BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION()) +#define BOOST_RESULT_OF_select_wrapper BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION()) +#define BOOST_RESULT_OF_is_callable BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION()) + +#else + +#define BOOST_RESULT_OF_ARGS T... +#define BOOST_RESULT_OF_typename_T , typename... T +#define BOOST_RESULT_OF_typename_T1 , typename... T +#define BOOST_RESULT_OF_enum_T T... +#define BOOST_RESULT_OF_enum_T1 T... +#define BOOST_RESULT_OF_trailing_T , T... +#define BOOST_RESULT_OF_declval_T boost::declval()... + +#define BOOST_RESULT_OF_callable2 result_of_callable_fun_2 +#define BOOST_RESULT_OF_callable result_of_callable_fun +#define BOOST_RESULT_OF_select_wrapper result_of_select_call_wrapper_type +#define BOOST_RESULT_OF_is_callable result_of_is_callable + +#endif + #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) -template +template struct tr1_result_of : mpl::if_< mpl::or_< is_pointer, is_member_function_pointer > @@ -37,14 +69,16 @@ struct tr1_result_of (boost::detail::has_result_type::value)> >::type { }; #endif +#ifndef BOOST_RESULT_OF_TR1_ONLY + #ifdef BOOST_RESULT_OF_USE_DECLTYPE -template +template struct result_of : detail::cpp0x_result_of { }; #endif // BOOST_RESULT_OF_USE_DECLTYPE #ifdef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK -template +template struct result_of : mpl::if_, detail::has_result >, tr1_result_of, @@ -55,16 +89,16 @@ struct result_of namespace detail { -template -struct cpp0x_result_of +template +struct cpp0x_result_of : mpl::if_< is_member_function_pointer , detail::tr1_result_of_impl< typename remove_cv::type, - typename remove_cv::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false + typename remove_cv::type(BOOST_RESULT_OF_enum_T), false > , detail::cpp0x_result_of_impl< - F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)) + F(BOOST_RESULT_OF_enum_T) > >::type {}; @@ -72,80 +106,70 @@ struct cpp0x_result_of #ifdef BOOST_NO_SFINAE_EXPR template -struct BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION()); +struct BOOST_RESULT_OF_callable2; -template -struct BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION()) { - R operator()(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T)) const; +template +struct BOOST_RESULT_OF_callable2 { + R operator()(BOOST_RESULT_OF_enum_T) const; typedef result_of_private_type const &(*pfn_t)(...); operator pfn_t() const volatile; }; template -struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION()); +struct BOOST_RESULT_OF_callable; template -struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION()) - : BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION()) +struct BOOST_RESULT_OF_callable + : BOOST_RESULT_OF_callable2 {}; template -struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION()) - : BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION()) +struct BOOST_RESULT_OF_callable + : BOOST_RESULT_OF_callable2 {}; template -struct BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION()) +struct BOOST_RESULT_OF_select_wrapper : mpl::eval_if< is_class::type>, result_of_wrap_callable_class, - mpl::identity::type> > + mpl::identity::type> > > {}; -template -struct BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION()) { - typedef typename BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION())::type wrapper_t; +template +struct BOOST_RESULT_OF_is_callable { + typedef typename BOOST_RESULT_OF_select_wrapper::type wrapper_t; static const bool value = ( sizeof(result_of_no_type) == sizeof(detail::result_of_is_private_type( - (boost::declval()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval() BOOST_PP_INTERCEPT)), result_of_weird_type()) + (boost::declval()(BOOST_RESULT_OF_declval_T), result_of_weird_type()) )) ); typedef mpl::bool_ type; }; -template -struct cpp0x_result_of_impl +template +struct cpp0x_result_of_impl : lazy_enable_if< - BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION()) - , cpp0x_result_of_impl + BOOST_RESULT_OF_is_callable + , cpp0x_result_of_impl > {}; -template -struct cpp0x_result_of_impl +template +struct cpp0x_result_of_impl { - typedef decltype( - boost::declval()( - BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval() BOOST_PP_INTERCEPT) - ) - ) type; + typedef decltype(boost::declval()(BOOST_RESULT_OF_declval_T)) type; }; #else // BOOST_NO_SFINAE_EXPR -template -struct cpp0x_result_of_impl +struct cpp0x_result_of_impl()( - BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval() BOOST_PP_INTERCEPT) - ) + boost::declval()(BOOST_RESULT_OF_declval_T) )>::type> { - typedef decltype( - boost::declval()( - BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval() BOOST_PP_INTERCEPT) - ) - ) type; + typedef decltype(boost::declval()(BOOST_RESULT_OF_declval_T)) type; }; #endif // BOOST_NO_SFINAE_EXPR @@ -155,61 +179,63 @@ struct cpp0x_result_of_impl +template struct result_of : tr1_result_of { }; #endif #endif // defined(BOOST_RESULT_OF_USE_DECLTYPE) +#endif // defined(BOOST_RESULT_OF_TR1_ONLY) + #undef BOOST_RESULT_OF_ARGS -#if BOOST_PP_ITERATION() >= 1 +#if defined(BOOST_RESULT_OF_USE_VARIADICS) || (BOOST_PP_ITERATION() >= 1) namespace detail { -template -struct tr1_result_of_impl +template +struct tr1_result_of_impl { typedef R type; }; -template -struct tr1_result_of_impl +template +struct tr1_result_of_impl { typedef R type; }; #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) -template -struct tr1_result_of_impl +struct tr1_result_of_impl { typedef R type; }; -template -struct tr1_result_of_impl +struct tr1_result_of_impl { typedef R type; }; -template -struct tr1_result_of_impl +struct tr1_result_of_impl { typedef R type; }; -template -struct tr1_result_of_impl +struct tr1_result_of_impl { diff --git a/include/boost/utility/result_of.hpp b/include/boost/utility/result_of.hpp index 206ae3088..6c9a52f89 100644 --- a/include/boost/utility/result_of.hpp +++ b/include/boost/utility/result_of.hpp @@ -198,9 +198,18 @@ struct tr1_result_of_impl } // end namespace detail +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + +# define BOOST_RESULT_OF_USE_VARIADICS +# include + +#else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + #define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,)) #include BOOST_PP_ITERATE() +#endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + #else # define BOOST_NO_RESULT_OF 1 #endif