Brian Silverman | 5962333 | 2018-08-04 23:36:56 -0700 | [diff] [blame^] | 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@boost-consulting.com">dave@boost-consulting.com</a>, <a class="reference external" href="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</a>, <a class="last reference external" href="mailto:witt@ive.uni-hannover.de">witt@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 <boost/function_output_iterator.hpp> |
| 72 | </pre> |
| 73 | <pre class="literal-block"> |
| 74 | template <class UnaryFunction> |
| 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 | |
| 83 | explicit function_output_iterator(); |
| 84 | |
| 85 | explicit function_output_iterator(const UnaryFunction& f); |
| 86 | |
| 87 | /* see below */ operator*(); |
| 88 | function_output_iterator& operator++(); |
| 89 | function_output_iterator& operator++(int); |
| 90 | private: |
| 91 | UnaryFunction m_f; // exposition only |
| 92 | }; |
| 93 | </pre> |
| 94 | </div> |
| 95 | <div class="section" id="function-output-iterator-requirements"> |
| 96 | <h1><a class="toc-backref" href="#id2"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> requirements</a></h1> |
| 97 | <p><tt class="docutils literal"><span class="pre">UnaryFunction</span></tt> must be Assignable and Copy Constructible.</p> |
| 98 | </div> |
| 99 | <div class="section" id="function-output-iterator-models"> |
| 100 | <h1><a class="toc-backref" href="#id3"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> models</a></h1> |
| 101 | <p><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> is a model of the Writable and |
| 102 | Incrementable Iterator concepts.</p> |
| 103 | </div> |
| 104 | <div class="section" id="function-output-iterator-operations"> |
| 105 | <h1><a class="toc-backref" href="#id4"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> operations</a></h1> |
| 106 | <p><tt class="docutils literal"><span class="pre">explicit</span> <span class="pre">function_output_iterator(const</span> <span class="pre">UnaryFunction&</span> <span class="pre">f</span> <span class="pre">=</span> <span class="pre">UnaryFunction());</span></tt></p> |
| 107 | <table class="docutils field-list" frame="void" rules="none"> |
| 108 | <col class="field-name" /> |
| 109 | <col class="field-body" /> |
| 110 | <tbody valign="top"> |
| 111 | <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> |
| 112 | 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> |
| 113 | </tr> |
| 114 | </tbody> |
| 115 | </table> |
| 116 | <p><tt class="docutils literal"><span class="pre">operator*();</span></tt></p> |
| 117 | <table class="docutils field-list" frame="void" rules="none"> |
| 118 | <col class="field-name" /> |
| 119 | <col class="field-body" /> |
| 120 | <tbody valign="top"> |
| 121 | <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> |
| 122 | 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> |
| 123 | </tr> |
| 124 | </tbody> |
| 125 | </table> |
| 126 | <p><tt class="docutils literal"><span class="pre">function_output_iterator&</span> <span class="pre">operator++();</span></tt></p> |
| 127 | <table class="docutils field-list" frame="void" rules="none"> |
| 128 | <col class="field-name" /> |
| 129 | <col class="field-body" /> |
| 130 | <tbody valign="top"> |
| 131 | <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td> |
| 132 | </tr> |
| 133 | </tbody> |
| 134 | </table> |
| 135 | <p><tt class="docutils literal"><span class="pre">function_output_iterator&</span> <span class="pre">operator++(int);</span></tt></p> |
| 136 | <table class="docutils field-list" frame="void" rules="none"> |
| 137 | <col class="field-name" /> |
| 138 | <col class="field-body" /> |
| 139 | <tbody valign="top"> |
| 140 | <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td> |
| 141 | </tr> |
| 142 | </tbody> |
| 143 | </table> |
| 144 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
| 145 | <!-- Software License, Version 1.0. (See accompanying --> |
| 146 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
| 147 | </div> |
| 148 | <div class="section" id="example"> |
| 149 | <h1><a class="toc-backref" href="#id5">Example</a></h1> |
| 150 | <pre class="literal-block"> |
| 151 | struct string_appender |
| 152 | { |
| 153 | string_appender(std::string& s) |
| 154 | : m_str(&s) |
| 155 | {} |
| 156 | |
| 157 | void operator()(const std::string& x) const |
| 158 | { |
| 159 | *m_str += x; |
| 160 | } |
| 161 | |
| 162 | std::string* m_str; |
| 163 | }; |
| 164 | |
| 165 | int main(int, char*[]) |
| 166 | { |
| 167 | std::vector<std::string> x; |
| 168 | x.push_back("hello"); |
| 169 | x.push_back(" "); |
| 170 | x.push_back("world"); |
| 171 | x.push_back("!"); |
| 172 | |
| 173 | std::string s = ""; |
| 174 | std::copy(x.begin(), x.end(), |
| 175 | boost::make_function_output_iterator(string_appender(s))); |
| 176 | |
| 177 | std::cout << s << std::endl; |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | </pre> |
| 182 | </div> |
| 183 | </div> |
| 184 | <div class="footer"> |
| 185 | <hr class="footer" /> |
| 186 | <a class="reference external" href="function_output_iterator.rst">View document source</a>. |
| 187 | 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. |
| 188 | |
| 189 | </div> |
| 190 | </body> |
| 191 | </html> |