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">
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" />
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" />
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>
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" />
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
55 <div class=
"contents topic" id=
"table-of-contents">
56 <p class=
"topic-title first">Table of Contents
</p>
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>
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
>
73 <pre class=
"literal-block">
74 template
<class UnaryFunction
>
75 class function_output_iterator {
77 typedef std::output_iterator_tag iterator_category;
78 typedef void value_type;
79 typedef void difference_type;
81 typedef void reference;
83 explicit function_output_iterator();
85 explicit function_output_iterator(const UnaryFunction
& f);
87 /* see below */ operator*();
88 function_output_iterator
& operator++();
89 function_output_iterator
& operator++(int);
91 UnaryFunction m_f; // exposition only
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>
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>
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" />
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>
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" />
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>
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" />
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>
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" />
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>
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) -->
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
153 string_appender(std::string
& s)
157 void operator()(const std::string
& x) const
165 int main(int, char*[])
167 std::vector
<std::string
> x;
168 x.push_back(
"hello
");
169 x.push_back(
" ");
170 x.push_back(
"world
");
171 x.push_back(
"!
");
173 std::string s =
"";
174 std::copy(x.begin(), x.end(),
175 boost::make_function_output_iterator(string_appender(s)));
177 std::cout
<< s
<< std::endl;
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.