1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="content-type" content="text/html;
6 <title>BOOST_PP_VA_OPT</title>
7 <link rel="stylesheet" type="text/css" href="../styles.css">
10 <div style="margin-left: 0px;"> The <b>BOOST_PP_VA_OPT</b> variadic
11 macro is a more flexible alternative to the C++20 __VA_OPT__
12 construct. It expands to either one of two inputs depending on
13 whether the variadic data is empty or not, whereas the C++20
14 __VA_OPT__ constructs expands to either its input or nothing
15 depending on whether the variadic data is empty or not. This macro
16 only exists when the compilation is at the C++20 level and the
17 __VA_OPT__ construct is supported.</div>
19 <div class="code"> <b>BOOST_PP_VA_OPT</b>(x,y,<i>...</i>) <a
20 href="../topics/variadic_macros.html#VNotation" target="_self"><sup>(v)</sup></a><br>
23 <p> x<br>
24 A tuple
25 whose data is the macro expansion if the <i>variadic data</i> is
27 y<br>
28 A tuple
29 whose data is the macro expansion if the <i>variadic data</i> is
31 ,,,<br>
32 The <i>variadic
33 data</i> to be checked for emptiness<br>
38 <div> When the macro invocation BOOST_PP_VARIADIC_HAS_OPT() expands
39 to 1, then this macro exists and can be invoked, otherwise this
40 macro does not exist and attempting to invoke it will lead to a
41 preprocessor error that the macro can not be found. Because of
42 this condition the header file for including this macro includes
43 the header file for the BOOST_PP_VARIADIC_HAS_OPT macro.<br>
45 The difference between this macro and the __VA_OPT__ construct
46 illustrates a limitation of the latter construct with a trade off
47 of simpler syntax. The differences between the __VA_OPT__
48 construct and this macro are:<br>
50 <li>The __VA_OPT__ construct offers a choice as its expansion
51 only between its input preprocessing tokens or nothing (
52 called a "single placemarker token" ) depending on whether the
53 implicit variadic data is empty or not. There is no way using
54 the __VA_OPT__ construct to specify any alternative but the
55 "single placemarker token" when the variadic data is empty
56 whereas any preprocessing tokens can be specified when the
57 variadic data is not empty. With the BOOST_PP_VA_OPT macro the
58 user can specify as its expansion preprocessing tokens both
59 when the variadic data is empty and when the variadic data is
61 <li>The __VA_OPT__ construct offers a simple syntax whereas this
62 macro is more verbose. The BOOST_PP_VA_OPT macro's first and
63 second parameters must be Boost PP tuples of data, in order to
64 expand to normal or variadic data, and the third parameter
65 must be the variadic data to check for emptiness, whereas the
66 __VA_OPT__ construct has an implied variadic data as
67 __VA_ARGS__ to check for emptiness and can specify its
68 expansion directly in terms of its input.</li>
69 <li>The __VA_OPT__ construct can only be specified in the
70 replacement list of some macro, whereas the BOOST_PP_VA_OPT
71 macro can be used both as an alternative to the __VA_OPT__
72 construct in the replacement list of some macro and anywhere
73 else a macro can be used.</li>
74 <li>It is impossible to have a left parenthesis '(' or a right
75 parenthesis ')' as preprocessing token data within the
76 __VA_OPT__ construct whereas both are possible as part of the
77 expanded data for the BOOST_PP_VA_OPT macro.<br>
81 The exact BOOST_PP_VA_OPT equivalent to the construct of
82 '__VA_OPT__ ( pp-tokens )' in the replacement list of a macro is
83 'BOOST_PP_VA_OPT (( pp-tokens ),(),__VA_ARGS__)'.</div>
86 <li><a href="variadic_has_opt.html">BOOST_PP_VARIADIC_HAS_OPT</a></li>
89 <div> <b>Header:</b> <a
90 href="../headers/facilities/va_opt.html"><boost/preprocessor/facilities/va_opt.hpp></a>
94 <pre>#include <<a href="../headers/facilities/va_opt.html">boost/preprocessor/facilities/va_opt.hpp</a>>
96 # if <a href="variadic_has_opt.html">BOOST_PP_VARIADIC_HAS_OPT</a>()
99 #define OBJECT OBJECT2
101 #define FUNC(x) FUNC2(x)
103 #define FUNC_GEN(x,y) (1,2,3)
105 <a href="va_opt.html">BOOST_PP_VA_OPT</a>((1),(2),DATA) // expands to 2
106 <a href="va_opt.html">BOOST_PP_VA_OPT</a>((3),(4),OBJECT) // expands to 4
107 <a href="va_opt.html">BOOST_PP_VA_OPT</a>((5),(6),FUNC(1)) // expands to 6
108 <a href="va_opt.html">BOOST_PP_VA_OPT</a>((7,8),(9,10),FUNC) // expands to 7,8
109 <a href="va_opt.html">BOOST_PP_VA_OPT</a>((1,2,3,4,5),(6,7,8,9,10),FUNC_GEN) // expands to 1,2,3,4,5
115 <div style="margin-left: 0px;"> <i>© Copyright Edward Diener 2019</i>
117 <div style="margin-left: 0px;">
118 <p><small>Distributed under the Boost Software License, Version
119 1.0. (See accompanying file <a
120 href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
121 copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>