1 // (C) Copyright Jeremy Siek 2001-2004. 2 // Distributed under the Boost Software License, Version 1.0. (See 3 // accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 // Revision History: 7 8 // 27 Feb 2001 Jeremy Siek 9 // Initial checkin. 10 11 #include <iostream> 12 #include <string> 13 #include <vector> 14 15 #include <boost/iterator/function_output_iterator.hpp> 16 17 struct string_appender 18 { string_appenderstring_appender19 string_appender(std::string& s) 20 : m_str(&s) 21 {} 22 operator ()string_appender23 void operator()(const std::string& x) const 24 { 25 *m_str += x; 26 } 27 28 std::string* m_str; 29 }; 30 main(int,char * [])31int main(int, char*[]) 32 { 33 std::vector<std::string> x; 34 x.push_back("hello"); 35 x.push_back(" "); 36 x.push_back("world"); 37 x.push_back("!"); 38 39 std::string s = ""; 40 std::copy(x.begin(), x.end(), 41 boost::make_function_output_iterator(string_appender(s))); 42 43 std::cout << s << std::endl; 44 45 return 0; 46 } 47