]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | /* Copyright 2003-2018 Joaquin M Lopez Munoz. |
7c673cae FG |
2 | * Distributed under the Boost Software License, Version 1.0. |
3 | * (See accompanying file LICENSE_1_0.txt or copy at | |
4 | * http://www.boost.org/LICENSE_1_0.txt) | |
5 | * | |
6 | * See http://www.boost.org/libs/multi_index for library home page. | |
7 | */ | |
8 | ||
9 | #ifndef BOOST_MULTI_INDEX_RANDOM_ACCESS_INDEX_HPP | |
10 | #define BOOST_MULTI_INDEX_RANDOM_ACCESS_INDEX_HPP | |
11 | ||
12 | #if defined(_MSC_VER) | |
13 | #pragma once | |
14 | #endif | |
15 | ||
16 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ | |
17 | #include <algorithm> | |
18 | #include <boost/bind.hpp> | |
19 | #include <boost/call_traits.hpp> | |
11fdf7f2 | 20 | #include <boost/core/addressof.hpp> |
7c673cae FG |
21 | #include <boost/detail/no_exceptions_support.hpp> |
22 | #include <boost/detail/workaround.hpp> | |
23 | #include <boost/foreach_fwd.hpp> | |
24 | #include <boost/iterator/reverse_iterator.hpp> | |
25 | #include <boost/move/core.hpp> | |
26 | #include <boost/move/utility.hpp> | |
27 | #include <boost/mpl/bool.hpp> | |
28 | #include <boost/mpl/not.hpp> | |
29 | #include <boost/mpl/push_front.hpp> | |
30 | #include <boost/multi_index/detail/access_specifier.hpp> | |
31 | #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp> | |
32 | #include <boost/multi_index/detail/index_node_base.hpp> | |
33 | #include <boost/multi_index/detail/rnd_node_iterator.hpp> | |
34 | #include <boost/multi_index/detail/rnd_index_node.hpp> | |
35 | #include <boost/multi_index/detail/rnd_index_ops.hpp> | |
36 | #include <boost/multi_index/detail/rnd_index_ptr_array.hpp> | |
37 | #include <boost/multi_index/detail/safe_mode.hpp> | |
38 | #include <boost/multi_index/detail/scope_guard.hpp> | |
39 | #include <boost/multi_index/detail/vartempl_support.hpp> | |
40 | #include <boost/multi_index/random_access_index_fwd.hpp> | |
41 | #include <boost/throw_exception.hpp> | |
42 | #include <boost/tuple/tuple.hpp> | |
43 | #include <boost/type_traits/is_integral.hpp> | |
44 | #include <cstddef> | |
45 | #include <functional> | |
46 | #include <stdexcept> | |
47 | #include <utility> | |
11fdf7f2 | 48 | #include <memory> |
7c673cae FG |
49 | |
50 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
51 | #include<initializer_list> | |
52 | #endif | |
53 | ||
54 | #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) | |
55 | #include <boost/multi_index/detail/rnd_index_loader.hpp> | |
56 | #endif | |
57 | ||
58 | #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING) | |
59 | #define BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT_OF(x) \ | |
60 | detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \ | |
61 | detail::make_obj_guard(x,&random_access_index::check_invariant_); \ | |
62 | BOOST_JOIN(check_invariant_,__LINE__).touch(); | |
63 | #define BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT \ | |
64 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT_OF(*this) | |
65 | #else | |
66 | #define BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT_OF(x) | |
67 | #define BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT | |
68 | #endif | |
69 | ||
70 | namespace boost{ | |
71 | ||
72 | namespace multi_index{ | |
73 | ||
74 | namespace detail{ | |
75 | ||
76 | /* random_access_index adds a layer of random access indexing | |
77 | * to a given Super | |
78 | */ | |
79 | ||
80 | template<typename SuperMeta,typename TagList> | |
81 | class random_access_index: | |
82 | BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS SuperMeta::type | |
83 | ||
84 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
85 | ,public safe_mode::safe_container< | |
86 | random_access_index<SuperMeta,TagList> > | |
87 | #endif | |
88 | ||
89 | { | |
90 | #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\ | |
91 | BOOST_WORKAROUND(__MWERKS__,<=0x3003) | |
92 | /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the | |
93 | * lifetime of const references bound to temporaries --precisely what | |
94 | * scopeguards are. | |
95 | */ | |
96 | ||
97 | #pragma parse_mfunc_templ off | |
98 | #endif | |
99 | ||
100 | typedef typename SuperMeta::type super; | |
101 | ||
102 | protected: | |
103 | typedef random_access_index_node< | |
104 | typename super::node_type> node_type; | |
105 | ||
106 | private: | |
107 | typedef typename node_type::impl_type node_impl_type; | |
108 | typedef random_access_index_ptr_array< | |
109 | typename super::final_allocator_type> ptr_array; | |
110 | typedef typename ptr_array::pointer node_impl_ptr_pointer; | |
111 | ||
112 | public: | |
113 | /* types */ | |
114 | ||
115 | typedef typename node_type::value_type value_type; | |
116 | typedef tuples::null_type ctor_args; | |
117 | typedef typename super::final_allocator_type allocator_type; | |
11fdf7f2 | 118 | #ifdef BOOST_NO_CXX11_ALLOCATOR |
7c673cae FG |
119 | typedef typename allocator_type::reference reference; |
120 | typedef typename allocator_type::const_reference const_reference; | |
11fdf7f2 TL |
121 | #else |
122 | typedef value_type& reference; | |
123 | typedef const value_type& const_reference; | |
124 | #endif | |
7c673cae FG |
125 | |
126 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
127 | typedef safe_mode::safe_iterator< | |
128 | rnd_node_iterator<node_type>, | |
129 | random_access_index> iterator; | |
130 | #else | |
131 | typedef rnd_node_iterator<node_type> iterator; | |
132 | #endif | |
133 | ||
134 | typedef iterator const_iterator; | |
135 | ||
136 | typedef std::size_t size_type; | |
137 | typedef std::ptrdiff_t difference_type; | |
11fdf7f2 | 138 | #ifdef BOOST_NO_CXX11_ALLOCATOR |
7c673cae FG |
139 | typedef typename allocator_type::pointer pointer; |
140 | typedef typename allocator_type::const_pointer const_pointer; | |
11fdf7f2 TL |
141 | #else |
142 | typedef std::allocator_traits<allocator_type> allocator_traits; | |
143 | typedef typename allocator_traits::pointer pointer; | |
144 | typedef typename allocator_traits::const_pointer const_pointer; | |
145 | #endif | |
7c673cae FG |
146 | typedef typename |
147 | boost::reverse_iterator<iterator> reverse_iterator; | |
148 | typedef typename | |
149 | boost::reverse_iterator<const_iterator> const_reverse_iterator; | |
150 | typedef TagList tag_list; | |
151 | ||
152 | protected: | |
153 | typedef typename super::final_node_type final_node_type; | |
154 | typedef tuples::cons< | |
155 | ctor_args, | |
156 | typename super::ctor_args_list> ctor_args_list; | |
157 | typedef typename mpl::push_front< | |
158 | typename super::index_type_list, | |
159 | random_access_index>::type index_type_list; | |
160 | typedef typename mpl::push_front< | |
161 | typename super::iterator_type_list, | |
162 | iterator>::type iterator_type_list; | |
163 | typedef typename mpl::push_front< | |
164 | typename super::const_iterator_type_list, | |
165 | const_iterator>::type const_iterator_type_list; | |
166 | typedef typename super::copy_map_type copy_map_type; | |
167 | ||
168 | #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) | |
169 | typedef typename super::index_saver_type index_saver_type; | |
170 | typedef typename super::index_loader_type index_loader_type; | |
171 | #endif | |
172 | ||
173 | private: | |
174 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
175 | typedef safe_mode::safe_container< | |
176 | random_access_index> safe_super; | |
177 | #endif | |
178 | ||
179 | typedef typename call_traits< | |
180 | value_type>::param_type value_param_type; | |
181 | ||
182 | /* Needed to avoid commas in BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL | |
183 | * expansion. | |
184 | */ | |
185 | ||
186 | typedef std::pair<iterator,bool> emplace_return_type; | |
187 | ||
188 | public: | |
189 | ||
190 | /* construct/copy/destroy | |
191 | * Default and copy ctors are in the protected section as indices are | |
192 | * not supposed to be created on their own. No range ctor either. | |
193 | */ | |
194 | ||
195 | random_access_index<SuperMeta,TagList>& operator=( | |
196 | const random_access_index<SuperMeta,TagList>& x) | |
197 | { | |
198 | this->final()=x.final(); | |
199 | return *this; | |
200 | } | |
201 | ||
202 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
203 | random_access_index<SuperMeta,TagList>& operator=( | |
204 | std::initializer_list<value_type> list) | |
205 | { | |
206 | this->final()=list; | |
207 | return *this; | |
208 | } | |
209 | #endif | |
210 | ||
211 | template <class InputIterator> | |
212 | void assign(InputIterator first,InputIterator last) | |
213 | { | |
214 | assign_iter(first,last,mpl::not_<is_integral<InputIterator> >()); | |
215 | } | |
216 | ||
217 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
218 | void assign(std::initializer_list<value_type> list) | |
219 | { | |
220 | assign(list.begin(),list.end()); | |
221 | } | |
222 | #endif | |
223 | ||
224 | void assign(size_type n,value_param_type value) | |
225 | { | |
226 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
227 | clear(); | |
228 | for(size_type i=0;i<n;++i)push_back(value); | |
229 | } | |
230 | ||
231 | allocator_type get_allocator()const BOOST_NOEXCEPT | |
232 | { | |
233 | return this->final().get_allocator(); | |
234 | } | |
235 | ||
236 | /* iterators */ | |
237 | ||
238 | iterator begin()BOOST_NOEXCEPT | |
239 | {return make_iterator(node_type::from_impl(*ptrs.begin()));} | |
240 | const_iterator begin()const BOOST_NOEXCEPT | |
241 | {return make_iterator(node_type::from_impl(*ptrs.begin()));} | |
242 | iterator | |
243 | end()BOOST_NOEXCEPT{return make_iterator(header());} | |
244 | const_iterator | |
245 | end()const BOOST_NOEXCEPT{return make_iterator(header());} | |
246 | reverse_iterator | |
247 | rbegin()BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());} | |
248 | const_reverse_iterator | |
249 | rbegin()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());} | |
250 | reverse_iterator | |
251 | rend()BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());} | |
252 | const_reverse_iterator | |
253 | rend()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());} | |
254 | const_iterator | |
255 | cbegin()const BOOST_NOEXCEPT{return begin();} | |
256 | const_iterator | |
257 | cend()const BOOST_NOEXCEPT{return end();} | |
258 | const_reverse_iterator | |
259 | crbegin()const BOOST_NOEXCEPT{return rbegin();} | |
260 | const_reverse_iterator | |
261 | crend()const BOOST_NOEXCEPT{return rend();} | |
262 | ||
263 | iterator iterator_to(const value_type& x) | |
264 | { | |
11fdf7f2 | 265 | return make_iterator(node_from_value<node_type>(boost::addressof(x))); |
7c673cae FG |
266 | } |
267 | ||
268 | const_iterator iterator_to(const value_type& x)const | |
269 | { | |
11fdf7f2 | 270 | return make_iterator(node_from_value<node_type>(boost::addressof(x))); |
7c673cae FG |
271 | } |
272 | ||
273 | /* capacity */ | |
274 | ||
275 | bool empty()const BOOST_NOEXCEPT{return this->final_empty_();} | |
276 | size_type size()const BOOST_NOEXCEPT{return this->final_size_();} | |
277 | size_type max_size()const BOOST_NOEXCEPT{return this->final_max_size_();} | |
278 | size_type capacity()const BOOST_NOEXCEPT{return ptrs.capacity();} | |
279 | ||
280 | void reserve(size_type n) | |
281 | { | |
282 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
283 | ptrs.reserve(n); | |
284 | } | |
285 | ||
286 | void shrink_to_fit() | |
287 | { | |
288 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
289 | ptrs.shrink_to_fit(); | |
290 | } | |
291 | ||
292 | void resize(size_type n) | |
293 | { | |
294 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
295 | if(n>size()) | |
296 | for(size_type m=n-size();m--;) | |
297 | this->final_emplace_(BOOST_MULTI_INDEX_NULL_PARAM_PACK); | |
298 | else if(n<size())erase(begin()+n,end()); | |
299 | } | |
300 | ||
301 | void resize(size_type n,value_param_type x) | |
302 | { | |
303 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
304 | if(n>size())for(size_type m=n-size();m--;)this->final_insert_(x); | |
305 | else if(n<size())erase(begin()+n,end()); | |
306 | } | |
307 | ||
308 | /* access: no non-const versions provided as random_access_index | |
309 | * handles const elements. | |
310 | */ | |
311 | ||
312 | const_reference operator[](size_type n)const | |
313 | { | |
314 | BOOST_MULTI_INDEX_SAFE_MODE_ASSERT(n<size(),safe_mode::out_of_bounds); | |
315 | return node_type::from_impl(*ptrs.at(n))->value(); | |
316 | } | |
317 | ||
318 | const_reference at(size_type n)const | |
319 | { | |
320 | if(n>=size())throw_exception(std::out_of_range("random access index")); | |
321 | return node_type::from_impl(*ptrs.at(n))->value(); | |
322 | } | |
323 | ||
324 | const_reference front()const{return operator[](0);} | |
325 | const_reference back()const{return operator[](size()-1);} | |
326 | ||
327 | /* modifiers */ | |
328 | ||
329 | BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL( | |
330 | emplace_return_type,emplace_front,emplace_front_impl) | |
331 | ||
332 | std::pair<iterator,bool> push_front(const value_type& x) | |
333 | {return insert(begin(),x);} | |
334 | std::pair<iterator,bool> push_front(BOOST_RV_REF(value_type) x) | |
335 | {return insert(begin(),boost::move(x));} | |
336 | void pop_front(){erase(begin());} | |
337 | ||
338 | BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL( | |
339 | emplace_return_type,emplace_back,emplace_back_impl) | |
340 | ||
341 | std::pair<iterator,bool> push_back(const value_type& x) | |
342 | {return insert(end(),x);} | |
343 | std::pair<iterator,bool> push_back(BOOST_RV_REF(value_type) x) | |
344 | {return insert(end(),boost::move(x));} | |
345 | void pop_back(){erase(--end());} | |
346 | ||
347 | BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG( | |
348 | emplace_return_type,emplace,emplace_impl,iterator,position) | |
349 | ||
350 | std::pair<iterator,bool> insert(iterator position,const value_type& x) | |
351 | { | |
352 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
353 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
354 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
355 | std::pair<final_node_type*,bool> p=this->final_insert_(x); | |
356 | if(p.second&&position.get_node()!=header()){ | |
357 | relocate(position.get_node(),p.first); | |
358 | } | |
359 | return std::pair<iterator,bool>(make_iterator(p.first),p.second); | |
360 | } | |
361 | ||
362 | std::pair<iterator,bool> insert(iterator position,BOOST_RV_REF(value_type) x) | |
363 | { | |
364 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
365 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
366 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
367 | std::pair<final_node_type*,bool> p=this->final_insert_rv_(x); | |
368 | if(p.second&&position.get_node()!=header()){ | |
369 | relocate(position.get_node(),p.first); | |
370 | } | |
371 | return std::pair<iterator,bool>(make_iterator(p.first),p.second); | |
372 | } | |
373 | ||
374 | void insert(iterator position,size_type n,value_param_type x) | |
375 | { | |
376 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
377 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
378 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
379 | size_type s=0; | |
380 | BOOST_TRY{ | |
381 | while(n--){ | |
382 | if(push_back(x).second)++s; | |
383 | } | |
384 | } | |
385 | BOOST_CATCH(...){ | |
386 | relocate(position,end()-s,end()); | |
387 | BOOST_RETHROW; | |
388 | } | |
389 | BOOST_CATCH_END | |
390 | relocate(position,end()-s,end()); | |
391 | } | |
392 | ||
393 | template<typename InputIterator> | |
394 | void insert(iterator position,InputIterator first,InputIterator last) | |
395 | { | |
396 | insert_iter(position,first,last,mpl::not_<is_integral<InputIterator> >()); | |
397 | } | |
398 | ||
399 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
400 | void insert(iterator position,std::initializer_list<value_type> list) | |
401 | { | |
402 | insert(position,list.begin(),list.end()); | |
403 | } | |
404 | #endif | |
405 | ||
406 | iterator erase(iterator position) | |
407 | { | |
408 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
409 | BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position); | |
410 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
411 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
412 | this->final_erase_(static_cast<final_node_type*>(position++.get_node())); | |
413 | return position; | |
414 | } | |
415 | ||
416 | iterator erase(iterator first,iterator last) | |
417 | { | |
418 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first); | |
419 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last); | |
420 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this); | |
421 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this); | |
422 | BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last); | |
423 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
424 | difference_type n=last-first; | |
425 | relocate(end(),first,last); | |
426 | while(n--)pop_back(); | |
427 | return last; | |
428 | } | |
429 | ||
430 | bool replace(iterator position,const value_type& x) | |
431 | { | |
432 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
433 | BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position); | |
434 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
435 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
436 | return this->final_replace_( | |
437 | x,static_cast<final_node_type*>(position.get_node())); | |
438 | } | |
439 | ||
440 | bool replace(iterator position,BOOST_RV_REF(value_type) x) | |
441 | { | |
442 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
443 | BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position); | |
444 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
445 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
446 | return this->final_replace_rv_( | |
447 | x,static_cast<final_node_type*>(position.get_node())); | |
448 | } | |
449 | ||
450 | template<typename Modifier> | |
451 | bool modify(iterator position,Modifier mod) | |
452 | { | |
453 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
454 | BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position); | |
455 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
456 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
457 | ||
458 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
459 | /* MSVC++ 6.0 optimizer on safe mode code chokes if this | |
460 | * this is not added. Left it for all compilers as it does no | |
461 | * harm. | |
462 | */ | |
463 | ||
464 | position.detach(); | |
465 | #endif | |
466 | ||
467 | return this->final_modify_( | |
468 | mod,static_cast<final_node_type*>(position.get_node())); | |
469 | } | |
470 | ||
471 | template<typename Modifier,typename Rollback> | |
472 | bool modify(iterator position,Modifier mod,Rollback back_) | |
473 | { | |
474 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
475 | BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position); | |
476 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
477 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
478 | ||
479 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
480 | /* MSVC++ 6.0 optimizer on safe mode code chokes if this | |
481 | * this is not added. Left it for all compilers as it does no | |
482 | * harm. | |
483 | */ | |
484 | ||
485 | position.detach(); | |
486 | #endif | |
487 | ||
488 | return this->final_modify_( | |
489 | mod,back_,static_cast<final_node_type*>(position.get_node())); | |
490 | } | |
491 | ||
492 | void swap(random_access_index<SuperMeta,TagList>& x) | |
493 | { | |
494 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
495 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT_OF(x); | |
496 | this->final_swap_(x.final()); | |
497 | } | |
498 | ||
499 | void clear()BOOST_NOEXCEPT | |
500 | { | |
501 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
502 | this->final_clear_(); | |
503 | } | |
504 | ||
505 | /* list operations */ | |
506 | ||
507 | void splice(iterator position,random_access_index<SuperMeta,TagList>& x) | |
508 | { | |
509 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
510 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
511 | BOOST_MULTI_INDEX_CHECK_DIFFERENT_CONTAINER(*this,x); | |
512 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
513 | iterator first=x.begin(),last=x.end(); | |
514 | size_type n=0; | |
515 | BOOST_TRY{ | |
516 | while(first!=last){ | |
517 | if(push_back(*first).second){ | |
518 | first=x.erase(first); | |
519 | ++n; | |
520 | } | |
521 | else ++first; | |
522 | } | |
523 | } | |
524 | BOOST_CATCH(...){ | |
525 | relocate(position,end()-n,end()); | |
526 | BOOST_RETHROW; | |
527 | } | |
528 | BOOST_CATCH_END | |
529 | relocate(position,end()-n,end()); | |
530 | } | |
531 | ||
532 | void splice( | |
533 | iterator position,random_access_index<SuperMeta,TagList>& x,iterator i) | |
534 | { | |
535 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
536 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
537 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i); | |
538 | BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i); | |
539 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,x); | |
540 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
541 | if(&x==this)relocate(position,i); | |
542 | else{ | |
543 | if(insert(position,*i).second){ | |
544 | ||
545 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
546 | /* MSVC++ 6.0 optimizer has a hard time with safe mode, and the following | |
547 | * workaround is needed. Left it for all compilers as it does no | |
548 | * harm. | |
549 | */ | |
550 | i.detach(); | |
551 | x.erase(x.make_iterator(i.get_node())); | |
552 | #else | |
553 | x.erase(i); | |
554 | #endif | |
555 | ||
556 | } | |
557 | } | |
558 | } | |
559 | ||
560 | void splice( | |
561 | iterator position,random_access_index<SuperMeta,TagList>& x, | |
562 | iterator first,iterator last) | |
563 | { | |
564 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
565 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
566 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first); | |
567 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last); | |
568 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,x); | |
569 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x); | |
570 | BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last); | |
571 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
572 | if(&x==this)relocate(position,first,last); | |
573 | else{ | |
574 | size_type n=0; | |
575 | BOOST_TRY{ | |
576 | while(first!=last){ | |
577 | if(push_back(*first).second){ | |
578 | first=x.erase(first); | |
579 | ++n; | |
580 | } | |
581 | else ++first; | |
582 | } | |
583 | } | |
584 | BOOST_CATCH(...){ | |
585 | relocate(position,end()-n,end()); | |
586 | BOOST_RETHROW; | |
587 | } | |
588 | BOOST_CATCH_END | |
589 | relocate(position,end()-n,end()); | |
590 | } | |
591 | } | |
592 | ||
593 | void remove(value_param_type value) | |
594 | { | |
595 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
596 | difference_type n= | |
597 | end()-make_iterator( | |
598 | random_access_index_remove<node_type>( | |
599 | ptrs, | |
600 | ::boost::bind(std::equal_to<value_type>(),::boost::arg<1>(),value))); | |
601 | while(n--)pop_back(); | |
602 | } | |
603 | ||
604 | template<typename Predicate> | |
605 | void remove_if(Predicate pred) | |
606 | { | |
607 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
608 | difference_type n= | |
609 | end()-make_iterator(random_access_index_remove<node_type>(ptrs,pred)); | |
610 | while(n--)pop_back(); | |
611 | } | |
612 | ||
613 | void unique() | |
614 | { | |
615 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
616 | difference_type n= | |
617 | end()-make_iterator( | |
618 | random_access_index_unique<node_type>( | |
619 | ptrs,std::equal_to<value_type>())); | |
620 | while(n--)pop_back(); | |
621 | } | |
622 | ||
623 | template <class BinaryPredicate> | |
624 | void unique(BinaryPredicate binary_pred) | |
625 | { | |
626 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
627 | difference_type n= | |
628 | end()-make_iterator( | |
629 | random_access_index_unique<node_type>(ptrs,binary_pred)); | |
630 | while(n--)pop_back(); | |
631 | } | |
632 | ||
633 | void merge(random_access_index<SuperMeta,TagList>& x) | |
634 | { | |
635 | if(this!=&x){ | |
636 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
637 | size_type s=size(); | |
638 | splice(end(),x); | |
639 | random_access_index_inplace_merge<node_type>( | |
640 | get_allocator(),ptrs,ptrs.at(s),std::less<value_type>()); | |
641 | } | |
642 | } | |
643 | ||
644 | template <typename Compare> | |
645 | void merge(random_access_index<SuperMeta,TagList>& x,Compare comp) | |
646 | { | |
647 | if(this!=&x){ | |
648 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
649 | size_type s=size(); | |
650 | splice(end(),x); | |
651 | random_access_index_inplace_merge<node_type>( | |
652 | get_allocator(),ptrs,ptrs.at(s),comp); | |
653 | } | |
654 | } | |
655 | ||
656 | void sort() | |
657 | { | |
658 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
659 | random_access_index_sort<node_type>( | |
660 | get_allocator(),ptrs,std::less<value_type>()); | |
661 | } | |
662 | ||
663 | template <typename Compare> | |
664 | void sort(Compare comp) | |
665 | { | |
666 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
667 | random_access_index_sort<node_type>( | |
668 | get_allocator(),ptrs,comp); | |
669 | } | |
670 | ||
671 | void reverse()BOOST_NOEXCEPT | |
672 | { | |
673 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
674 | node_impl_type::reverse(ptrs.begin(),ptrs.end()); | |
675 | } | |
676 | ||
677 | /* rearrange operations */ | |
678 | ||
679 | void relocate(iterator position,iterator i) | |
680 | { | |
681 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
682 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
683 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i); | |
684 | BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i); | |
685 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,*this); | |
686 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
687 | if(position!=i)relocate(position.get_node(),i.get_node()); | |
688 | } | |
689 | ||
690 | void relocate(iterator position,iterator first,iterator last) | |
691 | { | |
692 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
693 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
694 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first); | |
695 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last); | |
696 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this); | |
697 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this); | |
698 | BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last); | |
699 | BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last); | |
700 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
701 | if(position!=last)relocate( | |
702 | position.get_node(),first.get_node(),last.get_node()); | |
703 | } | |
704 | ||
705 | template<typename InputIterator> | |
706 | void rearrange(InputIterator first) | |
707 | { | |
708 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
709 | for(node_impl_ptr_pointer p0=ptrs.begin(),p0_end=ptrs.end(); | |
710 | p0!=p0_end;++first,++p0){ | |
711 | const value_type& v1=*first; | |
712 | node_impl_ptr_pointer p1=node_from_value<node_type>(&v1)->up(); | |
713 | ||
714 | std::swap(*p0,*p1); | |
715 | (*p0)->up()=p0; | |
716 | (*p1)->up()=p1; | |
717 | } | |
718 | } | |
719 | ||
720 | BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: | |
721 | random_access_index( | |
722 | const ctor_args_list& args_list,const allocator_type& al): | |
723 | super(args_list.get_tail(),al), | |
724 | ptrs(al,header()->impl(),0) | |
725 | { | |
726 | } | |
727 | ||
728 | random_access_index(const random_access_index<SuperMeta,TagList>& x): | |
729 | super(x), | |
730 | ||
731 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
732 | safe_super(), | |
733 | #endif | |
734 | ||
735 | ptrs(x.get_allocator(),header()->impl(),x.size()) | |
736 | { | |
737 | /* The actual copying takes place in subsequent call to copy_(). | |
738 | */ | |
739 | } | |
740 | ||
741 | random_access_index( | |
742 | const random_access_index<SuperMeta,TagList>& x,do_not_copy_elements_tag): | |
743 | super(x,do_not_copy_elements_tag()), | |
744 | ||
745 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
746 | safe_super(), | |
747 | #endif | |
748 | ||
749 | ptrs(x.get_allocator(),header()->impl(),0) | |
750 | { | |
751 | } | |
752 | ||
753 | ~random_access_index() | |
754 | { | |
755 | /* the container is guaranteed to be empty by now */ | |
756 | } | |
757 | ||
758 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
759 | iterator make_iterator(node_type* node){return iterator(node,this);} | |
760 | const_iterator make_iterator(node_type* node)const | |
761 | {return const_iterator(node,const_cast<random_access_index*>(this));} | |
762 | #else | |
763 | iterator make_iterator(node_type* node){return iterator(node);} | |
764 | const_iterator make_iterator(node_type* node)const | |
765 | {return const_iterator(node);} | |
766 | #endif | |
767 | ||
768 | void copy_( | |
769 | const random_access_index<SuperMeta,TagList>& x,const copy_map_type& map) | |
770 | { | |
771 | for(node_impl_ptr_pointer begin_org=x.ptrs.begin(), | |
772 | begin_cpy=ptrs.begin(), | |
773 | end_org=x.ptrs.end(); | |
774 | begin_org!=end_org;++begin_org,++begin_cpy){ | |
775 | *begin_cpy= | |
776 | static_cast<node_type*>( | |
777 | map.find( | |
778 | static_cast<final_node_type*>( | |
779 | node_type::from_impl(*begin_org))))->impl(); | |
780 | (*begin_cpy)->up()=begin_cpy; | |
781 | } | |
782 | ||
783 | super::copy_(x,map); | |
784 | } | |
785 | ||
786 | template<typename Variant> | |
787 | final_node_type* insert_( | |
788 | value_param_type v,final_node_type*& x,Variant variant) | |
789 | { | |
790 | ptrs.room_for_one(); | |
791 | final_node_type* res=super::insert_(v,x,variant); | |
792 | if(res==x)ptrs.push_back(static_cast<node_type*>(x)->impl()); | |
793 | return res; | |
794 | } | |
795 | ||
796 | template<typename Variant> | |
797 | final_node_type* insert_( | |
798 | value_param_type v,node_type* position,final_node_type*& x,Variant variant) | |
799 | { | |
800 | ptrs.room_for_one(); | |
801 | final_node_type* res=super::insert_(v,position,x,variant); | |
802 | if(res==x)ptrs.push_back(static_cast<node_type*>(x)->impl()); | |
803 | return res; | |
804 | } | |
805 | ||
806 | void erase_(node_type* x) | |
807 | { | |
808 | ptrs.erase(x->impl()); | |
809 | super::erase_(x); | |
810 | ||
811 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
812 | detach_iterators(x); | |
813 | #endif | |
814 | } | |
815 | ||
816 | void delete_all_nodes_() | |
817 | { | |
818 | for(node_impl_ptr_pointer x=ptrs.begin(),x_end=ptrs.end();x!=x_end;++x){ | |
819 | this->final_delete_node_( | |
820 | static_cast<final_node_type*>(node_type::from_impl(*x))); | |
821 | } | |
822 | } | |
823 | ||
824 | void clear_() | |
825 | { | |
826 | super::clear_(); | |
827 | ptrs.clear(); | |
828 | ||
829 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
830 | safe_super::detach_dereferenceable_iterators(); | |
831 | #endif | |
832 | } | |
833 | ||
834 | void swap_(random_access_index<SuperMeta,TagList>& x) | |
835 | { | |
836 | ptrs.swap(x.ptrs); | |
837 | ||
838 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
839 | safe_super::swap(x); | |
840 | #endif | |
841 | ||
842 | super::swap_(x); | |
843 | } | |
844 | ||
845 | void swap_elements_(random_access_index<SuperMeta,TagList>& x) | |
846 | { | |
847 | ptrs.swap(x.ptrs); | |
848 | ||
849 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
850 | safe_super::swap(x); | |
851 | #endif | |
852 | ||
853 | super::swap_elements_(x); | |
854 | } | |
855 | ||
856 | template<typename Variant> | |
857 | bool replace_(value_param_type v,node_type* x,Variant variant) | |
858 | { | |
859 | return super::replace_(v,x,variant); | |
860 | } | |
861 | ||
862 | bool modify_(node_type* x) | |
863 | { | |
864 | BOOST_TRY{ | |
865 | if(!super::modify_(x)){ | |
866 | ptrs.erase(x->impl()); | |
867 | ||
868 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
869 | detach_iterators(x); | |
870 | #endif | |
871 | ||
872 | return false; | |
873 | } | |
874 | else return true; | |
875 | } | |
876 | BOOST_CATCH(...){ | |
877 | ptrs.erase(x->impl()); | |
878 | ||
879 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
880 | detach_iterators(x); | |
881 | #endif | |
882 | ||
883 | BOOST_RETHROW; | |
884 | } | |
885 | BOOST_CATCH_END | |
886 | } | |
887 | ||
888 | bool modify_rollback_(node_type* x) | |
889 | { | |
890 | return super::modify_rollback_(x); | |
891 | } | |
892 | ||
b32b8144 FG |
893 | bool check_rollback_(node_type* x)const |
894 | { | |
895 | return super::check_rollback_(x); | |
896 | } | |
897 | ||
7c673cae FG |
898 | #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION) |
899 | /* serialization */ | |
900 | ||
901 | template<typename Archive> | |
902 | void save_( | |
903 | Archive& ar,const unsigned int version,const index_saver_type& sm)const | |
904 | { | |
905 | sm.save(begin(),end(),ar,version); | |
906 | super::save_(ar,version,sm); | |
907 | } | |
908 | ||
909 | template<typename Archive> | |
910 | void load_( | |
911 | Archive& ar,const unsigned int version,const index_loader_type& lm) | |
912 | { | |
913 | { | |
914 | typedef random_access_index_loader<node_type,allocator_type> loader; | |
915 | ||
916 | loader ld(get_allocator(),ptrs); | |
917 | lm.load( | |
918 | ::boost::bind( | |
919 | &loader::rearrange,&ld,::boost::arg<1>(),::boost::arg<2>()), | |
920 | ar,version); | |
921 | } /* exit scope so that ld frees its resources */ | |
922 | super::load_(ar,version,lm); | |
923 | } | |
924 | #endif | |
925 | ||
926 | #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING) | |
927 | /* invariant stuff */ | |
928 | ||
929 | bool invariant_()const | |
930 | { | |
931 | if(size()>capacity())return false; | |
932 | if(size()==0||begin()==end()){ | |
933 | if(size()!=0||begin()!=end())return false; | |
934 | } | |
935 | else{ | |
936 | size_type s=0; | |
937 | for(const_iterator it=begin(),it_end=end();;++it,++s){ | |
938 | if(*(it.get_node()->up())!=it.get_node()->impl())return false; | |
939 | if(it==it_end)break; | |
940 | } | |
941 | if(s!=size())return false; | |
942 | } | |
943 | ||
944 | return super::invariant_(); | |
945 | } | |
946 | ||
947 | /* This forwarding function eases things for the boost::mem_fn construct | |
948 | * in BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT. Actually, | |
949 | * final_check_invariant is already an inherited member function of index. | |
950 | */ | |
951 | void check_invariant_()const{this->final_check_invariant_();} | |
952 | #endif | |
953 | ||
954 | private: | |
955 | node_type* header()const{return this->final_header();} | |
956 | ||
957 | static void relocate(node_type* position,node_type* x) | |
958 | { | |
959 | node_impl_type::relocate(position->up(),x->up()); | |
960 | } | |
961 | ||
962 | static void relocate(node_type* position,node_type* first,node_type* last) | |
963 | { | |
964 | node_impl_type::relocate( | |
965 | position->up(),first->up(),last->up()); | |
966 | } | |
967 | ||
968 | #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) | |
969 | void detach_iterators(node_type* x) | |
970 | { | |
971 | iterator it=make_iterator(x); | |
972 | safe_mode::detach_equivalent_iterators(it); | |
973 | } | |
974 | #endif | |
975 | ||
976 | template <class InputIterator> | |
977 | void assign_iter(InputIterator first,InputIterator last,mpl::true_) | |
978 | { | |
979 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
980 | clear(); | |
981 | for(;first!=last;++first)this->final_insert_ref_(*first); | |
982 | } | |
983 | ||
984 | void assign_iter(size_type n,value_param_type value,mpl::false_) | |
985 | { | |
986 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
987 | clear(); | |
988 | for(size_type i=0;i<n;++i)push_back(value); | |
989 | } | |
990 | ||
991 | template<typename InputIterator> | |
992 | void insert_iter( | |
993 | iterator position,InputIterator first,InputIterator last,mpl::true_) | |
994 | { | |
995 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
996 | size_type s=0; | |
997 | BOOST_TRY{ | |
998 | for(;first!=last;++first){ | |
999 | if(this->final_insert_ref_(*first).second)++s; | |
1000 | } | |
1001 | } | |
1002 | BOOST_CATCH(...){ | |
1003 | relocate(position,end()-s,end()); | |
1004 | BOOST_RETHROW; | |
1005 | } | |
1006 | BOOST_CATCH_END | |
1007 | relocate(position,end()-s,end()); | |
1008 | } | |
1009 | ||
1010 | void insert_iter( | |
1011 | iterator position,size_type n,value_param_type x,mpl::false_) | |
1012 | { | |
1013 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
1014 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
1015 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
1016 | size_type s=0; | |
1017 | BOOST_TRY{ | |
1018 | while(n--){ | |
1019 | if(push_back(x).second)++s; | |
1020 | } | |
1021 | } | |
1022 | BOOST_CATCH(...){ | |
1023 | relocate(position,end()-s,end()); | |
1024 | BOOST_RETHROW; | |
1025 | } | |
1026 | BOOST_CATCH_END | |
1027 | relocate(position,end()-s,end()); | |
1028 | } | |
1029 | ||
1030 | template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK> | |
1031 | std::pair<iterator,bool> emplace_front_impl( | |
1032 | BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK) | |
1033 | { | |
1034 | return emplace_impl(begin(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); | |
1035 | } | |
1036 | ||
1037 | template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK> | |
1038 | std::pair<iterator,bool> emplace_back_impl( | |
1039 | BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK) | |
1040 | { | |
1041 | return emplace_impl(end(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); | |
1042 | } | |
1043 | ||
1044 | template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK> | |
1045 | std::pair<iterator,bool> emplace_impl( | |
1046 | iterator position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK) | |
1047 | { | |
1048 | BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position); | |
1049 | BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this); | |
1050 | BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; | |
1051 | std::pair<final_node_type*,bool> p= | |
1052 | this->final_emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); | |
1053 | if(p.second&&position.get_node()!=header()){ | |
1054 | relocate(position.get_node(),p.first); | |
1055 | } | |
1056 | return std::pair<iterator,bool>(make_iterator(p.first),p.second); | |
1057 | } | |
1058 | ||
1059 | ptr_array ptrs; | |
1060 | ||
1061 | #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\ | |
1062 | BOOST_WORKAROUND(__MWERKS__,<=0x3003) | |
1063 | #pragma parse_mfunc_templ reset | |
1064 | #endif | |
1065 | }; | |
1066 | ||
1067 | /* comparison */ | |
1068 | ||
1069 | template< | |
1070 | typename SuperMeta1,typename TagList1, | |
1071 | typename SuperMeta2,typename TagList2 | |
1072 | > | |
1073 | bool operator==( | |
1074 | const random_access_index<SuperMeta1,TagList1>& x, | |
1075 | const random_access_index<SuperMeta2,TagList2>& y) | |
1076 | { | |
1077 | return x.size()==y.size()&&std::equal(x.begin(),x.end(),y.begin()); | |
1078 | } | |
1079 | ||
1080 | template< | |
1081 | typename SuperMeta1,typename TagList1, | |
1082 | typename SuperMeta2,typename TagList2 | |
1083 | > | |
1084 | bool operator<( | |
1085 | const random_access_index<SuperMeta1,TagList1>& x, | |
1086 | const random_access_index<SuperMeta2,TagList2>& y) | |
1087 | { | |
1088 | return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()); | |
1089 | } | |
1090 | ||
1091 | template< | |
1092 | typename SuperMeta1,typename TagList1, | |
1093 | typename SuperMeta2,typename TagList2 | |
1094 | > | |
1095 | bool operator!=( | |
1096 | const random_access_index<SuperMeta1,TagList1>& x, | |
1097 | const random_access_index<SuperMeta2,TagList2>& y) | |
1098 | { | |
1099 | return !(x==y); | |
1100 | } | |
1101 | ||
1102 | template< | |
1103 | typename SuperMeta1,typename TagList1, | |
1104 | typename SuperMeta2,typename TagList2 | |
1105 | > | |
1106 | bool operator>( | |
1107 | const random_access_index<SuperMeta1,TagList1>& x, | |
1108 | const random_access_index<SuperMeta2,TagList2>& y) | |
1109 | { | |
1110 | return y<x; | |
1111 | } | |
1112 | ||
1113 | template< | |
1114 | typename SuperMeta1,typename TagList1, | |
1115 | typename SuperMeta2,typename TagList2 | |
1116 | > | |
1117 | bool operator>=( | |
1118 | const random_access_index<SuperMeta1,TagList1>& x, | |
1119 | const random_access_index<SuperMeta2,TagList2>& y) | |
1120 | { | |
1121 | return !(x<y); | |
1122 | } | |
1123 | ||
1124 | template< | |
1125 | typename SuperMeta1,typename TagList1, | |
1126 | typename SuperMeta2,typename TagList2 | |
1127 | > | |
1128 | bool operator<=( | |
1129 | const random_access_index<SuperMeta1,TagList1>& x, | |
1130 | const random_access_index<SuperMeta2,TagList2>& y) | |
1131 | { | |
1132 | return !(x>y); | |
1133 | } | |
1134 | ||
1135 | /* specialized algorithms */ | |
1136 | ||
1137 | template<typename SuperMeta,typename TagList> | |
1138 | void swap( | |
1139 | random_access_index<SuperMeta,TagList>& x, | |
1140 | random_access_index<SuperMeta,TagList>& y) | |
1141 | { | |
1142 | x.swap(y); | |
1143 | } | |
1144 | ||
1145 | } /* namespace multi_index::detail */ | |
1146 | ||
1147 | /* random access index specifier */ | |
1148 | ||
1149 | template <typename TagList> | |
1150 | struct random_access | |
1151 | { | |
1152 | BOOST_STATIC_ASSERT(detail::is_tag<TagList>::value); | |
1153 | ||
1154 | template<typename Super> | |
1155 | struct node_class | |
1156 | { | |
1157 | typedef detail::random_access_index_node<Super> type; | |
1158 | }; | |
1159 | ||
1160 | template<typename SuperMeta> | |
1161 | struct index_class | |
1162 | { | |
1163 | typedef detail::random_access_index< | |
1164 | SuperMeta,typename TagList::type> type; | |
1165 | }; | |
1166 | }; | |
1167 | ||
1168 | } /* namespace multi_index */ | |
1169 | ||
1170 | } /* namespace boost */ | |
1171 | ||
1172 | /* Boost.Foreach compatibility */ | |
1173 | ||
1174 | template<typename SuperMeta,typename TagList> | |
1175 | inline boost::mpl::true_* boost_foreach_is_noncopyable( | |
1176 | boost::multi_index::detail::random_access_index<SuperMeta,TagList>*&, | |
1177 | boost_foreach_argument_dependent_lookup_hack) | |
1178 | { | |
1179 | return 0; | |
1180 | } | |
1181 | ||
1182 | #undef BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT | |
1183 | #undef BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT_OF | |
1184 | ||
1185 | #endif |