fix doc example typo
[boost.git] / boost / bimap / detail / map_view_iterator.hpp
blobadc8d7c8615e01285dabf0b66dbbd292f71047ab
1 // Boost.Bimap
2 //
3 // Copyright (c) 2006-2007 Matias Capeletto
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 /// \file detail/map_view_iterator.hpp
10 /// \brief Iterator adaptors from multi-index to bimap.
12 #ifndef BOOST_BIMAP_DETAIL_MAP_VIEW_ITERATOR_HPP
13 #define BOOST_BIMAP_DETAIL_MAP_VIEW_ITERATOR_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
16 #pragma once
17 #endif
19 #include <boost/config.hpp>
21 // Boost
22 #include <boost/serialization/nvp.hpp>
23 #include <boost/iterator/detail/enable_if.hpp>
24 #include <boost/iterator/iterator_adaptor.hpp>
25 #include <boost/bimap/relation/support/pair_by.hpp>
27 namespace boost {
28 namespace bimaps {
29 namespace detail {
31 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
33 template< class Tag, class Relation, class CoreIterator > struct map_view_iterator;
35 template< class Tag, class Relation, class CoreIterator >
36 struct map_view_iterator_base
38 typedef iterator_adaptor
40 map_view_iterator< Tag, Relation, CoreIterator >,
41 CoreIterator,
42 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
43 pair_type_by<Tag,Relation>::type
45 > type;
48 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
50 /** \brief Map View Iterator adaptor from multi index to bimap.
52 This is class is based on transform iterator from Boost.Iterator that is
53 modified to allow serialization. It has been specialized for this
54 library, and EBO optimization was applied to the functor.
56 **/
58 template< class Tag, class Relation, class CoreIterator >
59 struct map_view_iterator : public map_view_iterator_base<Tag,Relation,CoreIterator>::type
61 typedef BOOST_DEDUCED_TYPENAME
62 map_view_iterator_base<Tag,Relation,CoreIterator>::type base_;
64 public:
66 map_view_iterator() {}
68 map_view_iterator(CoreIterator const& iter)
69 : base_(iter) {}
71 map_view_iterator(map_view_iterator const & iter)
72 : base_(iter.base()) {}
74 BOOST_DEDUCED_TYPENAME base_::reference dereference() const
76 return ::boost::bimaps::relation::support::pair_by<Tag>(
77 *const_cast<BOOST_DEDUCED_TYPENAME base_::base_type::value_type*>(
78 &(*this->base())
83 private:
85 friend class iterator_core_access;
87 #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
89 // Serialization support
91 BOOST_SERIALIZATION_SPLIT_MEMBER()
93 friend class ::boost::serialization::access;
95 template< class Archive >
96 void save(Archive & ar, const unsigned int version) const
98 ar << ::boost::serialization::make_nvp("mi_iterator",this->base());
101 template< class Archive >
102 void load(Archive & ar, const unsigned int version)
104 CoreIterator iter;
105 ar >> ::boost::serialization::make_nvp("mi_iterator",iter);
106 this->base_reference() = iter;
109 #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
113 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
115 template< class Tag, class Relation, class CoreIterator > struct const_map_view_iterator;
117 template< class Tag, class Relation, class CoreIterator >
118 struct const_map_view_iterator_base
120 typedef iterator_adaptor
122 const_map_view_iterator< Tag, Relation, CoreIterator >,
123 CoreIterator,
124 const BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
125 pair_type_by<Tag,Relation>::type
127 > type;
130 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
133 /** \brief Const Map View Iterator adaptor from multi index to bimap.
135 See also map_view_iterator.
138 template< class Tag, class Relation, class CoreIterator >
139 struct const_map_view_iterator :
141 public const_map_view_iterator_base<Tag,Relation,CoreIterator>::type
143 typedef BOOST_DEDUCED_TYPENAME
144 const_map_view_iterator_base<Tag,Relation,CoreIterator>::type base_;
146 public:
148 const_map_view_iterator() {}
150 const_map_view_iterator(CoreIterator const& iter)
151 : base_(iter) {}
153 const_map_view_iterator(const_map_view_iterator const & iter)
154 : base_(iter.base()) {}
156 const_map_view_iterator(map_view_iterator<Tag,Relation,CoreIterator> i)
157 : base_(i.base()) {}
159 BOOST_DEDUCED_TYPENAME base_::reference dereference() const
161 return ::boost::bimaps::relation::support::pair_by<Tag>(*this->base());
164 private:
166 friend class iterator_core_access;
168 #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
170 // Serialization support
172 BOOST_SERIALIZATION_SPLIT_MEMBER()
174 friend class ::boost::serialization::access;
176 template< class Archive >
177 void save(Archive & ar, const unsigned int version) const
179 ar << ::boost::serialization::make_nvp("mi_iterator",this->base());
182 template< class Archive >
183 void load(Archive & ar, const unsigned int version)
185 CoreIterator iter;
186 ar >> ::boost::serialization::make_nvp("mi_iterator",iter);
187 this->base_reference() = iter;
190 #endif // BOOST_BIMAP_DISABLE_SERIALIZATION
194 } // namespace detail
195 } // namespace bimaps
196 } // namespace boost
198 #endif // BOOST_BIMAP_DETAIL_MAP_VIEW_ITERATOR_HPP