Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/iterator/function_output_iterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_INCLUDED_
0012 #define BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP_INCLUDED_
0013 
0014 #include <cstddef>
0015 #include <iterator>
0016 #include <type_traits>
0017 
0018 namespace boost {
0019 namespace iterators {
0020 
0021 template< typename UnaryFunction >
0022 class function_output_iterator
0023 {
0024 private:
0025     class output_proxy
0026     {
0027     public:
0028         explicit output_proxy(UnaryFunction& f) noexcept :
0029             m_f(f)
0030         {}
0031 
0032         template< typename T >
0033         typename std::enable_if<
0034             !std::is_same< typename std::remove_cv< typename std::remove_reference< T >::type >::type, output_proxy >::value,
0035             output_proxy const&
0036         >::type operator=(T&& value) const
0037         {
0038             m_f(static_cast< T&& >(value));
0039             return *this;
0040         }
0041 
0042         output_proxy(output_proxy const& that) = default;
0043         output_proxy& operator=(output_proxy const&) = delete;
0044 
0045     private:
0046         UnaryFunction& m_f;
0047     };
0048 
0049 public:
0050     using iterator_category = std::output_iterator_tag;
0051     using value_type = void;
0052     using difference_type = std::ptrdiff_t;
0053     using pointer = void;
0054     using reference = void;
0055 
0056     template<
0057         bool Requires = std::is_class< UnaryFunction >::value,
0058         typename = typename std::enable_if< Requires >::type
0059     >
0060     function_output_iterator() :
0061         m_f()
0062     {}
0063 
0064     explicit function_output_iterator(UnaryFunction const& f) :
0065         m_f(f)
0066     {}
0067 
0068     output_proxy operator*() { return output_proxy(m_f); }
0069     function_output_iterator& operator++() { return *this; }
0070     function_output_iterator& operator++(int) { return *this; }
0071 
0072 private:
0073     UnaryFunction m_f;
0074 };
0075 
0076 template< typename UnaryFunction >
0077 inline function_output_iterator< UnaryFunction > make_function_output_iterator(UnaryFunction const& f = UnaryFunction())
0078 {
0079     return function_output_iterator< UnaryFunction >(f);
0080 }
0081 
0082 } // namespace iterators
0083 
0084 using iterators::function_output_iterator;
0085 using iterators::make_function_output_iterator;
0086 
0087 } // namespace boost
0088 
0089 #endif // BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP_INCLUDED_