Ticket #4084: tr1_result_of.patch

File tr1_result_of.patch, 13.7 KB (added by Eric Niebler, 13 years ago)

updated attachment that puts the decltype implementation on a switch BOOST_RESULT_OF_USE_DECLTYPE

  • boost/utility/detail/result_of_iterate.hpp

     
    1010# error Boost result_of - do not include this file!
    1111#endif
    1212
    13 #if defined(BOOST_HAS_DECLTYPE)
     13// CWPro8 requires an argument in a function type specialization
     14#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0
     15# define BOOST_RESULT_OF_ARGS void
     16#else
     17# define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)
     18#endif
    1419
     20#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
     21template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
     22         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
     23struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)>
     24    : mpl::if_<
     25          mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
     26        , boost::detail::tr1_result_of_impl<
     27            typename remove_cv<F>::type,
     28            typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS),
     29            (boost::detail::has_result_type<F>::value)>
     30        , boost::detail::tr1_result_of_impl<
     31            F,
     32            F(BOOST_RESULT_OF_ARGS),
     33            (boost::detail::has_result_type<F>::value)> >::type { };
     34#endif
     35
     36#if !defined(BOOST_NO_DECLTYPE) && defined(BOOST_RESULT_OF_USE_DECLTYPE)
     37
    1538// As of N2588, C++0x result_of only supports function call
    1639// expressions of the form f(x). This precludes support for member
    1740// function pointers, which are invoked with expressions of the form
     
    2144struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
    2245    : mpl::if_<
    2346          mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
    24         , detail::result_of_impl<
     47        , detail::tr1_result_of_impl<
    2548            typename remove_cv<F>::type,
    2649            typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false
    2750          >
    28         , detail::result_of_decltype_impl<
     51        , detail::cpp0x_result_of_impl<
    2952              F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))
    3053          >
    3154      >::type
     
    3962
    4063template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    4164         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    42 class result_of_decltype_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
     65class cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
    4366{
    4467  static F f;
    4568  BOOST_PP_REPEAT(BOOST_PP_ITERATION(), BOOST_RESULT_OF_STATIC_MEMBERS, _)
     
    5174
    5275#else // defined(BOOST_NO_DECLTYPE)
    5376
    54 // CWPro8 requires an argument in a function type specialization
    55 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0
    56 # define BOOST_RESULT_OF_ARGS void
    57 #else
    58 # define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)
    59 #endif
    60 
    6177#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
    6278template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    6379         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    6480struct result_of<F(BOOST_RESULT_OF_ARGS)>
    65     : mpl::if_<
    66           mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
    67         , boost::detail::result_of_impl<
    68             typename remove_cv<F>::type,
    69             typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS),
    70             (boost::detail::has_result_type<F>::value)>
    71         , boost::detail::result_of_impl<
    72             F,
    73             F(BOOST_RESULT_OF_ARGS),
    74             (boost::detail::has_result_type<F>::value)> >::type { };
     81    : tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { };
    7582#endif
    7683
     84#endif // defined(BOOST_NO_DECLTYPE)
     85
    7786#undef BOOST_RESULT_OF_ARGS
    7887
    79 #endif // defined(BOOST_NO_DECLTYPE)
    80 
    8188#if BOOST_PP_ITERATION() >= 1
    8289
    8390namespace detail {
    8491
    8592template<typename R,  typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    8693         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    87 struct result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
     94struct tr1_result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
    8895{
    8996  typedef R type;
    9097};
    9198
    9299template<typename R,  typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    93100         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    94 struct result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
     101struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
    95102{
    96103  typedef R type;
    97104};
     
    99106#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
    100107template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    101108         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    102 struct result_of_impl<R (T0::*)
     109struct tr1_result_of_impl<R (T0::*)
    103110                     (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)),
    104111                 FArgs, false>
    105112{
     
    108115
    109116template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    110117         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    111 struct result_of_impl<R (T0::*)
     118struct tr1_result_of_impl<R (T0::*)
    112119                     (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
    113120                     const,
    114121                 FArgs, false>
     
    118125
    119126template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    120127         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    121 struct result_of_impl<R (T0::*)
     128struct tr1_result_of_impl<R (T0::*)
    122129                     (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
    123130                     volatile,
    124131                 FArgs, false>
     
    128135
    129136template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
    130137         BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
    131 struct result_of_impl<R (T0::*)
     138struct tr1_result_of_impl<R (T0::*)
    132139                     (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
    133140                     const volatile,
    134141                 FArgs, false>
  • boost/utility/result_of.hpp

     
    3030namespace boost {
    3131
    3232template<typename F> struct result_of;
     33template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of
    3334
    3435#if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
    3536namespace detail {
    3637
    3738BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
    3839
    39 template<typename F, typename FArgs, bool HasResultType> struct result_of_impl;
    40 template<typename F> struct result_of_decltype_impl;
     40template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
     41template<typename F> struct cpp0x_result_of_impl;
    4142
    4243template<typename F>
    4344struct result_of_void_impl
     
    6061// Determine the return type of a function pointer or pointer to member.
    6162template<typename F, typename FArgs>
    6263struct result_of_pointer
    63   : result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
     64  : tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
    6465
    6566template<typename F, typename FArgs>
    66 struct result_of_impl<F, FArgs, true>
     67struct tr1_result_of_impl<F, FArgs, true>
    6768{
    6869  typedef typename F::result_type type;
    6970};
     
    7980{};
    8081
    8182template<typename F, typename FArgs>
    82 struct result_of_impl<F, FArgs, false>
     83struct tr1_result_of_impl<F, FArgs, false>
    8384  : mpl::if_<is_function_with_no_args<FArgs>,
    8485             result_of_void_impl<F>,
    8586             result_of_nested_result<F, FArgs> >::type
  • boost/tr1/functional.hpp

     
    4848
    4949namespace std{ namespace tr1{
    5050
    51    using ::boost::result_of;
     51   template<class F>
     52   struct result_of
     53     : ::boost::tr1_result_of<F>
     54   {};
    5255
    5356} }
    5457
  • libs/utility/test/result_of_test.cpp

     
    55//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
    66//  http://www.boost.org/LICENSE_1_0.txt)
    77
     8#define BOOST_RESULT_OF_USE_DECLTYPE
     9
    810// For more information, see http://www.boost.org/libs/utility
    911#include <boost/utility/result_of.hpp>
    1012#include <utility>
     
    131133  BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value));
    132134  BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value));
    133135
     136  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type(float)>::type, int>::value));
     137  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(double)>::type, int>::value));
     138  BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of(double)>::type, int>::value));
     139  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_template<void>(float)>::type, int>::value));
     140  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(double)>::type, int>::value));
     141  BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of_template<void>(double)>::type, int>::value));
     142
     143  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(void)>::type, void>::value));
     144  BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of(void)>::type, void>::value));
     145  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(void)>::type, void>::value));
     146  BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
     147
    134148  // Prior to decltype, result_of could not deduce the return type
    135149  // nullary function objects unless they exposed a result_type.
    136150#if !defined(BOOST_NO_DECLTYPE)
     
    145159  BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
    146160#endif
    147161
     162  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, int>::value));
     163  BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, int>::value));
     164
    148165  // Prior to decltype, result_of ignored a nested result<> if
    149166  // result_type was defined. After decltype, result_of deduces the
    150167  // actual return type of the function object, ignoring both
     
    168185  BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value));
    169186  BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(void)>::type, int>::value));
    170187
     188  BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(char, float)>::type, int>::value));
     189  BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref(char, float)>::type, int>::value));
     190  BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr_0()>::type, int>::value));
     191  BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref_0()>::type, int>::value));
     192  BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr(X,char)>::type, int>::value));
     193  BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_c(X,char)>::type, int>::value));
     194  BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_v(X,char)>::type, int>::value));
     195  BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_cv(X,char)>::type, int>::value));
     196  BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_0(X)>::type, int>::value));
     197  BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(void)>::type, int>::value));
     198
    171199  BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(double)>::type, double>::value));
    172200  BOOST_STATIC_ASSERT((is_same<result_of<const result_of_member_function_template(double)>::type, const double>::value));
    173201  BOOST_STATIC_ASSERT((is_same<result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value));
     
    177205  BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value));
    178206  BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value));
    179207
     208  BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(double)>::type, double>::value));
     209  BOOST_STATIC_ASSERT((is_same<tr1_result_of<const result_of_member_function_template(double)>::type, const double>::value));
     210  BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value));
     211  BOOST_STATIC_ASSERT((is_same<tr1_result_of<const volatile result_of_member_function_template(double)>::type, const volatile double>::value));
     212  BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int &, int)>::type, int &>::value));
     213  BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int const &, int)>::type, int const &>::value));
     214  BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value));
     215  BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value));
     216
    180217  typedef int (*pf_t)(int);
    181218  BOOST_STATIC_ASSERT((is_same<result_of<pf_t(int)>::type, int>::value));
    182219  BOOST_STATIC_ASSERT((is_same<result_of<pf_t const(int)>::type,int>::value));
    183220
     221  BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t(int)>::type, int>::value));
     222  BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t const(int)>::type,int>::value));
     223
    184224#if !defined(BOOST_NO_DECLTYPE)
    185225  BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(double)>::type, int>::value));
    186226  BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(void)>::type, unsigned int>::value));