Explanations about using tuples rather than arrays with variadic macro support.

This commit is contained in:
Edward Diener
2013-12-05 17:43:48 -05:00
parent 58cf4ccba9
commit 6978c83372
3 changed files with 324 additions and 322 deletions

View File

@ -1,37 +1,33 @@
<html> <html>
<head> <head>
<title>arrays.html</title> <title>arrays.html</title>
<link rel="stylesheet" type="text/css" href="../styles.css"> <link rel="stylesheet" type="text/css" href="../styles.css">
</head> </head>
<body> <body>
<h4>Arrays</h4> <h4>Arrays</h4>
<div> <div> An <i>array</i> is a data structure consisting of a two-element <i>tuple</i>.&nbsp;
An <i>array</i> is a data structure consisting of a two-element <i>tuple</i>.&nbsp;
The first element is the number of elements in the <i>array</i>.&nbsp; The first element is the number of elements in the <i>array</i>.&nbsp;
The second element is another <i>tuple</i> of the elements in the <i>array</i>.&nbsp; The second element is another <i>tuple</i> of the elements in the <i>array</i>.&nbsp;
For example, For example, </div>
</div> <div class="code"> (<i>3</i>, (<i>a</i>, <i>b</i>, <i>c</i>)) </div>
<div class="code"> <div> ...is an <i>array</i> of <i>3</i> elements--<i>a</i>, <i>b</i>, and
(<i>3</i>, (<i>a</i>, <i>b</i>, <i>c</i>)) <i>c</i>. </div>
</div> <div> The primary strength of <i>arrays</i> is that they store their own
<div> size.&nbsp; Because of this, access to elements does not require the
...is an <i>array</i> of <i>3</i> elements--<i>a</i>, <i>b</i>, and <i>c</i>. size.&nbsp; It only requires that an element exists at a certain index. </div>
</div> <div> This allows macro parameters to be variable in size and allows data
<div> states to change size without the user explicitly keeping track of the
The primary strength of <i>arrays</i> is that they store their own size.&nbsp; size independently.</div>
Because of this, access to elements does not require the size.&nbsp; <div>With variadic macro support a <i>tuple </i>has all of the
It only requires that an element exists at a certain index. functionality as an <i>array</i>, knows its own size, and is easier
</div> syntactically to use. Because of that an <i>array</i> should be used, as
<div> opposed to a <i>tuple</i>, only if your compiler does not support
This allows macro parameters to be variable in size and allows data states to change variadic macros.<br>
size without the user explicitly keeping track of the size independently. <br>
</div>
<div>
Elements of an <i>array</i> can be extracted with <b>BOOST_PP_ARRAY_ELEM</b>, Elements of an <i>array</i> can be extracted with <b>BOOST_PP_ARRAY_ELEM</b>,
an <i>array's</i> size can be extracted with <b>BOOST_PP_ARRAY_SIZE</b>, and an <i>array's</i> size can be extracted with <b>BOOST_PP_ARRAY_SIZE</b>,
an <i>array</i> can be converted to the more primitive <i>tuple</i> data structure and an <i>array</i> can be converted to the more primitive <i>tuple</i>
with <b>BOOST_PP_ARRAY_DATA</b>. data structure with <b>BOOST_PP_ARRAY_DATA</b>. </div>
</div>
<h4>Primitives</h4> <h4>Primitives</h4>
<ul> <ul>
<li><a href="../ref/array_data.html">BOOST_PP_ARRAY_DATA</a></li> <li><a href="../ref/array_data.html">BOOST_PP_ARRAY_DATA</a></li>
@ -39,15 +35,13 @@
<li><a href="../ref/array_size.html">BOOST_PP_ARRAY_SIZE</a></li> <li><a href="../ref/array_size.html">BOOST_PP_ARRAY_SIZE</a></li>
</ul> </ul>
<hr size="1"> <hr size="1">
<div style="margin-left: 0px;"> <div style="margin-left: 0px;"> <i><EFBFBD> Copyright <a href="http://www.housemarque.com"
<i><EFBFBD> Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i> target="_top">Housemarque Oy</a> 2002</i> <br>
</br><i><EFBFBD> Copyright Paul Mensonides 2002</i> <i><EFBFBD> Copyright Paul Mensonides 2002</i> </div>
</div>
<div style="margin-left: 0px;"> <div style="margin-left: 0px;">
<p><small>Distributed under the Boost Software License, Version 1.0. (See <p><small>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
copy at <a href= or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
"http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
</div> </div>
</body> </body>
</html> </html>

View File

@ -1,42 +1,35 @@
<html> <html>
<head> <head>
<title>tuples.html</title> <title>tuples.html</title>
<link rel="stylesheet" type="text/css" href="../styles.css"> <link rel="stylesheet" type="text/css" href="../styles.css">
</head> </head>
<body> <body>
<h4>Tuples</h4> <h4>Tuples</h4>
<div> <div> A <i>tuple</i> is a simple comma-separated list of elements inside
A <i>tuple</i> is a simple comma-separated list of elements inside parenthesis.&nbsp; parenthesis.&nbsp; For example, </div>
For example, <div class="code"> (<i>a</i>, <i>b</i>, <i>c</i>) </div>
</div> <div> ...is a <i>tuple</i> of <i>3</i> elements--<i>a</i>, <i>b</i>, and
<div class="code"> <i>c</i>. </div>
(<i>a</i>, <i>b</i>, <i>c</i>) <div> <i>Tuples</i> are fast and easy to use.&nbsp; With variadic macro
</div> support it is not necessary to know the size of a <i>tuple; </i>without
<div> variadic macro support&nbsp;all access to <i>tuples</i> requires
...is a <i>tuple</i> of <i>3</i> elements--<i>a</i>, <i>b</i>, and <i>c</i>. knowledge of its size. Use a <i>tuple </i>instead of an <i>array</i> if
</div> your compiler supports variadic macros, since a <i>tuple </i>has all of
<div> the functionality as an <i>array </i>and is easier syntactically to use.</div>
<i>Tuples</i> are fast and easy to use.&nbsp; <div> Elements of a <i>tuple</i> can be extracted with <b>BOOST_PP_TUPLE_ELEM</b>.
However, all access to <i>tuples</i> requires knowledge of its size.
</div>
<div>
Elements of a <i>tuple</i> can be extracted with
<b>BOOST_PP_TUPLE_ELEM</b>.
</div> </div>
<h4>Primitives</h4> <h4>Primitives</h4>
<ul> <ul>
<li><a href="../ref/tuple_elem.html">BOOST_PP_TUPLE_ELEM</a></li> <li><a href="../ref/tuple_elem.html">BOOST_PP_TUPLE_ELEM</a></li>
</ul> </ul>
<hr size="1"> <hr size="1">
<div style="margin-left: 0px;"> <div style="margin-left: 0px;"> <i><EFBFBD> Copyright <a href="http://www.housemarque.com"
<i><EFBFBD> Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i> target="_top">Housemarque Oy</a> 2002</i> <br>
</br><i><EFBFBD> Copyright Paul Mensonides 2002</i> <i><EFBFBD> Copyright Paul Mensonides 2002</i> </div>
</div>
<div style="margin-left: 0px;"> <div style="margin-left: 0px;">
<p><small>Distributed under the Boost Software License, Version 1.0. (See <p><small>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
copy at <a href= or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
"http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
</div> </div>
</body> </body>
</html> </html>

View File

@ -7,235 +7,250 @@
</style> </style>
</head> </head>
<body> <body>
<h4>Variadic Macros</h4> <h4>Variadic Macros</h4>
<div> Variadic macros are supported by a number of compilers. <div> Variadic macros are supported by a number of compilers.
They are They are
macros of the form: macros of the form:
</div> </div>
<div class="code"> <div class="code">
<pre>#define SOME_MACRO(ZeroOrMoreParameters,...) macro expansion possible specifying __VA_ARGS__<br></pre> <pre>#define SOME_MACRO(ZeroOrMoreParameters,...) macro expansion possible specifying __VA_ARGS__</pre>
</div> </div>
<div> The '...' in the parameter list represents the variadic <div> The '...' in the parameter list represents the variadic
data when the macro is invoked and the __VA_ARGS__ in the expansion data when the macro is invoked and the __VA_ARGS__ in the expansion
represents the variadic data in the expansion of the macro. Variadic represents the variadic data in the expansion of the macro. Variadic
data is of the form of 1 or more preprocessor tokens separated by data is of the form of 1 or more preprocessor tokens separated by
commas.<br> commas.<br>
<br> <br>
The '...' must be the last parameter in the macro definition and there The '...' must be the last parameter in the macro definition and there
may be 0 or more non-variadic parameters preceding it.<br> may be 0 or more non-variadic parameters preceding it.<br>
<br> <br>
In the expansion of the macro __VA_ARGS__ may be specified 0 or more In the expansion of the macro __VA_ARGS__ may be specified 0 or more
times to represent the variadic data. The variadic data in the times to represent the variadic data. The variadic data in the
expansion is a comma separated list of preprocessor tokens representing expansion is a comma separated list of preprocessor tokens representing
the variadic data which the invoker of the macro enters as the last the variadic data which the invoker of the macro enters as the last
arguments to the macro.<br> arguments to the macro.<br>
</div> </div>
<h4>Example<u> - Creating and invoking a variadic macro.</u></h4> <h4>Example<u> - Creating and invoking a variadic macro.</u></h4>
<div class="code"> <div class="code">
<pre>#define INITIALIZE_INT_ARRAY(array_name,...) \ <br> static int array_name[] = { __VA_ARGS__ }; \ <br> /**/<br><br> INITIALIZE_INT_ARRAY(myname,45,789,33510,9346,2)<br></pre> <pre>#define INITIALIZE_INT_ARRAY(array_name,...) \ <br> static int array_name[] = { __VA_ARGS__ }; \ <br> /**/<br><br> INITIALIZE_INT_ARRAY(myname,45,789,33510,9346,2)</pre>
</div> </div>
<u> <span style="font-weight: bold;">Preprocessor <u> <span style="font-weight: bold;">Preprocessor
Library Support<br> Library Support<br>
</span></u> </span></u>
<div>The library offers support for variadic macros for those <div>The library offers support for variadic macros for those
compilers compilers
which support the feature. The library can automatically detect whether which support the feature. The library can automatically detect whether
a compiler supports variadic macros and sets the macro a compiler supports variadic macros and sets the macro
BOOST_PP_VARIADICS accordingly to 1 if the compiler supports variadic BOOST_PP_VARIADICS accordingly to 1 if the compiler supports variadic
macros or 0 if the compiler does not support variadic macros.<br> macros or 0 if the compiler does not support variadic macros.<br>
<br> <br>
The end-user can #define BOOST_PP_VARIADICS to 1 or 0 himself in a The end-user can #define BOOST_PP_VARIADICS to 1 or 0 himself in a
translation unit, before including any preprocessor header files, to translation unit, before including any preprocessor header files, to
prevent the library from attempting to detect whether the compiler prevent the library from attempting to detect whether the compiler
supports variadic macros. This has the effect of manually turning on or supports variadic macros. This has the effect of manually turning on or
off variadic macro support in the library. Of course if one manually off variadic macro support in the library. Of course if one manually
turns on variadic macro support in the library, and one's compiler does turns on variadic macro support in the library, and one's compiler does
not support variadic macros, functionality in the library which uses not support variadic macros, functionality in the library which uses
variadic macros will fail with error messages from the compiler.<br> variadic macros will fail with error messages from the compiler.<br>
<br> <br>
When BOOST_PP_VARIADICS is 1, the library offers some extended When BOOST_PP_VARIADICS is 1, the library offers some extended
functionality functionality
by using variadic macros, and also offers extended support for working by using variadic macros, and also offers extended support for working
with variadic data.<br> with variadic data.<br>
<br> <br>
Support for working with variadic Support for working with variadic
data is largely centered on being able to convert variadic data to data is largely centered on being able to convert variadic data to
other library data types, since the other library data types, since the
functionality for working with those Boost preprocessor library data functionality for working with those Boost preprocessor library data
types is much greater than that for working with variadic data directly.<br> types is much greater than that for working with variadic data directly.<br>
</div> </div>
<a name="VNotation"></a> <a name="VNotation"></a>
<h4>Notation For Variadic Macros<br> <h4>Notation For Variadic Macros<br>
</h4> </h4>
<div>In the documentation, headers which have variadic macros, <div>In the documentation, headers which have variadic macros,
and and
variadic macros themselves, have a notation of '(v)' appended to them. variadic macros themselves, have a notation of '(v)' appended to them.
For the variadic macros themselves this signifies that For the variadic macros themselves this signifies that
BOOST_PP_VARIADICS must be 1 for those variadic macros to be usable. BOOST_PP_VARIADICS must be 1 for those variadic macros to be usable.
For variadic macros which have a non-variadic equivalent, the For variadic macros which have a non-variadic equivalent, the
non-variadic equivalent will be used if BOOST_PP_VARIADICS is set to 0. non-variadic equivalent will be used if BOOST_PP_VARIADICS is set to 0.
</div> </div>
<h4>Extended Functionality Using Variadic Macros<br> <h4>Extended Functionality Using Variadic Macros<br>
</h4> </h4>
<div>Some macros in the library offer extended <div>Some macros in the library offer extended
functionality through the use of variadic macros.<br> functionality through the use of variadic macros.<br>
<br> <br>
The variadic macro version offers the same functionality The variadic macro version offers the same functionality
as the non-variadic version, but because of the ability of the variadic as the non-variadic version, but because of the ability of the variadic
parameters to encompass a variable number of arguments, it also offers parameters to encompass a variable number of arguments, it also offers
an enhanced syntax using the same macro name.<br> an enhanced syntax using the same macro name.<br>
<br> <br>
The macros in the library which offer this enhanced functionality are The macros in the library which offer this enhanced functionality are
all all
centered on <i>tuple</i> manipulation. With variadic centered on <i>tuple</i> manipulation. With variadic
macros it is macros it is
possible to possible to
manipulate tuples without having to know the size of the tuple. So manipulate tuples without having to know the size of the tuple. So
while the invoker can still specify the size when using tuple macro while the invoker can still specify the size when using tuple macro
functionality, there are variadic versions of each of the tuple macros, functionality, there are variadic versions of each of the tuple macros,
with the exact same name as the non-variadic macro, where the size need with the exact same name as the non-variadic macro, where the size need
not be specified.<br> not be specified.<br>
</div> </div>
<h4>Extended Support For Variadic Data</h4> <h4>Extended Support For Variadic Data</h4>
<div>The library offers extended support for working with <div>The library offers extended support for working with
variadic data variadic data
which goes beyond the functionality offered by the C++ specification which goes beyond the functionality offered by the C++ specification
for variadic macros. It does this through preprocessor programming and for variadic macros. It does this through preprocessor programming and
by using some of the other functionality in the library itself. Header by using some of the other functionality in the library itself. Header
and macro names and macro names
in the library which offer extended support for working with variadic in the library which offer extended support for working with variadic
data, and need the compiler to support variadic macros, are marked with data, and need the compiler to support variadic macros, are marked with
a (v)<sup> </sup>to indicate a variadic macro.<br> a (v)<sup> </sup>to indicate a variadic macro.<br>
<br> <br>
The form of the functionality which the library offers is centered on The form of the functionality which the library offers is centered on
two macros which work with variadic data itself, and a set of macros two macros which work with variadic data itself, and a set of macros
which convert between variadic data and other library data which convert between variadic data and other library data
types.<br> types.<br>
<br> <br>
The two macros are BOOST_PP_VARIADIC_ELEM and BOOST_PP_VARIADIC_SIZE, The two macros are BOOST_PP_VARIADIC_ELEM and BOOST_PP_VARIADIC_SIZE,
which respectively return a particular token of variadic data and the which respectively return a particular token of variadic data and the
number of tokens of variadic data.<br> number of tokens of variadic data.<br>
<br> <br>
The macros for converting variadic data to the library's data types are The macros for converting variadic data to the library's data types are
BOOST_PP_VARIADIC_TO_ARRAY, BOOST_PP_VARIADIC_TO_LIST, BOOST_PP_VARIADIC_TO_ARRAY, BOOST_PP_VARIADIC_TO_LIST,
BOOST_PP_VARIADIC_TO_SEQ, and BOOST_PP_VARIADIC_TO_TUPLE.<br> BOOST_PP_VARIADIC_TO_SEQ, and BOOST_PP_VARIADIC_TO_TUPLE.<br>
<br> <br>
All of these macros need compiler support for variadic data and only All of these macros need compiler support for variadic data and only
exist if BOOST_PP_VARIADICS is 1. <br> exist if BOOST_PP_VARIADICS is 1. <br>
<br> <br>
The remaining four macros, which convert from a library data type The remaining four macros, which convert from a library data type
to comma-separated preprocessor tokens, which is the form of to comma-separated preprocessor tokens, which is the form of
variadic data, do not need compiler support for variadic variadic data, do not need compiler support for variadic
macros. These functions are BOOST_PP_ARRAY_ENUM, BOOST_PP_LIST_ENUM, 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 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 use this variadic data reliably as arguments to other macros, one needs
variadic macro support.<br> variadic macro support.<br>
</div> </div>
<u style="font-weight: bold;"> Using Variadic Data</u> <u style="font-weight: bold;"> Using a Tuple Instead of an Array<br>
<div>Variadic data exists in the </u>
form of comma-separated preprocessor tokens. This is the case whether <div>An array as a preprocessor data type is a two-element tuple where the
the variadic data comes from the __VA_ARGS__ of a variadic macro, from first element is the array size and the second element is a tuple which
the conversion of a library's data type to variadic data, or the constitutes the array data. Because a tuple knows its own size when the
manual construction of comma-separated preprocessing tokens by the compiler supports variadic macros, there is no reason to use the array preprocessor
programmer writing a macro.<br> data type as opposed to the tuple preprocessor data type; the tuple data
<br> type now has all of the functionality which the array data type has and is
The easiest way to work with syntactically easier to use. With variadic macro support, which is now
variadic data internally is to convert it to a library data type. officially part of the latest C++ standard, the preprocessor array data
Library data types, whether an <i>array</i>, <i>list</i>, type is essentially obsolete for conforming C++ compilers. Only if your
<i>sequence</i>, compiler does not support variadic macros is the preprocessor array data
or <i>tuple</i>, have a rich set of functionality for type still useful.</div>
manipulating <u style="font-weight: bold;">Using Variadic Data</u>
data whereas <div>Variadic data exists in the
variadic data functionality in the library only allows one to access form of comma-separated preprocessor tokens. This is the case whether
the variadic data as a whole or to access a single token of the the variadic data comes from the __VA_ARGS__ of a variadic macro, from
variadic data at a time.<br> the conversion of a library's data type to variadic data, or the
<br> manual construction of comma-separated preprocessing tokens by the
The user of the library still may programmer writing a macro.<br>
choose to pass variadic data back into internal macros rather than <br>
convert it to other library data types. There is no problem passing The easiest way to work with
variadic data as a whole to variadic macros as the last parameter of variadic data internally is to convert it to a library data type.
the macro. However: <br> Library data types, whether an <i>array</i>, <i>list</i>,
<br> <i>sequence</i>,
<span style="font-weight: bold;">Attempting to pass or <i>tuple</i>, have a rich set of functionality for
variadic data as a manipulating
whole directly into a non-variadic macro is not guaranteed to work and data whereas
may fail.<br> variadic data functionality in the library only allows one to access
</span><br> the variadic data as a whole or to access a single token of the
This occurs because of a preprocessor weakness in a number variadic data at a time.<br>
of compilers, currently most notably Visual C++. Even passing variadic <br>
data as arguments to a non-variadic macro, when it is not represented The user of the library still may
in choose to pass variadic data back into internal macros rather than
the form of&nbsp; __VA_ARGS__, may fail with certain compilers.<br> convert it to other library data types. There is no problem passing
<br> variadic data as a whole to variadic macros as the last parameter of
What follows are very simple examples, showing how variadic data can be the macro. However: <br>
passed to a non-variadic macro.<br> <br>
<br> <span style="font-weight: bold;">Attempting to pass
First an example of what NOT to do.<br> variadic data as a
</div> whole directly into a non-variadic macro is not guaranteed to work and
<h4>Example<u> - Passing variadic data as a whole to a may fail.<br>
non-variadic </span><br>
macro. DO NOT DO.</u></h4> This occurs because of a preprocessor weakness in a number
<div class="code"> of compilers, currently most notably Visual C++. Even passing variadic
<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><span style="font-weight: bold;"><span style="font-family: monospace;"></span></span>int xx = MACRO_ARG_2(VAR_MACRO(2,3));<br></pre> data as arguments to a non-variadic macro, when it is not represented
</div> in
<div> There are two ways to pass variadic data to a non-variadic the form of&nbsp; __VA_ARGS__, may fail with certain compilers.<br>
macro. <br>
The What follows are very simple examples, showing how variadic data can be
first of these is to pass the individual tokens of the variadic data passed to a non-variadic macro.<br>
separately to the non-variadic macro using the BOOST_PP_VARIADIC_ELEM <br>
macro in the library.<br> First an example of what NOT to do.<br>
</div> </div>
<h4>Example<u> - Passing individual variadic data tokens to <h4>Example<u> - Passing variadic data as a whole to a
a non-variadic
non-variadic macro.<br> macro. DO NOT DO.</u></h4>
</u></h4> <div class="code">
<div class="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><span
<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> style="font-weight: bold;"><span style="font-family: monospace;"></span></span>int xx = MACRO_ARG_2(VAR_MACRO(2,3));</pre>
</div> </div>
<div>The second way is to use a macro in the library called <div> There are two ways to pass variadic data to a non-variadic
BOOST_PP_OVERLOAD. macro.
This macro allows one to "overload" a variadic macro to non-variadic The
macros of different numbers of parameters, using a common prefix. first of these is to pass the individual tokens of the variadic data
</div> separately to the non-variadic macro using the BOOST_PP_VARIADIC_ELEM
<h4>Example<u> - Passing variadic data as a whole to macro in the library.<br>
BOOST_PP_OVERLOAD </div>
and on to a non-variadic macro.<br> <h4>Example<u> - Passing individual variadic data tokens to
</u></h4> a
<div class="code"> non-variadic macro.<br>
<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> </u></h4>
</div><br> <div class="code">
<div>Although these techniques will work when passing variadic <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>
data to </div>
non-variadic macros, it is much better and less problematical to <div>The second way is to use a macro in the library called
work internally with the existing library data types and to only use BOOST_PP_OVERLOAD.
variadic This macro allows one to "overload" a variadic macro to non-variadic
macros as an interface for end-users when there is a need to have a macros of different numbers of parameters, using a common prefix.
macro which takes a </div>
variable number of parameters.<br> <h4>Example<u> - Passing variadic data as a whole to
</div> BOOST_PP_OVERLOAD
<b>See</b> <b>Also</b><br> and on to a non-variadic macro.<br>
<ul> </u></h4>
<li><a href="../ref/variadics.html">BOOST_PP_VARIADICS</a></li> <div class="code">
<li><a href="../headers/tuple.html">Tuple Macros</a><br> <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>
</li> </div>
<li><a href="../headers/variadic.html">Variadic <br>
Macros<br> <div>Although these techniques will work when passing variadic
</a></li> data to
<li><a href="../ref/array_enum.html">BOOST_PP_ARRAY_ENUM</a></li> non-variadic macros, it is much better and less problematical to
<li><a href="../ref/list_enum_r.html">BOOST_PP_LIST_ENUM</a></li> work internally with the existing library data types and to only use
<li><a href="../ref/seq_enum.html">BOOST_PP_SEQ_ENUM</a></li> variadic
<li><a href="../ref/tuple_enum.html">BOOST_PP_TUPLE_ENUM</a></li> macros as an interface for end-users when there is a need to have a
<li><a href="../ref/overload.html">BOOST_PP_OVERLOAD</a></li> macro which takes a
</ul> variable number of parameters.<br>
<hr size="1"> </div>
<div style="margin-left: 0px;"> <i><EFBFBD> Copyright <b>See</b> <b>Also</b><br>
Edward Diener <ul>
2011,2013</i> </div> <li><a href="../ref/variadics.html">BOOST_PP_VARIADICS</a></li>
<div style="margin-left: 0px;"> <li><a href="../headers/tuple.html">Tuple Macros</a><br>
<p><small>Distributed under the Boost Software License, </li>
Version 1.0. <li><a href="../headers/variadic.html">Variadic
(See accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> Macros<br>
or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p> </a></li>
</div> <li><a href="../ref/array_enum.html">BOOST_PP_ARRAY_ENUM</a></li>
<li><a href="../ref/list_enum_r.html">BOOST_PP_LIST_ENUM</a></li>
<li><a href="../ref/seq_enum.html">BOOST_PP_SEQ_ENUM</a></li>
<li><a href="../ref/tuple_enum.html">BOOST_PP_TUPLE_ENUM</a></li>
<li><a href="../ref/overload.html">BOOST_PP_OVERLOAD</a></li>
</ul>
<hr size="1">
<div style="margin-left: 0px;"> <i><EFBFBD> Copyright
Edward Diener
2011,2013</i> </div>
<div style="margin-left: 0px;">
<p><small>Distributed under the Boost Software License,
Version 1.0.
(See accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
</div>
</body> </body>
</html> </html>