Updated doc doe BOOST_PP_OVERLOAD.

This commit is contained in:
Edward Diener
2020-07-03 14:18:44 -04:00
parent e231fe7ad9
commit 5c7ae49828
2 changed files with 56 additions and 48 deletions

View File

@ -1,17 +1,19 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252" http-equiv="content-type">
<meta content="text/html; charset=windows-1252"
http-equiv="content-type">
<title>BOOST_PP_OVERLOAD</title>
<link rel="stylesheet" type="text/css" href="../styles.css">
</head>
<body>
<div style="margin-left: 0px;"> The <b>BOOST_PP_OVERLOAD</b> variadic
macro expands to the name of a non-variadic macro having a given number of
parameters.<br>
<div style="margin-left: 0px;"> The <b>BOOST_PP_OVERLOAD</b>
variadic macro expands to the name of a non-variadic macro having
a given number of parameters.<br>
</div>
<h4>Usage</h4>
<div class="code"> <b>BOOST_PP_OVERLOAD</b>(<i>prefix</i>,...) <a href="../topics/variadic_macros.html#VNotation"
target="_self"><sup>(v)</sup></a><br>
<div class="code"> <b>BOOST_PP_OVERLOAD</b>(<i>prefix</i>,...) <a
href="../topics/variadic_macros.html#VNotation" target="_self"><sup>(v)</sup></a><br>
</div>
<h4>Arguments</h4>
<dl>
@ -20,39 +22,43 @@
<dd> The prefix of the non-variadic macro name. </dd>
<dt>...<br>
</dt>
<dd><i> Variadic data</i>. The number of variadic data
elements, as determined by BOOST_PP_VARIADIC_SIZE, is appended to the
<dd><i> Variadic data</i>. The number of variadic data elements,
as determined by BOOST_PP_VARIADIC_SIZE, is appended to the
prefix to form the output non-variadic macro name.<br>
</dd>
</dl>
<h4>Remarks</h4>
<div> This macro creates a macro name which depends on the number of
elements of variadic data. It should be used in the form of <br>
BOOST_PP_OVERLOAD(MACRO_NAME_,__VA_ARGS__)(__VA_ARGS__) in order to
call a non-variadic macro taking a given number of variadic data
elements as non-variadic arguments. In this way one can invoke a
variadic macro with a variable number of parameters which calls one of
a series of non-variadic macros doing very similar things.
BOOST_PP_OVERLOAD(MACRO_NAME_,__VA_ARGS__)(__VA_ARGS__) in order
to call a non-variadic macro taking a given number of variadic
data elements as non-variadic arguments. In this way one can
invoke a variadic macro with a variable number of parameters which
calls one of a series of non-variadic macros doing very similar
things.<br>
<br>
In <a
href="file:///E:/Programming/VersionControl/modular-boost/libs/preprocessor/doc/topics/variadic_macros.html#C20_Support_For_Variadic_Macros">C++
20</a> mode the <i>variadic</i> <i>data</i> can be empty and
the given number of parameters will be 0.<br>
</div>
<b>Requirements</b>
<div> <b>Header:</b> &nbsp;<a href="../headers/facilities/overload.html">&lt;boost/preprocessor/facilities/overload.hpp&gt;</a>
<div> <b>Header:</b> &nbsp;<a
href="../headers/facilities/overload.html">&lt;boost/preprocessor/facilities/overload.hpp&gt;</a>
</div>
<h4>Sample Code</h4>
<div>
<pre>#include &lt;<a href="../headers/facilities/overload.html">boost/preprocessor/facilities/overload.hpp</a>&gt;<br>#include <<a
href="../headers/cat.html">boost/preprocessor/cat.hpp</a>><br>#include <<a href="../headers/facilities/empty.html">boost/preprocessor/facilities/empty.hpp</a>><br>#include <<a
href="../headers/arithmetic/add.html">boost/preprocessor/arithmetic/add.hpp</a>><br><br>#define MACRO_1(number) MACRO_2(number,10)<br>#define MACRO_2(number1,number2) <a
href="add.html">BOOST_PP_ADD</a>(number1,number2)<br><br>#if !BOOST_PP_VARIADICS_MSVC<br><br>#define MACRO_ADD_NUMBERS(...) <a
href="overload.html">BOOST_PP_OVERLOAD</a>(MACRO_,__VA_ARGS__)(__VA_ARGS__)<br><br>#else<br><br>// or for Visual C++<br><br>#define MACRO_ADD_NUMBERS(...) \<br> <a
href="cat.html">BOOST_PP_CAT</a>(<a href="overload.html">BOOST_PP_OVERLOAD</a>(MACRO_,__VA_ARGS__)(__VA_ARGS__),<a
href="empty.html">BOOST_PP_EMPTY</a>())<br><br>#endif<br><br>MACRO_ADD_NUMBERS(5) // output is 15<br>MACRO_ADD_NUMBERS(3,6) // output is 9</pre>
<pre>#include &lt;<a href="../headers/facilities/overload.html">boost/preprocessor/facilities/overload.hpp</a>&gt;<br>#include &lt;<a href="../headers/cat.html">boost/preprocessor/cat.hpp</a>&gt;<br>#include &lt;<a href="../headers/facilities/empty.html">boost/preprocessor/facilities/empty.hpp</a>&gt;<br>#include &lt;<a href="../headers/arithmetic/add.html">boost/preprocessor/arithmetic/add.hpp</a>&gt;<br><br>#define MACRO_1(number) MACRO_2(number,10)<br>#define MACRO_2(number1,number2) <a href="add.html">BOOST_PP_ADD</a>(number1,number2)<br><br>#if !BOOST_PP_VARIADICS_MSVC<br><br>#define MACRO_ADD_NUMBERS(...) <a href="overload.html">BOOST_PP_OVERLOAD</a>(MACRO_,__VA_ARGS__)(__VA_ARGS__)<br><br>#else<br><br>// or for Visual C++<br><br>#define MACRO_ADD_NUMBERS(...) \<br> <a href="cat.html">BOOST_PP_CAT</a>(<a href="overload.html">BOOST_PP_OVERLOAD</a>(MACRO_,__VA_ARGS__)(__VA_ARGS__),<a href="empty.html">BOOST_PP_EMPTY</a>())<br><br>#endif<br><br>MACRO_ADD_NUMBERS(5) // output is 15<br>MACRO_ADD_NUMBERS(3,6) // output is 9</pre>
</div>
<hr size="1">
<div style="margin-left: 0px;"> <i></i><i><EFBFBD> Copyright Edward Diener 2011,2013,2016</i> </div>
<div style="margin-left: 0px;"> <i></i><i><EFBFBD> Copyright Edward Diener
2011,2013,2016</i> </div>
<div style="margin-left: 0px;">
<p><small>Distributed under the Boost Software License, Version 1.0.
<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></html>
</body>
</html>

