| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  | <head> | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <meta http-equiv="Content-Language" content="en-us"> | 
					
						
							|  |  |  |   <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <title>Generator Iterator Adaptor Documentation</title> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | </head> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <body bgcolor="#FFFFFF" text="#000000"> | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <img src="../../boost.png" alt="boost.png (6897 bytes)" align="middle" | 
					
						
							|  |  |  |   width="277" height="86"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <h1>Generator Iterator Adaptor</h1> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <p>Defined in header <a href= | 
					
						
							|  |  |  |   "../../boost/generator_iterator.hpp">boost/generator_iterator.hpp</a></p> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <p>The generator iterator adaptor makes it easier to create custom input | 
					
						
							|  |  |  |   iterators from 0-ary functions and function objects. The adaptor takes a | 
					
						
							|  |  |  |   <a href="http://www.sgi.com/tech/stl/Generator.html">Generator</a> and | 
					
						
							|  |  |  |   creates a model of <a href= | 
					
						
							|  |  |  |   "http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>. Each | 
					
						
							|  |  |  |   increment retrieves an item from the generator and makes it available to be | 
					
						
							|  |  |  |   retrieved by dereferencing. The motivation for this iterator is that some | 
					
						
							|  |  |  |   concepts can be more naturally expressed as a generator, while most STL | 
					
						
							|  |  |  |   algorithms expect an iterator. An example is the <a href= | 
					
						
							|  |  |  |   "../random/index.html">Random Number</a> library.</p> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <h2>Synopsis</h2> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <blockquote> | 
					
						
							|  |  |  |     <pre> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | namespace boost { | 
					
						
							|  |  |  |   template <class Generator> | 
					
						
							|  |  |  |   class generator_iterator_policies; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   template <class Generator> | 
					
						
							|  |  |  |   class generator_iterator_generator; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   template <class Generator> | 
					
						
							|  |  |  |   typename generator_iterator_generator<Generator>::type | 
					
						
							|  |  |  |   make_generator_iterator(Generator & gen); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | </pre> | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   </blockquote> | 
					
						
							|  |  |  |   <hr> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <h2>The Generator Iterator Generator Class</h2> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <p>The class generator_iterator_generator is a helper class whose purpose | 
					
						
							|  |  |  |   is to construct a generator iterator type. The template parameter for this | 
					
						
							|  |  |  |   class is the Generator function object type that is being wrapped. The | 
					
						
							|  |  |  |   generator iterator adaptor only holds a reference (or pointer) to the | 
					
						
							|  |  |  |   function object, therefore the function object must outlive the generator | 
					
						
							|  |  |  |   iterator adaptor constructed from it.</p> | 
					
						
							|  |  |  |   <pre> | 
					
						
							|  |  |  | template <class Generator> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | class generator_iterator_generator | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2005-08-03 13:01:57 +00:00
										 |  |  |   typedef <i>unspecified</i> type; // the resulting generator iterator type  | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | } | 
					
						
							|  |  |  | </pre> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <h3>Template Parameters</h3> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <table border summary=""> | 
					
						
							|  |  |  |     <tr> | 
					
						
							|  |  |  |       <th>Parameter</th> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |       <th>Description</th> | 
					
						
							|  |  |  |     </tr> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |     <tr> | 
					
						
							|  |  |  |       <td><tt><a href= | 
					
						
							|  |  |  |       "http://www.sgi.com/tech/stl/Generator.html">Generator</a></tt></td> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |       <td>The generator (0-ary function object) type being wrapped. The | 
					
						
							|  |  |  |       return type of the function must be defined as | 
					
						
							|  |  |  |       <tt>Generator::result_type</tt>. The function object must be a model of | 
					
						
							|  |  |  |       <a href= | 
					
						
							|  |  |  |       "http://www.sgi.com/tech/stl/Generator.html">Generator</a>.</td> | 
					
						
							|  |  |  |     </tr> | 
					
						
							|  |  |  |   </table> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <h3>Concept Model</h3> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <p>The generator iterator class is a model of <a href= | 
					
						
							|  |  |  |   "http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.</p> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <h3>Members</h3> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <p>The generator iterator implements the member functions and operators | 
					
						
							|  |  |  |   required of the <a href= | 
					
						
							|  |  |  |   "http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> | 
					
						
							|  |  |  |   concept.<br></p> | 
					
						
							|  |  |  |   <hr> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <h2><a name="make_generator_iterator" id="make_generator_iterator">The | 
					
						
							|  |  |  |   Generator Iterator Object Generator</a></h2> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <p>The <tt>make_generator_iterator()</tt> function provides a convenient | 
					
						
							|  |  |  |   way to create generator iterator objects. The function saves the user the | 
					
						
							|  |  |  |   trouble of explicitly writing out the iterator types.</p> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <blockquote> | 
					
						
							|  |  |  |     <pre> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | template <class Generator> | 
					
						
							|  |  |  | typename generator_iterator_generator<Generator>::type | 
					
						
							| 
									
										
										
										
											2002-11-11 19:50:05 +00:00
										 |  |  | make_generator_iterator(Generator & gen); | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | </pre> | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   </blockquote> | 
					
						
							|  |  |  |   <hr> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <h3>Example</h3> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <p>The following program shows how <code>generator_iterator</code> | 
					
						
							|  |  |  |   transforms a generator into an input iterator.</p> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <blockquote> | 
					
						
							|  |  |  |     <pre> | 
					
						
							|  |  |  | #include <iostream> | 
					
						
							|  |  |  | #include <boost/generator_iterator.hpp> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class my_generator | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |   typedef int result_type; | 
					
						
							|  |  |  |   my_generator() : state(0) { } | 
					
						
							|  |  |  |   int operator()() { return ++state; } | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |   int state; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   my_generator gen; | 
					
						
							| 
									
										
										
										
											2001-12-08 08:39:27 +00:00
										 |  |  |   boost::generator_iterator_generator<my_generator>::type it = boost::make_generator_iterator(gen); | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  |   for(int i = 0; i < 10; ++i, ++it) | 
					
						
							|  |  |  |     std::cout << *it << std::endl; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | </pre> | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   </blockquote> | 
					
						
							|  |  |  |   <hr> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= | 
					
						
							| 
									
										
										
										
											2009-05-16 14:23:59 +00:00
										 |  |  |   "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional" | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   height="31" width="88"></a></p> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <p>Revised  | 
					
						
							|  |  |  |   <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05 December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <p><i>Copyright © 2001 <a href= | 
					
						
							| 
									
										
										
										
											2008-02-10 14:56:22 +00:00
										 |  |  |   "http://www.boost.org/people/jens_maurer.htm">Jens Maurer</a></i></p> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-05 21:11:21 +00:00
										 |  |  |   <p><i>Distributed under the Boost Software License, Version 1.0. (See | 
					
						
							|  |  |  |   accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or | 
					
						
							|  |  |  |   copy at <a href= | 
					
						
							|  |  |  |   "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> | 
					
						
							| 
									
										
										
										
											2001-11-19 22:11:51 +00:00
										 |  |  | </body> | 
					
						
							|  |  |  | </html> |