The BOOST_PP_SEQ_FOLD_RIGHT macro folds (or accumulates) the elements of a seq right-to-left.

Usage

BOOST_PP_SEQ_FOLD_RIGHT(op, state, seq)

Arguments

op
A ternary operation of the form op(s, state, elem).  This macro is called for each element in seq--each time returning a new state.  This operation is expanded by BOOST_PP_SEQ_FOLD_RIGHT with the next available fold step, the current state, and the current element.
state
The initial state of the fold.
seq
The seq to be folded.

Remarks

For the seq, (0)(1)(2), this macro expands to:
op(s, op(s, op(s, state, 2), 1), 0)
For maximum efficiency, BOOST_PP_SEQ_FOLD_RIGHT can be reentered with BOOST_PP_SEQ_FOLD_RIGHT_s.

See Also

Requirements

Header:  <boost/preprocessor/seq/fold_right.hpp>

Sample Code

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/seq/fold_right.hpp>
#include <boost/preprocessor/seq/pop_back.hpp>

#define SEQ (t)(s)(o)(o)(b)

#define OP(s, state, x) BOOST_PP_CAT(state, x)

BOOST_PP_SEQ_FOLD_RIGHT(OP, BOOST_PP_SEQ_ELEM(4, SEQ), BOOST_PP_SEQ_POP_BACK(SEQ)) // expands to boost

© Copyright Housemarque Oy 2002
© Copyright Paul Mensonides 2002

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt)