function_output_iterator.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Revision History:
  6. // 27 Feb 2001 Jeremy Siek
  7. // Initial checkin.
  8. #ifndef BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP
  9. #define BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP
  10. #include <iterator>
  11. namespace boost {
  12. namespace iterators {
  13. template <class UnaryFunction>
  14. class function_output_iterator {
  15. typedef function_output_iterator self;
  16. public:
  17. typedef std::output_iterator_tag iterator_category;
  18. typedef void value_type;
  19. typedef void difference_type;
  20. typedef void pointer;
  21. typedef void reference;
  22. explicit function_output_iterator() {}
  23. explicit function_output_iterator(const UnaryFunction& f)
  24. : m_f(f) {}
  25. struct output_proxy {
  26. output_proxy(UnaryFunction& f) : m_f(f) { }
  27. template <class T> output_proxy& operator=(const T& value) {
  28. m_f(value);
  29. return *this;
  30. }
  31. UnaryFunction& m_f;
  32. };
  33. output_proxy operator*() { return output_proxy(m_f); }
  34. self& operator++() { return *this; }
  35. self& operator++(int) { return *this; }
  36. private:
  37. UnaryFunction m_f;
  38. };
  39. template <class UnaryFunction>
  40. inline function_output_iterator<UnaryFunction>
  41. make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) {
  42. return function_output_iterator<UnaryFunction>(f);
  43. }
  44. } // namespace iterators
  45. using iterators::function_output_iterator;
  46. using iterators::make_function_output_iterator;
  47. } // namespace boost
  48. #endif // BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP