Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Emptiness and Boost PP data types

While the VMD library supports the identification of empty input through the BOOST_VMD_IS_EMPTY macro, it is also possible to use Boost PP data types to pass empty data.

Empty arrays

The Boost PP array is largely obsolete when variadic macros are used, since the Boost PP tuple contains all of the functionality of the array, except in a single area. The array can truly be empty, and an empty array takes the form of:

(0,())

This is an empty array since its size is 0 and its data is empty. The VMD library has functionality to identify an empty array using the BOOST_VMD_IS_EMPTY_ARRAY macro. This macro takes a parameter as input and determines whether or not it is an empty array, expanding to 1 if it is and 0 if it is not.

Usage for BOOST_VMD_IS_EMPTY_ARRAY

To use the BOOST_VMD_IS_EMPTY_ARRAY macro either include the general header:

#include <boost/vmd/vmd.hpp>

or include the specific header:

#include <boost/vmd/array.hpp>

Empty lists

A Boost PP list can be empty, and an empty list takes the form of:

BOOST_PP_NIL

This is a truly empty list, whose size is 0 and which contains no list data. The VMD library has functionality to identify an empty list using the BOOST_VMD_IS_EMPTY_LIST macro. This macro takes a parameter as input and determines whether or not it is an empty list, expanding to 1 if it is and 0 if it is not.

Usage for BOOST_VMD_IS_EMPTY_LIST

To use the BOOST_VMD_IS_EMPTY_LIST macro either include the general header:

#include <boost/vmd/vmd.hpp>

or include the specific header:

#include <boost/vmd/list.hpp>

Emptiness with seqs and tuples

The Boost PP data types of a seq or a tuple are never empty. All seqs or tuples have a minimum size of 1. The form of:

()

can be either a seq whose single element contains no data or a tuple containing a single element of no data. In both cases the size of the seq or tuple are 1 even if the data is empty.

Even though a seq or a tuple is never empty you can choose to consider a seq or tuple whose single element data is empty as an empty construct. The VMD library has a macro called BOOST_VMD_IS_PARENS_EMPTY to identify this construct. The macro takes a single parameter and returns 1 if the parameter is a set of parenthesis with no data, or 0 if it is not.

Usage for BOOST_VMD_IS_PARENS_EMPTY

To use the BOOST_VMD_IS_PARENS_EMPTY macro either include the general header:

#include <boost/vmd/vmd.hpp>

or include the specific header:

#include <boost/vmd/is_parens_empty.hpp>

Conversions of "empty" data

The Boost PP array and list can be empty but a seq or a tuple are never considered empty, even if we use the form of a seq or tuple which represents a set of parenthesis which contains no data. Because of this we can convert between an empty array or an empty list, but if we convert from an empty array or list to a seq or tuple we get undefined behavior. On the other side if we convert from a seq or a tuple which is represented by a set of parenthesis which contain no data, we end up with an array or list whose size is 1 but whose single element contains no data. The following table illustrated these conversions in Boost PP:

Table 1.1. Boost PP data conversions for "empty" data

Data type

To array

To list

To seq

To tuple

Array

N/A

BOOST_PP_ARRAY_TO_LIST

result = empty list, BOOST_PP_NIL

BOOST_PP_ARRAY_TO_SEQ

result = undefined behavior

BOOST_PP_ARRAY_TO_TUPLE

result = undefined behavior

List

BOOST_PP_LIST_TO_ARRAY BOOST_PP_LIST_TO_ARRAY_D

result = empty array, (0,())

N/A

BOOST_PP_LIST_TO_SEQ BOOST_PP_LIST_TO_SEQ_R

result = undefined behavior

BOOST_PP_LIST_TO_TUPLE BOOST_PP_LIST_TO_TUPLE_R

result = undefined behavior

Seq

BOOST_PP_SEQ_TO_ARRAY

result = (1,())

BOOST_PP_SEQ_TO_LIST(

result = ((),BOOST_PP_NIL)

N/A

BOOST_PP_SEQ_TO_TUPLE

result = empty parenthesis, ()

Tuple

BOOST_PP_TUPLE_TO_ARRAY

result = (1,())

BOOST_PP_TUPLE_TO_LIST

result = ((),BOOST_PP_NIL)

BOOST_PP_TUPLE_TO_SEQ

result = empty parenthesis, ()

N/A


Empty parenthesis and VC++

Visual C++ 9 through 12 handles empty parenthesis correctly when it is passed as preprocessor data but Visual C++ 8 ( Visual Studio 2005 ) becomes confused by empty parenthesis passed as possibly parameter data between macros, so this technique for passing empty data as seqs or tuples should be avoided if the compiler being used could be VC++8. A C++ standard comforming preprocessor should have no problems handling data as an empty parenthesis.


PrevUpHomeNext