|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80605 - in trunk: boost/utility boost/utility/detail libs/utility/test
From: daniel.j.walker_at_[hidden]
Date: 2012-09-19 19:10:08
Author: djwalker
Date: 2012-09-19 19:10:08 EDT (Wed, 19 Sep 2012)
New Revision: 80605
URL: http://svn.boost.org/trac/boost/changeset/80605
Log:
SFINAE enabled result_of fixes [7343]
Text files modified:
trunk/boost/utility/detail/result_of_iterate.hpp | 66 ++++++++++++++++++++++++++++++++++++++-
trunk/boost/utility/result_of.hpp | 18 ++++++++++
trunk/libs/utility/test/result_of_test.cpp | 26 +++++++++++++++
3 files changed, 107 insertions(+), 3 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 2012-09-19 19:10:08 EDT (Wed, 19 Sep 2012)
@@ -58,17 +58,79 @@
namespace detail {
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
+
+template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
+class is_callable<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))> {
+ typedef char (&pass)[1];
+ typedef char (&fail)[2];
+
+ template<typename G BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename S)>
+ struct sub {};
+ template<typename S>
+ struct stub {};
+
+ template<typename G BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename S)>
+ static pass test(sub<G BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),S)>
+ , stub<
+ decltype(
+ boost::declval<G>()(
+ BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<S, >() BOOST_PP_INTERCEPT)
+ )
+ )
+ >* x = 0);
+ static fail test(...);
+
+public:
+ const static bool value = sizeof(pass) == sizeof(test(sub<F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)
+ >()));
+ typedef typename boost::mpl::bool_<value>::type type;
+};
+
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
+struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), true>
+ : lazy_enable_if<
+ is_callable<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
+ , cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false>
+ >
+{};
+
+template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
+struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false>
{
typedef decltype(
boost::declval<F>()(
- BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), declval<T, >() BOOST_PP_INTERCEPT)
+ BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)
+ )
+ ) type;
+};
+
+#else // BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
+
+template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
+ BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
+struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)),
+ typename result_of_always_void<decltype(
+ boost::declval<F>()(
+ BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)
+ )
+ )>::type> {
+ typedef decltype(
+ boost::declval<F>()(
+ BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)
)
) type;
};
+#endif // BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
+
} // namespace detail
#else // defined(BOOST_RESULT_OF_USE_DECLTYPE)
Modified: trunk/boost/utility/result_of.hpp
==============================================================================
--- trunk/boost/utility/result_of.hpp (original)
+++ trunk/boost/utility/result_of.hpp 2012-09-19 19:10:08 EDT (Wed, 19 Sep 2012)
@@ -25,6 +25,7 @@
#include <boost/type_traits/is_member_function_pointer.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/utility/declval.hpp>
+#include <boost/utility/enable_if.hpp>
#ifndef BOOST_RESULT_OF_NUM_ARGS
# define BOOST_RESULT_OF_NUM_ARGS 16
@@ -59,7 +60,22 @@
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
-template<typename F> struct cpp0x_result_of_impl;
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
+
+template<typename F> class is_callable;
+template<typename F, bool TestCallability = true> struct cpp0x_result_of_impl;
+
+#else // BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
+
+template<typename T>
+struct result_of_always_void
+{
+ typedef void type;
+};
+template<typename F, typename Enable = void> struct cpp0x_result_of_impl {};
+
+#endif // BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
template<typename F>
struct result_of_void_impl
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 2012-09-19 19:10:08 EDT (Wed, 19 Sep 2012)
@@ -129,6 +129,27 @@
#endif
};
+// sfinae_tests are derived from example code from Joel de Guzman,
+// which demonstrated the interaction between result_of and SFINAE.
+template <typename F, typename Arg>
+typename boost::result_of<F(Arg const&)>::type
+sfinae_test(F f, Arg const& arg)
+{
+ return f(arg);
+}
+
+template <typename F, typename Arg>
+typename boost::result_of<F(Arg&)>::type
+sfinae_test(F f, Arg& arg)
+{
+ return f(arg);
+}
+
+int sfinae_test_f(int& i)
+{
+ return i;
+}
+
struct X {};
int main()
@@ -268,5 +289,10 @@
#endif
#endif
+#if defined(BOOST_RESULT_OF_USE_DECLTYPE)
+ int i = 123;
+ sfinae_test(sfinae_test_f, i);
+#endif // defined(BOOST_RESULT_OF_USE_DECLTYPE)
+
return 0;
}
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