summaryrefslogtreecommitdiff
path: root/libs/container/test/input_from_forward_iterator.hpp
blob: 9436ceffac6f1fb411c78f6f69105e569ec5db84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP
#define BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP

#include <boost/container/detail/iterator.hpp>

namespace boost{
namespace container {
namespace test{

template<class FwdIterator>
class input_iterator_wrapper
   : public boost::container::iterator< std::input_iterator_tag
                         , typename boost::container::iterator_traits<FwdIterator>::value_type
                         , typename boost::container::iterator_traits<FwdIterator>::difference_type
                         , typename boost::container::iterator_traits<FwdIterator>::pointer
                         , typename boost::container::iterator_traits<FwdIterator>::reference
                         >
{
   FwdIterator m_it;

   public:
   input_iterator_wrapper()
      : m_it(0)
   {}

   explicit input_iterator_wrapper(FwdIterator it)
      : m_it(it)
   {}

   //Default copy constructor...
   //input_iterator_wrapper(const input_iterator_wrapper&);

   //Default assignment...
   //input_iterator_wrapper &operator=(const input_iterator_wrapper&);

   //Default destructor...
   //~input_iterator_wrapper();

   typename boost::container::iterator_traits<FwdIterator>::reference operator*() const
   { return *m_it; }

   typename boost::container::iterator_traits<FwdIterator>::pointer operator->() const
   { return m_it.operator->(); }

   input_iterator_wrapper& operator++()
   {  ++m_it;  return *this;  }

   input_iterator_wrapper operator++(int )
   {
      input_iterator_wrapper tmp(m_it);
      ++m_it;
      return tmp;
   }

   friend bool operator==(const input_iterator_wrapper &left, const input_iterator_wrapper &right)
   {  return left.m_it == right.m_it;  }

   friend bool operator!=(const input_iterator_wrapper &left, const input_iterator_wrapper &right)
   {  return left.m_it != right.m_it;  }
};

template<class FwdIterator>
input_iterator_wrapper<FwdIterator> make_input_from_forward_iterator(const FwdIterator &it)
{  return input_iterator_wrapper<FwdIterator>(it); }

}  //namespace test{
}  //namespace container {
}  //namespace boost{

#endif //BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP