fix doc example typo
[boost.git] / boost / bimap / container_adaptor / associative_container_adaptor.hpp
blob191a642ccc15f664a66a4d0f4ce06bb4a7c0c31a
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 container_adaptor/associative_container_adaptor.hpp
10 /// \brief Container adaptor to build a type that is compliant to the concept of an associative container.
12 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_ASSOCIATIVE_CONTAINER_ADAPTOR_HPP
13 #define BOOST_BIMAP_CONTAINER_ADAPTOR_ASSOCIATIVE_CONTAINER_ADAPTOR_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
16 #pragma once
17 #endif
19 #include <boost/config.hpp>
21 #include <utility>
23 #include <boost/mpl/vector.hpp>
24 #include <boost/mpl/if.hpp>
25 #include <boost/mpl/aux_/na.hpp>
26 #include <boost/bimap/container_adaptor/detail/identity_converters.hpp>
27 #include <boost/bimap/container_adaptor/container_adaptor.hpp>
28 #include <boost/call_traits.hpp>
30 namespace boost {
31 namespace bimaps {
32 namespace container_adaptor {
34 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
36 template
38 class Base, class Iterator, class ConstIterator, class KeyType,
39 class IteratorToBaseConverter, class IteratorFromBaseConverter,
40 class ValueToBaseConverter, class ValueFromBaseConverter, class KeyToBaseConverter,
41 class FunctorsFromDerivedClasses
43 struct associative_container_adaptor_base
45 typedef container_adaptor
47 Base,
49 Iterator, ConstIterator,
51 IteratorToBaseConverter, IteratorFromBaseConverter,
52 ValueToBaseConverter , ValueFromBaseConverter,
54 BOOST_DEDUCED_TYPENAME mpl::push_front<
56 FunctorsFromDerivedClasses,
58 BOOST_DEDUCED_TYPENAME mpl::if_< ::boost::mpl::is_na<KeyToBaseConverter>,
59 // {
60 detail::key_to_base_identity
62 BOOST_DEDUCED_TYPENAME Base::key_type, KeyType
64 // }
65 // else
66 // {
67 KeyToBaseConverter
68 // }
70 >::type
72 >::type
74 > type;
77 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
80 /// \brief Container adaptor to build a type that is compliant to the concept of an associative container.
82 template
84 class Base,
86 class Iterator,
87 class ConstIterator,
89 class KeyType,
91 class IteratorToBaseConverter = ::boost::mpl::na,
92 class IteratorFromBaseConverter = ::boost::mpl::na,
93 class ValueToBaseConverter = ::boost::mpl::na,
94 class ValueFromBaseConverter = ::boost::mpl::na,
95 class KeyToBaseConverter = ::boost::mpl::na,
97 class FunctorsFromDerivedClasses = mpl::vector<>
99 class associative_container_adaptor :
101 public associative_container_adaptor_base
103 Base, Iterator, ConstIterator, KeyType,
104 IteratorToBaseConverter, IteratorFromBaseConverter,
105 ValueToBaseConverter, ValueFromBaseConverter, KeyToBaseConverter,
106 FunctorsFromDerivedClasses
108 >::type
111 // MetaData -------------------------------------------------------------
113 typedef typename associative_container_adaptor_base
115 Base, Iterator, ConstIterator, KeyType,
116 IteratorToBaseConverter, IteratorFromBaseConverter,
117 ValueToBaseConverter, ValueFromBaseConverter, KeyToBaseConverter,
118 FunctorsFromDerivedClasses
120 >::type base_;
122 public:
124 typedef KeyType key_type;
126 protected:
128 typedef BOOST_DEDUCED_TYPENAME mpl::if_< ::boost::mpl::is_na<KeyToBaseConverter>,
129 // {
130 detail::key_to_base_identity
132 BOOST_DEDUCED_TYPENAME Base::key_type, KeyType
134 // }
135 // else
136 // {
137 KeyToBaseConverter
138 // }
140 >::type key_to_base;
142 public:
144 explicit associative_container_adaptor(Base & c)
145 : base_(c) {}
147 protected:
150 typedef associative_container_adaptor associative_container_adaptor_;
152 // Interface --------------------------------------------------------------
154 public:
156 template< class CompatibleKey >
157 BOOST_DEDUCED_TYPENAME base_::size_type erase(const CompatibleKey & k)
159 return this->base().erase
161 this->template functor<key_to_base>()(k)
165 // As we redefine erase, the other overloads need to be manually routed
167 BOOST_DEDUCED_TYPENAME base_::iterator erase(
168 BOOST_DEDUCED_TYPENAME base_::iterator pos)
170 return base_::container_adaptor_::erase(pos);
173 BOOST_DEDUCED_TYPENAME base_::iterator erase(
174 BOOST_DEDUCED_TYPENAME base_::iterator first,
175 BOOST_DEDUCED_TYPENAME base_::iterator last)
177 return base_::container_adaptor_::erase(first,last);
180 template< class CompatibleKey >
181 BOOST_DEDUCED_TYPENAME base_::size_type count(const CompatibleKey & k)
183 return this->base().count(
184 this->template functor<key_to_base>()(k)
188 template< class CompatibleKey >
189 BOOST_DEDUCED_TYPENAME base_::iterator find(const CompatibleKey & k)
191 return this->template functor<typename base_::iterator_from_base>()
193 this->base().find(
194 this->template functor<key_to_base>()(k)
199 template< class CompatibleKey >
200 BOOST_DEDUCED_TYPENAME base_::const_iterator
201 find(const CompatibleKey & k) const
203 return this->template functor<
204 BOOST_DEDUCED_TYPENAME base_::iterator_from_base>()
206 this->base().find(
207 this->template functor<key_to_base>()(k)
212 template< class CompatibleKey >
213 std::pair
215 BOOST_DEDUCED_TYPENAME base_::iterator,
216 BOOST_DEDUCED_TYPENAME base_::iterator
218 equal_range(const CompatibleKey & k)
220 std::pair<
222 BOOST_DEDUCED_TYPENAME Base::iterator,
223 BOOST_DEDUCED_TYPENAME Base::iterator
225 > r( this->base().equal_range(
226 this->template functor<key_to_base>()(k)
230 return std::pair
232 BOOST_DEDUCED_TYPENAME base_::iterator,
233 BOOST_DEDUCED_TYPENAME base_::iterator
235 this->template functor<
236 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
237 >() ( r.first ),
238 this->template functor<
239 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
240 >() ( r.second )
244 template< class CompatibleKey >
245 std::pair
247 BOOST_DEDUCED_TYPENAME base_::const_iterator,
248 BOOST_DEDUCED_TYPENAME base_::const_iterator
250 equal_range(const CompatibleKey & k) const
252 std::pair<
254 BOOST_DEDUCED_TYPENAME Base::const_iterator,
255 BOOST_DEDUCED_TYPENAME Base::const_iterator
257 > r( this->base().equal_range(
258 this->template functor<key_to_base>()(k)
262 return std::pair
264 BOOST_DEDUCED_TYPENAME base_::const_iterator,
265 BOOST_DEDUCED_TYPENAME base_::const_iterator
267 this->template functor<
268 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
269 >() ( r.first ),
270 this->template functor<
271 BOOST_DEDUCED_TYPENAME base_::iterator_from_base
272 >() ( r.second )
279 } // namespace container_adaptor
280 } // namespace bimaps
281 } // namespace boost
284 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_ASSOCIATIVE_CONTAINER_ADAPTOR_HPP