View File

@ -1,4 +1,4 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
@ -141,8 +141,8 @@
<div> In the C++20 specification there is a new construct which can
be used in the expansion of a variadic macro, called __VA_OPT__.
This construct when used in the expansion of a variadic macro is
followed by an opening paranthesis ('('), preprocessor data, and a
closing parenthesis ('}'). When the variadic data passed by the
followed by an opening paranthesis '(', preprocessor data, and a
closing parenthesis ')'. When the variadic data passed by the
invocation of a variadic macro is empty, this new construct
expands to nothing. When the variadic data passed by the
invocation of a variadic macro is not empty, this new construct
@ -159,18 +159,20 @@
it returns 0. <br>
<br>
When the __VA_OPT__ construct is supported in C++20 mode the
variadic data passed to the variadic macros can be empty,
otherwise when not in this mode variadic data passed to the
variadic macros should never be empty. In this C+++20 mode
invoking BOOST_PP_VARIADIC_SIZE with empty data expands to 0,
invoking BOOST_PP_VARIADIC_TO_ARRAY with empty data expands to the
empty array '(0,())', and invoking BOOST_PP_VARIADIC_TO_LIST with
empty data expands to the empty list 'BOOST_PP_NIL'. Similarly in
this C++20 mode passing an empty array '(0,())' to
BOOST_PP_ARRAY_ENUM expands to empty variadic data and passing an
empty list 'BOOST_PP_NIL' to BOOST_PP_LIST_ENUM also expands to
empty variadic data. Neither a seq or a tuple can be empty so
passing empty variadic data to either BOOST_PP_VARIADIC_TO_SEQ or
variadic data passed to the variadic macros and to
BOOST_PP_OVERLOAD can be empty, otherwise when not in this mode
variadic data passed to the variadic macros should never be empty.
In this C+++20 mode invoking BOOST_PP_VARIADIC_SIZE with empty
data expands to 0, invoking BOOST_PP_VARIADIC_TO_ARRAY with empty
data expands to the empty array '(0,())', invoking
BOOST_PP_VARIADIC_TO_LIST with empty data expands to the empty
list 'BOOST_PP_NIL', and invoking BOOST_PP_OVERLOAD with empty
data creates an overload name with 0 appended. Similarly in this
C++20 mode passing an empty array '(0,())' to BOOST_PP_ARRAY_ENUM
expands to empty variadic data and passing an empty list
'BOOST_PP_NIL' to BOOST_PP_LIST_ENUM also expands to empty
variadic data. Neither a seq or a tuple can be empty so passing
empty variadic data to either BOOST_PP_VARIADIC_TO_SEQ or
BOOST_PP_VARIADIC_TO_TUPLE is erroneous. Likewise passing empty
data to BOOST_PP_VARIADIC_ELEM is always erroneous since there are
no tokens of variadic data to access.<br>