###

# Boost.Preprocessor

## Reference

Prev Next Macros Headers

# #include <boost/preprocessor/list/adt.hpp>

This header defines the fundamental list operations.

### Note

- The internal representation of lists is hidden. Although there aren't compelling reasons to change the representation, you should avoid writing code that depends on the internal representation details.

## #define BOOST_PP_LIST_CONS(FIRST,REST)

List constructor.

Lists are build using list constructors BOOST_PP_LIST_NIL and BOOST_PP_LIST_CONS(). For example,

      BOOST_PP_LIST_CONS(1,
      BOOST_PP_LIST_CONS(2,
      BOOST_PP_LIST_CONS(3,
      BOOST_PP_LIST_CONS(4,
      BOOST_PP_LIST_CONS(5,
      BOOST_PP_LIST_NIL)))))

Short lists can also be build from tuples:

      BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5))

Both of the above lists contain 5 elements: 1, 2, 3, 4 and 5.

Longer lists can be built from short lists with BOOST_PP_LIST_APPEND_D() and BOOST_PP_LIST_FOLD_RIGHT_2ND():

      BOOST_PP_LIST_FOLD_RIGHT_2ND
      ( BOOST_PP_LIST_APPEND_D
      , BOOST_PP_TUPLE_TO_LIST
        ( N
        , BOOST_PP_TUPLE_TO_LIST(M, (E11, E12, ..., E1M) )
        , BOOST_PP_TUPLE_TO_LIST(M, (E21, E22, ..., E2M) )
        , ...
        , BOOST_PP_TUPLE_TO_LIST(M, (EN1, EN2, ..., ENM) )
        )
      )

## #define BOOST_PP_LIST_NIL

List nil constructor.

## #define BOOST_PP_LIST_IS_CONS(LIST)

Expands to 1 if the list is not nil and 0 otherwise.

## #define BOOST_PP_LIST_IS_NIL(LIST)

Expands to 1 if the list is nil and 0 otherwise.

## #define BOOST_PP_LIST_FIRST(LIST)

Expands to the first element of the list. The list must not be nil.

For example,

      BOOST_PP_LIST_FIRST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))

expands to 1.

## #define BOOST_PP_LIST_REST(LIST)

Expands to a list of all but the first element of the list.

The list must not be nil.

For example,

      BOOST_PP_LIST_REST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))

expands to the same as:

      BOOST_PP_TUPLE_TO_LIST(4,(2,3,4,5))

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.