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