multiset_of.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 multiset_of.hpp
  9. /// \brief Include support for multiset constrains for the bimap container
  10. #ifndef BOOST_BIMAP_MULTISET_OF_HPP
  11. #define BOOST_BIMAP_MULTISET_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 <functional>
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/concept_check.hpp>
  20. #include <boost/bimap/detail/concept_tags.hpp>
  21. #include <boost/bimap/tags/support/value_type_of.hpp>
  22. #include <boost/bimap/detail/generate_index_binder.hpp>
  23. #include <boost/bimap/detail/generate_view_binder.hpp>
  24. #include <boost/bimap/detail/generate_relation_binder.hpp>
  25. #include <boost/multi_index/ordered_index.hpp>
  26. #include <boost/bimap/views/multimap_view.hpp>
  27. #include <boost/bimap/views/multiset_view.hpp>
  28. namespace boost {
  29. namespace bimaps {
  30. /// \brief Set Type Specification
  31. /**
  32. This struct is used to specify a multiset specification.
  33. It is not a container, it is just a metaprogramming facility to
  34. express the type of a set. Generally, this specification will
  35. be used in other place to create a container.
  36. It has the same syntax that an std::set instantiation, except
  37. that the allocator cannot be specified. The rationale behind
  38. this difference is that the allocator is not part of the set
  39. type specification, rather it is a container configuration
  40. parameter.
  41. The first parameter is the type of the objects in the multiset,
  42. and the second one is a Functor that compares them.
  43. Bimap binding metafunctions can be used with this class in
  44. the following way:
  45. \code
  46. using namespace support;
  47. BOOST_STATIC_ASSERT( is_set_type_of< multiset_of<Type> >::value )
  48. BOOST_STATIC_ASSERT
  49. (
  50. is_same
  51. <
  52. compute_index_type
  53. <
  54. multiset_of<Type,KeyCompare>,
  55. KeyExtractor,
  56. Tag
  57. >::type
  58. ,
  59. ordered_nonunique< tag<Tag>, KeyExtractor, KeyCompare >
  60. >::value
  61. )
  62. typedef bimap
  63. <
  64. multiset_of<Type>, RightKeyType
  65. > bimap_with_left_type_as_multiset;
  66. BOOST_STATIC_ASSERT
  67. (
  68. is_same
  69. <
  70. compute_map_view_type
  71. <
  72. member_at::left,
  73. bimap_with_left_type_as_multiset
  74. >::type,
  75. multimap_view< member_at::left, bimap_with_left_type_as_multiset >
  76. >::value
  77. )
  78. \endcode
  79. See also multiset_of_relation.
  80. **/
  81. template
  82. <
  83. class KeyType,
  84. class KeyCompare = std::less< BOOST_DEDUCED_TYPENAME
  85. ::boost::bimaps::tags::support::value_type_of<KeyType>::type >
  86. >
  87. struct multiset_of : public ::boost::bimaps::detail::set_type_of_tag
  88. {
  89. /// User type, can be tagged
  90. typedef KeyType user_type;
  91. /// Type of the object that will be stored in the multiset
  92. typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::
  93. value_type_of<user_type>::type value_type;
  94. /// Functor that compare two keys
  95. typedef KeyCompare key_compare;
  96. struct lazy_concept_checked
  97. {
  98. BOOST_CLASS_REQUIRE ( value_type,
  99. boost, AssignableConcept );
  100. BOOST_CLASS_REQUIRE4( key_compare, bool, value_type, value_type,
  101. boost, BinaryFunctionConcept );
  102. typedef multiset_of type;
  103. };
  104. BOOST_BIMAP_GENERATE_INDEX_BINDER_1CP(
  105. // binds to
  106. multi_index::ordered_non_unique,
  107. // with
  108. key_compare
  109. )
  110. BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER(
  111. // binds to
  112. views::multimap_view
  113. )
  114. BOOST_BIMAP_GENERATE_SET_VIEW_BINDER(
  115. // binds to
  116. views::multiset_view
  117. )
  118. typedef mpl::bool_<false> mutable_key;
  119. };
  120. /// \brief Set Of Relation Specification
  121. /**
  122. This struct is similar to multiset_of but it is bind logically to a
  123. relation. It is used in the bimap instantiation to specify the
  124. desired type of the main view. This struct implements internally
  125. a metafunction named bind_to that manages the quite complicated
  126. task of finding the right type of the set for the relation.
  127. \code
  128. template<class Relation>
  129. struct bind_to
  130. {
  131. typedef -unspecified- type;
  132. };
  133. \endcode
  134. See also multiset_of, is_set_type_of_relation.
  135. **/
  136. template< class KeyCompare = std::less< _relation > >
  137. struct multiset_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag
  138. {
  139. /// Functor that compare two keys
  140. typedef KeyCompare key_compare;
  141. BOOST_BIMAP_GENERATE_RELATION_BINDER_1CP(
  142. // binds to
  143. multiset_of,
  144. // with
  145. key_compare
  146. )
  147. typedef mpl::bool_<false> left_mutable_key;
  148. typedef mpl::bool_<false> right_mutable_key;
  149. };
  150. } // namespace bimaps
  151. } // namespace boost
  152. #endif // BOOST_BIMAP_MULTISET_OF_HPP