function_output_iterator.hpp 1.5 KB

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