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/list_map_adaptor.hpp
10 /// \brief Container adaptor.
12 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_LIST_MAP_ADAPTOR_HPP
13 #define BOOST_BIMAP_CONTAINER_ADAPTOR_LIST_MAP_ADAPTOR_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
19 #include <boost/config.hpp>
21 #include <boost/mpl/list.hpp>
22 #include <boost/mpl/push_front.hpp>
24 #include <boost/bimap/container_adaptor/list_adaptor.hpp>
25 #include <boost/bimap/container_adaptor/detail/identity_converters.hpp>
26 #include <boost/bimap/container_adaptor/detail/key_extractor.hpp>
27 #include <boost/bimap/container_adaptor/detail/comparison_adaptor.hpp>
28 #include <boost/mpl/vector.hpp>
29 #include <boost/mpl/aux_/na.hpp>
30 #include <boost/mpl/if.hpp>
34 namespace container_adaptor
{
36 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
40 class Base
, class Iterator
, class ConstIterator
,
41 class ReverseIterator
, class ConstReverseIterator
,
42 class IteratorToBaseConverter
, class IteratorFromBaseConverter
,
43 class ReverseIteratorFromBaseConverter
,
44 class ValueToBaseConverter
, class ValueFromBaseConverter
,
45 class KeyFromBaseValueConverter
,
46 class FunctorsFromDerivedClasses
48 struct list_map_adaptor_base
54 Iterator
, ConstIterator
, ReverseIterator
, ConstReverseIterator
,
56 IteratorToBaseConverter
, IteratorFromBaseConverter
,
58 ReverseIteratorFromBaseConverter
,
60 ValueToBaseConverter
, ValueFromBaseConverter
,
62 BOOST_DEDUCED_TYPENAME
mpl::push_front
<
64 FunctorsFromDerivedClasses
,
66 BOOST_DEDUCED_TYPENAME
mpl::if_
< ::boost::mpl::is_na
<KeyFromBaseValueConverter
>,
68 detail::key_from_pair_extractor
70 BOOST_DEDUCED_TYPENAME
Iterator::value_type
75 KeyFromBaseValueConverter
85 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
87 /// \brief Container adaptor to easily build a list map container
95 class ReverseIterator
,
96 class ConstReverseIterator
,
98 class IteratorToBaseConverter
= ::boost::mpl::na
,
99 class IteratorFromBaseConverter
= ::boost::mpl::na
,
100 class ReverseIteratorFromBaseConverter
= ::boost::mpl::na
,
101 class ValueToBaseConverter
= ::boost::mpl::na
,
102 class ValueFromBaseConverter
= ::boost::mpl::na
,
103 class KeyFromBaseValueConverter
= ::boost::mpl::na
,
105 class FunctorsFromDerivedClasses
= mpl::vector
<>
107 class list_map_adaptor
:
109 public list_map_adaptor_base
111 Base
, Iterator
, ConstIterator
, ReverseIterator
, ConstReverseIterator
,
112 IteratorToBaseConverter
, IteratorFromBaseConverter
,
113 ReverseIteratorFromBaseConverter
,
114 ValueToBaseConverter
, ValueFromBaseConverter
,
115 KeyFromBaseValueConverter
,
116 FunctorsFromDerivedClasses
120 typedef BOOST_DEDUCED_TYPENAME list_map_adaptor_base
122 Base
, Iterator
, ConstIterator
, ReverseIterator
, ConstReverseIterator
,
123 IteratorToBaseConverter
, IteratorFromBaseConverter
,
124 ReverseIteratorFromBaseConverter
,
125 ValueToBaseConverter
, ValueFromBaseConverter
,
126 KeyFromBaseValueConverter
,
127 FunctorsFromDerivedClasses
131 // MetaData -------------------------------------------------------------
135 typedef BOOST_DEDUCED_TYPENAME
Iterator::value_type::first_type key_type
;
136 typedef BOOST_DEDUCED_TYPENAME
Iterator::value_type::second_type data_type
;
140 typedef BOOST_DEDUCED_TYPENAME
mpl::if_
< ::boost::mpl::is_na
<KeyFromBaseValueConverter
>,
142 detail::key_from_pair_extractor
< BOOST_DEDUCED_TYPENAME
Iterator::value_type
>,
146 KeyFromBaseValueConverter
149 >::type key_from_base_value
;
151 // Access -----------------------------------------------------------------
155 explicit list_map_adaptor(Base
& c
) :
160 typedef list_map_adaptor list_map_adaptor_
;
162 // Functions -------------------------------------------------------------
166 // The following functions are overwritten in order to work
167 // with key_type instead of value_type
169 template< class Predicate
>
170 void remove_if(Predicate pred
)
172 this->base().remove_if(
173 ::boost::bimaps::container_adaptor::detail::unary_check_adaptor
176 BOOST_DEDUCED_TYPENAME
Base::value_type
,
179 >( pred
, this->template functor
<key_from_base_value
>() )
186 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
188 std::equal_to
<key_type
>,
189 BOOST_DEDUCED_TYPENAME
Base::value_type
,
193 std::equal_to
<key_type
>(),
194 this->template functor
<key_from_base_value
>()
199 template< class BinaryPredicate
>
200 void unique(BinaryPredicate binary_pred
)
203 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
206 BOOST_DEDUCED_TYPENAME
Base::value_type
,
209 >( binary_pred
, this->template functor
<key_from_base_value
>() )
213 void merge(list_map_adaptor
& x
)
215 this->base().merge(x
.base(),
216 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
219 BOOST_DEDUCED_TYPENAME
Base::value_type
,
223 std::less
<key_type
>(),
224 this->template functor
<key_from_base_value
>()
229 template< class Compare
>
230 void merge(list_map_adaptor
& x
, Compare comp
)
232 this->base().merge(x
.base(),
233 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
236 BOOST_DEDUCED_TYPENAME
Base::value_type
,
239 >( comp
, this->template functor
<key_from_base_value
>() )
246 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
249 BOOST_DEDUCED_TYPENAME
Base::value_type
,
253 std::less
<key_type
>(),
254 this->template functor
<key_from_base_value
>()
259 template< class Compare
>
260 void sort(Compare comp
)
263 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
266 BOOST_DEDUCED_TYPENAME
Base::value_type
,
269 >( comp
, this->template functor
<key_from_base_value
>() )
276 } // namespace container_adaptor
277 } // namespace bimaps
281 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_LIST_MAP_ADAPTOR_HPP