Chris@16
|
1 // Boost.Bimap
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright (c) 2006-2007 Matias Capeletto
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 /// \file unordered_set_of.hpp
|
Chris@16
|
10 /// \brief Include support for unordered_set constrains for the bimap container
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_BIMAP_UNORDERED_SET_OF_HPP
|
Chris@16
|
13 #define BOOST_BIMAP_UNORDERED_SET_OF_HPP
|
Chris@16
|
14
|
Chris@101
|
15 #if defined(_MSC_VER)
|
Chris@16
|
16 #pragma once
|
Chris@16
|
17 #endif
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/config.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/bimap/detail/user_interface_config.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 #include <functional>
|
Chris@16
|
24 #include <boost/functional/hash.hpp>
|
Chris@16
|
25 #include <boost/mpl/bool.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/concept_check.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 #include <boost/bimap/detail/concept_tags.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 #include <boost/bimap/tags/support/value_type_of.hpp>
|
Chris@16
|
32
|
Chris@16
|
33 #include <boost/bimap/detail/generate_index_binder.hpp>
|
Chris@16
|
34 #include <boost/bimap/detail/generate_view_binder.hpp>
|
Chris@16
|
35 #include <boost/bimap/detail/generate_relation_binder.hpp>
|
Chris@16
|
36
|
Chris@16
|
37 #include <boost/multi_index/hashed_index.hpp>
|
Chris@16
|
38
|
Chris@16
|
39 #include <boost/bimap/views/unordered_map_view.hpp>
|
Chris@16
|
40 #include <boost/bimap/views/unordered_set_view.hpp>
|
Chris@16
|
41
|
Chris@16
|
42 namespace boost {
|
Chris@16
|
43 namespace bimaps {
|
Chris@16
|
44
|
Chris@16
|
45 /// \brief Set Type Specification
|
Chris@16
|
46 /**
|
Chris@16
|
47 This struct is used to specify an unordered_set specification.
|
Chris@16
|
48 It is not a container, it is just a metaprogramming facility to
|
Chris@16
|
49 express the type of a set. Generally, this specification will
|
Chris@16
|
50 be used in other place to create a container.
|
Chris@16
|
51 It has the same syntax that an tr1::unordered_set instantiation,
|
Chris@16
|
52 except that the allocator cannot be specified. The rationale behind
|
Chris@16
|
53 this difference is that the allocator is not part of the
|
Chris@16
|
54 unordered_set type specification, rather it is a container
|
Chris@16
|
55 configuration parameter.
|
Chris@16
|
56 The first parameter is the type of the objects in the set, the
|
Chris@16
|
57 second one is a Hash Functor that takes objects of this type, and
|
Chris@16
|
58 the third one is a Functor that compares them for equality.
|
Chris@16
|
59 Bimap binding metafunctions can be used with this class in
|
Chris@16
|
60 the following way:
|
Chris@16
|
61
|
Chris@16
|
62 \code
|
Chris@16
|
63 using namespace support;
|
Chris@16
|
64
|
Chris@16
|
65 BOOST_STATIC_ASSERT( is_set_type_of< unordered_set_of<Type> >::value )
|
Chris@16
|
66
|
Chris@16
|
67 BOOST_STATIC_ASSERT
|
Chris@16
|
68 (
|
Chris@16
|
69 is_same
|
Chris@16
|
70 <
|
Chris@16
|
71 unordered_set_of<Type,HashFunctor,EqualKey>::index_bind
|
Chris@16
|
72 <
|
Chris@16
|
73 KeyExtractor,
|
Chris@16
|
74 Tag
|
Chris@16
|
75
|
Chris@16
|
76 >::type,
|
Chris@16
|
77
|
Chris@16
|
78 hashed_unique< tag<Tag>, KeyExtractor, HashFunctor, EqualKey >
|
Chris@16
|
79
|
Chris@16
|
80 >::value
|
Chris@16
|
81 )
|
Chris@16
|
82
|
Chris@16
|
83 typedef bimap
|
Chris@16
|
84 <
|
Chris@16
|
85 unordered_set_of<Type>, RightKeyType
|
Chris@16
|
86
|
Chris@16
|
87 > bimap_with_left_type_as_unordered_set;
|
Chris@16
|
88
|
Chris@16
|
89 BOOST_STATIC_ASSERT
|
Chris@16
|
90 (
|
Chris@16
|
91 is_same
|
Chris@16
|
92 <
|
Chris@16
|
93 unordered_set_of<Type>::map_view_bind
|
Chris@16
|
94 <
|
Chris@16
|
95 member_at::left,
|
Chris@16
|
96 bimap_with_left_type_as_unordered_set
|
Chris@16
|
97
|
Chris@16
|
98 >::type,
|
Chris@16
|
99
|
Chris@16
|
100 unordered_map_view
|
Chris@16
|
101 <
|
Chris@16
|
102 member_at::left,
|
Chris@16
|
103 bimap_with_left_type_as_unordered_set
|
Chris@16
|
104 >
|
Chris@16
|
105
|
Chris@16
|
106 >::value
|
Chris@16
|
107 )
|
Chris@16
|
108
|
Chris@16
|
109 \endcode
|
Chris@16
|
110
|
Chris@16
|
111 See also unordered_set_of_relation.
|
Chris@16
|
112 **/
|
Chris@16
|
113
|
Chris@16
|
114 template
|
Chris@16
|
115 <
|
Chris@16
|
116 class KeyType,
|
Chris@16
|
117 class HashFunctor = hash< BOOST_DEDUCED_TYPENAME
|
Chris@16
|
118 ::boost::bimaps::tags::support::value_type_of<KeyType>::type >,
|
Chris@16
|
119 class EqualKey = std::equal_to< BOOST_DEDUCED_TYPENAME
|
Chris@16
|
120 ::boost::bimaps::tags::support::value_type_of<KeyType>::type >
|
Chris@16
|
121 >
|
Chris@16
|
122 struct unordered_set_of : public ::boost::bimaps::detail::set_type_of_tag
|
Chris@16
|
123 {
|
Chris@16
|
124 /// User type, can be tagged
|
Chris@16
|
125 typedef KeyType user_type;
|
Chris@16
|
126
|
Chris@16
|
127 /// Type of the object that will be stored in the container
|
Chris@16
|
128 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::
|
Chris@16
|
129 value_type_of<user_type>::type value_type;
|
Chris@16
|
130
|
Chris@16
|
131 /// Hash Functor that takes value_type objects
|
Chris@16
|
132 typedef HashFunctor hasher;
|
Chris@16
|
133
|
Chris@16
|
134 /// Functor that compare two value_type objects for equality
|
Chris@16
|
135 typedef EqualKey key_equal;
|
Chris@16
|
136
|
Chris@16
|
137 struct lazy_concept_checked
|
Chris@16
|
138 {
|
Chris@16
|
139 BOOST_CLASS_REQUIRE ( value_type,
|
Chris@16
|
140 boost, AssignableConcept );
|
Chris@16
|
141
|
Chris@16
|
142 BOOST_CLASS_REQUIRE3( hasher, std::size_t, value_type,
|
Chris@16
|
143 boost, UnaryFunctionConcept );
|
Chris@16
|
144
|
Chris@16
|
145 BOOST_CLASS_REQUIRE4( key_equal, bool, value_type, value_type,
|
Chris@16
|
146 boost, BinaryFunctionConcept );
|
Chris@16
|
147
|
Chris@16
|
148 typedef unordered_set_of type;
|
Chris@16
|
149 };
|
Chris@16
|
150
|
Chris@16
|
151 BOOST_BIMAP_GENERATE_INDEX_BINDER_2CP(
|
Chris@16
|
152
|
Chris@16
|
153 // binds to
|
Chris@16
|
154 multi_index::hashed_unique,
|
Chris@16
|
155
|
Chris@16
|
156 // with
|
Chris@16
|
157 hasher,
|
Chris@16
|
158 key_equal
|
Chris@16
|
159 )
|
Chris@16
|
160
|
Chris@16
|
161 BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER(
|
Chris@16
|
162
|
Chris@16
|
163 // binds to
|
Chris@16
|
164 views::unordered_map_view
|
Chris@16
|
165 )
|
Chris@16
|
166
|
Chris@16
|
167 BOOST_BIMAP_GENERATE_SET_VIEW_BINDER(
|
Chris@16
|
168
|
Chris@16
|
169 // binds to
|
Chris@16
|
170 views::unordered_set_view
|
Chris@16
|
171 )
|
Chris@16
|
172
|
Chris@16
|
173 typedef mpl::bool_<false> mutable_key;
|
Chris@16
|
174 };
|
Chris@16
|
175
|
Chris@16
|
176
|
Chris@16
|
177 /// \brief Set Of Relation Specification
|
Chris@16
|
178 /**
|
Chris@16
|
179 This struct is similar to unordered_set_of but it is bind logically to
|
Chris@16
|
180 a relation. It is used in the bimap instantiation to specify the
|
Chris@16
|
181 desired type of the main view. This struct implements internally
|
Chris@16
|
182 a metafunction named bind_to that manages the quite complicated
|
Chris@16
|
183 task of finding the right type of the set for the relation.
|
Chris@16
|
184
|
Chris@16
|
185 \code
|
Chris@16
|
186 template<class Relation>
|
Chris@16
|
187 struct bind_to
|
Chris@16
|
188 {
|
Chris@16
|
189 typedef -unspecified- type;
|
Chris@16
|
190 };
|
Chris@16
|
191 \endcode
|
Chris@16
|
192
|
Chris@16
|
193 See also unordered_set_of, is_set_type_of_relation.
|
Chris@16
|
194 **/
|
Chris@16
|
195
|
Chris@16
|
196 template
|
Chris@16
|
197 <
|
Chris@16
|
198 class HashFunctor = hash< _relation >,
|
Chris@16
|
199 class EqualKey = std::equal_to< _relation >
|
Chris@16
|
200 >
|
Chris@16
|
201 struct unordered_set_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag
|
Chris@16
|
202 {
|
Chris@16
|
203 /// Hash Functor that takes value_type objects
|
Chris@16
|
204 typedef HashFunctor hasher;
|
Chris@16
|
205
|
Chris@16
|
206 /// Functor that compare two value_type objects for equality
|
Chris@16
|
207 typedef EqualKey key_equal;
|
Chris@16
|
208
|
Chris@16
|
209
|
Chris@16
|
210 BOOST_BIMAP_GENERATE_RELATION_BINDER_2CP(
|
Chris@16
|
211
|
Chris@16
|
212 // binds to
|
Chris@16
|
213 unordered_set_of,
|
Chris@16
|
214
|
Chris@16
|
215 // with
|
Chris@16
|
216 hasher,
|
Chris@16
|
217 key_equal
|
Chris@16
|
218 )
|
Chris@16
|
219
|
Chris@16
|
220 typedef mpl::bool_<false> left_mutable_key;
|
Chris@16
|
221 typedef mpl::bool_<false> right_mutable_key;
|
Chris@16
|
222 };
|
Chris@16
|
223
|
Chris@16
|
224
|
Chris@16
|
225 } // namespace bimaps
|
Chris@16
|
226 } // namespace boost
|
Chris@16
|
227
|
Chris@16
|
228
|
Chris@16
|
229 #endif // BOOST_BIMAP_UNORDERED_SET_OF_HPP
|
Chris@16
|
230
|