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