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