1 ////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost 4 // Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 // See http://www.boost.org/libs/container for documentation. 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP 12 #define BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP 13 14 #include <boost/container/detail/iterator.hpp> 15 16 namespace boost{ 17 namespace container { 18 namespace test{ 19 20 template<class FwdIterator> 21 class input_iterator_wrapper 22 : public boost::container::iterator< std::input_iterator_tag 23 , typename boost::container::iterator_traits<FwdIterator>::value_type 24 , typename boost::container::iterator_traits<FwdIterator>::difference_type 25 , typename boost::container::iterator_traits<FwdIterator>::pointer 26 , typename boost::container::iterator_traits<FwdIterator>::reference 27 > 28 { 29 FwdIterator m_it; 30 31 public: input_iterator_wrapper()32 input_iterator_wrapper() 33 : m_it(0) 34 {} 35 input_iterator_wrapper(FwdIterator it)36 explicit input_iterator_wrapper(FwdIterator it) 37 : m_it(it) 38 {} 39 40 //Default copy constructor... 41 //input_iterator_wrapper(const input_iterator_wrapper&); 42 43 //Default assignment... 44 //input_iterator_wrapper &operator=(const input_iterator_wrapper&); 45 46 //Default destructor... 47 //~input_iterator_wrapper(); 48 operator *() const49 typename boost::container::iterator_traits<FwdIterator>::reference operator*() const 50 { return *m_it; } 51 operator ->() const52 typename boost::container::iterator_traits<FwdIterator>::pointer operator->() const 53 { return m_it.operator->(); } 54 operator ++()55 input_iterator_wrapper& operator++() 56 { ++m_it; return *this; } 57 operator ++(int)58 input_iterator_wrapper operator++(int ) 59 { 60 input_iterator_wrapper tmp(m_it); 61 ++m_it; 62 return tmp; 63 } 64 operator ==(const input_iterator_wrapper & left,const input_iterator_wrapper & right)65 friend bool operator==(const input_iterator_wrapper &left, const input_iterator_wrapper &right) 66 { return left.m_it == right.m_it; } 67 operator !=(const input_iterator_wrapper & left,const input_iterator_wrapper & right)68 friend bool operator!=(const input_iterator_wrapper &left, const input_iterator_wrapper &right) 69 { return left.m_it != right.m_it; } 70 }; 71 72 template<class FwdIterator> make_input_from_forward_iterator(const FwdIterator & it)73input_iterator_wrapper<FwdIterator> make_input_from_forward_iterator(const FwdIterator &it) 74 { return input_iterator_wrapper<FwdIterator>(it); } 75 76 } //namespace test{ 77 } //namespace container { 78 } //namespace boost{ 79 80 #endif //BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP 81