Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:55

0001 // (C) Copyright Jeremy Siek 2001.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 // Revision History:
0007 
0008 // 27 Feb 2001   Jeremy Siek
0009 //      Initial checkin.
0010 
0011 #ifndef BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP
0012 #define BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP
0013 
0014 #include <iterator>
0015 #include <boost/config.hpp>
0016 #include <boost/core/enable_if.hpp>
0017 #include <boost/type_traits/is_same.hpp>
0018 #include <boost/type_traits/remove_cv.hpp>
0019 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0020 #include <boost/type_traits/remove_reference.hpp>
0021 #endif
0022 
0023 namespace boost {
0024 namespace iterators {
0025 
0026   template <class UnaryFunction>
0027   class function_output_iterator {
0028   private:
0029     typedef function_output_iterator self;
0030 
0031     class output_proxy {
0032     public:
0033       explicit output_proxy(UnaryFunction& f) BOOST_NOEXCEPT : m_f(f) { }
0034 
0035 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
0036       template <class T>
0037       typename boost::disable_if_c<
0038         boost::is_same< typename boost::remove_cv< T >::type, output_proxy >::value,
0039         output_proxy&
0040       >::type operator=(const T& value) {
0041         m_f(value);
0042         return *this;
0043       }
0044 #else
0045       template <class T>
0046       typename boost::disable_if_c<
0047         boost::is_same< typename boost::remove_cv< typename boost::remove_reference< T >::type >::type, output_proxy >::value,
0048         output_proxy&
0049       >::type operator=(T&& value) {
0050         m_f(static_cast< T&& >(value));
0051         return *this;
0052       }
0053 #endif
0054 
0055       BOOST_DEFAULTED_FUNCTION(output_proxy(output_proxy const& that), BOOST_NOEXCEPT : m_f(that.m_f) {})
0056       BOOST_DELETED_FUNCTION(output_proxy& operator=(output_proxy const&))
0057 
0058     private:
0059       UnaryFunction& m_f;
0060     };
0061 
0062   public:
0063     typedef std::output_iterator_tag iterator_category;
0064     typedef void                value_type;
0065     typedef void                difference_type;
0066     typedef void                pointer;
0067     typedef void                reference;
0068 
0069     explicit function_output_iterator() {}
0070 
0071     explicit function_output_iterator(const UnaryFunction& f)
0072       : m_f(f) {}
0073 
0074     output_proxy operator*() { return output_proxy(m_f); }
0075     self& operator++() { return *this; }
0076     self& operator++(int) { return *this; }
0077 
0078   private:
0079     UnaryFunction m_f;
0080   };
0081 
0082   template <class UnaryFunction>
0083   inline function_output_iterator<UnaryFunction>
0084   make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) {
0085     return function_output_iterator<UnaryFunction>(f);
0086   }
0087 
0088 } // namespace iterators
0089 
0090 using iterators::function_output_iterator;
0091 using iterators::make_function_output_iterator;
0092 
0093 } // namespace boost
0094 
0095 #endif // BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP