map_iterator.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Boost.Pointer Container
  3. //
  4. // Copyright Thorsten Ottosen 2003-2005. Use, modification and
  5. // distribution is subject to the Boost Software License, Version
  6. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // For more information, see http://www.boost.org/libs/ptr_container/
  10. //
  11. #ifndef BOOST_PTR_CONTAINER_MAP_ITERATOR_HPP
  12. #define BOOST_PTR_CONTAINER_MAP_ITERATOR_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <boost/config.hpp>
  17. #include <boost/iterator/iterator_adaptor.hpp>
  18. #include <boost/utility/compare_pointees.hpp>
  19. #include <utility>
  20. #if defined(BOOST_MSVC)
  21. # pragma warning(push)
  22. # pragma warning(disable:4512) // Assignment operator could not be generated.
  23. #endif
  24. namespace boost
  25. {
  26. namespace ptr_container_detail
  27. {
  28. template< class F, class S >
  29. struct ref_pair
  30. {
  31. typedef F first_type;
  32. typedef S second_type;
  33. const F& first;
  34. S second;
  35. template< class F2, class S2 >
  36. ref_pair( const std::pair<F2,S2>& p )
  37. : first(p.first), second(static_cast<S>(p.second))
  38. { }
  39. template< class RP >
  40. ref_pair( const RP* rp )
  41. : first(rp->first), second(rp->second)
  42. { }
  43. const ref_pair* operator->() const
  44. {
  45. return this;
  46. }
  47. friend inline bool operator==( ref_pair l, ref_pair r )
  48. {
  49. return l.first == r.first &&
  50. boost::equal_pointees( l.second, r.second );
  51. }
  52. friend inline bool operator!=( ref_pair l, ref_pair r )
  53. {
  54. return !( l == r );
  55. }
  56. friend inline bool operator<( ref_pair l, ref_pair r )
  57. {
  58. if( l.first == r.first )
  59. return boost::less_pointees( l.second, r.second );
  60. else
  61. return l.first < r.first;
  62. }
  63. friend inline bool operator>( ref_pair l, ref_pair r )
  64. {
  65. return r < l;
  66. }
  67. friend inline bool operator<=( ref_pair l, ref_pair r )
  68. {
  69. return !(r < l);
  70. }
  71. friend inline bool operator>=( ref_pair l, ref_pair r )
  72. {
  73. return !(l < r);
  74. }
  75. };
  76. }
  77. template<
  78. class I, // base iterator
  79. class F, // first type, key type
  80. class S // second type, mapped type
  81. >
  82. class ptr_map_iterator :
  83. public boost::iterator_adaptor< ptr_map_iterator<I,F,S>, I,
  84. ptr_container_detail::ref_pair<F,S>,
  85. use_default,
  86. ptr_container_detail::ref_pair<F,S> >
  87. {
  88. typedef boost::iterator_adaptor< ptr_map_iterator<I,F,S>, I,
  89. ptr_container_detail::ref_pair<F,S>,
  90. use_default,
  91. ptr_container_detail::ref_pair<F,S> >
  92. base_type;
  93. public:
  94. ptr_map_iterator() : base_type()
  95. { }
  96. explicit ptr_map_iterator( const I& i ) : base_type(i)
  97. { }
  98. template< class I2, class F2, class S2 >
  99. ptr_map_iterator( const ptr_map_iterator<I2,F2,S2>& r )
  100. : base_type(r.base())
  101. { }
  102. }; // class 'ptr_map_iterator'
  103. }
  104. #if defined(BOOST_MSVC)
  105. # pragma warning(pop)
  106. #endif
  107. #endif