list_for_each_product_r.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <html>
  2. <head>
  3. <title>BOOST_PP_LIST_FOR_EACH_PRODUCT_R</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_LIST_FOR_EACH_PRODUCT_R</b> macro repeats a macro for each cartesian product of several <i>lists</i>.&nbsp;
  9. It reenters <b>BOOST_PP_FOR</b> with maximum efficiency.
  10. </div>
  11. <h4>Usage</h4>
  12. <div class="code">
  13. <b>BOOST_PP_LIST_FOR_EACH_PRODUCT_R</b>(<i>r</i>, <i>macro</i>, <i>size</i>, <i>tuple</i>)
  14. </div>
  15. <h4>Arguments</h4>
  16. <dl>
  17. <dt>r</dt>
  18. <dd>
  19. The next available <b>BOOST_PP_FOR</b> repetition.
  20. </dd>
  21. <dt>macro</dt>
  22. <dd>
  23. The binary macro of the form <i>macro</i>(<i>r</i>, <i>product</i>).&nbsp;
  24. This macro is expanded by <b>BOOST_PP_FOR_EACH_PRODUCT</b> with each cartesian product in <i>tuple</i>.&nbsp;
  25. It is expanded with the next available <b>BOOST_PP_FOR</b> repetition and a <i>tuple</i> containing a cartesian product.&nbsp;
  26. This <i>tuple</i> will have <i>size</i> elements.
  27. </dd>
  28. <dt>size</dt>
  29. <dd>
  30. The size of <i>tuple</i>.
  31. </dd>
  32. <dt>tuple</dt>
  33. <dd>
  34. A <i>tuple</i> of <i>lists</i> from which cartesian products are obtained.
  35. </dd>
  36. </dl>
  37. <h4>Remarks</h4>
  38. <div>
  39. This macro is a repetition construct.&nbsp;
  40. If two <i>lists</i> are (<i>a</i>, (<i>b</i>, (<i>c</i>, <b>BOOST_PP_NIL</b>))) and (<i>x</i>, (<i>y</i>, (<i>z</i>, <b>BOOST_PP_NIL</b>))),
  41. this macro will produce the following sequence:
  42. <div>
  43. <i>macro</i>(<i>r</i>, (<i>a</i>, <i>x</i>))
  44. <i>macro</i>(<i>r</i>, (<i>a</i>, <i>y</i>))
  45. <i>macro</i>(<i>r</i>, (<i>a</i>, <i>z</i>))<br>
  46. <i>macro</i>(<i>r</i>, (<i>b</i>, <i>x</i>))
  47. <i>macro</i>(<i>r</i>, (<i>b</i>, <i>y</i>))
  48. <i>macro</i>(<i>r</i>, (<i>b</i>, <i>z</i>))<br>
  49. <i>macro</i>(<i>r</i>, (<i>c</i>, <i>x</i>))
  50. <i>macro</i>(<i>r</i>, (<i>c</i>, <i>y</i>))
  51. <i>macro</i>(<i>r</i>, (<i>c</i>, <i>z</i>))
  52. </div>
  53. </div>
  54. <h4>See Also</h4>
  55. <ul>
  56. <li><a href="list_for_each_product.html">BOOST_PP_LIST_FOR_EACH_PRODUCT</a></li>
  57. </ul>
  58. <h4>Requirements</h4>
  59. <div>
  60. <b>Header:</b> &nbsp;<a href="../headers/list/for_each_product.html">&lt;boost/preprocessor/list/for_each_product.hpp&gt;</a>
  61. </div>
  62. <h4>Sample Code</h4>
  63. <div><pre>
  64. #include &lt;<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>&gt;
  65. #include &lt;<a href="../headers/list/for_each_product.html">boost/preprocessor/list/for_each_product.hpp</a>&gt;
  66. #include &lt;<a href="../headers/repetition/for.html">boost/preprocessor/repetition/for.hpp</a>&gt;
  67. #include &lt;<a href="../headers/tuple/elem.html">boost/preprocessor/tuple/elem.hpp</a>&gt;
  68. #define L1 (a, (b, <a href="nil.html">BOOST_PP_NIL</a>))
  69. #define L2 (x, (y, <a href="nil.html">BOOST_PP_NIL</a>))
  70. #define PRED(r, state) <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 0, state)
  71. #define OP(r, state) \
  72. ( \
  73. <a href="dec.html">BOOST_PP_DEC</a>( \
  74. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 0, state) \
  75. ), \
  76. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 1, state) \
  77. ) \
  78. /**/
  79. #define MACRO(r, state) \
  80. MACRO_I( \
  81. r, \
  82. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 0, state), \
  83. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, 1, state) \
  84. ) \
  85. /**/
  86. #define MACRO_I(r, c, t) \
  87. <a href="list_for_each_product_r.html">BOOST_PP_LIST_FOR_EACH_PRODUCT_R</a>( \
  88. r, MACRO_P, 2, \
  89. ( \
  90. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, <a href="dec.html">BOOST_PP_DEC</a>(c), t), \
  91. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(2, <a href="dec.html">BOOST_PP_DEC</a>(c), t) \
  92. ) \
  93. ) \
  94. /**/
  95. #define MACRO_P(r, product) product
  96. <a href="for.html">BOOST_PP_FOR</a>((2, (L1, L2)), PRED, OP, MACRO)
  97. // expands to (x, x) (x, y) (y, x) (y, y) (a, a) (a, b) (b, a) (b, b)
  98. </pre></div>
  99. <hr size="1">
  100. <div style="margin-left: 0px;">
  101. <i>© Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i>
  102. </br><i>© Copyright Paul Mensonides 2002</i>
  103. </div>
  104. <div style="margin-left: 0px;">
  105. <p><small>Distributed under the Boost Software License, Version 1.0. (See
  106. accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  107. copy at <a href=
  108. "http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  109. </div>
  110. </body>
  111. </html>