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)
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
42namespace boost {
43namespace bimaps {
44
45/// \brief Set Type Specification
46/**
47This struct is used to specify a set specification.
48It is not a container, it is just a metaprogramming facility to
49express the type of a set. Generally, this specification will
50be used in other place to create a container.
51It has the same syntax that an std::set instantiation, except
52that the allocator cannot be specified. The rationale behind
53this difference is that the allocator is not part of the set
54type specification, rather it is a container configuration
55parameter.
56The first parameter is the type of the objects in the set, and
57the second one is a Functor that compares them.
58Bimap binding metafunctions can be used with this class in
59the following way:
60
61\code
62using namespace support;
63
64BOOST_STATIC_ASSERT( is_set_type_of< set_of<Type> >::value )
65
66BOOST_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
82typedef bimap
83<
84 set_of<Type>, RightKeyType
85
86> bimap_with_left_type_as_set;
87
88BOOST_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
106See also set_of_relation.
107 **/
108
109template
110<
111 class KeyType,
112 class KeyCompare = std::less< BOOST_DEDUCED_TYPENAME
113 ::boost::bimaps::tags::support::value_type_of<KeyType>::type >
114>
115struct 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/**
165This struct is similar to set_of but it is bind logically to a
166relation. It is used in the bimap instantiation to specify the
167desired type of the main view. This struct implements internally
168a metafunction named bind_to that manages the quite complicated
169task of finding the right type of the set for the relation.
170
171\code
172template<class Relation>
173struct bind_to
174{
175 typedef -unspecified- type;
176};
177\endcode
178
179See also set_of, is_set_type_of_relation.
180 **/
181
182template< class KeyCompare = std::less< _relation > >
183struct 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
207

source code of boost/libs/bimap/include/boost/bimap/set_of.hpp