Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards


Modifiers and the single-element sequence

A single element sequence is what we normally think of when working with macro data. It is a single type of macro data passed as an input parameter to some macro and processed as such.

In its basic form without modifiers BOOST_VMD_ELEM serves to just return a particular element of a sequence. For a single element sequence BOOST_VMD_ELEM with element number 0, just returns the single-element sequence itself. This does not offer much functionality for our simple sequence. However with modifiers we can do things generically with our single-element sequence which correspond to working with a single type of data and extracting information about it.

With the return type modifier we can get the type of the data along with the data. Of course we can also use BOOST_VMD_GET_TYPE to retrieve just the type of data.

With our filter modifier we can retrieve the data only if it is a particular type, else retrieve emptiness.

With the identifier modifier we can retrieve an identifier only if it matches one or more other identifiers, else retrieve emptiness.

With our index modifier we can retrieve both our identifier and its numeric index if it matches one or more other identifiers, else retrieve a tuple of two empty elements if no match is found.