list_filter.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <html>
  2. <head>
  3. <title>BOOST_PP_LIST_FILTER</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_FILTER</b> macro filters a <i>list</i> according to a supplied criterion.
  9. </div>
  10. <h4>Usage</h4>
  11. <div class="code">
  12. <b>BOOST_PP_LIST_FILTER</b>(<i>pred</i>, <i>data</i>, <i>list</i>)
  13. </div>
  14. <h4>Arguments</h4>
  15. <dl>
  16. <dt>pred</dt>
  17. <dd>
  18. A ternary predicate of the form <i>pred</i>(<i>d</i>, <i>data</i>, <i>elem</i>).&nbsp;
  19. This predicate is expanded by <b>BOOST_PP_LIST_FILTER</b> for each element in <i>list</i> with the next available <b>BOOST_PP_WHILE</b> iteration,
  20. the auxiliary <i>data</i>, and the current element in <i>list</i>.&nbsp;
  21. This macro must return a integral value in the range of <i>0</i> to <b>BOOST_PP_LIMIT_MAG</b>.&nbsp;
  22. If this predicate expands to non-zero for a certain element, that element is included in the resulting <i>list</i>.
  23. </dd>
  24. <dt>data</dt>
  25. <dd>
  26. Auxiliary data passed to <i>pred</i>.
  27. </dd>
  28. <dt>list</dt>
  29. <dd>
  30. The <i>list</i> to be filtered.
  31. </dd>
  32. </dl>
  33. <h4>Remarks</h4>
  34. <div>
  35. This macro expands <i>pred</i> for each element in <i>list</i>.&nbsp;
  36. It builds a new <i>list</i> out of each element for which <i>pred</i> returns non-zero.
  37. </div>
  38. <div>
  39. Previously, this macro could not be used inside <b>BOOST_PP_WHILE</b>.&nbsp;
  40. There is no longer any such restriction.&nbsp;
  41. It is more efficient, however, to use <b>BOOST_PP_LIST_FILTER_D</b> in such a situation.
  42. </div>
  43. <h4>See Also</h4>
  44. <ul>
  45. <li><a href="limit_mag.html">BOOST_PP_LIMIT_MAG</a></li>
  46. <li><a href="list_filter_d.html">BOOST_PP_LIST_FILTER_D</a></li>
  47. </ul>
  48. <h4>Requirements</h4>
  49. <div>
  50. <b>Header:</b> &nbsp;<a href="../headers/list/filter.html">&lt;boost/preprocessor/list/filter.hpp&gt;</a>
  51. </div>
  52. <h4>Sample Code</h4>
  53. <div><pre>
  54. #include &lt;<a href="../headers/comparison/less_equal.html">boost/preprocessor/comparison/less_equal.hpp</a>&gt;
  55. #include &lt;<a href="../headers/list/filter.html">boost/preprocessor/list/filter.hpp</a>&gt;
  56. #define LIST (1, (3, (2, (5, <a href="nil.html">BOOST_PP_NIL</a>))))
  57. #define PRED(d, data, elem) <a href="less_equal.html">BOOST_PP_LESS_EQUAL</a>(elem, data)
  58. <a href="list_filter.html">BOOST_PP_LIST_FILTER</a>(PRED, 3, LIST)
  59. // expands to (1, (3, (2, <a href="nil.html">BOOST_PP_NIL</a>)))
  60. </pre></div>
  61. <hr size="1">
  62. <div style="margin-left: 0px;">
  63. <i>© Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i>
  64. </br><i>© Copyright Paul Mensonides 2002</i>
  65. </div>
  66. <div style="margin-left: 0px;">
  67. <p><small>Distributed under the Boost Software License, Version 1.0. (See
  68. accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  69. copy at <a href=
  70. "http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  71. </div>
  72. </body>
  73. </html>