|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61248 - in trunk: boost/tr1 boost/utility boost/utility/detail libs/utility/test
From: eric_at_[hidden]
Date: 2010-04-13 11:01:12
Author: eric_niebler
Date: 2010-04-13 11:01:11 EDT (Tue, 13 Apr 2010)
New Revision: 61248
URL: http://svn.boost.org/trac/boost/changeset/61248
Log:
add tr1_result_of that always behaves as TR1 specifies, fix Boost.TR1's result_of to use tr1_result_of
Text files modified:
trunk/boost/tr1/functional.hpp | 5 ++
trunk/boost/utility/detail/result_of_iterate.hpp | 65 ++++++++++++++++++++++-----------------
trunk/boost/utility/result_of.hpp | 11 +++---
trunk/libs/utility/test/result_of_test.cpp | 40 ++++++++++++++++++++++++
4 files changed, 86 insertions(+), 35 deletions(-)
Modified: trunk/boost/tr1/functional.hpp
==============================================================================
--- trunk/boost/tr1/functional.hpp (original)
+++ trunk/boost/tr1/functional.hpp 2010-04-13 11:01:11 EDT (Tue, 13 Apr 2010)
@@ -48,7 +48,10 @@
namespace std{ namespace tr1{
- using ::boost::result_of;
+ template<class F>
+ struct result_of
+ : ::boost::tr1_result_of<F>
+ {};
} }
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 2010-04-13 11:01:11 EDT (Tue, 13 Apr 2010)
@@ -10,7 +10,30 @@
# error Boost result_of - do not include this file!
#endif
-#if defined(BOOST_HAS_DECLTYPE)
+// 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
+#else
+# define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)
+#endif
+
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
+template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
+struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)>
+ : mpl::if_<
+ mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
+ , boost::detail::tr1_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::tr1_result_of_impl<
+ F,
+ F(BOOST_RESULT_OF_ARGS),
+ (boost::detail::has_result_type<F>::value)> >::type { };
+#endif
+
+#if !defined(BOOST_NO_DECLTYPE) && defined(BOOST_RESULT_OF_USE_DECLTYPE)
// As of N2588, C++0x result_of only supports function call
// expressions of the form f(x). This precludes support for member
@@ -21,11 +44,11 @@
struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
: mpl::if_<
mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
- , detail::result_of_impl<
+ , detail::tr1_result_of_impl<
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::cpp0x_result_of_impl<
F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))
>
>::type
@@ -39,7 +62,7 @@
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-class result_of_decltype_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
+class cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
{
static F f;
BOOST_PP_REPEAT(BOOST_PP_ITERATION(), BOOST_RESULT_OF_STATIC_MEMBERS, _)
@@ -51,47 +74,31 @@
#else // defined(BOOST_NO_DECLTYPE)
-// 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
-#else
-# define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)
-#endif
-
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
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)>
- : 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 { };
+ : tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { };
#endif
-#undef BOOST_RESULT_OF_ARGS
-
#endif // defined(BOOST_NO_DECLTYPE)
+#undef BOOST_RESULT_OF_ARGS
+
#if BOOST_PP_ITERATION() >= 1
namespace detail {
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
+struct tr1_result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
{
typedef R type;
};
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
+struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
{
typedef R type;
};
@@ -99,7 +106,7 @@
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (T0::*)
+struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)),
FArgs, false>
{
@@ -108,7 +115,7 @@
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (T0::*)
+struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
const,
FArgs, false>
@@ -118,7 +125,7 @@
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (T0::*)
+struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
volatile,
FArgs, false>
@@ -128,7 +135,7 @@
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (T0::*)
+struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
const volatile,
FArgs, false>
Modified: trunk/boost/utility/result_of.hpp
==============================================================================
--- trunk/boost/utility/result_of.hpp (original)
+++ trunk/boost/utility/result_of.hpp 2010-04-13 11:01:11 EDT (Tue, 13 Apr 2010)
@@ -30,14 +30,15 @@
namespace boost {
template<typename F> struct result_of;
+template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of
#if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
-template<typename F, typename FArgs, bool HasResultType> struct result_of_impl;
-template<typename F> struct result_of_decltype_impl;
+template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
+template<typename F> struct cpp0x_result_of_impl;
template<typename F>
struct result_of_void_impl
@@ -60,10 +61,10 @@
// 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> { };
+ : tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
template<typename F, typename FArgs>
-struct result_of_impl<F, FArgs, true>
+struct tr1_result_of_impl<F, FArgs, true>
{
typedef typename F::result_type type;
};
@@ -79,7 +80,7 @@
{};
template<typename F, typename FArgs>
-struct result_of_impl<F, FArgs, false>
+struct tr1_result_of_impl<F, FArgs, false>
: mpl::if_<is_function_with_no_args<FArgs>,
result_of_void_impl<F>,
result_of_nested_result<F, FArgs> >::type
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 2010-04-13 11:01:11 EDT (Tue, 13 Apr 2010)
@@ -5,6 +5,8 @@
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
+#define BOOST_RESULT_OF_USE_DECLTYPE
+
// For more information, see http://www.boost.org/libs/utility
#include <boost/utility/result_of.hpp>
#include <utility>
@@ -131,6 +133,18 @@
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type(float)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(double)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of(double)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_template<void>(float)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(double)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of_template<void>(double)>::type, int>::value));
+
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(void)>::type, void>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of(void)>::type, void>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(void)>::type, void>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
+
// Prior to decltype, result_of could not deduce the return type
// nullary function objects unless they exposed a result_type.
#if !defined(BOOST_NO_DECLTYPE)
@@ -145,6 +159,9 @@
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
#endif
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, int>::value));
+
// Prior to decltype, result_of ignored a nested result<> if
// result_type was defined. After decltype, result_of deduces the
// actual return type of the function object, ignoring both
@@ -168,6 +185,17 @@
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(void)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(char, float)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref(char, float)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr_0()>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref_0()>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr(X,char)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_c(X,char)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_v(X,char)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_cv(X,char)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_0(X)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(void)>::type, int>::value));
+
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(double)>::type, double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const result_of_member_function_template(double)>::type, const double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value));
@@ -177,10 +205,22 @@
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<tr1_result_of<result_of_member_function_template(double)>::type, double>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<const result_of_member_function_template(double)>::type, const double>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<const volatile result_of_member_function_template(double)>::type, const volatile double>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int &, int)>::type, int &>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int const &, int)>::type, int const &>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_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));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t(int)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t const(int)>::type,int>::value));
+
#if !defined(BOOST_NO_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