Struct template callable_context
boost::proto::context::callable_context — An evaluation context adaptor that makes authoring a context a simple matter of
writing function overloads, rather then writing template specializations.
Synopsis
Description
proto::callable_context<>
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,
DefaultCtx
.
proto::callable_context<>
is defined simply as:
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>,
proto::context::callable_eval<Expr, ThisContext>,
typename DefaultCtx::template eval<Expr, Context>
>::type
{};
};
Булева метафункция<is_expr_handled_<>
>использует трюки метапрограммирования, чтобы определить, имеет ли<Context
>оператор вызова перегруженной функции, который принимает разветвленные составляющие выражения типа<Expr
>. Если это так, то обращение с выражением отсылается к<proto::context::callable_eval<>
>. Если нет, то он отправляется пользователю<DefaultCtx
>.
Пример:
struct increment_ints :
proto::context::callable_context<
increment_ints const
proto::context::null_context const
>
{
typedef void result_type;
void operator()(proto::tag::terminal, int &i) const
{
++i;
}
};
С<increment_ints
>мы можем сделать следующее:
proto::literal<int> i = 0, j = 10;
proto::eval( i - j * 3.14, increment_ints() );
assert( i.get() == 1 && j.get() == 11 );