Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Parsing Boost PP data

There are macros for the Boost PP data types that can parse the particular data type at the beginning of a v-sequence. Unlike the equivalent functionality for v-identifiers and v-numbers the only parameter that is allowed is the v-sequence itself.

The macros are:

Each of these macros expand to a tuple of two elements. If the particular data type is found at the beginning of the v-sequence the first tuple element is that data type and the second tuple element is the rest of the input v-sequence. If the particular data type is not found at the beginning of the input v-sequence of both tuple elements is empty.

Usage

In order to use any of the macros you can include the general header:

#include <boost/vmd/vmd.hpp>

or include the appropriate specific header:

#include <boost/vmd/array.hpp> // BOOST_VMD_ARRAY
#include <boost/vmd/list.hpp> // BOOST_VMD_LIST
#include <boost/vmd/seq.hpp> // BOOST_VMD_SEQ
#include <boost/vmd/tuple.hpp> // BOOST_VMD_TUPLE
Data types and tuples

An array and a non-empty list are also tuples. A seq is a series of single element tuples. Therefore if a v-sequence begins with an array, non-empty list, or seq, and you use BOOST_VMD_TUPLE passing that v-sequence, you will successfully find the beginning tuple. In the case of an array or a non-empty list what is returned will be exactly the same as a tuple. In the case of a seq what is returned will only be the same if the seq is a single one-element tuple.

As an example:

#define INPUT_D1 (3,(a,b,c)) data

BOOST_VMD_ARRAY(INPUT_D1)
BOOST_VMD_TUPLE(INPUT_D1)

expands to ((3,(a,b,c)),data)

#define INPUT_D2 (a,(b,(c,BOOST_PP_NIL))) 204

BOOST_VMD_LIST(INPUT_D2)
BOOST_VMD_TUPLE(INPUT_D2)

expands to ((a,(b,(c,BOOST_PP_NIL))),204)

#define INPUT_D3 (a)(b)(c) anything

BOOST_VMD_SEQ(INPUT_D3)

expands to ((a)(b)(c),anything)

BOOST_VMD_TUPLE(INPUT_D3)

expands to ((a),(b)(c) anything)

On the other hand not every tuple is a non-empty list or array while only a single element tuple is also a seq.

As an example:

#define INPUT_D4 (z,(a,b,c)) data

BOOST_VMD_ARRAY(INPUT_D4)

expands to (,) since the beginning tuple is not an array

BOOST_VMD_TUPLE(INPUT_D4)

expands to ((z,(a,b,c)),data) since there is a beginning tuple

#define INPUT_D5 (a,(b,(c))) 204

BOOST_VMD_LIST(INPUT_D5)

expands to (,) since the beginning tuple is not a list ( missing BOOST_PP_NIL terminator )

BOOST_VMD_TUPLE(INPUT_D5)

expands to ((a,(b,(c))),204) since there is a beginning tuple

#define INPUT_D6 (a,b)(c) anything

BOOST_VMD_SEQ(INPUT_D6)

expands to (,) since the beginning tuple here cannot start a seq

BOOST_VMD_TUPLE(INPUT_D6)

expands to ((a,b),(c) anything) since there is a beginning tuple

#define INPUT_D7 (abc) anything

BOOST_VMD_SEQ(INPUT_D7)
BOOST_VMD_TUPLE(INPUT_D7)

expands to ((abc),anything) since the beginning tuple is also a beginning seq


PrevUpHomeNext