Chris@16
|
1 /* Multiply indexed container.
|
Chris@16
|
2 *
|
Chris@16
|
3 * Copyright 2003-2013 Joaquin M Lopez Munoz.
|
Chris@16
|
4 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
5 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 *
|
Chris@16
|
8 * See http://www.boost.org/libs/multi_index for library home page.
|
Chris@16
|
9 */
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_MULTI_INDEX_HPP
|
Chris@16
|
12 #define BOOST_MULTI_INDEX_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
|
Chris@16
|
15 #pragma once
|
Chris@16
|
16 #endif
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
|
Chris@16
|
19 #include <algorithm>
|
Chris@16
|
20 #include <boost/detail/allocator_utilities.hpp>
|
Chris@16
|
21 #include <boost/detail/no_exceptions_support.hpp>
|
Chris@16
|
22 #include <boost/detail/workaround.hpp>
|
Chris@16
|
23 #include <boost/move/core.hpp>
|
Chris@16
|
24 #include <boost/mpl/at.hpp>
|
Chris@16
|
25 #include <boost/mpl/contains.hpp>
|
Chris@16
|
26 #include <boost/mpl/find_if.hpp>
|
Chris@16
|
27 #include <boost/mpl/identity.hpp>
|
Chris@16
|
28 #include <boost/mpl/int.hpp>
|
Chris@16
|
29 #include <boost/mpl/size.hpp>
|
Chris@16
|
30 #include <boost/mpl/deref.hpp>
|
Chris@16
|
31 #include <boost/multi_index_container_fwd.hpp>
|
Chris@16
|
32 #include <boost/multi_index/detail/access_specifier.hpp>
|
Chris@16
|
33 #include <boost/multi_index/detail/adl_swap.hpp>
|
Chris@16
|
34 #include <boost/multi_index/detail/base_type.hpp>
|
Chris@16
|
35 #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
|
Chris@16
|
36 #include <boost/multi_index/detail/converter.hpp>
|
Chris@16
|
37 #include <boost/multi_index/detail/header_holder.hpp>
|
Chris@16
|
38 #include <boost/multi_index/detail/has_tag.hpp>
|
Chris@16
|
39 #include <boost/multi_index/detail/no_duplicate_tags.hpp>
|
Chris@16
|
40 #include <boost/multi_index/detail/prevent_eti.hpp>
|
Chris@16
|
41 #include <boost/multi_index/detail/safe_mode.hpp>
|
Chris@16
|
42 #include <boost/multi_index/detail/scope_guard.hpp>
|
Chris@16
|
43 #include <boost/multi_index/detail/vartempl_support.hpp>
|
Chris@16
|
44 #include <boost/static_assert.hpp>
|
Chris@16
|
45 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
46 #include <boost/utility/base_from_member.hpp>
|
Chris@16
|
47
|
Chris@16
|
48 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
Chris@16
|
49 #include <initializer_list>
|
Chris@16
|
50 #endif
|
Chris@16
|
51
|
Chris@16
|
52 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
|
Chris@16
|
53 #include <boost/multi_index/detail/archive_constructed.hpp>
|
Chris@16
|
54 #include <boost/multi_index/detail/serialization_version.hpp>
|
Chris@16
|
55 #include <boost/serialization/collection_size_type.hpp>
|
Chris@16
|
56 #include <boost/serialization/nvp.hpp>
|
Chris@16
|
57 #include <boost/serialization/split_member.hpp>
|
Chris@16
|
58 #include <boost/serialization/version.hpp>
|
Chris@16
|
59 #include <boost/throw_exception.hpp>
|
Chris@16
|
60 #endif
|
Chris@16
|
61
|
Chris@16
|
62 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
|
Chris@16
|
63 #include <boost/multi_index/detail/invariant_assert.hpp>
|
Chris@16
|
64 #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x) \
|
Chris@16
|
65 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
|
Chris@16
|
66 detail::make_obj_guard(x,&multi_index_container::check_invariant_); \
|
Chris@16
|
67 BOOST_JOIN(check_invariant_,__LINE__).touch();
|
Chris@16
|
68 #define BOOST_MULTI_INDEX_CHECK_INVARIANT \
|
Chris@16
|
69 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(*this)
|
Chris@16
|
70 #else
|
Chris@16
|
71 #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x)
|
Chris@16
|
72 #define BOOST_MULTI_INDEX_CHECK_INVARIANT
|
Chris@16
|
73 #endif
|
Chris@16
|
74
|
Chris@16
|
75 namespace boost{
|
Chris@16
|
76
|
Chris@16
|
77 namespace multi_index{
|
Chris@16
|
78
|
Chris@16
|
79 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
|
Chris@16
|
80 #pragma warning(push)
|
Chris@16
|
81 #pragma warning(disable:4522) /* spurious warning on multiple operator=()'s */
|
Chris@16
|
82 #endif
|
Chris@16
|
83
|
Chris@16
|
84 template<typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
85 class multi_index_container:
|
Chris@16
|
86 private ::boost::base_from_member<
|
Chris@16
|
87 typename boost::detail::allocator::rebind_to<
|
Chris@16
|
88 Allocator,
|
Chris@16
|
89 typename detail::multi_index_node_type<
|
Chris@16
|
90 Value,IndexSpecifierList,Allocator>::type
|
Chris@16
|
91 >::type>,
|
Chris@16
|
92 BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS detail::header_holder<
|
Chris@16
|
93 typename detail::prevent_eti<
|
Chris@16
|
94 Allocator,
|
Chris@16
|
95 typename boost::detail::allocator::rebind_to<
|
Chris@16
|
96 Allocator,
|
Chris@16
|
97 typename detail::multi_index_node_type<
|
Chris@16
|
98 Value,IndexSpecifierList,Allocator>::type
|
Chris@16
|
99 >::type
|
Chris@16
|
100 >::type::pointer,
|
Chris@16
|
101 multi_index_container<Value,IndexSpecifierList,Allocator> >,
|
Chris@16
|
102 public detail::multi_index_base_type<
|
Chris@16
|
103 Value,IndexSpecifierList,Allocator>::type
|
Chris@16
|
104 {
|
Chris@16
|
105 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
|
Chris@16
|
106 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
|
Chris@16
|
107 /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
|
Chris@16
|
108 * lifetime of const references bound to temporaries --precisely what
|
Chris@16
|
109 * scopeguards are.
|
Chris@16
|
110 */
|
Chris@16
|
111
|
Chris@16
|
112 #pragma parse_mfunc_templ off
|
Chris@16
|
113 #endif
|
Chris@16
|
114
|
Chris@16
|
115 private:
|
Chris@16
|
116 BOOST_COPYABLE_AND_MOVABLE(multi_index_container)
|
Chris@16
|
117
|
Chris@16
|
118 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
Chris@16
|
119 template <typename,typename,typename> friend class detail::index_base;
|
Chris@16
|
120 template <typename,typename> friend struct detail::header_holder;
|
Chris@16
|
121 template <typename,typename> friend struct detail::converter;
|
Chris@16
|
122 #endif
|
Chris@16
|
123
|
Chris@16
|
124 typedef typename detail::multi_index_base_type<
|
Chris@16
|
125 Value,IndexSpecifierList,Allocator>::type super;
|
Chris@16
|
126 typedef typename
|
Chris@16
|
127 boost::detail::allocator::rebind_to<
|
Chris@16
|
128 Allocator,
|
Chris@16
|
129 typename super::node_type
|
Chris@16
|
130 >::type node_allocator;
|
Chris@16
|
131 typedef ::boost::base_from_member<
|
Chris@16
|
132 node_allocator> bfm_allocator;
|
Chris@16
|
133 typedef detail::header_holder<
|
Chris@16
|
134 typename detail::prevent_eti<
|
Chris@16
|
135 Allocator,
|
Chris@16
|
136 node_allocator
|
Chris@16
|
137 >::type::pointer,
|
Chris@16
|
138 multi_index_container> bfm_header;
|
Chris@16
|
139
|
Chris@16
|
140 #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
|
Chris@16
|
141 /* see definition of index_type_list below */
|
Chris@16
|
142 typedef typename super::index_type_list super_index_type_list;
|
Chris@16
|
143 #endif
|
Chris@16
|
144
|
Chris@16
|
145 public:
|
Chris@16
|
146 /* All types are inherited from super, a few are explicitly
|
Chris@16
|
147 * brought forward here to save us some typename's.
|
Chris@16
|
148 */
|
Chris@16
|
149
|
Chris@16
|
150 typedef typename super::ctor_args_list ctor_args_list;
|
Chris@16
|
151 typedef IndexSpecifierList index_specifier_type_list;
|
Chris@16
|
152
|
Chris@16
|
153 #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
|
Chris@16
|
154 /* MSVC++ 6.0 chokes on moderately long index lists (around 6 indices
|
Chris@16
|
155 * or more), with errors ranging from corrupt exes to duplicate
|
Chris@16
|
156 * comdats. The following type hiding hack alleviates this condition;
|
Chris@16
|
157 * best results combined with type hiding of the indexed_by construct
|
Chris@16
|
158 * itself, as explained in the "Compiler specifics" section of
|
Chris@16
|
159 * the documentation.
|
Chris@16
|
160 */
|
Chris@16
|
161
|
Chris@16
|
162 struct index_type_list:super_index_type_list
|
Chris@16
|
163 {
|
Chris@16
|
164 typedef index_type_list type;
|
Chris@16
|
165 typedef typename super_index_type_list::back back;
|
Chris@16
|
166 typedef mpl::v_iter<type,0> begin;
|
Chris@16
|
167 typedef mpl::v_iter<
|
Chris@16
|
168 type,
|
Chris@16
|
169 mpl::size<super_index_type_list>::value> end;
|
Chris@16
|
170 };
|
Chris@16
|
171 #else
|
Chris@16
|
172 typedef typename super::index_type_list index_type_list;
|
Chris@16
|
173 #endif
|
Chris@16
|
174
|
Chris@16
|
175 typedef typename super::iterator_type_list iterator_type_list;
|
Chris@16
|
176 typedef typename super::const_iterator_type_list const_iterator_type_list;
|
Chris@16
|
177 typedef typename super::value_type value_type;
|
Chris@16
|
178 typedef typename super::final_allocator_type allocator_type;
|
Chris@16
|
179 typedef typename super::iterator iterator;
|
Chris@16
|
180 typedef typename super::const_iterator const_iterator;
|
Chris@16
|
181
|
Chris@16
|
182 BOOST_STATIC_ASSERT(
|
Chris@16
|
183 detail::no_duplicate_tags_in_index_list<index_type_list>::value);
|
Chris@16
|
184
|
Chris@16
|
185 /* global project() needs to see this publicly */
|
Chris@16
|
186
|
Chris@16
|
187 typedef typename super::node_type node_type;
|
Chris@16
|
188
|
Chris@16
|
189 /* construct/copy/destroy */
|
Chris@16
|
190
|
Chris@16
|
191 explicit multi_index_container(
|
Chris@16
|
192
|
Chris@16
|
193 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
|
Chris@16
|
194 /* VisualAge seems to have an ETI issue with the default values
|
Chris@16
|
195 * for arguments args_list and al.
|
Chris@16
|
196 */
|
Chris@16
|
197
|
Chris@16
|
198 const ctor_args_list& args_list=
|
Chris@16
|
199 typename mpl::identity<multi_index_container>::type::
|
Chris@16
|
200 ctor_args_list(),
|
Chris@16
|
201 const allocator_type& al=
|
Chris@16
|
202 typename mpl::identity<multi_index_container>::type::
|
Chris@16
|
203 allocator_type()):
|
Chris@16
|
204 #else
|
Chris@16
|
205 const ctor_args_list& args_list=ctor_args_list(),
|
Chris@16
|
206 const allocator_type& al=allocator_type()):
|
Chris@16
|
207 #endif
|
Chris@16
|
208
|
Chris@16
|
209 bfm_allocator(al),
|
Chris@16
|
210 super(args_list,bfm_allocator::member),
|
Chris@16
|
211 node_count(0)
|
Chris@16
|
212 {
|
Chris@16
|
213 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
214 }
|
Chris@16
|
215
|
Chris@16
|
216 explicit multi_index_container(const allocator_type& al):
|
Chris@16
|
217 bfm_allocator(al),
|
Chris@16
|
218 super(ctor_args_list(),bfm_allocator::member),
|
Chris@16
|
219 node_count(0)
|
Chris@16
|
220 {
|
Chris@16
|
221 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
222 }
|
Chris@16
|
223
|
Chris@16
|
224 template<typename InputIterator>
|
Chris@16
|
225 multi_index_container(
|
Chris@16
|
226 InputIterator first,InputIterator last,
|
Chris@16
|
227
|
Chris@16
|
228 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
|
Chris@16
|
229 /* VisualAge seems to have an ETI issue with the default values
|
Chris@16
|
230 * for arguments args_list and al.
|
Chris@16
|
231 */
|
Chris@16
|
232
|
Chris@16
|
233 const ctor_args_list& args_list=
|
Chris@16
|
234 typename mpl::identity<multi_index_container>::type::
|
Chris@16
|
235 ctor_args_list(),
|
Chris@16
|
236 const allocator_type& al=
|
Chris@16
|
237 typename mpl::identity<multi_index_container>::type::
|
Chris@16
|
238 allocator_type()):
|
Chris@16
|
239 #else
|
Chris@16
|
240 const ctor_args_list& args_list=ctor_args_list(),
|
Chris@16
|
241 const allocator_type& al=allocator_type()):
|
Chris@16
|
242 #endif
|
Chris@16
|
243
|
Chris@16
|
244 bfm_allocator(al),
|
Chris@16
|
245 super(args_list,bfm_allocator::member),
|
Chris@16
|
246 node_count(0)
|
Chris@16
|
247 {
|
Chris@16
|
248 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
249 BOOST_TRY{
|
Chris@16
|
250 iterator hint=super::end();
|
Chris@16
|
251 for(;first!=last;++first){
|
Chris@16
|
252 hint=super::make_iterator(
|
Chris@16
|
253 insert_ref_(*first,hint.get_node()).first);
|
Chris@16
|
254 ++hint;
|
Chris@16
|
255 }
|
Chris@16
|
256 }
|
Chris@16
|
257 BOOST_CATCH(...){
|
Chris@16
|
258 clear_();
|
Chris@16
|
259 BOOST_RETHROW;
|
Chris@16
|
260 }
|
Chris@16
|
261 BOOST_CATCH_END
|
Chris@16
|
262 }
|
Chris@16
|
263
|
Chris@16
|
264 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
Chris@16
|
265 multi_index_container(
|
Chris@16
|
266 std::initializer_list<Value> list,
|
Chris@16
|
267 const ctor_args_list& args_list=ctor_args_list(),
|
Chris@16
|
268 const allocator_type& al=allocator_type()):
|
Chris@16
|
269 bfm_allocator(al),
|
Chris@16
|
270 super(args_list,bfm_allocator::member),
|
Chris@16
|
271 node_count(0)
|
Chris@16
|
272 {
|
Chris@16
|
273 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
274 BOOST_TRY{
|
Chris@16
|
275 typedef typename std::initializer_list<Value>::iterator init_iterator;
|
Chris@16
|
276
|
Chris@16
|
277 iterator hint=super::end();
|
Chris@16
|
278 for(init_iterator first=list.begin(),last=list.end();
|
Chris@16
|
279 first!=last;++first){
|
Chris@16
|
280 hint=super::make_iterator(insert_(*first,hint.get_node()).first);
|
Chris@16
|
281 ++hint;
|
Chris@16
|
282 }
|
Chris@16
|
283 }
|
Chris@16
|
284 BOOST_CATCH(...){
|
Chris@16
|
285 clear_();
|
Chris@16
|
286 BOOST_RETHROW;
|
Chris@16
|
287 }
|
Chris@16
|
288 BOOST_CATCH_END
|
Chris@16
|
289 }
|
Chris@16
|
290 #endif
|
Chris@16
|
291
|
Chris@16
|
292 multi_index_container(
|
Chris@16
|
293 const multi_index_container<Value,IndexSpecifierList,Allocator>& x):
|
Chris@16
|
294 bfm_allocator(x.bfm_allocator::member),
|
Chris@16
|
295 bfm_header(),
|
Chris@16
|
296 super(x),
|
Chris@16
|
297 node_count(0)
|
Chris@16
|
298 {
|
Chris@16
|
299 copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
|
Chris@16
|
300 for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
|
Chris@16
|
301 map.clone(it.get_node());
|
Chris@16
|
302 }
|
Chris@16
|
303 super::copy_(x,map);
|
Chris@16
|
304 map.release();
|
Chris@16
|
305 node_count=x.size();
|
Chris@16
|
306
|
Chris@16
|
307 /* Not until this point are the indices required to be consistent,
|
Chris@16
|
308 * hence the position of the invariant checker.
|
Chris@16
|
309 */
|
Chris@16
|
310
|
Chris@16
|
311 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
312 }
|
Chris@16
|
313
|
Chris@16
|
314 multi_index_container(BOOST_RV_REF(multi_index_container) x):
|
Chris@16
|
315 bfm_allocator(x.bfm_allocator::member),
|
Chris@16
|
316 bfm_header(),
|
Chris@16
|
317 super(x,detail::do_not_copy_elements_tag()),
|
Chris@16
|
318 node_count(0)
|
Chris@16
|
319 {
|
Chris@16
|
320 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
321 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
|
Chris@16
|
322 swap_elements_(x);
|
Chris@16
|
323 }
|
Chris@16
|
324
|
Chris@16
|
325 ~multi_index_container()
|
Chris@16
|
326 {
|
Chris@16
|
327 delete_all_nodes_();
|
Chris@16
|
328 }
|
Chris@16
|
329
|
Chris@16
|
330 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
331 /* As per http://www.boost.org/doc/html/move/emulation_limitations.html
|
Chris@16
|
332 * #move.emulation_limitations.assignment_operator
|
Chris@16
|
333 */
|
Chris@16
|
334
|
Chris@16
|
335 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
|
Chris@16
|
336 const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
|
Chris@16
|
337 {
|
Chris@16
|
338 multi_index_container y(x);
|
Chris@16
|
339 this->swap(y);
|
Chris@16
|
340 return *this;
|
Chris@16
|
341 }
|
Chris@16
|
342 #endif
|
Chris@16
|
343
|
Chris@16
|
344 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
|
Chris@16
|
345 BOOST_COPY_ASSIGN_REF(multi_index_container) x)
|
Chris@16
|
346 {
|
Chris@16
|
347 multi_index_container y(x);
|
Chris@16
|
348 this->swap(y);
|
Chris@16
|
349 return *this;
|
Chris@16
|
350 }
|
Chris@16
|
351
|
Chris@16
|
352 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
|
Chris@16
|
353 BOOST_RV_REF(multi_index_container) x)
|
Chris@16
|
354 {
|
Chris@16
|
355 this->swap(x);
|
Chris@16
|
356 return *this;
|
Chris@16
|
357 }
|
Chris@16
|
358
|
Chris@16
|
359 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
Chris@16
|
360 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
|
Chris@16
|
361 std::initializer_list<Value> list)
|
Chris@16
|
362 {
|
Chris@16
|
363 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
364 typedef typename std::initializer_list<Value>::iterator init_iterator;
|
Chris@16
|
365
|
Chris@16
|
366 multi_index_container x(*this,detail::do_not_copy_elements_tag());
|
Chris@16
|
367 iterator hint=x.end();
|
Chris@16
|
368 for(init_iterator first=list.begin(),last=list.end();
|
Chris@16
|
369 first!=last;++first){
|
Chris@16
|
370 hint=x.make_iterator(x.insert_(*first,hint.get_node()).first);
|
Chris@16
|
371 ++hint;
|
Chris@16
|
372 }
|
Chris@16
|
373 x.swap_elements_(*this);
|
Chris@16
|
374 return*this;
|
Chris@16
|
375 }
|
Chris@16
|
376 #endif
|
Chris@16
|
377
|
Chris@16
|
378 allocator_type get_allocator()const
|
Chris@16
|
379 {
|
Chris@16
|
380 return allocator_type(bfm_allocator::member);
|
Chris@16
|
381 }
|
Chris@16
|
382
|
Chris@16
|
383 /* retrieval of indices by number */
|
Chris@16
|
384
|
Chris@16
|
385 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
|
Chris@16
|
386 template<int N>
|
Chris@16
|
387 struct nth_index
|
Chris@16
|
388 {
|
Chris@16
|
389 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
|
Chris@16
|
390 typedef typename mpl::at_c<index_type_list,N>::type type;
|
Chris@16
|
391 };
|
Chris@16
|
392
|
Chris@16
|
393 template<int N>
|
Chris@16
|
394 typename nth_index<N>::type& get(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
|
Chris@16
|
395 {
|
Chris@16
|
396 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
|
Chris@16
|
397 return *this;
|
Chris@16
|
398 }
|
Chris@16
|
399
|
Chris@16
|
400 template<int N>
|
Chris@16
|
401 const typename nth_index<N>::type& get(
|
Chris@16
|
402 BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int,N))const
|
Chris@16
|
403 {
|
Chris@16
|
404 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
|
Chris@16
|
405 return *this;
|
Chris@16
|
406 }
|
Chris@16
|
407 #endif
|
Chris@16
|
408
|
Chris@16
|
409 /* retrieval of indices by tag */
|
Chris@16
|
410
|
Chris@16
|
411 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
|
Chris@16
|
412 template<typename Tag>
|
Chris@16
|
413 struct index
|
Chris@16
|
414 {
|
Chris@16
|
415 typedef typename mpl::find_if<
|
Chris@16
|
416 index_type_list,
|
Chris@16
|
417 detail::has_tag<Tag>
|
Chris@16
|
418 >::type iter;
|
Chris@16
|
419
|
Chris@16
|
420 BOOST_STATIC_CONSTANT(
|
Chris@16
|
421 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
|
Chris@16
|
422 BOOST_STATIC_ASSERT(index_found);
|
Chris@16
|
423
|
Chris@16
|
424 typedef typename mpl::deref<iter>::type type;
|
Chris@16
|
425 };
|
Chris@16
|
426
|
Chris@16
|
427 template<typename Tag>
|
Chris@16
|
428 typename index<Tag>::type& get(BOOST_EXPLICIT_TEMPLATE_TYPE(Tag))
|
Chris@16
|
429 {
|
Chris@16
|
430 return *this;
|
Chris@16
|
431 }
|
Chris@16
|
432
|
Chris@16
|
433 template<typename Tag>
|
Chris@16
|
434 const typename index<Tag>::type& get(
|
Chris@16
|
435 BOOST_EXPLICIT_TEMPLATE_TYPE(Tag))const
|
Chris@16
|
436 {
|
Chris@16
|
437 return *this;
|
Chris@16
|
438 }
|
Chris@16
|
439 #endif
|
Chris@16
|
440
|
Chris@16
|
441 /* projection of iterators by number */
|
Chris@16
|
442
|
Chris@16
|
443 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
|
Chris@16
|
444 template<int N>
|
Chris@16
|
445 struct nth_index_iterator
|
Chris@16
|
446 {
|
Chris@16
|
447 typedef typename nth_index<N>::type::iterator type;
|
Chris@16
|
448 };
|
Chris@16
|
449
|
Chris@16
|
450 template<int N>
|
Chris@16
|
451 struct nth_index_const_iterator
|
Chris@16
|
452 {
|
Chris@16
|
453 typedef typename nth_index<N>::type::const_iterator type;
|
Chris@16
|
454 };
|
Chris@16
|
455
|
Chris@16
|
456 template<int N,typename IteratorType>
|
Chris@16
|
457 typename nth_index_iterator<N>::type project(
|
Chris@16
|
458 IteratorType it
|
Chris@16
|
459 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
|
Chris@16
|
460 {
|
Chris@16
|
461 typedef typename nth_index<N>::type index;
|
Chris@16
|
462
|
Chris@16
|
463 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
|
Chris@16
|
464 BOOST_STATIC_ASSERT(
|
Chris@16
|
465 (mpl::contains<iterator_type_list,IteratorType>::value));
|
Chris@16
|
466 #endif
|
Chris@16
|
467
|
Chris@16
|
468 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
469 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
|
Chris@16
|
470 it,static_cast<typename IteratorType::container_type&>(*this));
|
Chris@16
|
471
|
Chris@16
|
472 return index::make_iterator(static_cast<node_type*>(it.get_node()));
|
Chris@16
|
473 }
|
Chris@16
|
474
|
Chris@16
|
475 template<int N,typename IteratorType>
|
Chris@16
|
476 typename nth_index_const_iterator<N>::type project(
|
Chris@16
|
477 IteratorType it
|
Chris@16
|
478 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))const
|
Chris@16
|
479 {
|
Chris@16
|
480 typedef typename nth_index<N>::type index;
|
Chris@16
|
481
|
Chris@16
|
482 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
|
Chris@16
|
483 BOOST_STATIC_ASSERT((
|
Chris@16
|
484 mpl::contains<iterator_type_list,IteratorType>::value||
|
Chris@16
|
485 mpl::contains<const_iterator_type_list,IteratorType>::value));
|
Chris@16
|
486 #endif
|
Chris@16
|
487
|
Chris@16
|
488 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
489 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
|
Chris@16
|
490 it,static_cast<const typename IteratorType::container_type&>(*this));
|
Chris@16
|
491 return index::make_iterator(static_cast<node_type*>(it.get_node()));
|
Chris@16
|
492 }
|
Chris@16
|
493 #endif
|
Chris@16
|
494
|
Chris@16
|
495 /* projection of iterators by tag */
|
Chris@16
|
496
|
Chris@16
|
497 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
|
Chris@16
|
498 template<typename Tag>
|
Chris@16
|
499 struct index_iterator
|
Chris@16
|
500 {
|
Chris@16
|
501 typedef typename index<Tag>::type::iterator type;
|
Chris@16
|
502 };
|
Chris@16
|
503
|
Chris@16
|
504 template<typename Tag>
|
Chris@16
|
505 struct index_const_iterator
|
Chris@16
|
506 {
|
Chris@16
|
507 typedef typename index<Tag>::type::const_iterator type;
|
Chris@16
|
508 };
|
Chris@16
|
509
|
Chris@16
|
510 template<typename Tag,typename IteratorType>
|
Chris@16
|
511 typename index_iterator<Tag>::type project(
|
Chris@16
|
512 IteratorType it
|
Chris@16
|
513 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
|
Chris@16
|
514 {
|
Chris@16
|
515 typedef typename index<Tag>::type index;
|
Chris@16
|
516
|
Chris@16
|
517 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
|
Chris@16
|
518 BOOST_STATIC_ASSERT(
|
Chris@16
|
519 (mpl::contains<iterator_type_list,IteratorType>::value));
|
Chris@16
|
520 #endif
|
Chris@16
|
521
|
Chris@16
|
522 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
523 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
|
Chris@16
|
524 it,static_cast<typename IteratorType::container_type&>(*this));
|
Chris@16
|
525 return index::make_iterator(static_cast<node_type*>(it.get_node()));
|
Chris@16
|
526 }
|
Chris@16
|
527
|
Chris@16
|
528 template<typename Tag,typename IteratorType>
|
Chris@16
|
529 typename index_const_iterator<Tag>::type project(
|
Chris@16
|
530 IteratorType it
|
Chris@16
|
531 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))const
|
Chris@16
|
532 {
|
Chris@16
|
533 typedef typename index<Tag>::type index;
|
Chris@16
|
534
|
Chris@16
|
535 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
|
Chris@16
|
536 BOOST_STATIC_ASSERT((
|
Chris@16
|
537 mpl::contains<iterator_type_list,IteratorType>::value||
|
Chris@16
|
538 mpl::contains<const_iterator_type_list,IteratorType>::value));
|
Chris@16
|
539 #endif
|
Chris@16
|
540
|
Chris@16
|
541 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
542 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
|
Chris@16
|
543 it,static_cast<const typename IteratorType::container_type&>(*this));
|
Chris@16
|
544 return index::make_iterator(static_cast<node_type*>(it.get_node()));
|
Chris@16
|
545 }
|
Chris@16
|
546 #endif
|
Chris@16
|
547
|
Chris@16
|
548 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
|
Chris@16
|
549 typedef typename super::copy_map_type copy_map_type;
|
Chris@16
|
550
|
Chris@16
|
551 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
Chris@16
|
552 multi_index_container(
|
Chris@16
|
553 const multi_index_container<Value,IndexSpecifierList,Allocator>& x,
|
Chris@16
|
554 detail::do_not_copy_elements_tag):
|
Chris@16
|
555 bfm_allocator(x.bfm_allocator::member),
|
Chris@16
|
556 bfm_header(),
|
Chris@16
|
557 super(x,detail::do_not_copy_elements_tag()),
|
Chris@16
|
558 node_count(0)
|
Chris@16
|
559 {
|
Chris@16
|
560 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
561 }
|
Chris@16
|
562 #endif
|
Chris@16
|
563
|
Chris@16
|
564 node_type* header()const
|
Chris@16
|
565 {
|
Chris@16
|
566 return &*bfm_header::member;
|
Chris@16
|
567 }
|
Chris@16
|
568
|
Chris@16
|
569 node_type* allocate_node()
|
Chris@16
|
570 {
|
Chris@16
|
571 return &*bfm_allocator::member.allocate(1);
|
Chris@16
|
572 }
|
Chris@16
|
573
|
Chris@16
|
574 void deallocate_node(node_type* x)
|
Chris@16
|
575 {
|
Chris@16
|
576 typedef typename node_allocator::pointer node_pointer;
|
Chris@16
|
577 bfm_allocator::member.deallocate(static_cast<node_pointer>(x),1);
|
Chris@16
|
578 }
|
Chris@16
|
579
|
Chris@16
|
580 bool empty_()const
|
Chris@16
|
581 {
|
Chris@16
|
582 return node_count==0;
|
Chris@16
|
583 }
|
Chris@16
|
584
|
Chris@16
|
585 std::size_t size_()const
|
Chris@16
|
586 {
|
Chris@16
|
587 return node_count;
|
Chris@16
|
588 }
|
Chris@16
|
589
|
Chris@16
|
590 std::size_t max_size_()const
|
Chris@16
|
591 {
|
Chris@16
|
592 return static_cast<std::size_t >(-1);
|
Chris@16
|
593 }
|
Chris@16
|
594
|
Chris@16
|
595 template<typename Variant>
|
Chris@16
|
596 std::pair<node_type*,bool> insert_(const Value& v,Variant variant)
|
Chris@16
|
597 {
|
Chris@16
|
598 node_type* x=allocate_node();
|
Chris@16
|
599 BOOST_TRY{
|
Chris@16
|
600 node_type* res=super::insert_(v,x,variant);
|
Chris@16
|
601 if(res==x){
|
Chris@16
|
602 ++node_count;
|
Chris@16
|
603 return std::pair<node_type*,bool>(res,true);
|
Chris@16
|
604 }
|
Chris@16
|
605 else{
|
Chris@16
|
606 deallocate_node(x);
|
Chris@16
|
607 return std::pair<node_type*,bool>(res,false);
|
Chris@16
|
608 }
|
Chris@16
|
609 }
|
Chris@16
|
610 BOOST_CATCH(...){
|
Chris@16
|
611 deallocate_node(x);
|
Chris@16
|
612 BOOST_RETHROW;
|
Chris@16
|
613 }
|
Chris@16
|
614 BOOST_CATCH_END
|
Chris@16
|
615 }
|
Chris@16
|
616
|
Chris@16
|
617 std::pair<node_type*,bool> insert_(const Value& v)
|
Chris@16
|
618 {
|
Chris@16
|
619 return insert_(v,detail::lvalue_tag());
|
Chris@16
|
620 }
|
Chris@16
|
621
|
Chris@16
|
622 std::pair<node_type*,bool> insert_rv_(const Value& v)
|
Chris@16
|
623 {
|
Chris@16
|
624 return insert_(v,detail::rvalue_tag());
|
Chris@16
|
625 }
|
Chris@16
|
626
|
Chris@16
|
627 template<typename T>
|
Chris@16
|
628 std::pair<node_type*,bool> insert_ref_(T& t)
|
Chris@16
|
629 {
|
Chris@16
|
630 node_type* x=allocate_node();
|
Chris@16
|
631 BOOST_TRY{
|
Chris@16
|
632 new(&x->value()) value_type(t);
|
Chris@16
|
633 BOOST_TRY{
|
Chris@16
|
634 node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
|
Chris@16
|
635 if(res==x){
|
Chris@16
|
636 ++node_count;
|
Chris@16
|
637 return std::pair<node_type*,bool>(res,true);
|
Chris@16
|
638 }
|
Chris@16
|
639 else{
|
Chris@16
|
640 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
641 deallocate_node(x);
|
Chris@16
|
642 return std::pair<node_type*,bool>(res,false);
|
Chris@16
|
643 }
|
Chris@16
|
644 }
|
Chris@16
|
645 BOOST_CATCH(...){
|
Chris@16
|
646 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
647 BOOST_RETHROW;
|
Chris@16
|
648 }
|
Chris@16
|
649 BOOST_CATCH_END
|
Chris@16
|
650 }
|
Chris@16
|
651 BOOST_CATCH(...){
|
Chris@16
|
652 deallocate_node(x);
|
Chris@16
|
653 BOOST_RETHROW;
|
Chris@16
|
654 }
|
Chris@16
|
655 BOOST_CATCH_END
|
Chris@16
|
656 }
|
Chris@16
|
657
|
Chris@16
|
658 std::pair<node_type*,bool> insert_ref_(const value_type& x)
|
Chris@16
|
659 {
|
Chris@16
|
660 return insert_(x);
|
Chris@16
|
661 }
|
Chris@16
|
662
|
Chris@16
|
663 std::pair<node_type*,bool> insert_ref_(value_type& x)
|
Chris@16
|
664 {
|
Chris@16
|
665 return insert_(x);
|
Chris@16
|
666 }
|
Chris@16
|
667
|
Chris@16
|
668 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
|
Chris@16
|
669 std::pair<node_type*,bool> emplace_(
|
Chris@16
|
670 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
|
Chris@16
|
671 {
|
Chris@16
|
672 node_type* x=allocate_node();
|
Chris@16
|
673 BOOST_TRY{
|
Chris@16
|
674 detail::vartempl_placement_new(
|
Chris@16
|
675 &x->value(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
|
Chris@16
|
676 BOOST_TRY{
|
Chris@16
|
677 node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
|
Chris@16
|
678 if(res==x){
|
Chris@16
|
679 ++node_count;
|
Chris@16
|
680 return std::pair<node_type*,bool>(res,true);
|
Chris@16
|
681 }
|
Chris@16
|
682 else{
|
Chris@16
|
683 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
684 deallocate_node(x);
|
Chris@16
|
685 return std::pair<node_type*,bool>(res,false);
|
Chris@16
|
686 }
|
Chris@16
|
687 }
|
Chris@16
|
688 BOOST_CATCH(...){
|
Chris@16
|
689 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
690 BOOST_RETHROW;
|
Chris@16
|
691 }
|
Chris@16
|
692 BOOST_CATCH_END
|
Chris@16
|
693 }
|
Chris@16
|
694 BOOST_CATCH(...){
|
Chris@16
|
695 deallocate_node(x);
|
Chris@16
|
696 BOOST_RETHROW;
|
Chris@16
|
697 }
|
Chris@16
|
698 BOOST_CATCH_END
|
Chris@16
|
699 }
|
Chris@16
|
700
|
Chris@16
|
701 template<typename Variant>
|
Chris@16
|
702 std::pair<node_type*,bool> insert_(
|
Chris@16
|
703 const Value& v,node_type* position,Variant variant)
|
Chris@16
|
704 {
|
Chris@16
|
705 node_type* x=allocate_node();
|
Chris@16
|
706 BOOST_TRY{
|
Chris@16
|
707 node_type* res=super::insert_(v,position,x,variant);
|
Chris@16
|
708 if(res==x){
|
Chris@16
|
709 ++node_count;
|
Chris@16
|
710 return std::pair<node_type*,bool>(res,true);
|
Chris@16
|
711 }
|
Chris@16
|
712 else{
|
Chris@16
|
713 deallocate_node(x);
|
Chris@16
|
714 return std::pair<node_type*,bool>(res,false);
|
Chris@16
|
715 }
|
Chris@16
|
716 }
|
Chris@16
|
717 BOOST_CATCH(...){
|
Chris@16
|
718 deallocate_node(x);
|
Chris@16
|
719 BOOST_RETHROW;
|
Chris@16
|
720 }
|
Chris@16
|
721 BOOST_CATCH_END
|
Chris@16
|
722 }
|
Chris@16
|
723
|
Chris@16
|
724 std::pair<node_type*,bool> insert_(const Value& v,node_type* position)
|
Chris@16
|
725 {
|
Chris@16
|
726 return insert_(v,position,detail::lvalue_tag());
|
Chris@16
|
727 }
|
Chris@16
|
728
|
Chris@16
|
729 std::pair<node_type*,bool> insert_rv_(const Value& v,node_type* position)
|
Chris@16
|
730 {
|
Chris@16
|
731 return insert_(v,position,detail::rvalue_tag());
|
Chris@16
|
732 }
|
Chris@16
|
733
|
Chris@16
|
734 template<typename T>
|
Chris@16
|
735 std::pair<node_type*,bool> insert_ref_(
|
Chris@16
|
736 T& t,node_type* position)
|
Chris@16
|
737 {
|
Chris@16
|
738 node_type* x=allocate_node();
|
Chris@16
|
739 BOOST_TRY{
|
Chris@16
|
740 new(&x->value()) value_type(t);
|
Chris@16
|
741 BOOST_TRY{
|
Chris@16
|
742 node_type* res=super::insert_(
|
Chris@16
|
743 x->value(),position,x,detail::emplaced_tag());
|
Chris@16
|
744 if(res==x){
|
Chris@16
|
745 ++node_count;
|
Chris@16
|
746 return std::pair<node_type*,bool>(res,true);
|
Chris@16
|
747 }
|
Chris@16
|
748 else{
|
Chris@16
|
749 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
750 deallocate_node(x);
|
Chris@16
|
751 return std::pair<node_type*,bool>(res,false);
|
Chris@16
|
752 }
|
Chris@16
|
753 }
|
Chris@16
|
754 BOOST_CATCH(...){
|
Chris@16
|
755 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
756 BOOST_RETHROW;
|
Chris@16
|
757 }
|
Chris@16
|
758 BOOST_CATCH_END
|
Chris@16
|
759 }
|
Chris@16
|
760 BOOST_CATCH(...){
|
Chris@16
|
761 deallocate_node(x);
|
Chris@16
|
762 BOOST_RETHROW;
|
Chris@16
|
763 }
|
Chris@16
|
764 BOOST_CATCH_END
|
Chris@16
|
765 }
|
Chris@16
|
766
|
Chris@16
|
767 std::pair<node_type*,bool> insert_ref_(
|
Chris@16
|
768 const value_type& x,node_type* position)
|
Chris@16
|
769 {
|
Chris@16
|
770 return insert_(x,position);
|
Chris@16
|
771 }
|
Chris@16
|
772
|
Chris@16
|
773 std::pair<node_type*,bool> insert_ref_(
|
Chris@16
|
774 value_type& x,node_type* position)
|
Chris@16
|
775 {
|
Chris@16
|
776 return insert_(x,position);
|
Chris@16
|
777 }
|
Chris@16
|
778
|
Chris@16
|
779 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
|
Chris@16
|
780 std::pair<node_type*,bool> emplace_hint_(
|
Chris@16
|
781 node_type* position,
|
Chris@16
|
782 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
|
Chris@16
|
783 {
|
Chris@16
|
784 node_type* x=allocate_node();
|
Chris@16
|
785 BOOST_TRY{
|
Chris@16
|
786 detail::vartempl_placement_new(
|
Chris@16
|
787 &x->value(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
|
Chris@16
|
788 BOOST_TRY{
|
Chris@16
|
789 node_type* res=super::insert_(
|
Chris@16
|
790 x->value(),position,x,detail::emplaced_tag());
|
Chris@16
|
791 if(res==x){
|
Chris@16
|
792 ++node_count;
|
Chris@16
|
793 return std::pair<node_type*,bool>(res,true);
|
Chris@16
|
794 }
|
Chris@16
|
795 else{
|
Chris@16
|
796 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
797 deallocate_node(x);
|
Chris@16
|
798 return std::pair<node_type*,bool>(res,false);
|
Chris@16
|
799 }
|
Chris@16
|
800 }
|
Chris@16
|
801 BOOST_CATCH(...){
|
Chris@16
|
802 boost::detail::allocator::destroy(&x->value());
|
Chris@16
|
803 BOOST_RETHROW;
|
Chris@16
|
804 }
|
Chris@16
|
805 BOOST_CATCH_END
|
Chris@16
|
806 }
|
Chris@16
|
807 BOOST_CATCH(...){
|
Chris@16
|
808 deallocate_node(x);
|
Chris@16
|
809 BOOST_RETHROW;
|
Chris@16
|
810 }
|
Chris@16
|
811 BOOST_CATCH_END
|
Chris@16
|
812 }
|
Chris@16
|
813
|
Chris@16
|
814 void erase_(node_type* x)
|
Chris@16
|
815 {
|
Chris@16
|
816 --node_count;
|
Chris@16
|
817 super::erase_(x);
|
Chris@16
|
818 deallocate_node(x);
|
Chris@16
|
819 }
|
Chris@16
|
820
|
Chris@16
|
821 void delete_node_(node_type* x)
|
Chris@16
|
822 {
|
Chris@16
|
823 super::delete_node_(x);
|
Chris@16
|
824 deallocate_node(x);
|
Chris@16
|
825 }
|
Chris@16
|
826
|
Chris@16
|
827 void delete_all_nodes_()
|
Chris@16
|
828 {
|
Chris@16
|
829 super::delete_all_nodes_();
|
Chris@16
|
830 }
|
Chris@16
|
831
|
Chris@16
|
832 void clear_()
|
Chris@16
|
833 {
|
Chris@16
|
834 delete_all_nodes_();
|
Chris@16
|
835 super::clear_();
|
Chris@16
|
836 node_count=0;
|
Chris@16
|
837 }
|
Chris@16
|
838
|
Chris@16
|
839 void swap_(multi_index_container<Value,IndexSpecifierList,Allocator>& x)
|
Chris@16
|
840 {
|
Chris@16
|
841 if(bfm_allocator::member!=x.bfm_allocator::member){
|
Chris@16
|
842 detail::adl_swap(bfm_allocator::member,x.bfm_allocator::member);
|
Chris@16
|
843 }
|
Chris@16
|
844 std::swap(bfm_header::member,x.bfm_header::member);
|
Chris@16
|
845 super::swap_(x);
|
Chris@16
|
846 std::swap(node_count,x.node_count);
|
Chris@16
|
847 }
|
Chris@16
|
848
|
Chris@16
|
849 void swap_elements_(
|
Chris@16
|
850 multi_index_container<Value,IndexSpecifierList,Allocator>& x)
|
Chris@16
|
851 {
|
Chris@16
|
852 std::swap(bfm_header::member,x.bfm_header::member);
|
Chris@16
|
853 super::swap_elements_(x);
|
Chris@16
|
854 std::swap(node_count,x.node_count);
|
Chris@16
|
855 }
|
Chris@16
|
856
|
Chris@16
|
857 bool replace_(const Value& k,node_type* x)
|
Chris@16
|
858 {
|
Chris@16
|
859 return super::replace_(k,x,detail::lvalue_tag());
|
Chris@16
|
860 }
|
Chris@16
|
861
|
Chris@16
|
862 bool replace_rv_(const Value& k,node_type* x)
|
Chris@16
|
863 {
|
Chris@16
|
864 return super::replace_(k,x,detail::rvalue_tag());
|
Chris@16
|
865 }
|
Chris@16
|
866
|
Chris@16
|
867 template<typename Modifier>
|
Chris@16
|
868 bool modify_(Modifier& mod,node_type* x)
|
Chris@16
|
869 {
|
Chris@16
|
870 mod(const_cast<value_type&>(x->value()));
|
Chris@16
|
871
|
Chris@16
|
872 BOOST_TRY{
|
Chris@16
|
873 if(!super::modify_(x)){
|
Chris@16
|
874 deallocate_node(x);
|
Chris@16
|
875 --node_count;
|
Chris@16
|
876 return false;
|
Chris@16
|
877 }
|
Chris@16
|
878 else return true;
|
Chris@16
|
879 }
|
Chris@16
|
880 BOOST_CATCH(...){
|
Chris@16
|
881 deallocate_node(x);
|
Chris@16
|
882 --node_count;
|
Chris@16
|
883 BOOST_RETHROW;
|
Chris@16
|
884 }
|
Chris@16
|
885 BOOST_CATCH_END
|
Chris@16
|
886 }
|
Chris@16
|
887
|
Chris@16
|
888 template<typename Modifier,typename Rollback>
|
Chris@16
|
889 bool modify_(Modifier& mod,Rollback& back,node_type* x)
|
Chris@16
|
890 {
|
Chris@16
|
891 mod(const_cast<value_type&>(x->value()));
|
Chris@16
|
892
|
Chris@16
|
893 bool b;
|
Chris@16
|
894 BOOST_TRY{
|
Chris@16
|
895 b=super::modify_rollback_(x);
|
Chris@16
|
896 }
|
Chris@16
|
897 BOOST_CATCH(...){
|
Chris@16
|
898 BOOST_TRY{
|
Chris@16
|
899 back(const_cast<value_type&>(x->value()));
|
Chris@16
|
900 BOOST_RETHROW;
|
Chris@16
|
901 }
|
Chris@16
|
902 BOOST_CATCH(...){
|
Chris@16
|
903 this->erase_(x);
|
Chris@16
|
904 BOOST_RETHROW;
|
Chris@16
|
905 }
|
Chris@16
|
906 BOOST_CATCH_END
|
Chris@16
|
907 }
|
Chris@16
|
908 BOOST_CATCH_END
|
Chris@16
|
909
|
Chris@16
|
910 BOOST_TRY{
|
Chris@16
|
911 if(!b){
|
Chris@16
|
912 back(const_cast<value_type&>(x->value()));
|
Chris@16
|
913 return false;
|
Chris@16
|
914 }
|
Chris@16
|
915 else return true;
|
Chris@16
|
916 }
|
Chris@16
|
917 BOOST_CATCH(...){
|
Chris@16
|
918 this->erase_(x);
|
Chris@16
|
919 BOOST_RETHROW;
|
Chris@16
|
920 }
|
Chris@16
|
921 BOOST_CATCH_END
|
Chris@16
|
922 }
|
Chris@16
|
923
|
Chris@16
|
924 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
|
Chris@16
|
925 /* serialization */
|
Chris@16
|
926
|
Chris@16
|
927 friend class boost::serialization::access;
|
Chris@16
|
928
|
Chris@16
|
929 BOOST_SERIALIZATION_SPLIT_MEMBER()
|
Chris@16
|
930
|
Chris@16
|
931 typedef typename super::index_saver_type index_saver_type;
|
Chris@16
|
932 typedef typename super::index_loader_type index_loader_type;
|
Chris@16
|
933
|
Chris@16
|
934 template<class Archive>
|
Chris@16
|
935 void save(Archive& ar,const unsigned int version)const
|
Chris@16
|
936 {
|
Chris@16
|
937
|
Chris@16
|
938 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
939 const serialization::collection_size_type s(size_());
|
Chris@16
|
940 const detail::serialization_version<value_type> value_version;
|
Chris@16
|
941 ar<<serialization::make_nvp("count",s);
|
Chris@16
|
942 ar<<serialization::make_nvp("value_version",value_version);
|
Chris@16
|
943 #else
|
Chris@16
|
944 const std::size_t s=size_();
|
Chris@16
|
945 const unsigned int value_version=0;
|
Chris@16
|
946 ar<<serialization::make_nvp("count",s);
|
Chris@16
|
947 #endif
|
Chris@16
|
948
|
Chris@16
|
949 index_saver_type sm(bfm_allocator::member,s);
|
Chris@16
|
950
|
Chris@16
|
951 for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
|
Chris@16
|
952 serialization::save_construct_data_adl(ar,&*it,value_version);
|
Chris@16
|
953 ar<<serialization::make_nvp("item",*it);
|
Chris@16
|
954 sm.add(it.get_node(),ar,version);
|
Chris@16
|
955 }
|
Chris@16
|
956 sm.add_track(header(),ar,version);
|
Chris@16
|
957
|
Chris@16
|
958 super::save_(ar,version,sm);
|
Chris@16
|
959 }
|
Chris@16
|
960
|
Chris@16
|
961 template<class Archive>
|
Chris@16
|
962 void load(Archive& ar,const unsigned int version)
|
Chris@16
|
963 {
|
Chris@16
|
964 BOOST_MULTI_INDEX_CHECK_INVARIANT;
|
Chris@16
|
965
|
Chris@16
|
966 clear_();
|
Chris@16
|
967
|
Chris@16
|
968 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
969 serialization::collection_size_type s;
|
Chris@16
|
970 detail::serialization_version<value_type> value_version;
|
Chris@16
|
971 if(version<1){
|
Chris@16
|
972 std::size_t sz;
|
Chris@16
|
973 ar>>serialization::make_nvp("count",sz);
|
Chris@16
|
974 s=static_cast<serialization::collection_size_type>(sz);
|
Chris@16
|
975 }
|
Chris@16
|
976 else{
|
Chris@16
|
977 ar>>serialization::make_nvp("count",s);
|
Chris@16
|
978 }
|
Chris@16
|
979 if(version<2){
|
Chris@16
|
980 value_version=0;
|
Chris@16
|
981 }
|
Chris@16
|
982 else{
|
Chris@16
|
983 ar>>serialization::make_nvp("value_version",value_version);
|
Chris@16
|
984 }
|
Chris@16
|
985 #else
|
Chris@16
|
986 std::size_t s;
|
Chris@16
|
987 unsigned int value_version=0;
|
Chris@16
|
988 ar>>serialization::make_nvp("count",s);
|
Chris@16
|
989 #endif
|
Chris@16
|
990
|
Chris@16
|
991 index_loader_type lm(bfm_allocator::member,s);
|
Chris@16
|
992
|
Chris@16
|
993 for(std::size_t n=0;n<s;++n){
|
Chris@16
|
994 detail::archive_constructed<Value> value("item",ar,value_version);
|
Chris@16
|
995 std::pair<node_type*,bool> p=insert_(
|
Chris@16
|
996 value.get(),super::end().get_node());
|
Chris@16
|
997 if(!p.second)throw_exception(
|
Chris@16
|
998 archive::archive_exception(
|
Chris@16
|
999 archive::archive_exception::other_exception));
|
Chris@16
|
1000 ar.reset_object_address(&p.first->value(),&value.get());
|
Chris@16
|
1001 lm.add(p.first,ar,version);
|
Chris@16
|
1002 }
|
Chris@16
|
1003 lm.add_track(header(),ar,version);
|
Chris@16
|
1004
|
Chris@16
|
1005 super::load_(ar,version,lm);
|
Chris@16
|
1006 }
|
Chris@16
|
1007 #endif
|
Chris@16
|
1008
|
Chris@16
|
1009 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
|
Chris@16
|
1010 /* invariant stuff */
|
Chris@16
|
1011
|
Chris@16
|
1012 bool invariant_()const
|
Chris@16
|
1013 {
|
Chris@16
|
1014 return super::invariant_();
|
Chris@16
|
1015 }
|
Chris@16
|
1016
|
Chris@16
|
1017 void check_invariant_()const
|
Chris@16
|
1018 {
|
Chris@16
|
1019 BOOST_MULTI_INDEX_INVARIANT_ASSERT(invariant_());
|
Chris@16
|
1020 }
|
Chris@16
|
1021 #endif
|
Chris@16
|
1022
|
Chris@16
|
1023 private:
|
Chris@16
|
1024 std::size_t node_count;
|
Chris@16
|
1025
|
Chris@16
|
1026 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
|
Chris@16
|
1027 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
|
Chris@16
|
1028 #pragma parse_mfunc_templ reset
|
Chris@16
|
1029 #endif
|
Chris@16
|
1030 };
|
Chris@16
|
1031
|
Chris@16
|
1032 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
|
Chris@16
|
1033 #pragma warning(pop) /* C4522 */
|
Chris@16
|
1034 #endif
|
Chris@16
|
1035
|
Chris@16
|
1036 /* retrieval of indices by number */
|
Chris@16
|
1037
|
Chris@16
|
1038 template<typename MultiIndexContainer,int N>
|
Chris@16
|
1039 struct nth_index
|
Chris@16
|
1040 {
|
Chris@16
|
1041 BOOST_STATIC_CONSTANT(
|
Chris@16
|
1042 int,
|
Chris@16
|
1043 M=mpl::size<typename MultiIndexContainer::index_type_list>::type::value);
|
Chris@16
|
1044 BOOST_STATIC_ASSERT(N>=0&&N<M);
|
Chris@16
|
1045 typedef typename mpl::at_c<
|
Chris@16
|
1046 typename MultiIndexContainer::index_type_list,N>::type type;
|
Chris@16
|
1047 };
|
Chris@16
|
1048
|
Chris@16
|
1049 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1050 typename nth_index<
|
Chris@16
|
1051 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
|
Chris@16
|
1052 get(
|
Chris@16
|
1053 multi_index_container<Value,IndexSpecifierList,Allocator>& m
|
Chris@16
|
1054 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
|
Chris@16
|
1055 {
|
Chris@16
|
1056 typedef multi_index_container<
|
Chris@16
|
1057 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1058 typedef typename nth_index<
|
Chris@16
|
1059 multi_index_container<
|
Chris@16
|
1060 Value,IndexSpecifierList,Allocator>,
|
Chris@16
|
1061 N
|
Chris@16
|
1062 >::type index;
|
Chris@16
|
1063
|
Chris@16
|
1064 BOOST_STATIC_ASSERT(N>=0&&
|
Chris@16
|
1065 N<
|
Chris@16
|
1066 mpl::size<
|
Chris@16
|
1067 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
|
Chris@16
|
1068 >::type::value);
|
Chris@16
|
1069
|
Chris@16
|
1070 return detail::converter<multi_index_type,index>::index(m);
|
Chris@16
|
1071 }
|
Chris@16
|
1072
|
Chris@16
|
1073 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1074 const typename nth_index<
|
Chris@16
|
1075 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
|
Chris@16
|
1076 get(
|
Chris@16
|
1077 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
|
Chris@16
|
1078 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
|
Chris@16
|
1079 {
|
Chris@16
|
1080 typedef multi_index_container<
|
Chris@16
|
1081 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1082 typedef typename nth_index<
|
Chris@16
|
1083 multi_index_container<
|
Chris@16
|
1084 Value,IndexSpecifierList,Allocator>,
|
Chris@16
|
1085 N
|
Chris@16
|
1086 >::type index;
|
Chris@16
|
1087
|
Chris@16
|
1088 BOOST_STATIC_ASSERT(N>=0&&
|
Chris@16
|
1089 N<
|
Chris@16
|
1090 mpl::size<
|
Chris@16
|
1091 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
|
Chris@16
|
1092 >::type::value);
|
Chris@16
|
1093
|
Chris@16
|
1094 return detail::converter<multi_index_type,index>::index(m);
|
Chris@16
|
1095 }
|
Chris@16
|
1096
|
Chris@16
|
1097 /* retrieval of indices by tag */
|
Chris@16
|
1098
|
Chris@16
|
1099 template<typename MultiIndexContainer,typename Tag>
|
Chris@16
|
1100 struct index
|
Chris@16
|
1101 {
|
Chris@16
|
1102 typedef typename MultiIndexContainer::index_type_list index_type_list;
|
Chris@16
|
1103
|
Chris@16
|
1104 typedef typename mpl::find_if<
|
Chris@16
|
1105 index_type_list,
|
Chris@16
|
1106 detail::has_tag<Tag>
|
Chris@16
|
1107 >::type iter;
|
Chris@16
|
1108
|
Chris@16
|
1109 BOOST_STATIC_CONSTANT(
|
Chris@16
|
1110 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
|
Chris@16
|
1111 BOOST_STATIC_ASSERT(index_found);
|
Chris@16
|
1112
|
Chris@16
|
1113 typedef typename mpl::deref<iter>::type type;
|
Chris@16
|
1114 };
|
Chris@16
|
1115
|
Chris@16
|
1116 template<
|
Chris@16
|
1117 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
|
Chris@16
|
1118 >
|
Chris@16
|
1119 typename ::boost::multi_index::index<
|
Chris@16
|
1120 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
|
Chris@16
|
1121 get(
|
Chris@16
|
1122 multi_index_container<Value,IndexSpecifierList,Allocator>& m
|
Chris@16
|
1123 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
|
Chris@16
|
1124 {
|
Chris@16
|
1125 typedef multi_index_container<
|
Chris@16
|
1126 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1127 typedef typename ::boost::multi_index::index<
|
Chris@16
|
1128 multi_index_container<
|
Chris@16
|
1129 Value,IndexSpecifierList,Allocator>,
|
Chris@16
|
1130 Tag
|
Chris@16
|
1131 >::type index;
|
Chris@16
|
1132
|
Chris@16
|
1133 return detail::converter<multi_index_type,index>::index(m);
|
Chris@16
|
1134 }
|
Chris@16
|
1135
|
Chris@16
|
1136 template<
|
Chris@16
|
1137 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
|
Chris@16
|
1138 >
|
Chris@16
|
1139 const typename ::boost::multi_index::index<
|
Chris@16
|
1140 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
|
Chris@16
|
1141 get(
|
Chris@16
|
1142 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
|
Chris@16
|
1143 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
|
Chris@16
|
1144 {
|
Chris@16
|
1145 typedef multi_index_container<
|
Chris@16
|
1146 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1147 typedef typename ::boost::multi_index::index<
|
Chris@16
|
1148 multi_index_container<
|
Chris@16
|
1149 Value,IndexSpecifierList,Allocator>,
|
Chris@16
|
1150 Tag
|
Chris@16
|
1151 >::type index;
|
Chris@16
|
1152
|
Chris@16
|
1153 return detail::converter<multi_index_type,index>::index(m);
|
Chris@16
|
1154 }
|
Chris@16
|
1155
|
Chris@16
|
1156 /* projection of iterators by number */
|
Chris@16
|
1157
|
Chris@16
|
1158 template<typename MultiIndexContainer,int N>
|
Chris@16
|
1159 struct nth_index_iterator
|
Chris@16
|
1160 {
|
Chris@16
|
1161 typedef typename detail::prevent_eti<
|
Chris@16
|
1162 nth_index<MultiIndexContainer,N>,
|
Chris@16
|
1163 typename nth_index<MultiIndexContainer,N>::type>::type::iterator type;
|
Chris@16
|
1164 };
|
Chris@16
|
1165
|
Chris@16
|
1166 template<typename MultiIndexContainer,int N>
|
Chris@16
|
1167 struct nth_index_const_iterator
|
Chris@16
|
1168 {
|
Chris@16
|
1169 typedef typename detail::prevent_eti<
|
Chris@16
|
1170 nth_index<MultiIndexContainer,N>,
|
Chris@16
|
1171 typename nth_index<MultiIndexContainer,N>::type
|
Chris@16
|
1172 >::type::const_iterator type;
|
Chris@16
|
1173 };
|
Chris@16
|
1174
|
Chris@16
|
1175 template<
|
Chris@16
|
1176 int N,typename IteratorType,
|
Chris@16
|
1177 typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1178 typename nth_index_iterator<
|
Chris@16
|
1179 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
|
Chris@16
|
1180 project(
|
Chris@16
|
1181 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
|
Chris@16
|
1182 IteratorType it
|
Chris@16
|
1183 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
|
Chris@16
|
1184 {
|
Chris@16
|
1185 typedef multi_index_container<
|
Chris@16
|
1186 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1187 typedef typename nth_index<multi_index_type,N>::type index;
|
Chris@16
|
1188
|
Chris@16
|
1189 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
|
Chris@16
|
1190 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
|
Chris@16
|
1191 BOOST_STATIC_ASSERT((
|
Chris@16
|
1192 mpl::contains<
|
Chris@16
|
1193 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
|
Chris@16
|
1194 IteratorType>::value));
|
Chris@16
|
1195 #endif
|
Chris@16
|
1196
|
Chris@16
|
1197 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
1198
|
Chris@16
|
1199 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
Chris@16
|
1200 typedef detail::converter<
|
Chris@16
|
1201 multi_index_type,
|
Chris@16
|
1202 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
|
Chris@16
|
1203 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
|
Chris@16
|
1204 #endif
|
Chris@16
|
1205
|
Chris@16
|
1206 return detail::converter<multi_index_type,index>::iterator(
|
Chris@16
|
1207 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
|
Chris@16
|
1208 }
|
Chris@16
|
1209
|
Chris@16
|
1210 template<
|
Chris@16
|
1211 int N,typename IteratorType,
|
Chris@16
|
1212 typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1213 typename nth_index_const_iterator<
|
Chris@16
|
1214 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
|
Chris@16
|
1215 project(
|
Chris@16
|
1216 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
|
Chris@16
|
1217 IteratorType it
|
Chris@16
|
1218 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
|
Chris@16
|
1219 {
|
Chris@16
|
1220 typedef multi_index_container<
|
Chris@16
|
1221 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1222 typedef typename nth_index<multi_index_type,N>::type index;
|
Chris@16
|
1223
|
Chris@16
|
1224 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
|
Chris@16
|
1225 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
|
Chris@16
|
1226 BOOST_STATIC_ASSERT((
|
Chris@16
|
1227 mpl::contains<
|
Chris@16
|
1228 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
|
Chris@16
|
1229 IteratorType>::value||
|
Chris@16
|
1230 mpl::contains<
|
Chris@16
|
1231 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
|
Chris@16
|
1232 IteratorType>::value));
|
Chris@16
|
1233 #endif
|
Chris@16
|
1234
|
Chris@16
|
1235 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
1236
|
Chris@16
|
1237 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
Chris@16
|
1238 typedef detail::converter<
|
Chris@16
|
1239 multi_index_type,
|
Chris@16
|
1240 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
|
Chris@16
|
1241 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
|
Chris@16
|
1242 #endif
|
Chris@16
|
1243
|
Chris@16
|
1244 return detail::converter<multi_index_type,index>::const_iterator(
|
Chris@16
|
1245 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
|
Chris@16
|
1246 }
|
Chris@16
|
1247
|
Chris@16
|
1248 /* projection of iterators by tag */
|
Chris@16
|
1249
|
Chris@16
|
1250 template<typename MultiIndexContainer,typename Tag>
|
Chris@16
|
1251 struct index_iterator
|
Chris@16
|
1252 {
|
Chris@16
|
1253 typedef typename ::boost::multi_index::index<
|
Chris@16
|
1254 MultiIndexContainer,Tag>::type::iterator type;
|
Chris@16
|
1255 };
|
Chris@16
|
1256
|
Chris@16
|
1257 template<typename MultiIndexContainer,typename Tag>
|
Chris@16
|
1258 struct index_const_iterator
|
Chris@16
|
1259 {
|
Chris@16
|
1260 typedef typename ::boost::multi_index::index<
|
Chris@16
|
1261 MultiIndexContainer,Tag>::type::const_iterator type;
|
Chris@16
|
1262 };
|
Chris@16
|
1263
|
Chris@16
|
1264 template<
|
Chris@16
|
1265 typename Tag,typename IteratorType,
|
Chris@16
|
1266 typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1267 typename index_iterator<
|
Chris@16
|
1268 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
|
Chris@16
|
1269 project(
|
Chris@16
|
1270 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
|
Chris@16
|
1271 IteratorType it
|
Chris@16
|
1272 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
|
Chris@16
|
1273 {
|
Chris@16
|
1274 typedef multi_index_container<
|
Chris@16
|
1275 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1276 typedef typename ::boost::multi_index::index<
|
Chris@16
|
1277 multi_index_type,Tag>::type index;
|
Chris@16
|
1278
|
Chris@16
|
1279 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
|
Chris@16
|
1280 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
|
Chris@16
|
1281 BOOST_STATIC_ASSERT((
|
Chris@16
|
1282 mpl::contains<
|
Chris@16
|
1283 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
|
Chris@16
|
1284 IteratorType>::value));
|
Chris@16
|
1285 #endif
|
Chris@16
|
1286
|
Chris@16
|
1287 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
1288
|
Chris@16
|
1289 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
Chris@16
|
1290 typedef detail::converter<
|
Chris@16
|
1291 multi_index_type,
|
Chris@16
|
1292 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
|
Chris@16
|
1293 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
|
Chris@16
|
1294 #endif
|
Chris@16
|
1295
|
Chris@16
|
1296 return detail::converter<multi_index_type,index>::iterator(
|
Chris@16
|
1297 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
|
Chris@16
|
1298 }
|
Chris@16
|
1299
|
Chris@16
|
1300 template<
|
Chris@16
|
1301 typename Tag,typename IteratorType,
|
Chris@16
|
1302 typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1303 typename index_const_iterator<
|
Chris@16
|
1304 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
|
Chris@16
|
1305 project(
|
Chris@16
|
1306 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
|
Chris@16
|
1307 IteratorType it
|
Chris@16
|
1308 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
|
Chris@16
|
1309 {
|
Chris@16
|
1310 typedef multi_index_container<
|
Chris@16
|
1311 Value,IndexSpecifierList,Allocator> multi_index_type;
|
Chris@16
|
1312 typedef typename ::boost::multi_index::index<
|
Chris@16
|
1313 multi_index_type,Tag>::type index;
|
Chris@16
|
1314
|
Chris@16
|
1315 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
|
Chris@16
|
1316 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
|
Chris@16
|
1317 BOOST_STATIC_ASSERT((
|
Chris@16
|
1318 mpl::contains<
|
Chris@16
|
1319 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
|
Chris@16
|
1320 IteratorType>::value||
|
Chris@16
|
1321 mpl::contains<
|
Chris@16
|
1322 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
|
Chris@16
|
1323 IteratorType>::value));
|
Chris@16
|
1324 #endif
|
Chris@16
|
1325
|
Chris@16
|
1326 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
|
Chris@16
|
1327
|
Chris@16
|
1328 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
Chris@16
|
1329 typedef detail::converter<
|
Chris@16
|
1330 multi_index_type,
|
Chris@16
|
1331 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
|
Chris@16
|
1332 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
|
Chris@16
|
1333 #endif
|
Chris@16
|
1334
|
Chris@16
|
1335 return detail::converter<multi_index_type,index>::const_iterator(
|
Chris@16
|
1336 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
|
Chris@16
|
1337 }
|
Chris@16
|
1338
|
Chris@16
|
1339 /* Comparison. Simple forward to first index. */
|
Chris@16
|
1340
|
Chris@16
|
1341 template<
|
Chris@16
|
1342 typename Value1,typename IndexSpecifierList1,typename Allocator1,
|
Chris@16
|
1343 typename Value2,typename IndexSpecifierList2,typename Allocator2
|
Chris@16
|
1344 >
|
Chris@16
|
1345 bool operator==(
|
Chris@16
|
1346 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
|
Chris@16
|
1347 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
|
Chris@16
|
1348 {
|
Chris@16
|
1349 return get<0>(x)==get<0>(y);
|
Chris@16
|
1350 }
|
Chris@16
|
1351
|
Chris@16
|
1352 template<
|
Chris@16
|
1353 typename Value1,typename IndexSpecifierList1,typename Allocator1,
|
Chris@16
|
1354 typename Value2,typename IndexSpecifierList2,typename Allocator2
|
Chris@16
|
1355 >
|
Chris@16
|
1356 bool operator<(
|
Chris@16
|
1357 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
|
Chris@16
|
1358 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
|
Chris@16
|
1359 {
|
Chris@16
|
1360 return get<0>(x)<get<0>(y);
|
Chris@16
|
1361 }
|
Chris@16
|
1362
|
Chris@16
|
1363 template<
|
Chris@16
|
1364 typename Value1,typename IndexSpecifierList1,typename Allocator1,
|
Chris@16
|
1365 typename Value2,typename IndexSpecifierList2,typename Allocator2
|
Chris@16
|
1366 >
|
Chris@16
|
1367 bool operator!=(
|
Chris@16
|
1368 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
|
Chris@16
|
1369 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
|
Chris@16
|
1370 {
|
Chris@16
|
1371 return get<0>(x)!=get<0>(y);
|
Chris@16
|
1372 }
|
Chris@16
|
1373
|
Chris@16
|
1374 template<
|
Chris@16
|
1375 typename Value1,typename IndexSpecifierList1,typename Allocator1,
|
Chris@16
|
1376 typename Value2,typename IndexSpecifierList2,typename Allocator2
|
Chris@16
|
1377 >
|
Chris@16
|
1378 bool operator>(
|
Chris@16
|
1379 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
|
Chris@16
|
1380 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
|
Chris@16
|
1381 {
|
Chris@16
|
1382 return get<0>(x)>get<0>(y);
|
Chris@16
|
1383 }
|
Chris@16
|
1384
|
Chris@16
|
1385 template<
|
Chris@16
|
1386 typename Value1,typename IndexSpecifierList1,typename Allocator1,
|
Chris@16
|
1387 typename Value2,typename IndexSpecifierList2,typename Allocator2
|
Chris@16
|
1388 >
|
Chris@16
|
1389 bool operator>=(
|
Chris@16
|
1390 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
|
Chris@16
|
1391 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
|
Chris@16
|
1392 {
|
Chris@16
|
1393 return get<0>(x)>=get<0>(y);
|
Chris@16
|
1394 }
|
Chris@16
|
1395
|
Chris@16
|
1396 template<
|
Chris@16
|
1397 typename Value1,typename IndexSpecifierList1,typename Allocator1,
|
Chris@16
|
1398 typename Value2,typename IndexSpecifierList2,typename Allocator2
|
Chris@16
|
1399 >
|
Chris@16
|
1400 bool operator<=(
|
Chris@16
|
1401 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
|
Chris@16
|
1402 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
|
Chris@16
|
1403 {
|
Chris@16
|
1404 return get<0>(x)<=get<0>(y);
|
Chris@16
|
1405 }
|
Chris@16
|
1406
|
Chris@16
|
1407 /* specialized algorithms */
|
Chris@16
|
1408
|
Chris@16
|
1409 template<typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1410 void swap(
|
Chris@16
|
1411 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
|
Chris@16
|
1412 multi_index_container<Value,IndexSpecifierList,Allocator>& y)
|
Chris@16
|
1413 {
|
Chris@16
|
1414 x.swap(y);
|
Chris@16
|
1415 }
|
Chris@16
|
1416
|
Chris@16
|
1417 } /* namespace multi_index */
|
Chris@16
|
1418
|
Chris@16
|
1419 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)&&\
|
Chris@16
|
1420 !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
1421 /* class version = 1 : we now serialize the size through
|
Chris@16
|
1422 * boost::serialization::collection_size_type.
|
Chris@16
|
1423 * class version = 2 : proper use of {save|load}_construct_data.
|
Chris@16
|
1424 */
|
Chris@16
|
1425
|
Chris@16
|
1426 namespace serialization {
|
Chris@16
|
1427 template<typename Value,typename IndexSpecifierList,typename Allocator>
|
Chris@16
|
1428 struct version<
|
Chris@16
|
1429 boost::multi_index_container<Value,IndexSpecifierList,Allocator>
|
Chris@16
|
1430 >
|
Chris@16
|
1431 {
|
Chris@16
|
1432 BOOST_STATIC_CONSTANT(int,value=2);
|
Chris@16
|
1433 };
|
Chris@16
|
1434 } /* namespace serialization */
|
Chris@16
|
1435 #endif
|
Chris@16
|
1436
|
Chris@16
|
1437 /* Associated global functions are promoted to namespace boost, except
|
Chris@16
|
1438 * comparison operators and swap, which are meant to be Koenig looked-up.
|
Chris@16
|
1439 */
|
Chris@16
|
1440
|
Chris@16
|
1441 using multi_index::get;
|
Chris@16
|
1442 using multi_index::project;
|
Chris@16
|
1443
|
Chris@16
|
1444 } /* namespace boost */
|
Chris@16
|
1445
|
Chris@16
|
1446 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT
|
Chris@16
|
1447 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT_OF
|
Chris@16
|
1448
|
Chris@16
|
1449 #endif
|