Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Macro BOOST_PROTO_REPEAT_FROM_TO

BOOST_PROTO_REPEAT_FROM_TO — Repeatedly invoke the specified macro.

Synopsis

// In header: <boost/proto/repeat.hpp>

BOOST_PROTO_REPEAT_FROM_TO(FROM, TO, MACRO)

Description

BOOST_PROTO_REPEAT_FROM_TO() is used to generate the kind of repetitive code that is typical of EDSLs built with Proto. BOOST_PROTO_REPEAT_FROM_TO(FROM, TO, MACRO) is equivalent to:

MACRO(FROM, BOOST_PROTO_typename_A, BOOST_PROTO_A_const_ref, BOOST_PROTO_A_const_ref_a, BOOST_PROTO_ref_a)
MACRO(FROM+1, BOOST_PROTO_typename_A, BOOST_PROTO_A_const_ref, BOOST_PROTO_A_const_ref_a, BOOST_PROTO_ref_a)
...
MACRO(TO-1, BOOST_PROTO_typename_A, BOOST_PROTO_A_const_ref, BOOST_PROTO_A_const_ref_a, BOOST_PROTO_ref_a)

Example:

// Generate BOOST_PROTO_MAX_ARITY-1 overloads of the
// following construct() function template.
#define M0(N, typename_A, A_const_ref, A_const_ref_a, ref_a)      \
template<typename T, typename_A(N)>                               \
typename proto::result_of::make_expr<                             \
    proto::tag::function                                          \
  , construct_helper<T>                                           \
  , A_const_ref(N)                                                \
>::type const                                                     \
construct(A_const_ref_a(N))                                       \
{                                                                 \
    return proto::make_expr<                                      \
        proto::tag::function                                      \
    >(                                                            \
        construct_helper<T>()                                     \
      , ref_a(N)                                                  \
    );                                                            \
}
BOOST_PROTO_REPEAT_FROM_TO(1, BOOST_PROTO_MAX_ARITY, M0)
#undef M0

The above invocation of BOOST_PROTO_REPEAT_FROM_TO() will generate the following code:

template<typename T, typename A0>
typename proto::result_of::make_expr<
    proto::tag::function
  , construct_helper<T>
  , A0 const &
>::type const
construct(A0 const & a0)
{
    return proto::make_expr<
        proto::tag::function
    >(
        construct_helper<T>()
      , boost::ref(a0)
    );
}

template<typename T, typename A0, typename A1>
typename proto::result_of::make_expr<
    proto::tag::function
  , construct_helper<T>
  , A0 const &
  , A1 const &
>::type const
construct(A0 const & a0, A1 const & a1)
{
    return proto::make_expr<
        proto::tag::function
    >(
        construct_helper<T>()
      , boost::ref(a0)
      , boost::ref(a1)
    );
}

// ... and so on, up to BOOST_PROTO_MAX_ARITY-1 arguments ...


PrevUpHomeNext