function_output_iterator.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
  7. <title>Function Output Iterator</title>
  8. <meta name="author" content="David Abrahams, Jeremy Siek, Thomas Witt" />
  9. <meta name="organization" content="Boost Consulting, Indiana University Open Systems Lab, University of Hanover Institute for Transport Railway Operation and Construction" />
  10. <meta name="date" content="2006-09-11" />
  11. <meta name="copyright" content="Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003." />
  12. <link rel="stylesheet" href="../../../rst.css" type="text/css" />
  13. </head>
  14. <body>
  15. <div class="document" id="function-output-iterator">
  16. <h1 class="title">Function Output Iterator</h1>
  17. <table class="docinfo" frame="void" rules="none">
  18. <col class="docinfo-name" />
  19. <col class="docinfo-content" />
  20. <tbody valign="top">
  21. <tr><th class="docinfo-name">Author:</th>
  22. <td>David Abrahams, Jeremy Siek, Thomas Witt</td></tr>
  23. <tr><th class="docinfo-name">Contact:</th>
  24. <td><a class="first reference external" href="mailto:dave&#64;boost-consulting.com">dave&#64;boost-consulting.com</a>, <a class="reference external" href="mailto:jsiek&#64;osl.iu.edu">jsiek&#64;osl.iu.edu</a>, <a class="last reference external" href="mailto:witt&#64;ive.uni-hannover.de">witt&#64;ive.uni-hannover.de</a></td></tr>
  25. <tr><th class="docinfo-name">Organization:</th>
  26. <td><a class="first reference external" href="http://www.boost-consulting.com">Boost Consulting</a>, Indiana University <a class="reference external" href="http://www.osl.iu.edu">Open Systems
  27. Lab</a>, University of Hanover <a class="last reference external" href="http://www.ive.uni-hannover.de">Institute for Transport
  28. Railway Operation and Construction</a></td></tr>
  29. <tr><th class="docinfo-name">Date:</th>
  30. <td>2006-09-11</td></tr>
  31. <tr><th class="docinfo-name">Copyright:</th>
  32. <td>Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.</td></tr>
  33. </tbody>
  34. </table>
  35. <!-- Distributed under the Boost -->
  36. <!-- Software License, Version 1.0. (See accompanying -->
  37. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  38. <table class="docutils field-list" frame="void" rules="none">
  39. <col class="field-name" />
  40. <col class="field-body" />
  41. <tbody valign="top">
  42. <tr class="field"><th class="field-name">abstract:</th><td class="field-body"><!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  43. <!-- Software License, Version 1.0. (See accompanying -->
  44. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  45. The function output iterator adaptor makes it easier to create custom
  46. output iterators. The adaptor takes a unary function and creates a
  47. model of Output Iterator. Each item assigned to the output iterator is
  48. passed as an argument to the unary function. The motivation for this
  49. iterator is that creating a conforming output iterator is non-trivial,
  50. particularly because the proper implementation usually requires a
  51. proxy object.</td>
  52. </tr>
  53. </tbody>
  54. </table>
  55. <div class="contents topic" id="table-of-contents">
  56. <p class="topic-title first">Table of Contents</p>
  57. <ul class="simple">
  58. <li><a class="reference internal" href="#header" id="id1">Header</a></li>
  59. <li><a class="reference internal" href="#function-output-iterator-requirements" id="id2"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> requirements</a></li>
  60. <li><a class="reference internal" href="#function-output-iterator-models" id="id3"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> models</a></li>
  61. <li><a class="reference internal" href="#function-output-iterator-operations" id="id4"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> operations</a></li>
  62. <li><a class="reference internal" href="#example" id="id5">Example</a></li>
  63. </ul>
  64. </div>
  65. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  66. <!-- Software License, Version 1.0. (See accompanying -->
  67. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  68. <div class="section" id="header">
  69. <h1><a class="toc-backref" href="#id1">Header</a></h1>
  70. <pre class="literal-block">
  71. #include &lt;boost/function_output_iterator.hpp&gt;
  72. </pre>
  73. <pre class="literal-block">
  74. template &lt;class UnaryFunction&gt;
  75. class function_output_iterator {
  76. public:
  77. typedef std::output_iterator_tag iterator_category;
  78. typedef void value_type;
  79. typedef void difference_type;
  80. typedef void pointer;
  81. typedef void reference;
  82. explicit function_output_iterator();
  83. explicit function_output_iterator(const UnaryFunction&amp; f);
  84. /* see below */ operator*();
  85. function_output_iterator&amp; operator++();
  86. function_output_iterator&amp; operator++(int);
  87. private:
  88. UnaryFunction m_f; // exposition only
  89. };
  90. </pre>
  91. </div>
  92. <div class="section" id="function-output-iterator-requirements">
  93. <h1><a class="toc-backref" href="#id2"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> requirements</a></h1>
  94. <p><tt class="docutils literal"><span class="pre">UnaryFunction</span></tt> must be Assignable and Copy Constructible.</p>
  95. </div>
  96. <div class="section" id="function-output-iterator-models">
  97. <h1><a class="toc-backref" href="#id3"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> models</a></h1>
  98. <p><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> is a model of the Writable and
  99. Incrementable Iterator concepts.</p>
  100. </div>
  101. <div class="section" id="function-output-iterator-operations">
  102. <h1><a class="toc-backref" href="#id4"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> operations</a></h1>
  103. <p><tt class="docutils literal"><span class="pre">explicit</span> <span class="pre">function_output_iterator(const</span> <span class="pre">UnaryFunction&amp;</span> <span class="pre">f</span> <span class="pre">=</span> <span class="pre">UnaryFunction());</span></tt></p>
  104. <table class="docutils field-list" frame="void" rules="none">
  105. <col class="field-name" />
  106. <col class="field-body" />
  107. <tbody valign="top">
  108. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs an instance of <tt class="docutils literal"><span class="pre">function_output_iterator</span></tt>
  109. with <tt class="docutils literal"><span class="pre">m_f</span></tt> constructed from <tt class="docutils literal"><span class="pre">f</span></tt>.</td>
  110. </tr>
  111. </tbody>
  112. </table>
  113. <p><tt class="docutils literal"><span class="pre">operator*();</span></tt></p>
  114. <table class="docutils field-list" frame="void" rules="none">
  115. <col class="field-name" />
  116. <col class="field-body" />
  117. <tbody valign="top">
  118. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">An object <tt class="docutils literal"><span class="pre">r</span></tt> of unspecified type such that <tt class="docutils literal"><span class="pre">r</span> <span class="pre">=</span> <span class="pre">t</span></tt>
  119. is equivalent to <tt class="docutils literal"><span class="pre">m_f(t)</span></tt> for all <tt class="docutils literal"><span class="pre">t</span></tt>.</td>
  120. </tr>
  121. </tbody>
  122. </table>
  123. <p><tt class="docutils literal"><span class="pre">function_output_iterator&amp;</span> <span class="pre">operator++();</span></tt></p>
  124. <table class="docutils field-list" frame="void" rules="none">
  125. <col class="field-name" />
  126. <col class="field-body" />
  127. <tbody valign="top">
  128. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  129. </tr>
  130. </tbody>
  131. </table>
  132. <p><tt class="docutils literal"><span class="pre">function_output_iterator&amp;</span> <span class="pre">operator++(int);</span></tt></p>
  133. <table class="docutils field-list" frame="void" rules="none">
  134. <col class="field-name" />
  135. <col class="field-body" />
  136. <tbody valign="top">
  137. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  138. </tr>
  139. </tbody>
  140. </table>
  141. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  142. <!-- Software License, Version 1.0. (See accompanying -->
  143. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  144. </div>
  145. <div class="section" id="example">
  146. <h1><a class="toc-backref" href="#id5">Example</a></h1>
  147. <pre class="literal-block">
  148. struct string_appender
  149. {
  150. string_appender(std::string&amp; s)
  151. : m_str(&amp;s)
  152. {}
  153. void operator()(const std::string&amp; x) const
  154. {
  155. *m_str += x;
  156. }
  157. std::string* m_str;
  158. };
  159. int main(int, char*[])
  160. {
  161. std::vector&lt;std::string&gt; x;
  162. x.push_back(&quot;hello&quot;);
  163. x.push_back(&quot; &quot;);
  164. x.push_back(&quot;world&quot;);
  165. x.push_back(&quot;!&quot;);
  166. std::string s = &quot;&quot;;
  167. std::copy(x.begin(), x.end(),
  168. boost::make_function_output_iterator(string_appender(s)));
  169. std::cout &lt;&lt; s &lt;&lt; std::endl;
  170. return 0;
  171. }
  172. </pre>
  173. </div>
  174. </div>
  175. <div class="footer">
  176. <hr class="footer" />
  177. <a class="reference external" href="function_output_iterator.rst">View document source</a>.
  178. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
  179. </div>
  180. </body>
  181. </html>