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