###  | # Boost.Preprocessor ## Header <boost/preprocessor/list/fold_left.hpp>

Prev Next Macros Headers

### #define BOOST_PP_LIST_FOLD_LEFT(OP,STATE,LIST)

Iterates `OP(D,STATE,X)` for each element `X` of the list `LIST` (from the left or the start of the list).

In other words, expands to:

    OP
    ( D
    , ... OP(D, OP(D,STATE,BOOST_PP_LIST_AT(LIST,0)), BOOST_PP_LIST_AT(LIST,1)) ...
    , BOOST_PP_LIST_AT(LIST,BOOST_PP_DEC(BOOST_PP_LIST_SIZE(LIST))
    )

For example,

    #define TEST(D,STATE,X) BOOST_PP_CAT(STATE,X)
    BOOST_PP_LIST_FOLD_LEFT(TEST,_,BOOST_PP_TUPLE_TO_LIST(3,(A,B,C)))

expands to:

    _ABC

### Note

- Folding, or accumulation, is a very general pattern of computation. Most list operations can be implemented in terms of folding.

### See

- BOOST_PP_LIST_FOLD_RIGHT()

### Test

- list_test.cpp

### #define BOOST_PP_LIST_FOLD_LEFT_D(D,OP,STATE,LIST)

Can be used inside BOOST_PP_WHILE() (see for an explanation of the D parameter).

### Note

- BOOST_PP_LIST_FOLD_LEFT_D() implements automatic recursion. You can use a fold in the OP macro.

### #define BOOST_PP_LIST_FOLD_LEFT_2ND

Obsolete, just use BOOST_PP_LIST_FOLD_LEFT().

### #define BOOST_PP_LIST_FOLD_LEFT_2ND_D

Obsolete, just use BOOST_PP_LIST_FOLD_LEFT_D().

Prev Next Macros Headers

Revised

© Copyright Housemarque Oy 2002

Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.