]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright Jeremy Siek 2001. |
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 | #ifndef BOOST_FUNCTION_OUTPUT_ITERATOR_HPP | |
12 | #define BOOST_FUNCTION_OUTPUT_ITERATOR_HPP | |
13 | ||
14 | #include <iterator> | |
15 | ||
16 | namespace boost { | |
17 | namespace iterators { | |
18 | ||
19 | template <class UnaryFunction> | |
20 | class function_output_iterator { | |
21 | typedef function_output_iterator self; | |
22 | public: | |
23 | typedef std::output_iterator_tag iterator_category; | |
24 | typedef void value_type; | |
25 | typedef void difference_type; | |
26 | typedef void pointer; | |
27 | typedef void reference; | |
28 | ||
29 | explicit function_output_iterator() {} | |
30 | ||
31 | explicit function_output_iterator(const UnaryFunction& f) | |
32 | : m_f(f) {} | |
33 | ||
34 | struct output_proxy { | |
35 | output_proxy(UnaryFunction& f) : m_f(f) { } | |
36 | template <class T> output_proxy& operator=(const T& value) { | |
37 | m_f(value); | |
38 | return *this; | |
39 | } | |
40 | UnaryFunction& m_f; | |
41 | }; | |
42 | output_proxy operator*() { return output_proxy(m_f); } | |
43 | self& operator++() { return *this; } | |
44 | self& operator++(int) { return *this; } | |
45 | private: | |
46 | UnaryFunction m_f; | |
47 | }; | |
48 | ||
49 | template <class UnaryFunction> | |
50 | inline function_output_iterator<UnaryFunction> | |
51 | make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) { | |
52 | return function_output_iterator<UnaryFunction>(f); | |
53 | } | |
54 | ||
55 | } // namespace iterators | |
56 | ||
57 | using iterators::function_output_iterator; | |
58 | using iterators::make_function_output_iterator; | |
59 | ||
60 | } // namespace boost | |
61 | ||
62 | #endif // BOOST_FUNCTION_OUTPUT_ITERATOR_HPP |