base_type.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright 2003-2013 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_BASE_TYPE_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_BASE_TYPE_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/detail/workaround.hpp>
  15. #include <boost/mpl/at.hpp>
  16. #include <boost/mpl/apply.hpp>
  17. #include <boost/mpl/size.hpp>
  18. #include <boost/multi_index/detail/index_base.hpp>
  19. #include <boost/multi_index/detail/is_index_list.hpp>
  20. #include <boost/static_assert.hpp>
  21. namespace boost{
  22. namespace multi_index{
  23. namespace detail{
  24. /* MPL machinery to construct a linear hierarchy of indices out of
  25. * a index list.
  26. */
  27. struct index_applier
  28. {
  29. template<typename IndexSpecifierMeta,typename SuperMeta>
  30. struct apply
  31. {
  32. typedef typename IndexSpecifierMeta::type index_specifier;
  33. typedef typename index_specifier::
  34. BOOST_NESTED_TEMPLATE index_class<SuperMeta>::type type;
  35. };
  36. };
  37. template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
  38. struct nth_layer
  39. {
  40. BOOST_STATIC_CONSTANT(int,length=mpl::size<IndexSpecifierList>::value);
  41. typedef typename mpl::eval_if_c<
  42. N==length,
  43. mpl::identity<index_base<Value,IndexSpecifierList,Allocator> >,
  44. mpl::apply2<
  45. index_applier,
  46. mpl::at_c<IndexSpecifierList,N>,
  47. nth_layer<N+1,Value,IndexSpecifierList,Allocator>
  48. >
  49. >::type type;
  50. };
  51. template<typename Value,typename IndexSpecifierList,typename Allocator>
  52. struct multi_index_base_type:nth_layer<0,Value,IndexSpecifierList,Allocator>
  53. {
  54. BOOST_STATIC_ASSERT(detail::is_index_list<IndexSpecifierList>::value);
  55. };
  56. } /* namespace multi_index::detail */
  57. } /* namespace multi_index */
  58. } /* namespace boost */
  59. #endif