tag.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_TAG_HPP
  9. #define BOOST_MULTI_INDEX_TAG_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/multi_index/detail/no_duplicate_tags.hpp>
  15. #include <boost/mpl/identity.hpp>
  16. #include <boost/mpl/transform.hpp>
  17. #include <boost/mpl/vector.hpp>
  18. #include <boost/preprocessor/facilities/intercept.hpp>
  19. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  20. #include <boost/preprocessor/repetition/enum_params.hpp>
  21. #include <boost/static_assert.hpp>
  22. #include <boost/type_traits/is_base_and_derived.hpp>
  23. /* A wrapper of mpl::vector used to hide MPL from the user.
  24. * tag contains types used as tag names for indices in get() functions.
  25. */
  26. /* This user_definable macro limits the number of elements of a tag;
  27. * useful for shortening resulting symbol names (MSVC++ 6.0, for instance,
  28. * has problems coping with very long symbol names.)
  29. */
  30. #if !defined(BOOST_MULTI_INDEX_LIMIT_TAG_SIZE)
  31. #define BOOST_MULTI_INDEX_LIMIT_TAG_SIZE BOOST_MPL_LIMIT_VECTOR_SIZE
  32. #endif
  33. #if BOOST_MULTI_INDEX_LIMIT_TAG_SIZE<BOOST_MPL_LIMIT_VECTOR_SIZE
  34. #define BOOST_MULTI_INDEX_TAG_SIZE BOOST_MULTI_INDEX_LIMIT_TAG_SIZE
  35. #else
  36. #define BOOST_MULTI_INDEX_TAG_SIZE BOOST_MPL_LIMIT_VECTOR_SIZE
  37. #endif
  38. namespace boost{
  39. namespace multi_index{
  40. namespace detail{
  41. struct tag_marker{};
  42. template<typename T>
  43. struct is_tag
  44. {
  45. BOOST_STATIC_CONSTANT(bool,value=(is_base_and_derived<tag_marker,T>::value));
  46. };
  47. } /* namespace multi_index::detail */
  48. template<
  49. BOOST_PP_ENUM_BINARY_PARAMS(
  50. BOOST_MULTI_INDEX_TAG_SIZE,
  51. typename T,
  52. =mpl::na BOOST_PP_INTERCEPT)
  53. >
  54. struct tag:private detail::tag_marker
  55. {
  56. /* The mpl::transform pass produces shorter symbols (without
  57. * trailing mpl::na's.)
  58. */
  59. typedef typename mpl::transform<
  60. mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_MULTI_INDEX_TAG_SIZE,T)>,
  61. mpl::identity<mpl::_1>
  62. >::type type;
  63. BOOST_STATIC_ASSERT(detail::no_duplicate_tags<type>::value);
  64. };
  65. } /* namespace multi_index */
  66. } /* namespace boost */
  67. #undef BOOST_MULTI_INDEX_TAG_SIZE
  68. #endif