overload.html 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <html>
  2. <head>
  3. <meta content="text/html; charset=windows-1252" http-equiv="content-type">
  4. <title>BOOST_PP_OVERLOAD</title>
  5. <link rel="stylesheet" type="text/css" href="../styles.css">
  6. </head>
  7. <body>
  8. <div style="margin-left: 0px;"> The <b>BOOST_PP_OVERLOAD</b> variadic
  9. macro expands to the name of a non-variadic macro having a given number of
  10. parameters.<br>
  11. </div>
  12. <h4>Usage</h4>
  13. <div class="code"> <b>BOOST_PP_OVERLOAD</b>(<i>prefix</i>,...) <a href="../topics/variadic_macros.html#VNotation"
  14. target="_self"><sup>(v)</sup></a><br>
  15. </div>
  16. <h4>Arguments</h4>
  17. <dl>
  18. <dt>prefix<br>
  19. </dt>
  20. <dd> The prefix of the non-variadic macro name. </dd>
  21. <dt>...<br>
  22. </dt>
  23. <dd><i> Variadic data</i>. The number of variadic data
  24. elements, as determined by BOOST_PP_VARIADIC_SIZE, is appended to the
  25. prefix to form the output non-variadic macro name.<br>
  26. </dd>
  27. </dl>
  28. <h4>Remarks</h4>
  29. <div> This macro creates a macro name which depends on the number of
  30. elements of variadic data. It should be used in the form of <br>
  31. BOOST_PP_OVERLOAD(MACRO_NAME_,__VA_ARGS__)(__VA_ARGS__) in order to
  32. call a non-variadic macro taking a given number of variadic data
  33. elements as non-variadic arguments. In this way one can invoke a
  34. variadic macro with a variable number of parameters which calls one of
  35. a series of non-variadic macros doing very similar things.
  36. </div>
  37. <b>Requirements</b>
  38. <div> <b>Header:</b> &nbsp;<a href="../headers/facilities/overload.html">&lt;boost/preprocessor/facilities/overload.hpp&gt;</a>
  39. </div>
  40. <h4>Sample Code</h4>
  41. <div>
  42. <pre>#include &lt;<a href="../headers/facilities/overload.html">boost/preprocessor/facilities/overload.hpp</a>&gt;<br>#include <<a
  43. 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
  44. 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
  45. href="add.html">BOOST_PP_ADD</a>(number1,number2)<br><br>#if !BOOST_PP_VARIADICS_MSVC<br><br>#define MACRO_ADD_NUMBERS(...) <a
  46. 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
  47. href="cat.html">BOOST_PP_CAT</a>(<a href="overload.html">BOOST_PP_OVERLOAD</a>(MACRO_,__VA_ARGS__)(__VA_ARGS__),<a
  48. 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>
  49. </div>
  50. <hr size="1">
  51. <div style="margin-left: 0px;"> <i></i><i>© Copyright Edward Diener 2011,2013,2016</i> </div>
  52. <div style="margin-left: 0px;">
  53. <p><small>Distributed under the Boost Software License, Version 1.0.
  54. (See accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
  55. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  56. </div>
  57. </body></html>