Brian Silverman | 5962333 | 2018-08-04 23:36:56 -0700 | [diff] [blame^] | 1 | .. Copyright David Abrahams 2006. Distributed under the Boost |
| 2 | .. Software License, Version 1.0. (See accompanying |
| 3 | .. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 4 | |
| 5 | Example |
| 6 | ....... |
| 7 | |
| 8 | :: |
| 9 | |
| 10 | struct string_appender |
| 11 | { |
| 12 | string_appender(std::string& s) |
| 13 | : m_str(&s) |
| 14 | {} |
| 15 | |
| 16 | void operator()(const std::string& x) const |
| 17 | { |
| 18 | *m_str += x; |
| 19 | } |
| 20 | |
| 21 | std::string* m_str; |
| 22 | }; |
| 23 | |
| 24 | int main(int, char*[]) |
| 25 | { |
| 26 | std::vector<std::string> x; |
| 27 | x.push_back("hello"); |
| 28 | x.push_back(" "); |
| 29 | x.push_back("world"); |
| 30 | x.push_back("!"); |
| 31 | |
| 32 | std::string s = ""; |
| 33 | std::copy(x.begin(), x.end(), |
| 34 | boost::make_function_output_iterator(string_appender(s))); |
| 35 | |
| 36 | std::cout << s << std::endl; |
| 37 | |
| 38 | return 0; |
| 39 | } |