vector_of.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // Boost.Bimap
  2. //
  3. // Copyright (c) 2006-2007 Matias Capeletto
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. /// \file vector_of.hpp
  9. /// \brief Include support for vector constrains for the bimap container
  10. #ifndef BOOST_BIMAP_VECTOR_OF_HPP
  11. #define BOOST_BIMAP_VECTOR_OF_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <boost/bimap/detail/user_interface_config.hpp>
  17. #include <boost/mpl/bool.hpp>
  18. #include <boost/concept_check.hpp>
  19. #include <boost/bimap/detail/concept_tags.hpp>
  20. #include <boost/bimap/tags/support/value_type_of.hpp>
  21. #include <boost/bimap/detail/generate_index_binder.hpp>
  22. #include <boost/bimap/detail/generate_view_binder.hpp>
  23. #include <boost/bimap/detail/generate_relation_binder.hpp>
  24. #include <boost/multi_index/random_access_index.hpp>
  25. #include <boost/bimap/views/vector_map_view.hpp>
  26. #include <boost/bimap/views/vector_set_view.hpp>
  27. namespace boost {
  28. namespace bimaps {
  29. /// \brief Set Type Specification
  30. /**
  31. This struct is used to specify a set specification.
  32. It is not a container, it is just a metaprogramming facility to
  33. express the type of a set. Generally, this specification will
  34. be used in other place to create a container.
  35. It has the same syntax that an std::vector instantiation, except
  36. that the allocator cannot be specified. The rationale behind
  37. this difference is that the allocator is not part of the set
  38. type specification, rather it is a container configuration
  39. parameter.
  40. The first parameter is the type of the objects in the set, and
  41. the second one is a Functor that compares them.
  42. Bimap binding metafunctions can be used with this class in
  43. the following way:
  44. \code
  45. using namespace support;
  46. BOOST_STATIC_ASSERT( is_set_type_of< vector_of<Type> >::value )
  47. BOOST_STATIC_ASSERT
  48. (
  49. is_same
  50. <
  51. vector_of<Type>::index_bind
  52. <
  53. KeyExtractor,
  54. Tag
  55. >::type,
  56. random_access< tag<Tag>, KeyExtractor >
  57. >::value
  58. )
  59. typedef bimap
  60. <
  61. vector_of<Type>, RightKeyType
  62. > bimap_with_left_type_as_vector;
  63. BOOST_STATIC_ASSERT
  64. (
  65. is_same
  66. <
  67. vector_of<Type>::map_view_bind
  68. <
  69. member_at::left,
  70. bimap_with_left_type_as_vector
  71. >::type,
  72. vector_map_view< member_at::left, bimap_with_left_type_as_vector >
  73. >::value
  74. )
  75. \endcode
  76. See also vector_of_relation.
  77. **/
  78. template< class Type >
  79. struct vector_of : public ::boost::bimaps::detail::set_type_of_tag
  80. {
  81. /// User type, can be tagged
  82. typedef Type user_type;
  83. /// Type of the object that will be stored in the vector
  84. typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::
  85. value_type_of<user_type>::type value_type;
  86. struct lazy_concept_checked
  87. {
  88. BOOST_CLASS_REQUIRE ( value_type,
  89. boost, AssignableConcept );
  90. typedef vector_of type;
  91. };
  92. BOOST_BIMAP_GENERATE_INDEX_BINDER_0CP_NO_EXTRACTOR(
  93. // binds to
  94. multi_index::random_access
  95. )
  96. BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER(
  97. // binds to
  98. views::vector_map_view
  99. )
  100. BOOST_BIMAP_GENERATE_SET_VIEW_BINDER(
  101. // binds to
  102. views::vector_set_view
  103. )
  104. typedef mpl::bool_<true> mutable_key;
  105. };
  106. /// \brief Set Of Relation Specification
  107. /**
  108. This struct is similar to vector_of but it is bind logically to a
  109. relation. It is used in the bimap instantiation to specify the
  110. desired type of the main view. This struct implements internally
  111. a metafunction named bind_to that manages the quite complicated
  112. task of finding the right type of the set for the relation.
  113. \code
  114. template<class Relation>
  115. struct bind_to
  116. {
  117. typedef -unspecified- type;
  118. };
  119. \endcode
  120. See also vector_of, is_set_type_of_relation.
  121. **/
  122. struct vector_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag
  123. {
  124. BOOST_BIMAP_GENERATE_RELATION_BINDER_0CP(
  125. // binds to
  126. vector_of
  127. )
  128. typedef mpl::bool_<true> left_mutable_key;
  129. typedef mpl::bool_<true> right_mutable_key;
  130. };
  131. } // namespace bimaps
  132. } // namespace boost
  133. #endif // BOOST_BIMAP_VECTOR_OF_HPP