unordered_multiset_of.hpp 5.9 KB

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