mirror of
https://github.com/boostorg/phoenix.git
synced 2026-02-02 21:12:13 +00:00
Merge pull request #26 from Flast/variadics/core/function_eval
variadics: core/function_eval
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
Copyright (c) 2015 Kohei Takahashi
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -16,6 +17,13 @@
|
||||
#include <boost/phoenix/core/detail/phx2_result.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#ifndef BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EVAL
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/type_traits/is_reference.hpp>
|
||||
#endif
|
||||
|
||||
// XXX: Currently, we should use preprocessed files since
|
||||
// core/expression.hpp does not support c++11 variadic templates yet.
|
||||
#include <boost/phoenix/core/detail/cpp03/function_eval_expr.hpp>
|
||||
|
||||
namespace boost { namespace phoenix {
|
||||
@@ -26,7 +34,7 @@ namespace boost { namespace phoenix {
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
T const& help_rvalue_deduction(T const& x)
|
||||
{
|
||||
@@ -38,6 +46,7 @@ namespace boost { namespace phoenix {
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
#ifdef BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EVAL
|
||||
template <typename This, typename F, typename Context>
|
||||
struct result<This(F, Context)>
|
||||
{
|
||||
@@ -65,8 +74,70 @@ namespace boost { namespace phoenix {
|
||||
}
|
||||
|
||||
#include <boost/phoenix/core/detail/cpp03/function_eval.hpp>
|
||||
#else
|
||||
template <typename, typename, typename...> struct result_impl;
|
||||
|
||||
template <typename F, typename... A, typename Head, typename... Tail>
|
||||
struct result_impl<F, void(A...), Head, Tail...>
|
||||
: result_impl<F, void(A..., Head), Tail...>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename F, typename... A, typename Context>
|
||||
struct result_impl<F, void(A...), Context>
|
||||
{
|
||||
typedef typename
|
||||
remove_reference<
|
||||
typename boost::result_of<evaluator(F, Context)>::type
|
||||
>::type
|
||||
fn;
|
||||
|
||||
|
||||
typedef typename
|
||||
boost::result_of<
|
||||
fn(
|
||||
typename boost::add_reference<
|
||||
typename boost::add_const<
|
||||
typename boost::result_of<boost::phoenix::evaluator(A, Context)>::type
|
||||
>::type
|
||||
>::type...
|
||||
)
|
||||
>::type
|
||||
type;
|
||||
|
||||
static type call(F f, A... a, Context ctx)
|
||||
{
|
||||
return boost::phoenix::eval(f, ctx)(help_rvalue_deduction(boost::phoenix::eval(a, ctx))...);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename This, typename F, typename... A>
|
||||
struct result<This(F, A...)>
|
||||
: result_impl<F, void(), A...>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename F, typename... A>
|
||||
typename result<
|
||||
function_eval(
|
||||
F const &
|
||||
, typename mpl::if_<is_reference<A>, A, A const &>::type...
|
||||
)
|
||||
>::type
|
||||
// 'A &... a, Context const &ctx' doesn't work as intended: type deduction always fail.
|
||||
operator()(F && f, A &&... a) const
|
||||
{
|
||||
return
|
||||
result<
|
||||
function_eval(
|
||||
typename mpl::if_<is_reference<F>, F, F const &>::type
|
||||
, typename mpl::if_<is_reference<A>, A, A const &>::type...
|
||||
)
|
||||
>::call(f, a...);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
template <typename Dummy>
|
||||
|
||||
@@ -38,9 +38,11 @@
|
||||
# define BOOST_PHOENIX_NO_VARIADIC_ACTOR
|
||||
# define BOOST_PHOENIX_NO_VARIADIC_CALL
|
||||
# define BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EQUAL
|
||||
# define BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EVAL
|
||||
#endif
|
||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
# define BOOST_PHOENIX_NO_VARIADIC_ACTOR
|
||||
# define BOOST_PHOENIX_NO_VARIADIC_FUNCTION_EVAL
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_PHOENIX_ARG_LIMIT)
|
||||
|
||||
Reference in New Issue
Block a user