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 views/vector_map_view.hpp
10 /// \brief View of a side of a bimap.
12 #ifndef BOOST_BIMAP_VIEWS_VECTOR_MAP_VIEW_HPP
13 #define BOOST_BIMAP_VIEWS_VECTOR_MAP_VIEW_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
19 #include <boost/config.hpp>
21 #include <boost/bimap/container_adaptor/vector_map_adaptor.hpp>
22 #include <boost/bimap/support/iterator_type_by.hpp>
23 #include <boost/bimap/detail/map_view_base.hpp>
24 #include <boost/bimap/container_adaptor/detail/comparison_adaptor.hpp>
30 /// \brief View of a side of a bimap.
33 This class uses container_adaptor and iterator_adaptor to wrapped a index of the
34 multi_index bimap core.
36 See also const_map_view.
38 template< class Tag
, class BimapType
>
41 public BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
44 reverse_iterator_type_by
, const_reverse_iterator_type_by
47 public ::boost::bimaps::detail::
48 map_view_base
< vector_map_view
<Tag
,BimapType
>,Tag
,BimapType
>
50 typedef BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(
53 reverse_iterator_type_by
, const_reverse_iterator_type_by
57 BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(vector_map_view
,Tag
,BimapType
)
59 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::data_extractor
62 BOOST_DEDUCED_TYPENAME
BimapType::relation
64 >::type key_from_base_value
;
68 typedef BOOST_DEDUCED_TYPENAME
base_::value_type::info_type info_type
;
70 vector_map_view(BOOST_DEDUCED_TYPENAME
base_::base_type
& c
) :
73 vector_map_view
& operator=(const vector_map_view
& v
)
75 this->base() = v
.base();
79 BOOST_BIMAP_VIEW_ASSIGN_IMPLEMENTATION(base_
)
81 BOOST_BIMAP_VIEW_FRONT_BACK_IMPLEMENTATION(base_
)
85 void splice(BOOST_DEDUCED_TYPENAME
base_::iterator position
, vector_map_view
& x
)
88 this->template functor
<
89 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(position
),
94 void splice(BOOST_DEDUCED_TYPENAME
base_::iterator position
,
96 BOOST_DEDUCED_TYPENAME
base_::iterator i
)
99 this->template functor
<
100 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(position
),
102 this->template functor
<
103 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(i
)
107 void splice(BOOST_DEDUCED_TYPENAME
base_::iterator position
,
109 BOOST_DEDUCED_TYPENAME
base_::iterator first
,
110 BOOST_DEDUCED_TYPENAME
base_::iterator last
)
113 this->template functor
<
114 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(position
),
116 this->template functor
<
117 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(first
),
118 this->template functor
<
119 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(last
)
123 void remove(BOOST_DEDUCED_TYPENAME ::boost::call_traits
<
124 BOOST_DEDUCED_TYPENAME
base_::value_type
>::param_type value
)
127 this->template functor
<
128 BOOST_DEDUCED_TYPENAME
base_::value_to_base
>()(value
)
132 template< class Predicate
>
133 void remove_if(Predicate pred
)
135 this->base().remove_if(
136 ::boost::bimaps::container_adaptor::detail::unary_check_adaptor
139 BOOST_DEDUCED_TYPENAME
base_::base_type::value_type
,
142 >( pred
, key_from_base_value() )
149 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
151 std::equal_to
<BOOST_DEDUCED_TYPENAME
base_::key_type
>,
152 BOOST_DEDUCED_TYPENAME
base_::base_type::value_type
,
155 >(std::equal_to
<BOOST_DEDUCED_TYPENAME
base_::key_type
>(),
156 key_from_base_value() )
160 template< class BinaryPredicate
>
161 void unique(BinaryPredicate binary_pred
)
164 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
167 BOOST_DEDUCED_TYPENAME
base_::base_type::value_type
,
170 >( binary_pred
, key_from_base_value() )
174 void merge(vector_map_view
& x
)
176 this->base().merge(x
.base(),
177 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
179 std::less
<BOOST_DEDUCED_TYPENAME
base_::key_type
>,
180 BOOST_DEDUCED_TYPENAME
base_::base_type::value_type
,
183 >( std::less
<BOOST_DEDUCED_TYPENAME
base_::key_type
>(),
184 key_from_base_value() )
188 template< class Compare
>
189 void merge(vector_map_view
& x
, Compare comp
)
191 this->base().merge(x
.base(),
192 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
195 BOOST_DEDUCED_TYPENAME
base_::base_type::value_type
,
198 >( comp
, key_from_base_value() )
205 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
207 std::less
<BOOST_DEDUCED_TYPENAME
base_::key_type
>,
208 BOOST_DEDUCED_TYPENAME
base_::base_type::value_type
,
211 >( std::less
<BOOST_DEDUCED_TYPENAME
base_::key_type
>(),
212 key_from_base_value() )
216 template< class Compare
>
217 void sort(Compare comp
)
220 ::boost::bimaps::container_adaptor::detail::comparison_adaptor
223 BOOST_DEDUCED_TYPENAME
base_::base_type::value_type
,
226 >( comp
, key_from_base_value() )
232 this->base().reverse();
235 // Rearrange Operations
237 void relocate(BOOST_DEDUCED_TYPENAME
base_::iterator position
,
238 BOOST_DEDUCED_TYPENAME
base_::iterator i
)
240 this->base().relocate(
241 this->template functor
<
242 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(position
),
243 this->template functor
<
244 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(i
)
248 void relocate(BOOST_DEDUCED_TYPENAME
base_::iterator position
,
249 BOOST_DEDUCED_TYPENAME
base_::iterator first
,
250 BOOST_DEDUCED_TYPENAME
base_::iterator last
)
252 this->base().relocate(
253 this->template functor
<
254 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(position
),
255 this->template functor
<
256 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(first
),
257 this->template functor
<
258 BOOST_DEDUCED_TYPENAME
base_::iterator_to_base
>()(last
)
267 /*===========================================================================*/
268 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,TYPENAME) \
269 typedef BOOST_DEDUCED_TYPENAME MAP_VIEW::TYPENAME \
270 BOOST_PP_CAT(SIDE,BOOST_PP_CAT(_,TYPENAME));
271 /*===========================================================================*/
273 /*===========================================================================*/
274 #define BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(MAP_VIEW,SIDE) \
275 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,reverse_iterator) \
276 BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF(MAP_VIEW,SIDE,const_reverse_iterator) \
277 /*===========================================================================*/
281 template< class Tag
, class BimapType
>
282 struct left_map_view_extra_typedefs
< ::boost::bimaps::views::vector_map_view
<Tag
,BimapType
> >
284 private: typedef ::boost::bimaps::views::vector_map_view
<Tag
,BimapType
> map_view_
;
285 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_
,left
)
288 template< class Tag
, class BimapType
>
289 struct right_map_view_extra_typedefs
< ::boost::bimaps::views::vector_map_view
<Tag
,BimapType
> >
291 private: typedef ::boost::bimaps::views::vector_map_view
<Tag
,BimapType
> map_view_
;
292 public : BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY(map_view_
,right
)
295 } // namespace detail
297 /*===========================================================================*/
298 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEF
299 #undef BOOST_BIMAP_MAP_VIEW_EXTRA_TYPEDEFS_BODY
300 /*===========================================================================*/
302 } // namespace bimaps
305 #endif // BOOST_BIMAP_VIEWS_VECTOR_MAP_VIEW_HPP