index_access_sequence.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright 2003-2021 Joaquin M Lopez Munoz.
  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. #ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_ACCESS_SEQUENCE_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_INDEX_ACCESS_SEQUENCE_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/mpl/if.hpp>
  15. #include <boost/mpl/size.hpp>
  16. #include <boost/multi_index_container_fwd.hpp>
  17. namespace boost{
  18. namespace multi_index{
  19. namespace detail{
  20. /* Successive access to the indices of a multi_index_container. Used as dst in
  21. * backbone function extract_(x,dst) to retrieve the destination indices
  22. * where iterators referring to x must be transferred to (in merging
  23. * operations).
  24. */
  25. template<typename MultiIndexContainer,int N=0>
  26. struct index_access_sequence;
  27. struct index_access_sequence_terminal
  28. {
  29. index_access_sequence_terminal(void*){}
  30. };
  31. template<typename MultiIndexContainer,int N>
  32. struct index_access_sequence_normal
  33. {
  34. MultiIndexContainer* p;
  35. index_access_sequence_normal(MultiIndexContainer* p_):p(p_){}
  36. typename nth_index<MultiIndexContainer,N>::type&
  37. get(){return p->template get<N>();}
  38. index_access_sequence<MultiIndexContainer,N+1>
  39. next(){return index_access_sequence<MultiIndexContainer,N+1>(p);}
  40. };
  41. template<typename MultiIndexContainer,int N>
  42. struct index_access_sequence_base:
  43. mpl::if_c<
  44. N<mpl::size<typename MultiIndexContainer::index_type_list>::type::value,
  45. index_access_sequence_normal<MultiIndexContainer,N>,
  46. index_access_sequence_terminal
  47. >
  48. {};
  49. template<typename MultiIndexContainer,int N>
  50. struct index_access_sequence:
  51. index_access_sequence_base<MultiIndexContainer,N>::type
  52. {
  53. typedef typename index_access_sequence_base<
  54. MultiIndexContainer,N>::type super;
  55. index_access_sequence(MultiIndexContainer* p):super(p){}
  56. };
  57. } /* namespace multi_index::detail */
  58. } /* namespace multi_index */
  59. } /* namespace boost */
  60. #endif