Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48620 - in trunk: boost/utility boost/utility/detail libs/utility/test
From: dgregor_at_[hidden]
Date: 2008-09-05 15:58:31


Author: dgregor
Date: 2008-09-05 15:58:30 EDT (Fri, 05 Sep 2008)
New Revision: 48620
URL: http://svn.boost.org/trac/boost/changeset/48620

Log:
Fix result_of to work with const-qualified function pointers. Fixes #1310
Text files modified:
   trunk/boost/utility/detail/result_of_iterate.hpp | 14 ++++++++++++--
   trunk/boost/utility/result_of.hpp | 6 ++++++
   trunk/libs/utility/test/result_of_test.cpp | 4 ++++
   3 files changed, 22 insertions(+), 2 deletions(-)

Modified: trunk/boost/utility/detail/result_of_iterate.hpp
==============================================================================
--- trunk/boost/utility/detail/result_of_iterate.hpp (original)
+++ trunk/boost/utility/detail/result_of_iterate.hpp 2008-09-05 15:58:30 EDT (Fri, 05 Sep 2008)
@@ -22,7 +22,8 @@
     : mpl::if_<
           mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
         , detail::result_of_impl<
- F, F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false
+ typename remove_cv<F>::type,
+ typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false
>
         , detail::result_of_decltype_impl<
               F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))
@@ -61,7 +62,16 @@
 template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
          BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
 struct result_of<F(BOOST_RESULT_OF_ARGS)>
- : boost::detail::result_of_impl<F, F(BOOST_RESULT_OF_ARGS), (boost::detail::has_result_type<F>::value)> {};
+ : mpl::if_<
+ mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
+ , boost::detail::result_of_impl<
+ typename remove_cv<F>::type,
+ typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS),
+ (boost::detail::has_result_type<F>::value)>
+ , boost::detail::result_of_impl<
+ F,
+ F(BOOST_RESULT_OF_ARGS),
+ (boost::detail::has_result_type<F>::value)> >::type { };
 #endif
 
 #undef BOOST_RESULT_OF_ARGS

Modified: trunk/boost/utility/result_of.hpp
==============================================================================
--- trunk/boost/utility/result_of.hpp (original)
+++ trunk/boost/utility/result_of.hpp 2008-09-05 15:58:30 EDT (Fri, 05 Sep 2008)
@@ -21,6 +21,7 @@
 #include <boost/mpl/or.hpp>
 #include <boost/type_traits/is_pointer.hpp>
 #include <boost/type_traits/is_member_function_pointer.hpp>
+#include <boost/type_traits/remove_cv.hpp>
 
 #ifndef BOOST_RESULT_OF_NUM_ARGS
 # define BOOST_RESULT_OF_NUM_ARGS 10
@@ -56,6 +57,11 @@
   typedef R type;
 };
 
+// Determine the return type of a function pointer or pointer to member.
+template<typename F, typename FArgs>
+struct result_of_pointer
+ : result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
+
 template<typename F, typename FArgs>
 struct result_of_impl<F, FArgs, true>
 {

Modified: trunk/libs/utility/test/result_of_test.cpp
==============================================================================
--- trunk/libs/utility/test/result_of_test.cpp (original)
+++ trunk/libs/utility/test/result_of_test.cpp 2008-09-05 15:58:30 EDT (Fri, 05 Sep 2008)
@@ -177,6 +177,10 @@
   BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value));
   BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value));
 
+ typedef int (*pf_t)(int);
+ BOOST_STATIC_ASSERT((is_same<result_of<pf_t(int)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<result_of<pf_t const(int)>::type,int>::value));
+
 #if defined(BOOST_HAS_DECLTYPE)
   BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(double)>::type, int>::value));
   BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(void)>::type, unsigned int>::value));


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk