Packets: some minor GenericTLV clean ups
[senf.git] / boost / bimap / unordered_set_of.hpp
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) && (_MSC_VER>=1200)
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         typedef void (boost::UnaryFunctionConcept <hasher,std::size_t,value_type>::*
143                       funchasherstdsize_tvalue_typeconcept)();
144         template <funchasherstdsize_tvalue_typeconcept Tp1_>
145         struct concept_checking_hasherstdsize_tvalue_typeconcept { };
146         typedef concept_checking_hasherstdsize_tvalue_typeconcept<
147             BOOST_FPTR boost::UnaryFunctionConcept<hasher,std::size_t,value_type>::constraints>
148         concept_checking_typedef_hasherstdsize_tvalue_typeconcept;
149         
150         BOOST_CLASS_REQUIRE4( key_equal, bool, value_type, value_type,
151                               boost, BinaryFunctionConcept );
152
153         typedef unordered_set_of type; 
154     };
155
156     BOOST_BIMAP_GENERATE_INDEX_BINDER_2CP(
157
158         // binds to
159         multi_index::hashed_unique,
160
161         // with
162         hasher,
163         key_equal
164     )
165
166     BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER(
167
168         // binds to
169         views::unordered_map_view
170     )
171
172     BOOST_BIMAP_GENERATE_SET_VIEW_BINDER(
173
174         // binds to
175         views::unordered_set_view
176     )
177
178     typedef mpl::bool_<false> mutable_key;
179 };
180
181
182 /// \brief Set Of Relation Specification
183 /**
184 This struct is similar to unordered_set_of but it is bind logically to
185 a relation. It is used in the bimap instantiation to specify the
186 desired type of the main view. This struct implements internally
187 a metafunction named bind_to that manages the quite complicated
188 task of finding the right type of the set for the relation.
189
190 \code
191 template<class Relation>
192 struct bind_to
193 {
194     typedef -unspecified- type;
195 };
196 \endcode
197
198 See also unordered_set_of, is_set_type_of_relation.
199                                                                 **/
200
201 template
202 <
203     class HashFunctor   = hash< _relation >,
204     class EqualKey      = std::equal_to< _relation >
205 >
206 struct unordered_set_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag
207 {
208     /// Hash Functor that takes value_type objects
209     typedef HashFunctor     hasher;
210
211     /// Functor that compare two value_type objects for equality
212     typedef EqualKey        key_equal;
213
214
215     BOOST_BIMAP_GENERATE_RELATION_BINDER_2CP(
216
217         // binds to
218         unordered_set_of,
219
220         // with
221         hasher,
222         key_equal
223     )
224
225     typedef mpl::bool_<false>  left_mutable_key;
226     typedef mpl::bool_<false> right_mutable_key;
227 };
228
229
230 } // namespace bimaps
231 } // namespace boost
232
233
234 #endif // BOOST_BIMAP_UNORDERED_SET_OF_HPP
235