BOOST_PP_VARIADIC_TO_SEQ, and BOOST_PP_VARIADIC_TO_TUPLE.<br>
<br>
All of these macros need compiler support for variadic data and only
exist if BOOST_PP_VARIADICS is 1. <br>
<br>
The remaining four macros, which convert from a library data type
to comma-separated preprocessor tokens, which is the form of
variadic data, do not need compiler support for variadic
macros. These functions are BOOST_PP_ARRAY_ENUM, BOOST_PP_LIST_ENUM,
BOOST_PP_SEQ_ENUM, and BOOST_PP_TUPLE_ENUM. However if one wishes to
use this variadic data reliably as arguments to other macros, one needs
variadic macro support.<br>
</div>
<ustyle="font-weight: bold;"> Using Variadic Data</u>
<div>Variadic data exists in the
form of comma-separated preprocessor tokens. This is the case whether
the variadic data comes from the __VA_ARGS__ of a variadic macro, from
the conversion of a library's data type to variadic data, or the
manual construction of comma-separated preprocessing tokens by the
programmer writing a macro.<br>
<br>
The easiest way to work with
variadic data internally is to convert it to a library data type.
Library data types, whether an <i>array</i>, <i>list</i>,
<i>sequence</i>,
or <i>tuple</i>, have a rich set of functionality for
manipulating
data whereas
variadic data functionality in the library only allows one to access
the variadic data as a whole or to access a single token of the
variadic data at a time.<br>
<br>
The user of the library still may
choose to pass variadic data back into internal macros rather than
convert it to other library data types. There is no problem passing
variadic data as a whole to variadic macros as the last parameter of
the macro. However: <br>
<br>
<spanstyle="font-weight: bold;">Attempting to pass
variadic data as a
whole directly into a non-variadic macro is not guaranteed to work and
may fail.<br>
</span><br>
This occurs because of a preprocessor weakness in a number
of compilers, currently most notably Visual C++. Even passing variadic
data as arguments to a non-variadic macro, when it is not represented
in
the form of __VA_ARGS__, may fail with certain compilers.<br>
<br>
What follows are very simple examples, showing how variadic data can be
passed to a non-variadic macro.<br>
<br>
First an example of what NOT to do.<br>
</div>
<h4>Example<u> - Passing variadic data as a whole to a
non-variadic
macro. DO NOT DO.</u></h4>
<divclass="code">
<pre>#define MACRO_ARG_2(x,y) BOOST_PP_ADD(x,y)<br>#define VAR_MACRO(...) __VA_ARGS__<br><br>/* The following should not be done and is not guaranteed to work with compilers. */<br><br><spanstyle="font-weight: bold;"><spanstyle="font-family: monospace;"></span></span>int xx = MACRO_ARG_2(VAR_MACRO(2,3));<br></pre>
</div>
<div> There are two ways to pass variadic data to a non-variadic
macro.
The
first of these is to pass the individual tokens of the variadic data
separately to the non-variadic macro using the BOOST_PP_VARIADIC_ELEM
macro in the library.<br>
</div>
<h4>Example<u> - Passing individual variadic data tokens to
a
non-variadic macro.<br>
</u></h4>
<divclass="code">
<pre>#define MACRO_ARG_2(x,y) BOOST_PP_ADD(x,y)<br>#define VAR_MACRO(...) __VA_ARGS__<br><br>/* The following will work correctly */<br><br>int xx = MACRO_ARG_2<br> (<br> BOOST_PP_VARIADIC_ELEM(0,VAR_MACRO(2,3)),<br> BOOST_PP_VARIADIC_ELEM(1,VAR_MACRO(2,3))<br> );</pre>
</div>
<div>The second way is to use a macro in the library called
BOOST_PP_OVERLOAD.
This macro allows one to "overload" a variadic macro to non-variadic
macros of different numbers of parameters, using a common prefix.
</div>
<h4>Example<u> - Passing variadic data as a whole to
BOOST_PP_OVERLOAD
and on to a non-variadic macro.<br>
</u></h4>
<divclass="code">
<pre>#define MACRO_ARG_2(x,y) BOOST_PP_ADD(x,y)<br>#define VAR_MACRO(...) __VA_ARGS__<br><br>/* The following will work correctly */<br><br>int xx = BOOST_PP_OVERLOAD(MACRO_ARG_,VAR_MACRO(2,3))(VAR_MACRO(2,3));<br><br>/* For Visual C++ it is necessary to do this */<br><br>int xx = <br>BOOST_PP_CAT(BOOST_PP_OVERLOAD(MACRO_ARG_,VAR_MACRO(2,3))(VAR_MACRO(2,3)),BOOST_PP_EMPTY());</pre>
</div><br>
<div>Although these techniques will work when passing variadic
data to
non-variadic macros, it is much better and less problematical to
work internally with the existing library data types and to only use
variadic
macros as an interface for end-users when there is a need to have a