mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
SFINAE enabled result_of fixes [7343]
[SVN r80605]
This commit is contained in:
parent
b6a55f878c
commit
ac9f617f7f
@ -58,17 +58,79 @@ struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
|
||||||
|
|
||||||
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 cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),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)), 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(
|
typedef decltype(
|
||||||
boost::declval<F>()(
|
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;
|
) 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
|
} // namespace detail
|
||||||
|
|
||||||
#else // defined(BOOST_RESULT_OF_USE_DECLTYPE)
|
#else // defined(BOOST_RESULT_OF_USE_DECLTYPE)
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#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>
|
#include <boost/type_traits/remove_cv.hpp>
|
||||||
#include <boost/utility/declval.hpp>
|
#include <boost/utility/declval.hpp>
|
||||||
|
#include <boost/utility/enable_if.hpp>
|
||||||
|
|
||||||
#ifndef BOOST_RESULT_OF_NUM_ARGS
|
#ifndef BOOST_RESULT_OF_NUM_ARGS
|
||||||
# define BOOST_RESULT_OF_NUM_ARGS 16
|
# define BOOST_RESULT_OF_NUM_ARGS 16
|
||||||
@ -59,7 +60,22 @@ namespace detail {
|
|||||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
||||||
|
|
||||||
template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
|
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>
|
template<typename F>
|
||||||
struct result_of_void_impl
|
struct result_of_void_impl
|
||||||
|
@ -129,6 +129,27 @@ struct no_result_type_or_result_template
|
|||||||
#endif
|
#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 {};
|
struct X {};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -268,5 +289,10 @@ int main()
|
|||||||
#endif
|
#endif
|
||||||
#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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user