annotate DEPENDENCIES/generic/include/boost/multi_index_container.hpp @ 125:34e428693f5d vext

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