fix doc example typo
[boost.git] / boost / bimap / container_adaptor / list_map_adaptor.hpp
blobff7a5407af636a0b9d39da46e186051b081871af
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/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)
16 #pragma once
17 #endif
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>
32 namespace boost {
33 namespace bimaps {
34 namespace container_adaptor {
36 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
38 template
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
50 typedef list_adaptor
52 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>,
67 // {
68 detail::key_from_pair_extractor
70 BOOST_DEDUCED_TYPENAME Iterator::value_type
72 // }
73 // else
74 // {
75 KeyFromBaseValueConverter
76 // }
78 >::type
80 >::type
82 > type;
85 #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
87 /// \brief Container adaptor to easily build a list map container
89 template
91 class Base,
93 class Iterator,
94 class ConstIterator,
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
118 >::type
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
129 >::type base_;
131 // MetaData -------------------------------------------------------------
133 public:
135 typedef BOOST_DEDUCED_TYPENAME Iterator::value_type::first_type key_type;
136 typedef BOOST_DEDUCED_TYPENAME Iterator::value_type::second_type data_type;
138 protected:
140 typedef BOOST_DEDUCED_TYPENAME mpl::if_< ::boost::mpl::is_na<KeyFromBaseValueConverter>,
141 // {
142 detail::key_from_pair_extractor< BOOST_DEDUCED_TYPENAME Iterator::value_type >,
143 // }
144 // else
145 // {
146 KeyFromBaseValueConverter
147 // }
149 >::type key_from_base_value;
151 // Access -----------------------------------------------------------------
153 public:
155 explicit list_map_adaptor(Base & c) :
156 base_(c) {}
158 protected:
160 typedef list_map_adaptor list_map_adaptor_;
162 // Functions -------------------------------------------------------------
164 public:
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
175 Predicate,
176 BOOST_DEDUCED_TYPENAME Base::value_type,
177 key_from_base_value
179 >( pred, this->template functor<key_from_base_value>() )
183 void unique()
185 this->base().unique(
186 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
188 std::equal_to<key_type>,
189 BOOST_DEDUCED_TYPENAME Base::value_type,
190 key_from_base_value
193 std::equal_to<key_type>(),
194 this->template functor<key_from_base_value>()
199 template< class BinaryPredicate >
200 void unique(BinaryPredicate binary_pred)
202 this->base().unique(
203 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
205 BinaryPredicate,
206 BOOST_DEDUCED_TYPENAME Base::value_type,
207 key_from_base_value
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
218 std::less<key_type>,
219 BOOST_DEDUCED_TYPENAME Base::value_type,
220 key_from_base_value
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
235 Compare,
236 BOOST_DEDUCED_TYPENAME Base::value_type,
237 key_from_base_value
239 >( comp, this->template functor<key_from_base_value>() )
243 void sort()
245 this->base().sort(
246 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
248 std::less<key_type>,
249 BOOST_DEDUCED_TYPENAME Base::value_type,
250 key_from_base_value
253 std::less<key_type>(),
254 this->template functor<key_from_base_value>()
259 template< class Compare >
260 void sort(Compare comp)
262 this->base().sort(
263 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
265 Compare,
266 BOOST_DEDUCED_TYPENAME Base::value_type,
267 key_from_base_value
269 >( comp, this->template functor<key_from_base_value>() )
276 } // namespace container_adaptor
277 } // namespace bimaps
278 } // namespace boost
281 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_LIST_MAP_ADAPTOR_HPP