add_d.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <html>
  2. <head>
  3. <title>BOOST_PP_ADD_D</title>
  4. <link rel="stylesheet" type="text/css" href="../styles.css">
  5. </head>
  6. <body>
  7. <div style="margin-left: 0px;">
  8. The <b>BOOST_PP_ADD_D</b> macro expands to the sum of its second and third arguments.&nbsp;
  9. It reenters <b>BOOST_PP_WHILE</b> with maximum efficiency.
  10. </div>
  11. <h4>Usage</h4>
  12. <div class="code">
  13. <b>BOOST_PP_ADD_D</b>(<i>d</i>, <i>x</i>, <i>y</i>)
  14. </div>
  15. <h4>Arguments</h4>
  16. <dl>
  17. <dt>d</dt>
  18. <dd>
  19. The next available <b>BOOST_PP_WHILE</b> iteration.&nbsp;
  20. </dd>
  21. <dt>x</dt>
  22. <dd>
  23. The first addend of the operation.&nbsp;
  24. Valid values range from <i>0</i> to <b>BOOST_PP_LIMIT_MAG</b>.
  25. </dd>
  26. <dt>y</dt>
  27. <dd>
  28. The second addend of the operation.&nbsp;
  29. Valid values range from <i>0</i> to <b>BOOST_PP_LIMIT_MAG</b>.
  30. </dd>
  31. </dl>
  32. <h4>Remarks</h4>
  33. <div>
  34. If the sum of <i>x</i> and <i>y</i> is greater than <b>BOOST_PP_LIMIT_MAG</b>, the result is saturated to <b>BOOST_PP_LIMIT_MAG</b>.
  35. </div>
  36. <div>
  37. This macro is the most efficient when <i>x</i> is greater than or equal to <i>y</i>.&nbsp;
  38. However, the efficiency gain is not worth actually comparing the two arguments prior to invocation.&nbsp;
  39. In other words, <i>x</i> should be the addend that is <i>most likely</i> to be the largest of the two operands.
  40. </div>
  41. <h4>See Also</h4>
  42. <ul>
  43. <li><a href="add.html">BOOST_PP_ADD</a></li>
  44. <li><a href="limit_mag.html">BOOST_PP_LIMIT_MAG</a></li>
  45. </ul>
  46. <h4>Requirements</h4>
  47. <div>
  48. <b>Header:</b> &nbsp;<a href="../headers/arithmetic/add.html">&lt;boost/preprocessor/arithmetic/add.hpp&gt;</a>
  49. </div>
  50. <h4>Sample Code</h4>
  51. <div><pre>
  52. #include &lt;<a href="../headers/arithmetic/add.html">boost/preprocessor/arithmetic/add.hpp</a>&gt;
  53. #include &lt;<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>&gt;
  54. #include &lt;<a href="../headers/control/while.html">boost/preprocessor/control/while.hpp</a>&gt;
  55. #include &lt;<a href="../headers/tuple/elem.html">boost/preprocessor/tuple/elem.hpp</a>&gt;
  56. #define PRED(d, data) <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 0, data)
  57. #define OP(d, data) \
  58. ( \
  59. <a href="dec.html">BOOST_PP_DEC</a>( \
  60. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 0, data) \
  61. ), \
  62. <a href="add_d.html">BOOST_PP_ADD_D</a>( \
  63. d, \
  64. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 1, data), \
  65. 2 \
  66. ) \
  67. ) \
  68. /**/
  69. // increment 'x' by 2 'n' times
  70. #define STRIDE(x, n) <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 1, <a href="while.html">BOOST_PP_WHILE</a>(PRED, OP, (n, x)))
  71. STRIDE(10, 2) // expands to 14
  72. STRIDE(51, 6) // expands to 63
  73. </pre></div>
  74. <hr size="1">
  75. <div style="margin-left: 0px;">
  76. <i>© Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i>
  77. </br><i>© Copyright Paul Mensonides 2002</i>
  78. </div>
  79. <div style="margin-left: 0px;">
  80. <p><small>Distributed under the Boost Software License, Version 1.0. (See
  81. accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  82. copy at <a href=
  83. "http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  84. </div>
  85. </body>
  86. </html>