Line data Source code
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_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP_INCLUDED_ 12 : #define BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP_INCLUDED_ 13 : 14 : #include <cstddef> 15 : #include <iterator> 16 : #include <type_traits> 17 : 18 : namespace boost { 19 : namespace iterators { 20 : 21 : template< typename UnaryFunction > 22 : class function_output_iterator 23 : { 24 : private: 25 : class output_proxy 26 : { 27 : public: 28 0 : explicit output_proxy(UnaryFunction& f) noexcept : 29 0 : m_f(f) 30 0 : {} 31 : 32 : template< typename T > 33 : typename std::enable_if< 34 : !std::is_same< typename std::remove_cv< typename std::remove_reference< T >::type >::type, output_proxy >::value, 35 : output_proxy const& 36 0 : >::type operator=(T&& value) const 37 : { 38 0 : m_f(static_cast< T&& >(value)); 39 0 : return *this; 40 : } 41 : 42 : output_proxy(output_proxy const& that) = default; 43 : output_proxy& operator=(output_proxy const&) = delete; 44 : 45 : private: 46 : UnaryFunction& m_f; 47 : }; 48 : 49 : public: 50 : using iterator_category = std::output_iterator_tag; 51 : using value_type = void; 52 : using difference_type = std::ptrdiff_t; 53 : using pointer = void; 54 : using reference = void; 55 : 56 : template< 57 : bool Requires = std::is_class< UnaryFunction >::value, 58 : typename = typename std::enable_if< Requires >::type 59 : > 60 0 : function_output_iterator() : 61 : m_f() 62 0 : {} 63 : 64 : explicit function_output_iterator(UnaryFunction const& f) : 65 : m_f(f) 66 : {} 67 : 68 0 : output_proxy operator*() { return output_proxy(m_f); } 69 : function_output_iterator& operator++() { return *this; } 70 0 : function_output_iterator& operator++(int) { return *this; } 71 : 72 : private: 73 : UnaryFunction m_f; 74 : }; 75 : 76 : template< typename UnaryFunction > 77 : inline function_output_iterator< UnaryFunction > make_function_output_iterator(UnaryFunction const& f = UnaryFunction()) 78 : { 79 : return function_output_iterator< UnaryFunction >(f); 80 : } 81 : 82 : } // namespace iterators 83 : 84 : using iterators::function_output_iterator; 85 : using iterators::make_function_output_iterator; 86 : 87 : } // namespace boost 88 : 89 : #endif // BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP_INCLUDED_