Fix result_of to work with const-qualified function pointers. Fixes #1310

[SVN r48620]
This commit is contained in:
Douglas Gregor 2008-09-05 19:58:30 +00:00
parent 9f08ed6de0
commit a487f72329
3 changed files with 22 additions and 2 deletions

View File

@ -22,7 +22,8 @@ struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
: mpl::if_< : mpl::if_<
mpl::or_< is_pointer<F>, is_member_function_pointer<F> > mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
, detail::result_of_impl< , 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< , detail::result_of_decltype_impl<
F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)) F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))
@ -61,7 +62,16 @@ public:
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of<F(BOOST_RESULT_OF_ARGS)> 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 #endif
#undef BOOST_RESULT_OF_ARGS #undef BOOST_RESULT_OF_ARGS

View File

@ -21,6 +21,7 @@
#include <boost/mpl/or.hpp> #include <boost/mpl/or.hpp>
#include <boost/type_traits/is_pointer.hpp> #include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_member_function_pointer.hpp> #include <boost/type_traits/is_member_function_pointer.hpp>
#include <boost/type_traits/remove_cv.hpp>
#ifndef BOOST_RESULT_OF_NUM_ARGS #ifndef BOOST_RESULT_OF_NUM_ARGS
# define BOOST_RESULT_OF_NUM_ARGS 10 # define BOOST_RESULT_OF_NUM_ARGS 10
@ -56,6 +57,11 @@ struct result_of_void_impl<R (&)(void)>
typedef R type; 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> template<typename F, typename FArgs>
struct result_of_impl<F, FArgs, true> struct result_of_impl<F, FArgs, true>
{ {

View File

@ -177,6 +177,10 @@ int main()
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 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)); 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) #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(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(void)>::type, unsigned int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(void)>::type, unsigned int>::value));