Imported existing code

This commit is contained in:
Hazim Gazov
2010-04-02 02:48:44 -03:00
parent 48fbc5ae91
commit 7a86d01598
13996 changed files with 2468699 additions and 0 deletions

View File

@@ -0,0 +1,329 @@
#ifndef BOOST_PP_IS_ITERATING
///////////////////////////////////////////////////////////////////////////////
/// \file callable.hpp
/// Definintion of callable_context\<\>, an evaluation context for
/// proto::eval() that explodes each node and calls the derived context
/// type with the expressions constituents. If the derived context doesn't
/// have an overload that handles this node, fall back to some other
/// context.
//
// Copyright 2008 Eric Niebler. 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)
#ifndef BOOST_PROTO_CONTEXT_CALLABLE_HPP_EAN_06_23_2007
#define BOOST_PROTO_CONTEXT_CALLABLE_HPP_EAN_06_23_2007
#include <boost/proto/detail/prefix.hpp> // must be first include
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/facilities/intercept.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/selection/max.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/proto/proto_fwd.hpp>
#include <boost/proto/traits.hpp> // for child_c
#include <boost/proto/detail/suffix.hpp> // must be last include
namespace boost { namespace proto
{
namespace detail
{
template<typename T>
yes_type check_is_expr_handled(T const &);
no_type check_is_expr_handled(private_type_ const &);
template<typename Context, long Arity>
struct callable_context_wrapper;
template<typename Expr, typename Context, long Arity = Expr::proto_arity_c>
struct is_expr_handled;
template<typename Expr, typename Context>
struct is_expr_handled<Expr, Context, 0>
{
static callable_context_wrapper<Context, 1> &sctx_;
static Expr &sexpr_;
static typename Expr::proto_tag &stag_;
BOOST_STATIC_CONSTANT(bool, value =
(
sizeof(yes_type) ==
sizeof(
detail::check_is_expr_handled(
(sctx_(stag_, proto::value(sexpr_)), 0)
)
)));
typedef mpl::bool_<value> type;
};
}
namespace context
{
/// \brief A BinaryFunction that accepts a Proto expression and a
/// callable context and calls the context with the expression tag
/// and children as arguments, effectively fanning the expression
/// out.
///
/// <tt>callable_eval\<\></tt> requires that \c Context is a
/// PolymorphicFunctionObject that can be invoked with \c Expr's
/// tag and children as expressions, as follows:
///
/// \code
/// context(Expr::proto_tag(), child_c<0>(expr), child_c<1>(expr), ...)
/// \endcode
template<
typename Expr
, typename Context
, long Arity BOOST_PROTO_WHEN_BUILDING_DOCS(= Expr::proto_arity_c)
>
struct callable_eval
{};
/// \brief A BinaryFunction that accepts a Proto expression and a
/// callable context and calls the context with the expression tag
/// and children as arguments, effectively fanning the expression
/// out.
///
/// <tt>callable_eval\<\></tt> requires that \c Context is a
/// PolymorphicFunctionObject that can be invoked with \c Expr's
/// tag and children as expressions, as follows:
///
/// \code
/// context(Expr::proto_tag(), value(expr))
/// \endcode
template<typename Expr, typename Context>
struct callable_eval<Expr, Context, 0>
{
typedef typename proto::result_of::value<Expr const &>::type value_type;
typedef
typename boost::result_of<
Context(typename Expr::proto_tag, value_type)
>::type
result_type;
/// \param expr The current expression
/// \param context The callable evaluation context
/// \return <tt>context(Expr::proto_tag(), value(expr))</tt>
result_type operator ()(Expr &expr, Context &context) const
{
return context(typename Expr::proto_tag(), proto::value(expr));
}
};
/// \brief An evaluation context adaptor that makes authoring a
/// context a simple matter of writing function overloads, rather
/// then writing template specializations.
///
/// <tt>callable_context\<\></tt> is a base class that implements
/// the context protocol by passing fanned-out expression nodes to
/// the derived context, making it easy to customize the handling
/// of expression types by writing function overloads. Only those
/// expression types needing special handling require explicit
/// handling. All others are dispatched to a user-specified
/// default context, \c DefaultCtx.
///
/// <tt>callable_context\<\></tt> is defined simply as:
///
/// \code
/// template<typename Context, typename DefaultCtx = default_context>
/// struct callable_context
/// {
/// template<typename Expr, typename ThisContext = Context>
/// struct eval
/// : mpl::if_<
/// is_expr_handled_<Expr, Context> // For exposition
/// , callable_eval<Expr, ThisContext>
/// , typename DefaultCtx::template eval<Expr, Context>
/// >::type
/// {};
/// };
/// \endcode
///
/// The Boolean metafunction <tt>is_expr_handled_\<\></tt> uses
/// metaprogramming tricks to determine whether \c Context has
/// an overloaded function call operator that accepts the
/// fanned-out constituents of an expression of type \c Expr.
/// If so, the handling of the expression is dispatched to
/// <tt>callable_eval\<\></tt>. If not, it is dispatched to
/// the user-specified \c DefaultCtx.
///
/// Below is an example of how to use <tt>callable_context\<\></tt>:
///
/// \code
/// // An evaluation context that increments all
/// // integer terminals in-place.
/// struct increment_ints
/// : callable_context<
/// increment_ints const // derived context
/// , null_context const // fall-back context
/// >
/// {
/// typedef void result_type;
///
/// // Handle int terminals here:
/// void operator()(proto::tag::terminal, int &i) const
/// {
/// ++i;
/// }
/// };
/// \endcode
///
/// With \c increment_ints, we can do the following:
///
/// \code
/// literal<int> i = 0, j = 10;
/// proto::eval( i - j * 3.14, increment_ints() );
///
/// assert( i.get() == 1 && j.get() == 11 );
/// \endcode
template<
typename Context
, typename DefaultCtx BOOST_PROTO_WHEN_BUILDING_DOCS(= default_context)
>
struct callable_context
{
/// A BinaryFunction that accepts an \c Expr and a
/// \c Context, and either fans out the expression and passes
/// it to the context, or else hands off the expression to
/// \c DefaultCtx.
///
/// If \c Context is a PolymorphicFunctionObject such that
/// it can be invoked with the tag and children of \c Expr,
/// as <tt>ctx(Expr::proto_tag(), child_c\<0\>(expr), child_c\<1\>(expr)...)</tt>,
/// then <tt>eval\<Expr, ThisContext\></tt> inherits from
/// <tt>callable_eval\<Expr, ThisContext\></tt>. Otherwise,
/// <tt>eval\<Expr, ThisContext\></tt> inherits from
/// <tt>DefaultCtx::eval\<Expr, Context\></tt>.
template<typename Expr, typename ThisContext = Context>
struct eval
: mpl::if_<
detail::is_expr_handled<Expr, Context>
, callable_eval<Expr, ThisContext>
, typename DefaultCtx::template eval<Expr, Context>
>::type
{};
};
}
#define BOOST_PROTO_CHILD_N_TYPE(Z, N, Expr) \
typedef typename proto::result_of::child_c<Expr const &, N>::type BOOST_PP_CAT(child, N); \
/**/
#define BOOST_PROTO_CHILD_N(Z, N, expr) \
proto::child_c<N>(expr) \
/**/
#define BOOST_PP_ITERATION_PARAMS_1 \
(3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/context/callable.hpp>)) \
/**/
#include BOOST_PP_ITERATE()
#undef BOOST_PROTO_CHILD_N_TYPE
#undef BOOST_PROTO_CHILD_N
}}
#endif
#else
#define N BOOST_PP_ITERATION()
namespace detail
{
template<typename Context>
struct callable_context_wrapper<Context, N>
: remove_cv<Context>::type
{
callable_context_wrapper();
typedef
private_type_ const &fun_type(
BOOST_PP_ENUM_PARAMS(
BOOST_PP_INC(N)
, detail::dont_care BOOST_PP_INTERCEPT
)
);
operator fun_type *() const;
};
template<typename Expr, typename Context>
struct is_expr_handled<Expr, Context, N>
{
static callable_context_wrapper<Context, N> &sctx_;
static Expr &sexpr_;
static typename Expr::proto_tag &stag_;
BOOST_STATIC_CONSTANT(bool, value =
(
sizeof(yes_type) ==
sizeof(
detail::check_is_expr_handled(
(sctx_(
stag_
BOOST_PP_ENUM_TRAILING(N, BOOST_PROTO_CHILD_N, sexpr_)
), 0)
)
)));
typedef mpl::bool_<value> type;
};
}
namespace context
{
/// \brief A BinaryFunction that accepts a Proto expression and a
/// callable context and calls the context with the expression tag
/// and children as arguments, effectively fanning the expression
/// out.
///
/// <tt>callable_eval\<\></tt> requires that \c Context is a
/// PolymorphicFunctionObject that can be invoked with \c Expr's
/// tag and children as expressions, as follows:
///
/// \code
/// context(Expr::proto_tag(), child_c\<0\>(expr), child_c\<1\>(expr), ...)
/// \endcode
template<typename Expr, typename Context>
struct callable_eval<Expr, Context, N>
{
BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD_N_TYPE, Expr)
typedef
typename boost::result_of<
Context(
typename Expr::proto_tag
BOOST_PP_ENUM_TRAILING_PARAMS(N, child)
)
>::type
result_type;
/// \param expr The current expression
/// \param context The callable evaluation context
/// \return <tt>context(Expr::proto_tag(), child_c\<0\>(expr), child_c\<1\>(expr), ...)</tt>
result_type operator ()(Expr &expr, Context &context) const
{
return context(
typename Expr::proto_tag()
BOOST_PP_ENUM_TRAILING(N, BOOST_PROTO_CHILD_N, expr)
);
}
};
}
#undef N
#endif

