1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
5 <meta http-equiv=
"Content-Language" content=
"en-us">
6 <meta http-equiv=
"Content-Type" content=
"text/html; charset=us-ascii">
8 <title>Generator Iterator Adaptor Documentation
</title>
11 <body bgcolor=
"#FFFFFF" text=
"#000000">
12 <img src=
"../../boost.png" alt=
"boost.png (6897 bytes)" align=
"middle"
13 width=
"277" height=
"86">
15 <h1>Generator Iterator Adaptor
</h1>
17 <p>Defined in header
<a href=
18 "../../boost/generator_iterator.hpp">boost/generator_iterator.hpp
</a></p>
20 <p>The generator iterator adaptor makes it easier to create custom input
21 iterators from
0-ary functions and function objects. The adaptor takes a
22 <a href=
"http://www.sgi.com/tech/stl/Generator.html">Generator
</a> and
23 creates a model of
<a href=
24 "http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator
</a>. Each
25 increment retrieves an item from the generator and makes it available to be
26 retrieved by dereferencing. The motivation for this iterator is that some
27 concepts can be more naturally expressed as a generator, while most STL
28 algorithms expect an iterator. An example is the
<a href=
29 "../random/index.html">Random Number
</a> library.
</p>
36 template
<class Generator
>
37 class generator_iterator_policies;
39 template
<class Generator
>
40 class generator_iterator_generator;
42 template
<class Generator
>
43 typename generator_iterator_generator
<Generator
>::type
44 make_generator_iterator(Generator
& gen);
50 <h2>The Generator Iterator Generator Class
</h2>
52 <p>The class generator_iterator_generator is a helper class whose purpose
53 is to construct a generator iterator type. The template parameter for this
54 class is the Generator function object type that is being wrapped. The
55 generator iterator adaptor only holds a reference (or pointer) to the
56 function object, therefore the function object must outlive the generator
57 iterator adaptor constructed from it.
</p>
59 template
<class Generator
>
60 class generator_iterator_generator
63 typedef
<i>unspecified
</i> type; // the resulting generator iterator type
67 <h3>Template Parameters
</h3>
69 <table border
summary=
"">
78 "http://www.sgi.com/tech/stl/Generator.html">Generator
</a></tt></td>
80 <td>The generator (
0-ary function object) type being wrapped. The
81 return type of the function must be defined as
82 <tt>Generator::result_type
</tt>. The function object must be a model of
84 "http://www.sgi.com/tech/stl/Generator.html">Generator
</a>.
</td>
88 <h3>Concept Model
</h3>
90 <p>The generator iterator class is a model of
<a href=
91 "http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator
</a>.
</p>
95 <p>The generator iterator implements the member functions and operators
96 required of the
<a href=
97 "http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator
</a>
101 <h2><a name=
"make_generator_iterator" id=
"make_generator_iterator">The
102 Generator Iterator Object Generator
</a></h2>
104 <p>The
<tt>make_generator_iterator()
</tt> function provides a convenient
105 way to create generator iterator objects. The function saves the user the
106 trouble of explicitly writing out the iterator types.
</p>
110 template
<class Generator
>
111 typename generator_iterator_generator
<Generator
>::type
112 make_generator_iterator(Generator
& gen);
119 <p>The following program shows how
<code>generator_iterator
</code>
120 transforms a generator into an input iterator.
</p>
124 #include
<iostream
>
125 #include
<boost/generator_iterator.hpp
>
130 typedef int result_type;
131 my_generator() : state(
0) { }
132 int operator()() { return ++state; }
140 boost::generator_iterator_generator
<my_generator
>::type it = boost::make_generator_iterator(gen);
141 for(int i =
0; i
< 10; ++i, ++it)
142 std::cout
<< *it
<< std::endl;
148 <p><a href=
"http://validator.w3.org/check?uri=referer"><img border=
"0" src=
149 "../../doc/images/valid-html401.png" alt=
"Valid HTML 4.01 Transitional"
150 height=
"31" width=
"88"></a></p>
153 <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05 December,
2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
155 <p><i>Copyright
© 2001 <a href=
156 "http://www.boost.org/people/jens_maurer.htm">Jens Maurer
</a></i></p>
158 <p><i>Distributed under the Boost Software License, Version
1.0. (See
159 accompanying file
<a href=
"../../LICENSE_1_0.txt">LICENSE_1_0.txt
</a> or
161 "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt
</a>)
</i></p>