Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

Struct template callable_context

Boost , The Boost C++ Libraries BoostBook Documentation Subset , Reference

Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

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

// In header: <boost/proto/context/callable.hpp>
template<typename Context, 
         typename DefaultCtx = proto::context::default_context> 
struct callable_context {
  // member classes/structs/unions
  template<typename Expr, typename ThisContext = Context> 
  struct eval :  see-below {
  };
};

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>, // For exposition
      proto::context::callable_eval<Expr, ThisContext>,
      typename DefaultCtx::template eval<Expr, Context>
    >::type
  {};
};

Булева метафункция<is_expr_handled_<>>использует трюки метапрограммирования, чтобы определить, имеет ли<Context>оператор вызова перегруженной функции, который принимает разветвленные составляющие выражения типа<Expr>. Если это так, то обращение с выражением отсылается к<proto::context::callable_eval<>>. Если нет, то он отправляется пользователю<DefaultCtx>.

Пример:

// An evaluation context that increments all
// integer terminals in-place.
struct increment_ints :
  proto::context::callable_context<
    increment_ints const                // derived context
    proto::context::null_context const  // fall-back context
  >
{
    typedef void result_type;
    // Handle int terminals here:
    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 );


PrevUpHomeNext

Статья Struct template callable_context раздела The Boost C++ Libraries BoostBook Documentation Subset Reference может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Reference ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-19 21:11:57/0.0064101219177246/0