View File

@@ -0,0 +1,434 @@
#ifndef BOOST_PP_IS_ITERATING
///////////////////////////////////////////////////////////////////////////////
/// \file default.hpp
/// Definintion of default_context, a default evaluation context for
/// proto::eval() that uses Boost.Typeof to deduce return types
/// of the built-in operators.
//
// Copyright 2008 Eric Niebler. 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)
#ifndef BOOST_PROTO_CONTEXT_DEFAULT_HPP_EAN_01_08_2007
#define BOOST_PROTO_CONTEXT_DEFAULT_HPP_EAN_01_08_2007
#include <boost/proto/detail/prefix.hpp> // must be first include
#include <boost/config.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum_shifted.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/is_member_pointer.hpp>
#include <boost/type_traits/is_member_object_pointer.hpp>
#include <boost/type_traits/is_member_function_pointer.hpp>
#include <boost/proto/proto_fwd.hpp>
#include <boost/proto/tags.hpp>
#include <boost/proto/eval.hpp>
#include <boost/proto/traits.hpp> // for proto::child_c()
#include <boost/proto/detail/decltype.hpp>
#include <boost/proto/detail/suffix.hpp> // must be last include
namespace boost { namespace proto
{
/// INTERNAL ONLY
///
#define UNREF(x) typename boost::remove_reference<x>::type
namespace context
{
template<
typename Expr
, typename Context
, typename Tag BOOST_PROTO_WHEN_BUILDING_DOCS(= typename Expr::proto_tag)
, long Arity BOOST_PROTO_WHEN_BUILDING_DOCS(= Expr::proto_arity_c)
>
struct default_eval
{};
/// INTERNAL ONLY
///
#define BOOST_PROTO_UNARY_OP_RESULT(OP, TAG, MAKE) \
template<typename Expr, typename Context> \
struct default_eval<Expr, Context, TAG, 1> \
{ \
private: \
typedef typename proto::result_of::child_c<Expr, 0>::type e0; \
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0; \
public: \
BOOST_PROTO_DECLTYPE_(OP proto::detail::MAKE<r0>(), result_type) \
result_type operator ()(Expr &expr, Context &ctx) const \
{ \
return OP proto::eval(proto::child_c<0>(expr), ctx); \
} \
}; \
/**/
/// INTERNAL ONLY
///
#define BOOST_PROTO_BINARY_OP_RESULT(OP, TAG, LMAKE, RMAKE) \
template<typename Expr, typename Context> \
struct default_eval<Expr, Context, TAG, 2> \
{ \
private: \
typedef typename proto::result_of::child_c<Expr, 0>::type e0; \
typedef typename proto::result_of::child_c<Expr, 1>::type e1; \
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0; \
typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1; \
public: \
BOOST_PROTO_DECLTYPE_( \
proto::detail::LMAKE<r0>() OP proto::detail::RMAKE<r1>() \
, result_type \
) \
result_type operator ()(Expr &expr, Context &ctx) const \
{ \
return proto::eval( \
proto::child_c<0>(expr), ctx) OP proto::eval(proto::child_c<1>(expr) \
, ctx \
); \
} \
}; \
/**/
BOOST_PROTO_UNARY_OP_RESULT(+, proto::tag::unary_plus, make)
BOOST_PROTO_UNARY_OP_RESULT(-, proto::tag::negate, make)
BOOST_PROTO_UNARY_OP_RESULT(*, proto::tag::dereference, make)
BOOST_PROTO_UNARY_OP_RESULT(~, proto::tag::complement, make)
BOOST_PROTO_UNARY_OP_RESULT(&, proto::tag::address_of, make)
BOOST_PROTO_UNARY_OP_RESULT(!, proto::tag::logical_not, make)
BOOST_PROTO_UNARY_OP_RESULT(++, proto::tag::pre_inc, make_mutable)
BOOST_PROTO_UNARY_OP_RESULT(--, proto::tag::pre_dec, make_mutable)
BOOST_PROTO_BINARY_OP_RESULT(<<, proto::tag::shift_left, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(>>, proto::tag::shift_right, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(*, proto::tag::multiplies, make, make)
BOOST_PROTO_BINARY_OP_RESULT(/, proto::tag::divides, make, make)
BOOST_PROTO_BINARY_OP_RESULT(%, proto::tag::modulus, make, make)
BOOST_PROTO_BINARY_OP_RESULT(+, proto::tag::plus, make, make)
BOOST_PROTO_BINARY_OP_RESULT(-, proto::tag::minus, make, make)
BOOST_PROTO_BINARY_OP_RESULT(<, proto::tag::less, make, make)
BOOST_PROTO_BINARY_OP_RESULT(>, proto::tag::greater, make, make)
BOOST_PROTO_BINARY_OP_RESULT(<=, proto::tag::less_equal, make, make)
BOOST_PROTO_BINARY_OP_RESULT(>=, proto::tag::greater_equal, make, make)
BOOST_PROTO_BINARY_OP_RESULT(==, proto::tag::equal_to, make, make)
BOOST_PROTO_BINARY_OP_RESULT(!=, proto::tag::not_equal_to, make, make)
BOOST_PROTO_BINARY_OP_RESULT(||, proto::tag::logical_or, make, make)
BOOST_PROTO_BINARY_OP_RESULT(&&, proto::tag::logical_and, make, make)
BOOST_PROTO_BINARY_OP_RESULT(&, proto::tag::bitwise_and, make, make)
BOOST_PROTO_BINARY_OP_RESULT(|, proto::tag::bitwise_or, make, make)
BOOST_PROTO_BINARY_OP_RESULT(^, proto::tag::bitwise_xor, make, make)
BOOST_PROTO_BINARY_OP_RESULT(=, proto::tag::assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(<<=, proto::tag::shift_left_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(>>=, proto::tag::shift_right_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(*=, proto::tag::multiplies_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(/=, proto::tag::divides_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(%=, proto::tag::modulus_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(+=, proto::tag::plus_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(-=, proto::tag::minus_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(&=, proto::tag::bitwise_and_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(|=, proto::tag::bitwise_or_assign, make_mutable, make)
BOOST_PROTO_BINARY_OP_RESULT(^=, proto::tag::bitwise_xor_assign, make_mutable, make)
#undef BOOST_PROTO_UNARY_OP_RESULT
#undef BOOST_PROTO_BINARY_OP_RESULT
/// INTERNAL ONLY
template<typename Expr, typename Context>
struct is_member_function_eval
{
typedef typename proto::result_of::child_c<Expr, 1>::type e1;
typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1;
typedef typename remove_const<typename remove_reference<r1>::type>::type uncvref_r1;
typedef typename is_member_function_pointer<uncvref_r1>::type type;
BOOST_STATIC_CONSTANT(bool, value = type::value);
};
/// INTERNAL ONLY
template<typename Expr, typename Context, bool IsMemFunCall>
struct memfun_eval
{
private:
typedef typename result_of::child_c<Expr, 0>::type e0;
typedef typename result_of::child_c<Expr, 1>::type e1;
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1;
public:
typedef typename detail::mem_ptr_fun<r0, r1>::result_type result_type;
result_type operator ()(Expr &expr, Context &ctx) const
{
return detail::mem_ptr_fun<r0, r1>()(
proto::eval(proto::child_c<0>(expr), ctx)
, proto::eval(proto::child_c<1>(expr), ctx)
);
}
};
/// INTERNAL ONLY
template<typename Expr, typename Context>
struct memfun_eval<Expr, Context, true>
{
private:
typedef typename result_of::child_c<Expr, 0>::type e0;
typedef typename result_of::child_c<Expr, 1>::type e1;
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1;
public:
typedef detail::memfun<r0, r1> result_type;
result_type const operator ()(Expr &expr, Context &ctx) const
{
return detail::memfun<r0, r1>(
proto::eval(proto::child_c<0>(expr), ctx)
, proto::eval(proto::child_c<1>(expr), ctx)
);
}
};
template<typename Expr, typename Context>
struct default_eval<Expr, Context, tag::mem_ptr, 2>
: memfun_eval<Expr, Context, is_member_function_eval<Expr, Context>::value>
{};
template<typename Expr, typename Context, typename Tag>
struct default_eval<Expr, Context, Tag, 0>
{
typedef
typename proto::result_of::value<Expr &>::type
result_type;
result_type operator ()(Expr &expr, Context &) const
{
return proto::value(expr);
}
};
// Handle post-increment specially.
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::post_inc, 1>
{
private:
typedef typename proto::result_of::child_c<Expr, 0>::type e0;
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
public:
BOOST_PROTO_DECLTYPE_(proto::detail::make_mutable<r0>() ++, result_type)
result_type operator ()(Expr &expr, Context &ctx) const
{
return proto::eval(proto::child_c<0>(expr), ctx) ++;
}
};
// Handle post-decrement specially.
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::post_dec, 1>
{
private:
typedef typename proto::result_of::child_c<Expr, 0>::type e0;
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
public:
BOOST_PROTO_DECLTYPE_(proto::detail::make_mutable<r0>() --, result_type)
result_type operator ()(Expr &expr, Context &ctx) const
{
return proto::eval(proto::child_c<0>(expr), ctx) --;
}
};
// Handle subscript specially.
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::subscript, 2>
{
private:
typedef typename proto::result_of::child_c<Expr, 0>::type e0;
typedef typename proto::result_of::child_c<Expr, 1>::type e1;
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1;
public:
BOOST_PROTO_DECLTYPE_(proto::detail::make_subscriptable<r0>()[proto::detail::make<r1>()], result_type)
result_type operator ()(Expr &expr, Context &ctx) const
{
return proto::eval(proto::child_c<0>(expr), ctx)[proto::eval(proto::child_c<1>(expr), ctx)];
}
};
// Handle if_else_ specially.
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::if_else_, 3>
{
private:
typedef typename proto::result_of::child_c<Expr, 0>::type e0;
typedef typename proto::result_of::child_c<Expr, 1>::type e1;
typedef typename proto::result_of::child_c<Expr, 2>::type e2;
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1;
typedef typename proto::result_of::eval<UNREF(e2), Context>::type r2;
public:
BOOST_PROTO_DECLTYPE_(
proto::detail::make<r0>()
? proto::detail::make<r1>()
: proto::detail::make<r2>()
, result_type
)
result_type operator ()(Expr &expr, Context &ctx) const
{
return proto::eval(proto::child_c<0>(expr), ctx)
? proto::eval(proto::child_c<1>(expr), ctx)
: proto::eval(proto::child_c<2>(expr), ctx);
}
};
// Handle comma specially.
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::comma, 2>
{
private:
typedef typename proto::result_of::child_c<Expr, 0>::type e0;
typedef typename proto::result_of::child_c<Expr, 1>::type e1;
typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0;
typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1;
public:
typedef typename proto::detail::comma_result<r0, r1>::type result_type;
result_type operator ()(Expr &expr, Context &ctx) const
{
return proto::eval(proto::child_c<0>(expr), ctx), proto::eval(proto::child_c<1>(expr), ctx);
}
};
// Handle function specially
#define EVAL_TYPE(Z, N, DATA) \
typename proto::result_of::eval< \
typename remove_reference< \
typename proto::result_of::child_c<DATA, N>::type \
>::type \
, Context \
>::type \
/**/
#define EVAL(Z, N, DATA) \
proto::eval(proto::child_c<N>(DATA), context) \
/**/
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::function, 1>
{
typedef
typename proto::detail::result_of_fixup<EVAL_TYPE(~, 0, Expr)>::type
function_type;
typedef
typename boost::result_of<function_type()>::type
result_type;
result_type operator ()(Expr &expr, Context &context) const
{
return EVAL(~, 0, expr)();
}
};
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::function, 2>
{
typedef
typename proto::detail::result_of_fixup<EVAL_TYPE(~, 0, Expr)>::type
function_type;
typedef
typename detail::result_of_<function_type(EVAL_TYPE(~, 1, Expr))>::type
result_type;
result_type operator ()(Expr &expr, Context &context) const
{
return this->invoke(
expr
, context
, is_member_function_pointer<function_type>()
, is_member_object_pointer<function_type>()
);
}
private:
result_type invoke(Expr &expr, Context &context, mpl::false_, mpl::false_) const
{
return EVAL(~, 0, expr)(EVAL(~, 1, expr));
}
result_type invoke(Expr &expr, Context &context, mpl::true_, mpl::false_) const
{
using namespace detail::get_pointer_;
return (get_pointer(EVAL(~, 1, expr)) ->* EVAL(~, 0, expr))();
}
result_type invoke(Expr &expr, Context &context, mpl::false_, mpl::true_) const
{
using namespace detail::get_pointer_;
return (get_pointer(EVAL(~, 1, expr)) ->* EVAL(~, 0, expr));
}
};
#define BOOST_PP_ITERATION_PARAMS_1 (3, (3, BOOST_PROTO_MAX_ARITY, <boost/proto/context/default.hpp>))
#include BOOST_PP_ITERATE()
#undef EVAL_TYPE
#undef EVAL
/// default_context
///
struct default_context
{
/// default_context::eval
///
template<typename Expr, typename ThisContext = default_context const>
struct eval
: default_eval<Expr, ThisContext>
{};
};
} // namespace context
}} // namespace boost::proto
#undef UNREF
#endif
#else
#define N BOOST_PP_ITERATION()
template<typename Expr, typename Context>
struct default_eval<Expr, Context, proto::tag::function, N>
{
typedef
typename proto::detail::result_of_fixup<EVAL_TYPE(~, 0, Expr)>::type
function_type;
typedef
typename boost::result_of<
function_type(BOOST_PP_ENUM_SHIFTED(N, EVAL_TYPE, Expr))
>::type
result_type;
result_type operator ()(Expr &expr, Context &context) const
{
return this->invoke(expr, context, is_member_function_pointer<function_type>());
}
private:
result_type invoke(Expr &expr, Context &context, mpl::false_) const
{
return EVAL(~, 0, expr)(BOOST_PP_ENUM_SHIFTED(N, EVAL, expr));
}
result_type invoke(Expr &expr, Context &context, mpl::true_) const
{
#define M0(Z, M, expr) BOOST_PP_COMMA_IF(BOOST_PP_SUB(M, 2)) EVAL(Z, M, expr)
using namespace detail::get_pointer_;
return (get_pointer(EVAL(~, 1, expr)) ->* EVAL(~, 0, expr))(
BOOST_PP_REPEAT_FROM_TO(2, N, M0, expr)
);
#undef M0
}
};
#undef N
#endif

View File

@@ -0,0 +1,87 @@
#ifndef BOOST_PP_IS_ITERATING
///////////////////////////////////////////////////////////////////////////////
/// \file null.hpp
/// Definintion of null_context\<\>, an evaluation context for
/// proto::eval() that simply evaluates each child expression, doesn't
/// combine the results at all, and returns void.
//
// Copyright 2008 Eric Niebler. 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)
#ifndef BOOST_PROTO_CONTEXT_NULL_HPP_EAN_06_24_2007
#define BOOST_PROTO_CONTEXT_NULL_HPP_EAN_06_24_2007
#include <boost/proto/detail/prefix.hpp> // must be first include
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/proto/proto_fwd.hpp>
#include <boost/proto/eval.hpp>
#include <boost/proto/traits.hpp>
#include <boost/proto/detail/suffix.hpp> // must be last include
namespace boost { namespace proto { namespace context
{
template<
typename Expr
, typename Context
, long Arity BOOST_PROTO_WHEN_BUILDING_DOCS(= Expr::proto_arity_c)
>
struct null_eval
{};
template<typename Expr, typename Context>
struct null_eval<Expr, Context, 0>
{
typedef void result_type;
void operator()(Expr &, Context &) const
{}
};
#define BOOST_PROTO_EVAL_N(Z, N, DATA) \
proto::eval(proto::child_c<N>(expr), ctx); \
/**/
#define BOOST_PP_ITERATION_PARAMS_1 \
(3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/context/null.hpp>)) \
/**/
#include BOOST_PP_ITERATE()
#undef BOOST_PROTO_EVAL_N
/// null_context
///
struct null_context
{
/// null_context::eval
///
template<typename Expr, typename ThisContext = null_context const>
struct eval
: null_eval<Expr, ThisContext>
{};
};
}}}
#endif
#else
#define N BOOST_PP_ITERATION()
template<typename Expr, typename Context>
struct null_eval<Expr, Context, N>
{
typedef void result_type;
void operator ()(Expr &expr, Context &ctx) const
{
BOOST_PP_REPEAT(N, BOOST_PROTO_EVAL_N, ~)
}
};
#undef N
#endif