input_from_forward_iterator.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP
  11. #define BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP
  12. #include <boost/container/detail/iterator.hpp>
  13. namespace boost{
  14. namespace container {
  15. namespace test{
  16. template<class FwdIterator>
  17. class input_iterator_wrapper
  18. : public boost::container::iterator< std::input_iterator_tag
  19. , typename boost::container::iterator_traits<FwdIterator>::value_type
  20. , typename boost::container::iterator_traits<FwdIterator>::difference_type
  21. , typename boost::container::iterator_traits<FwdIterator>::pointer
  22. , typename boost::container::iterator_traits<FwdIterator>::reference
  23. >
  24. {
  25. FwdIterator m_it;
  26. public:
  27. input_iterator_wrapper()
  28. : m_it(0)
  29. {}
  30. explicit input_iterator_wrapper(FwdIterator it)
  31. : m_it(it)
  32. {}
  33. //Default copy constructor...
  34. //input_iterator_wrapper(const input_iterator_wrapper&);
  35. //Default assignment...
  36. //input_iterator_wrapper &operator=(const input_iterator_wrapper&);
  37. //Default destructor...
  38. //~input_iterator_wrapper();
  39. typename boost::container::iterator_traits<FwdIterator>::reference operator*() const
  40. { return *m_it; }
  41. typename boost::container::iterator_traits<FwdIterator>::pointer operator->() const
  42. { return m_it.operator->(); }
  43. input_iterator_wrapper& operator++()
  44. { ++m_it; return *this; }
  45. input_iterator_wrapper operator++(int )
  46. {
  47. input_iterator_wrapper tmp(m_it);
  48. ++m_it;
  49. return tmp;
  50. }
  51. friend bool operator==(const input_iterator_wrapper &left, const input_iterator_wrapper &right)
  52. { return left.m_it == right.m_it; }
  53. friend bool operator!=(const input_iterator_wrapper &left, const input_iterator_wrapper &right)
  54. { return left.m_it != right.m_it; }
  55. };
  56. template<class FwdIterator>
  57. input_iterator_wrapper<FwdIterator> make_input_from_forward_iterator(const FwdIterator &it)
  58. { return input_iterator_wrapper<FwdIterator>(it); }
  59. } //namespace test{
  60. } //namespace container {
  61. } //namespace boost{
  62. #endif //BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP