forked from boostorg/utility
		
	
		
			
	
	
		
			170 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
		
		
			
		
	
	
			170 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| 
								 | 
							
								<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<html>
							 | 
						||
| 
								 | 
							
								<head>
							 | 
						||
| 
								 | 
							
								    <meta name="generator" content="HTML Tidy, see www.w3.org">
							 | 
						||
| 
								 | 
							
								    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
							 | 
						||
| 
								 | 
							
								    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
							 | 
						||
| 
								 | 
							
								    <meta name="ProgId" content="FrontPage.Editor.Document">
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <title>Function Output Iterator Adaptor Documentation</title>
							 | 
						||
| 
								 | 
							
								</head>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<body bgcolor="#FFFFFF" text="#000000">
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								    <img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align=
							 | 
						||
| 
								 | 
							
								    "center" width="277" height="86"> 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <h1>Function Output Iterator Adaptor</h1>
							 | 
						||
| 
								 | 
							
								    Defined in header <a href=
							 | 
						||
| 
								 | 
							
								    "../../boost/function_output_iterator.hpp">boost/function_output_iterator.hpp</a> 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <p>The function output iterator adaptor makes it easier to create
							 | 
						||
| 
								 | 
							
								    custom output iterators. The adaptor takes a <a
							 | 
						||
| 
								 | 
							
								    href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary
							 | 
						||
| 
								 | 
							
								    Function</a> and creates a model of <a
							 | 
						||
| 
								 | 
							
								    href="http://www.sgi.com/tech/stl/OutputIterator.html">Output
							 | 
						||
| 
								 | 
							
								    Iterator</a>. Each item assigned to the output iterator is passed
							 | 
						||
| 
								 | 
							
								    as an argument to the unary function.  The motivation for this
							 | 
						||
| 
								 | 
							
								    iterator is that creating a C++ Standard conforming output
							 | 
						||
| 
								 | 
							
								    iterator is non-trivial, particularly because the proper
							 | 
						||
| 
								 | 
							
								    implementation usually requires a proxy object. On the other hand,
							 | 
						||
| 
								 | 
							
								    creating a function (or function object) is much simpler.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <h2>Synopsis</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <blockquote>
							 | 
						||
| 
								 | 
							
								<pre>
							 | 
						||
| 
								 | 
							
								namespace boost {
							 | 
						||
| 
								 | 
							
								  template <class UnaryFunction>
							 | 
						||
| 
								 | 
							
								  class function_output_iterator;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  template <class UnaryFunction>
							 | 
						||
| 
								 | 
							
								  function_output_iterator<UnaryFunction>
							 | 
						||
| 
								 | 
							
								  make_function_output_iterator(const UnaryFunction& f = UnaryFunction())
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								</pre>
							 | 
						||
| 
								 | 
							
								    </blockquote>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <h3>Example</h3>
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								    In this example we create an output iterator that appends
							 | 
						||
| 
								 | 
							
								    each item onto the end of a string, using the <tt>string_appender</tt>
							 | 
						||
| 
								 | 
							
								    function. 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <blockquote>
							 | 
						||
| 
								 | 
							
								<pre>
							 | 
						||
| 
								 | 
							
								#include <iostream>
							 | 
						||
| 
								 | 
							
								#include <string>
							 | 
						||
| 
								 | 
							
								#include <vector>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include <boost/function_output_iterator.hpp>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								struct string_appender {
							 | 
						||
| 
								 | 
							
								  string_appender(std::string& s) : m_str(s) { }
							 | 
						||
| 
								 | 
							
								  void operator()(const std::string& x) const {
							 | 
						||
| 
								 | 
							
								    m_str += x;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  std::string& m_str;
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int main(int, char*[])
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								  std::vector<std::string> x;
							 | 
						||
| 
								 | 
							
								  x.push_back("hello");
							 | 
						||
| 
								 | 
							
								  x.push_back(" ");
							 | 
						||
| 
								 | 
							
								  x.push_back("world");
							 | 
						||
| 
								 | 
							
								  x.push_back("!");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  std::string s = "";
							 | 
						||
| 
								 | 
							
								  std::copy(x.begin(), x.end(), 
							 | 
						||
| 
								 | 
							
								            boost::make_function_output_iterator(string_appender(s)));
							 | 
						||
| 
								 | 
							
								  
							 | 
						||
| 
								 | 
							
								  std::cout << s << std::endl;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								</pre>
							 | 
						||
| 
								 | 
							
								    </blockquote>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <hr>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <h2><a name="function_output_iterator">The Function Output Iterator Class</a></h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <blockquote>
							 | 
						||
| 
								 | 
							
								<pre>
							 | 
						||
| 
								 | 
							
								template <class UnaryFunction>
							 | 
						||
| 
								 | 
							
								class function_output_iterator;
							 | 
						||
| 
								 | 
							
								</pre>
							 | 
						||
| 
								 | 
							
								    </blockquote>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    The <tt>function_output_iterator</tt> class creates an <a
							 | 
						||
| 
								 | 
							
								    href="http://www.sgi.com/tech/stl/OutputIterator.html">Output
							 | 
						||
| 
								 | 
							
								    Iterator</a> out of a
							 | 
						||
| 
								 | 
							
								    <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary
							 | 
						||
| 
								 | 
							
								    Function</a>. Each item assigned to the output iterator is passed
							 | 
						||
| 
								 | 
							
								    as an argument to the unary function.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <h3>Template Parameters</h3>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <table border>
							 | 
						||
| 
								 | 
							
								      <tr>
							 | 
						||
| 
								 | 
							
								        <th>Parameter
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        <th>Description
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								      <tr>
							 | 
						||
| 
								 | 
							
								        <td><tt>UnaryFunction</tt> 
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        <td>The function type being wrapped. The return type of the
							 | 
						||
| 
								 | 
							
								        function is not used, so it can be <tt>void</tt>.  The
							 | 
						||
| 
								 | 
							
								        function must be a model of <a
							 | 
						||
| 
								 | 
							
								        href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary
							 | 
						||
| 
								 | 
							
								        Function</a>.</td>
							 | 
						||
| 
								 | 
							
								    </table>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <h3>Concept Model</h3>
							 | 
						||
| 
								 | 
							
								    The function output iterator class is a model of <a
							 | 
						||
| 
								 | 
							
								    href="http://www.sgi.com/tech/stl/OutputIterator.html">Output
							 | 
						||
| 
								 | 
							
								    Iterator</a>.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <h2>Members</h3>
							 | 
						||
| 
								 | 
							
								    The function output iterator implements the member functions
							 | 
						||
| 
								 | 
							
								    and operators required of the <a
							 | 
						||
| 
								 | 
							
								    href="http://www.sgi.com/tech/stl/OutputIterator.html">Output
							 | 
						||
| 
								 | 
							
								    Iterator</a> concept. In addition it has the following constructor:
							 | 
						||
| 
								 | 
							
								<pre>
							 | 
						||
| 
								 | 
							
								explicit function_output_iterator(const UnaryFunction& f = UnaryFunction())
							 | 
						||
| 
								 | 
							
								</pre>
							 | 
						||
| 
								 | 
							
								   <br>    
							 | 
						||
| 
								 | 
							
								    <br>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <hr>
							 | 
						||
| 
								 | 
							
								    <h2><a name="make_function_output_iterator">The Function Output Iterator Object
							 | 
						||
| 
								 | 
							
								    Generator</a></h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    The <tt>make_function_output_iterator()</tt> function provides a
							 | 
						||
| 
								 | 
							
								    more convenient way to create function output iterator objects. The
							 | 
						||
| 
								 | 
							
								    function saves the user the trouble of explicitly writing out the
							 | 
						||
| 
								 | 
							
								    iterator types. If the default argument is used, the function
							 | 
						||
| 
								 | 
							
								    type must be provided as an explicit template argument.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <blockquote>
							 | 
						||
| 
								 | 
							
								<pre>
							 | 
						||
| 
								 | 
							
								template <class UnaryFunction>
							 | 
						||
| 
								 | 
							
								function_output_iterator<UnaryFunction>
							 | 
						||
| 
								 | 
							
								make_function_output_iterator(const UnaryFunction& f = UnaryFunction())
							 | 
						||
| 
								 | 
							
								</pre>
							 | 
						||
| 
								 | 
							
								    </blockquote>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <hr>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    <p>© Copyright Jeremy Siek 2001. Permission to copy, use,
							 | 
						||
| 
								 | 
							
								    modify, sell and distribute this document is granted provided this
							 | 
						||
| 
								 | 
							
								    copyright notice appears in all copies. This document is provided
							 | 
						||
| 
								 | 
							
								    "as is" without express or implied warranty, and with no claim as
							 | 
						||
| 
								 | 
							
								    to its suitability for any purpose.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								</body>
							 | 
						||
| 
								 | 
							
								</html>
							 |