3 // Copyright (c) 2006-2007 Matias Capeletto
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)
19 #include <boost/config.hpp>
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>
32 namespace container_adaptor
{
34 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
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
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
>,
60 detail::key_to_base_identity
62 BOOST_DEDUCED_TYPENAME
Base::key_type
, KeyType
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.
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
111 // MetaData -------------------------------------------------------------
113 typedef typename associative_container_adaptor_base
115 Base
, Iterator
, ConstIterator
, KeyType
,
116 IteratorToBaseConverter
, IteratorFromBaseConverter
,
117 ValueToBaseConverter
, ValueFromBaseConverter
, KeyToBaseConverter
,
118 FunctorsFromDerivedClasses
124 typedef KeyType key_type
;
128 typedef BOOST_DEDUCED_TYPENAME
mpl::if_
< ::boost::mpl::is_na
<KeyToBaseConverter
>,
130 detail::key_to_base_identity
132 BOOST_DEDUCED_TYPENAME
Base::key_type
, KeyType
144 explicit associative_container_adaptor(Base
& c
)
150 typedef associative_container_adaptor associative_container_adaptor_
;
152 // Interface --------------------------------------------------------------
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
>()
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
>()
207 this->template functor
<key_to_base
>()(k
)
212 template< class CompatibleKey
>
215 BOOST_DEDUCED_TYPENAME
base_::iterator
,
216 BOOST_DEDUCED_TYPENAME
base_::iterator
218 equal_range(const CompatibleKey
& k
)
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
)
232 BOOST_DEDUCED_TYPENAME
base_::iterator
,
233 BOOST_DEDUCED_TYPENAME
base_::iterator
235 this->template functor
<
236 BOOST_DEDUCED_TYPENAME
base_::iterator_from_base
238 this->template functor
<
239 BOOST_DEDUCED_TYPENAME
base_::iterator_from_base
244 template< class CompatibleKey
>
247 BOOST_DEDUCED_TYPENAME
base_::const_iterator
,
248 BOOST_DEDUCED_TYPENAME
base_::const_iterator
250 equal_range(const CompatibleKey
& k
) const
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
)
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
270 this->template functor
<
271 BOOST_DEDUCED_TYPENAME
base_::iterator_from_base
279 } // namespace container_adaptor
280 } // namespace bimaps
284 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_ASSOCIATIVE_CONTAINER_ADAPTOR_HPP