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