| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
|
2 |
|
// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
|
| 3 |
|
|
3 |
|
|
| 4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
| 5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
|
|
6 |
|
|
| 7 |
|
// Official repository: https://github.com/cppalliance/http
|
7 |
|
// Official repository: https://github.com/cppalliance/http
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_HTTP_POLYSTORE_HPP
|
10 |
|
#ifndef BOOST_HTTP_POLYSTORE_HPP
|
| 11 |
|
#define BOOST_HTTP_POLYSTORE_HPP
|
11 |
|
#define BOOST_HTTP_POLYSTORE_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/http/detail/config.hpp>
|
13 |
|
#include <boost/http/detail/config.hpp>
|
| 14 |
|
#include <boost/http/detail/except.hpp>
|
14 |
|
#include <boost/http/detail/except.hpp>
|
| 15 |
|
#include <boost/core/typeinfo.hpp>
|
15 |
|
#include <boost/core/typeinfo.hpp>
|
| 16 |
|
#include <boost/core/detail/static_assert.hpp>
|
16 |
|
#include <boost/core/detail/static_assert.hpp>
|
| 17 |
|
|
17 |
|
|
| 18 |
|
|
18 |
|
|
| 19 |
|
|
19 |
|
|
| 20 |
|
|
20 |
|
|
| 21 |
|
|
21 |
|
|
| 22 |
|
|
22 |
|
|
| 23 |
|
#if ! defined( BOOST_NO_TYPEID )
|
23 |
|
#if ! defined( BOOST_NO_TYPEID )
|
| 24 |
|
|
24 |
|
|
| 25 |
|
|
25 |
|
|
| 26 |
|
|
26 |
|
|
| 27 |
|
|
27 |
|
|
| 28 |
|
|
28 |
|
|
| 29 |
|
|
29 |
|
|
| 30 |
|
|
30 |
|
|
| 31 |
|
|
31 |
|
|
| 32 |
|
#if defined( BOOST_NO_TYPEID )
|
32 |
|
#if defined( BOOST_NO_TYPEID )
|
| 33 |
|
|
33 |
|
|
| 34 |
|
|
34 |
|
|
| 35 |
|
|
35 |
|
|
| 36 |
|
|
36 |
|
|
| 37 |
|
core::typeinfo const& ti) noexcept
|
37 |
|
core::typeinfo const& ti) noexcept
|
| 38 |
|
: n_(std::strlen(ti.name()))
|
38 |
|
: n_(std::strlen(ti.name()))
|
| 39 |
|
|
39 |
|
|
| 40 |
|
|
40 |
|
|
| 41 |
|
|
41 |
|
|
| 42 |
|
|
42 |
|
|
| 43 |
|
std::size_t hash_code() const noexcept
|
43 |
|
std::size_t hash_code() const noexcept
|
| 44 |
|
|
44 |
|
|
| 45 |
|
constexpr std::size_t offset_basis =
|
45 |
|
constexpr std::size_t offset_basis =
|
| 46 |
|
(sizeof(std::size_t) == 8)
|
46 |
|
(sizeof(std::size_t) == 8)
|
| 47 |
|
|
47 |
|
|
| 48 |
|
|
48 |
|
|
| 49 |
|
constexpr std::size_t prime =
|
49 |
|
constexpr std::size_t prime =
|
| 50 |
|
(sizeof(std::size_t) == 8)
|
50 |
|
(sizeof(std::size_t) == 8)
|
| 51 |
|
|
51 |
|
|
| 52 |
|
|
52 |
|
|
| 53 |
|
auto const s = ti_->name();
|
53 |
|
auto const s = ti_->name();
|
| 54 |
|
std::size_t h = offset_basis;
|
54 |
|
std::size_t h = offset_basis;
|
| 55 |
|
for(std::size_t i = 0; i < n_; ++i)
|
55 |
|
for(std::size_t i = 0; i < n_; ++i)
|
| 56 |
|
h = (h ^ static_cast<unsigned char>(s[i])) * prime;
|
56 |
|
h = (h ^ static_cast<unsigned char>(s[i])) * prime;
|
| 57 |
|
|
57 |
|
|
| 58 |
|
|
58 |
|
|
| 59 |
|
|
59 |
|
|
| 60 |
|
bool operator==(typeindex const& other) const noexcept
|
60 |
|
bool operator==(typeindex const& other) const noexcept
|
| 61 |
|
|
61 |
|
|
| 62 |
|
return n_ == other.n_ && *ti_ == *other.ti_;
|
62 |
|
return n_ == other.n_ && *ti_ == *other.ti_;
|
| 63 |
|
|
63 |
|
|
| 64 |
|
|
64 |
|
|
| 65 |
|
|
65 |
|
|
| 66 |
|
|
66 |
|
|
| 67 |
|
core::typeinfo const* ti_;
|
67 |
|
core::typeinfo const* ti_;
|
| 68 |
|
|
68 |
|
|
| 69 |
|
|
69 |
|
|
| 70 |
|
|
70 |
|
|
| 71 |
|
|
71 |
|
|
| 72 |
|
|
72 |
|
|
| 73 |
|
|
73 |
|
|
| 74 |
|
|
74 |
|
|
| 75 |
|
struct hash< boost::http::detail::typeindex >
|
75 |
|
struct hash< boost::http::detail::typeindex >
|
| 76 |
|
|
76 |
|
|
| 77 |
|
|
77 |
|
|
| 78 |
|
boost::http::detail::typeindex const& t) const noexcept
|
78 |
|
boost::http::detail::typeindex const& t) const noexcept
|
| 79 |
|
|
79 |
|
|
| 80 |
|
|
80 |
|
|
| 81 |
|
|
81 |
|
|
| 82 |
|
|
82 |
|
|
| 83 |
|
|
83 |
|
|
| 84 |
|
|
84 |
|
|
| 85 |
|
|
85 |
|
|
| 86 |
|
|
86 |
|
|
| 87 |
|
|
87 |
|
|
| 88 |
|
|
88 |
|
|
| 89 |
|
|
89 |
|
|
| 90 |
|
using typeindex = std::type_index;
|
90 |
|
using typeindex = std::type_index;
|
| 91 |
|
|
91 |
|
|
| 92 |
|
|
92 |
|
|
| 93 |
|
|
93 |
|
|
| 94 |
|
//------------------------------------------------
|
94 |
|
//------------------------------------------------
|
| 95 |
|
|
95 |
|
|
| 96 |
|
|
96 |
|
|
| 97 |
|
|
97 |
|
|
| 98 |
|
//------------------------------------------------
|
98 |
|
//------------------------------------------------
|
| 99 |
|
|
99 |
|
|
| 100 |
|
|
100 |
|
|
| 101 |
|
|
101 |
|
|
| 102 |
|
|
102 |
|
|
| 103 |
|
|
103 |
|
|
| 104 |
|
struct call_traits : std::false_type {};
|
104 |
|
struct call_traits : std::false_type {};
|
| 105 |
|
|
105 |
|
|
| 106 |
|
template<class R, class... Args>
|
106 |
|
template<class R, class... Args>
|
| 107 |
|
struct call_traits<R(*)(Args...)> : std::true_type
|
107 |
|
struct call_traits<R(*)(Args...)> : std::true_type
|
| 108 |
|
|
108 |
|
|
| 109 |
|
|
109 |
|
|
| 110 |
|
using arg_types = type_list<Args...>;
|
110 |
|
using arg_types = type_list<Args...>;
|
| 111 |
|
|
111 |
|
|
| 112 |
|
|
112 |
|
|
| 113 |
|
template<class R, class... Args>
|
113 |
|
template<class R, class... Args>
|
| 114 |
|
struct call_traits<R(&)(Args...)> : std::true_type
|
114 |
|
struct call_traits<R(&)(Args...)> : std::true_type
|
| 115 |
|
|
115 |
|
|
| 116 |
|
|
116 |
|
|
| 117 |
|
using arg_types = type_list<Args...>;
|
117 |
|
using arg_types = type_list<Args...>;
|
| 118 |
|
|
118 |
|
|
| 119 |
|
|
119 |
|
|
| 120 |
|
template<class C, class R, class... Args>
|
120 |
|
template<class C, class R, class... Args>
|
| 121 |
|
struct call_traits<R(C::*)(Args...)> : std::true_type
|
121 |
|
struct call_traits<R(C::*)(Args...)> : std::true_type
|
| 122 |
|
|
122 |
|
|
| 123 |
|
|
123 |
|
|
| 124 |
|
|
124 |
|
|
| 125 |
|
using arg_types = type_list<Args...>;
|
125 |
|
using arg_types = type_list<Args...>;
|
| 126 |
|
|
126 |
|
|
| 127 |
|
|
127 |
|
|
| 128 |
|
template<class C, class R, class... Args>
|
128 |
|
template<class C, class R, class... Args>
|
| 129 |
|
struct call_traits<R(C::*)(Args...) const> : std::true_type
|
129 |
|
struct call_traits<R(C::*)(Args...) const> : std::true_type
|
| 130 |
|
|
130 |
|
|
| 131 |
|
|
131 |
|
|
| 132 |
|
|
132 |
|
|
| 133 |
|
using arg_types = type_list<Args...>;
|
133 |
|
using arg_types = type_list<Args...>;
|
| 134 |
|
|
134 |
|
|
| 135 |
|
|
135 |
|
|
| 136 |
|
template<class R, class... Args>
|
136 |
|
template<class R, class... Args>
|
| 137 |
|
struct call_traits<R(*)(Args...) noexcept> : std::true_type
|
137 |
|
struct call_traits<R(*)(Args...) noexcept> : std::true_type
|
| 138 |
|
|
138 |
|
|
| 139 |
|
|
139 |
|
|
| 140 |
|
using arg_types = type_list<Args...>;
|
140 |
|
using arg_types = type_list<Args...>;
|
| 141 |
|
|
141 |
|
|
| 142 |
|
|
142 |
|
|
| 143 |
|
template<class R, class... Args>
|
143 |
|
template<class R, class... Args>
|
| 144 |
|
struct call_traits<R(&)(Args...) noexcept> : std::true_type
|
144 |
|
struct call_traits<R(&)(Args...) noexcept> : std::true_type
|
| 145 |
|
|
145 |
|
|
| 146 |
|
|
146 |
|
|
| 147 |
|
using arg_types = type_list<Args...>;
|
147 |
|
using arg_types = type_list<Args...>;
|
| 148 |
|
|
148 |
|
|
| 149 |
|
|
149 |
|
|
| 150 |
|
template<class C, class R, class... Args>
|
150 |
|
template<class C, class R, class... Args>
|
| 151 |
|
struct call_traits<R(C::*)(Args...) noexcept> : std::true_type
|
151 |
|
struct call_traits<R(C::*)(Args...) noexcept> : std::true_type
|
| 152 |
|
|
152 |
|
|
| 153 |
|
|
153 |
|
|
| 154 |
|
|
154 |
|
|
| 155 |
|
using arg_types = type_list<Args...>;
|
155 |
|
using arg_types = type_list<Args...>;
|
| 156 |
|
|
156 |
|
|
| 157 |
|
|
157 |
|
|
| 158 |
|
template<class C, class R, class... Args>
|
158 |
|
template<class C, class R, class... Args>
|
| 159 |
|
struct call_traits<R(C::*)(Args...) const noexcept> : std::true_type
|
159 |
|
struct call_traits<R(C::*)(Args...) const noexcept> : std::true_type
|
| 160 |
|
|
160 |
|
|
| 161 |
|
|
161 |
|
|
| 162 |
|
|
162 |
|
|
| 163 |
|
using arg_types = type_list<Args...>;
|
163 |
|
using arg_types = type_list<Args...>;
|
| 164 |
|
|
164 |
|
|
| 165 |
|
|
165 |
|
|
| 166 |
|
|
166 |
|
|
| 167 |
|
requires requires { &F::operator(); } &&
|
167 |
|
requires requires { &F::operator(); } &&
|
| 168 |
|
std::is_member_function_pointer_v<decltype(&F::operator())>
|
168 |
|
std::is_member_function_pointer_v<decltype(&F::operator())>
|
| 169 |
|
struct call_traits<F> : call_traits<decltype(&F::operator())> {};
|
169 |
|
struct call_traits<F> : call_traits<decltype(&F::operator())> {};
|
| 170 |
|
|
170 |
|
|
| 171 |
|
|
171 |
|
|
| 172 |
|
|
172 |
|
|
| 173 |
|
/** A container of type-erased objects
|
173 |
|
/** A container of type-erased objects
|
| 174 |
|
|
174 |
|
|
| 175 |
|
Objects are stored and retrieved by their type.
|
175 |
|
Objects are stored and retrieved by their type.
|
| 176 |
|
Each type may be stored at most once. Types
|
176 |
|
Each type may be stored at most once. Types
|
| 177 |
|
may specify a nested `key_type` to be used
|
177 |
|
may specify a nested `key_type` to be used
|
| 178 |
|
as the unique identifier instead of the type
|
178 |
|
as the unique identifier instead of the type
|
| 179 |
|
itself. In this case, a reference to the type
|
179 |
|
itself. In this case, a reference to the type
|
| 180 |
|
must be convertible to a reference to the key type.
|
180 |
|
must be convertible to a reference to the key type.
|
| 181 |
|
|
181 |
|
|
| 182 |
|
|
182 |
|
|
| 183 |
|
|
183 |
|
|
| 184 |
|
|
184 |
|
|
| 185 |
|
|
185 |
|
|
| 186 |
|
|
186 |
|
|
| 187 |
|
|
187 |
|
|
| 188 |
|
|
188 |
|
|
| 189 |
|
|
189 |
|
|
| 190 |
|
|
190 |
|
|
| 191 |
|
|
191 |
|
|
| 192 |
|
|
192 |
|
|
| 193 |
|
|
193 |
|
|
| 194 |
|
|
194 |
|
|
| 195 |
|
|
195 |
|
|
| 196 |
|
|
196 |
|
|
| 197 |
|
|
197 |
|
|
| 198 |
|
|
198 |
|
|
| 199 |
|
|
199 |
|
|
| 200 |
|
|
200 |
|
|
| 201 |
|
|
201 |
|
|
| 202 |
|
|
202 |
|
|
| 203 |
|
|
203 |
|
|
| 204 |
|
|
204 |
|
|
| 205 |
|
|
205 |
|
|
| 206 |
|
|
206 |
|
|
| 207 |
|
|
207 |
|
|
| 208 |
|
assert(ps.get<A>().i == 1);
|
208 |
|
assert(ps.get<A>().i == 1);
|
| 209 |
|
assert(ps.get<B>().c == '2');
|
209 |
|
assert(ps.get<B>().c == '2');
|
| 210 |
|
assert(ps.get<C>().d == 3.14);
|
210 |
|
assert(ps.get<C>().d == 3.14);
|
| 211 |
|
invoke(ps, [](A& a){ a.i = 0; });
|
211 |
|
invoke(ps, [](A& a){ a.i = 0; });
|
| 212 |
|
invoke(ps, [](A const&, B& b){ b.c = 0; });
|
212 |
|
invoke(ps, [](A const&, B& b){ b.c = 0; });
|
| 213 |
|
assert(ps.get<A>().i == 0);
|
213 |
|
assert(ps.get<A>().i == 0);
|
| 214 |
|
assert(ps.get<B>().c == 0);
|
214 |
|
assert(ps.get<B>().c == 0);
|
| 215 |
|
|
215 |
|
|
| 216 |
|
|
216 |
|
|
| 217 |
|
|
217 |
|
|
| 218 |
|
|
218 |
|
|
| 219 |
|
template<class T, class = void>
|
219 |
|
template<class T, class = void>
|
| 220 |
|
struct get_key : std::false_type
|
220 |
|
struct get_key : std::false_type
|
| 221 |
|
|
221 |
|
|
| 222 |
|
|
222 |
|
|
| 223 |
|
|
223 |
|
|
| 224 |
|
|
224 |
|
|
| 225 |
|
struct get_key<T, typename std::enable_if<
|
225 |
|
struct get_key<T, typename std::enable_if<
|
| 226 |
|
! std::is_same<T, typename T::key_type>::value>::type>
|
226 |
|
! std::is_same<T, typename T::key_type>::value>::type>
|
| 227 |
|
|
227 |
|
|
| 228 |
|
|
228 |
|
|
| 229 |
|
using type = typename T::key_type;
|
229 |
|
using type = typename T::key_type;
|
| 230 |
|
|
230 |
|
|
| 231 |
|
|
231 |
|
|
| 232 |
|
|
232 |
|
|
| 233 |
|
|
233 |
|
|
| 234 |
|
|
234 |
|
|
| 235 |
|
All objects stored in the container are destroyed in
|
235 |
|
All objects stored in the container are destroyed in
|
| 236 |
|
the reverse order of construction.
|
236 |
|
the reverse order of construction.
|
| 237 |
|
|
237 |
|
|
| 238 |
|
|
238 |
|
|
| 239 |
|
|
239 |
|
|
| 240 |
|
|
240 |
|
|
| 241 |
|
|
241 |
|
|
| 242 |
|
The moved-from container will be empty.
|
242 |
|
The moved-from container will be empty.
|
| 243 |
|
|
243 |
|
|
| 244 |
|
|
244 |
|
|
| 245 |
|
polystore(polystore&& other) noexcept;
|
245 |
|
polystore(polystore&& other) noexcept;
|
| 246 |
|
|
246 |
|
|
| 247 |
|
|
247 |
|
|
| 248 |
|
The moved-from container will be empty.
|
248 |
|
The moved-from container will be empty.
|
| 249 |
|
@return A reference to `*this`.
|
249 |
|
@return A reference to `*this`.
|
| 250 |
|
|
250 |
|
|
| 251 |
|
|
251 |
|
|
| 252 |
|
polystore& operator=(polystore&& other) noexcept;
|
252 |
|
polystore& operator=(polystore&& other) noexcept;
|
| 253 |
|
|
253 |
|
|
| 254 |
|
|
254 |
|
|
| 255 |
|
The container is initially empty.
|
255 |
|
The container is initially empty.
|
| 256 |
|
|
256 |
|
|
| 257 |
|
|
257 |
|
|
| 258 |
|
|
258 |
|
|
| 259 |
|
/** Return a pointer to the object associated with type `T`, or `nullptr`
|
259 |
|
/** Return a pointer to the object associated with type `T`, or `nullptr`
|
| 260 |
|
|
260 |
|
|
| 261 |
|
If no object associated with `T` exists in the container,
|
261 |
|
If no object associated with `T` exists in the container,
|
| 262 |
|
|
262 |
|
|
| 263 |
|
|
263 |
|
|
| 264 |
|
|
264 |
|
|
| 265 |
|
`const` member function calls are thread-safe.
|
265 |
|
`const` member function calls are thread-safe.
|
| 266 |
|
Calls to non-`const` member functions must not run concurrently
|
266 |
|
Calls to non-`const` member functions must not run concurrently
|
| 267 |
|
with other member functions on the same object.
|
267 |
|
with other member functions on the same object.
|
| 268 |
|
|
268 |
|
|
| 269 |
|
@tparam T The type of object to find.
|
269 |
|
@tparam T The type of object to find.
|
| 270 |
|
@return A pointer to the associated object, or `nullptr` if none exists.
|
270 |
|
@return A pointer to the associated object, or `nullptr` if none exists.
|
| 271 |
|
|
271 |
|
|
| 272 |
|
|
272 |
|
|
| 273 |
|
|
273 |
|
|
| 274 |
|
|
274 |
|
|
| 275 |
|
return static_cast<T*>(find(BOOST_CORE_TYPEID(T)));
|
275 |
|
return static_cast<T*>(find(BOOST_CORE_TYPEID(T)));
|
| 276 |
|
|
276 |
|
|
| 277 |
|
|
277 |
|
|
| 278 |
|
/** Assign the pointer for the object associated with `T`, or `nullptr`.
|
278 |
|
/** Assign the pointer for the object associated with `T`, or `nullptr`.
|
| 279 |
|
|
279 |
|
|
| 280 |
|
If no object of type `T` is stored, @p t is set to `nullptr`.
|
280 |
|
If no object of type `T` is stored, @p t is set to `nullptr`.
|
| 281 |
|
|
281 |
|
|
| 282 |
|
|
282 |
|
|
| 283 |
|
`const` member functions are thread-safe. Non-`const` functions
|
283 |
|
`const` member functions are thread-safe. Non-`const` functions
|
| 284 |
|
must not run concurrently with any other member function on the
|
284 |
|
must not run concurrently with any other member function on the
|
| 285 |
|
|
285 |
|
|
| 286 |
|
|
286 |
|
|
| 287 |
|
@param t The pointer to assign.
|
287 |
|
@param t The pointer to assign.
|
| 288 |
|
@return `true` if an object of type `T` is present, otherwise `false`.
|
288 |
|
@return `true` if an object of type `T` is present, otherwise `false`.
|
| 289 |
|
|
289 |
|
|
| 290 |
|
|
290 |
|
|
| 291 |
|
bool find(T*& t) const noexcept
|
291 |
|
bool find(T*& t) const noexcept
|
| 292 |
|
|
292 |
|
|
| 293 |
|
|
293 |
|
|
| 294 |
|
|
294 |
|
|
| 295 |
|
|
295 |
|
|
| 296 |
|
|
296 |
|
|
| 297 |
|
/** Return a reference to the object associated with type T
|
297 |
|
/** Return a reference to the object associated with type T
|
| 298 |
|
|
298 |
|
|
| 299 |
|
If no such object exists in the container, an exception is thrown.
|
299 |
|
If no such object exists in the container, an exception is thrown.
|
| 300 |
|
|
300 |
|
|
| 301 |
|
|
301 |
|
|
| 302 |
|
|
302 |
|
|
| 303 |
|
|
303 |
|
|
| 304 |
|
|
304 |
|
|
| 305 |
|
Calls to `const` member functions are thread-safe.
|
305 |
|
Calls to `const` member functions are thread-safe.
|
| 306 |
|
Calls to non-`const` member functions must not run concurrently
|
306 |
|
Calls to non-`const` member functions must not run concurrently
|
| 307 |
|
with other member functions on the same object.
|
307 |
|
with other member functions on the same object.
|
| 308 |
|
|
308 |
|
|
| 309 |
|
|
309 |
|
|
| 310 |
|
If no object associated with type `T` is present.
|
310 |
|
If no object associated with type `T` is present.
|
| 311 |
|
@tparam T The type of object to retrieve.
|
311 |
|
@tparam T The type of object to retrieve.
|
| 312 |
|
@return A reference to the associated object.
|
312 |
|
@return A reference to the associated object.
|
| 313 |
|
|
313 |
|
|
| 314 |
|
|
314 |
|
|
| 315 |
|
|
315 |
|
|
| 316 |
|
|
316 |
|
|
| 317 |
|
|
317 |
|
|
| 318 |
|
|
318 |
|
|
| 319 |
|
detail::throw_bad_typeid();
|
319 |
|
detail::throw_bad_typeid();
|
| 320 |
|
|
320 |
|
|
| 321 |
|
|
321 |
|
|
| 322 |
|
/** Construct and insert an anonymous object into the container
|
322 |
|
/** Construct and insert an anonymous object into the container
|
| 323 |
|
|
323 |
|
|
| 324 |
|
A new object of type `T` is constructed in place using the provided
|
324 |
|
A new object of type `T` is constructed in place using the provided
|
| 325 |
|
arguments and inserted into the container without associating it
|
325 |
|
arguments and inserted into the container without associating it
|
| 326 |
|
with any key. A reference to the stored object is returned.
|
326 |
|
with any key. A reference to the stored object is returned.
|
| 327 |
|
|
327 |
|
|
| 328 |
|
|
328 |
|
|
| 329 |
|
|
329 |
|
|
| 330 |
|
|
330 |
|
|
| 331 |
|
|
331 |
|
|
| 332 |
|
|
332 |
|
|
| 333 |
|
|
333 |
|
|
| 334 |
|
@tparam T The type of object to construct and insert.
|
334 |
|
@tparam T The type of object to construct and insert.
|
| 335 |
|
@param args Arguments forwarded to the constructor of `T`.
|
335 |
|
@param args Arguments forwarded to the constructor of `T`.
|
| 336 |
|
@return A reference to the inserted object.
|
336 |
|
@return A reference to the inserted object.
|
| 337 |
|
|
337 |
|
|
| 338 |
|
template<class T, class... Args>
|
338 |
|
template<class T, class... Args>
|
| 339 |
|
T& emplace_anon(Args&&... args)
|
339 |
|
T& emplace_anon(Args&&... args)
|
| 340 |
|
|
340 |
|
|
| 341 |
|
return *static_cast<T*>(insert_impl(
|
341 |
|
return *static_cast<T*>(insert_impl(
|
| 342 |
|
make_any<T>(std::forward<Args>(args)...)));
|
342 |
|
make_any<T>(std::forward<Args>(args)...)));
|
| 343 |
|
|
343 |
|
|
| 344 |
|
|
344 |
|
|
| 345 |
|
/** Insert an anonymous object by moving or copying it into the container
|
345 |
|
/** Insert an anonymous object by moving or copying it into the container
|
| 346 |
|
|
346 |
|
|
| 347 |
|
A new object of type `T` is inserted into the container without
|
347 |
|
A new object of type `T` is inserted into the container without
|
| 348 |
|
associating it with any key. The object is move-constructed or
|
348 |
|
associating it with any key. The object is move-constructed or
|
| 349 |
|
copy-constructed from the provided argument, and a reference to
|
349 |
|
copy-constructed from the provided argument, and a reference to
|
| 350 |
|
the stored object is returned.
|
350 |
|
the stored object is returned.
|
| 351 |
|
|
351 |
|
|
| 352 |
|
|
352 |
|
|
| 353 |
|
|
353 |
|
|
| 354 |
|
|
354 |
|
|
| 355 |
|
|
355 |
|
|
| 356 |
|
|
356 |
|
|
| 357 |
|
|
357 |
|
|
| 358 |
|
@tparam T The type of object to insert.
|
358 |
|
@tparam T The type of object to insert.
|
| 359 |
|
@param t The object to insert.
|
359 |
|
@param t The object to insert.
|
| 360 |
|
@return A reference to the inserted object.
|
360 |
|
@return A reference to the inserted object.
|
| 361 |
|
|
361 |
|
|
| 362 |
|
|
362 |
|
|
| 363 |
|
|
363 |
|
|
| 364 |
|
|
364 |
|
|
| 365 |
|
return emplace_anon<typename
|
365 |
|
return emplace_anon<typename
|
| 366 |
|
std::remove_cv<T>::type>(
|
366 |
|
std::remove_cv<T>::type>(
|
| 367 |
|
|
367 |
|
|
| 368 |
|
|
368 |
|
|
| 369 |
|
|
369 |
|
|
| 370 |
|
/** Construct and insert an object with a nested key type
|
370 |
|
/** Construct and insert an object with a nested key type
|
| 371 |
|
|
371 |
|
|
| 372 |
|
A new object of type `T` is constructed in place using the provided
|
372 |
|
A new object of type `T` is constructed in place using the provided
|
| 373 |
|
arguments and inserted into the container. The type `T` must define
|
373 |
|
arguments and inserted into the container. The type `T` must define
|
| 374 |
|
a nested type `key_type`, which is used as the key for insertion.
|
374 |
|
a nested type `key_type`, which is used as the key for insertion.
|
| 375 |
|
No additional key types may be specified. The type `T&` must be
|
375 |
|
No additional key types may be specified. The type `T&` must be
|
| 376 |
|
convertible to a reference to `key_type`.
|
376 |
|
convertible to a reference to `key_type`.
|
| 377 |
|
|
377 |
|
|
| 378 |
|
|
378 |
|
|
| 379 |
|
`T::key_type` must name a type.
|
379 |
|
`T::key_type` must name a type.
|
| 380 |
|
|
380 |
|
|
| 381 |
|
|
381 |
|
|
| 382 |
|
|
382 |
|
|
| 383 |
|
|
383 |
|
|
| 384 |
|
|
384 |
|
|
| 385 |
|
|
385 |
|
|
| 386 |
|
|
386 |
|
|
| 387 |
|
@throws std::invalid_argument On duplicate insertion.
|
387 |
|
@throws std::invalid_argument On duplicate insertion.
|
| 388 |
|
@tparam T The type of object to construct and insert.
|
388 |
|
@tparam T The type of object to construct and insert.
|
| 389 |
|
@param args Arguments forwarded to the constructor of `T`.
|
389 |
|
@param args Arguments forwarded to the constructor of `T`.
|
| 390 |
|
@return A reference to the inserted object.
|
390 |
|
@return A reference to the inserted object.
|
| 391 |
|
|
391 |
|
|
| 392 |
|
template<class T, class... Keys, class... Args>
|
392 |
|
template<class T, class... Keys, class... Args>
|
| 393 |
|
auto emplace(Args&&... args) ->
|
393 |
|
auto emplace(Args&&... args) ->
|
| 394 |
|
typename std::enable_if<get_key<T>::value, T&>::type
|
394 |
|
typename std::enable_if<get_key<T>::value, T&>::type
|
| 395 |
|
|
395 |
|
|
| 396 |
|
// Can't have Keys with nested key_type
|
396 |
|
// Can't have Keys with nested key_type
|
| 397 |
|
BOOST_CORE_STATIC_ASSERT(sizeof...(Keys) == 0);
|
397 |
|
BOOST_CORE_STATIC_ASSERT(sizeof...(Keys) == 0);
|
| 398 |
|
// T& must be convertible to key_type&
|
398 |
|
// T& must be convertible to key_type&
|
| 399 |
|
BOOST_CORE_STATIC_ASSERT(std::is_convertible<
|
399 |
|
BOOST_CORE_STATIC_ASSERT(std::is_convertible<
|
| 400 |
|
T&, typename get_key<T>::type&>::value);
|
400 |
|
T&, typename get_key<T>::type&>::value);
|
| 401 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
401 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
| 402 |
|
keyset<T, typename get_key<T>::type> ks(
|
402 |
|
keyset<T, typename get_key<T>::type> ks(
|
| 403 |
|
*static_cast<T*>(p->get()));
|
403 |
|
*static_cast<T*>(p->get()));
|
| 404 |
|
return *static_cast<T*>(insert_impl(
|
404 |
|
return *static_cast<T*>(insert_impl(
|
| 405 |
|
std::move(p), ks.kn, ks.N));
|
405 |
|
std::move(p), ks.kn, ks.N));
|
| 406 |
|
|
406 |
|
|
| 407 |
|
|
407 |
|
|
| 408 |
|
/** Construct and insert an object into the container
|
408 |
|
/** Construct and insert an object into the container
|
| 409 |
|
|
409 |
|
|
| 410 |
|
A new object of type `T` is constructed in place using the provided
|
410 |
|
A new object of type `T` is constructed in place using the provided
|
| 411 |
|
arguments and inserted into the container. The type `T` must not
|
411 |
|
arguments and inserted into the container. The type `T` must not
|
| 412 |
|
already exist in the container, nor may any of the additional key
|
412 |
|
already exist in the container, nor may any of the additional key
|
| 413 |
|
types refer to an existing object. The type `T&` must be convertible
|
413 |
|
types refer to an existing object. The type `T&` must be convertible
|
| 414 |
|
to a reference to each specified key type.
|
414 |
|
to a reference to each specified key type.
|
| 415 |
|
|
415 |
|
|
| 416 |
|
|
416 |
|
|
| 417 |
|
`T::key_type` must not name a type.
|
417 |
|
`T::key_type` must not name a type.
|
| 418 |
|
|
418 |
|
|
| 419 |
|
|
419 |
|
|
| 420 |
|
|
420 |
|
|
| 421 |
|
|
421 |
|
|
| 422 |
|
|
422 |
|
|
| 423 |
|
|
423 |
|
|
| 424 |
|
|
424 |
|
|
| 425 |
|
@throws std::invalid_argument On duplicate insertion.
|
425 |
|
@throws std::invalid_argument On duplicate insertion.
|
| 426 |
|
@tparam T The type of object to construct and insert.
|
426 |
|
@tparam T The type of object to construct and insert.
|
| 427 |
|
@tparam Keys Optional key types associated with the object.
|
427 |
|
@tparam Keys Optional key types associated with the object.
|
| 428 |
|
@param args Arguments forwarded to the constructor of `T`.
|
428 |
|
@param args Arguments forwarded to the constructor of `T`.
|
| 429 |
|
@return A reference to the inserted object.
|
429 |
|
@return A reference to the inserted object.
|
| 430 |
|
|
430 |
|
|
| 431 |
|
template<class T, class... Keys, class... Args>
|
431 |
|
template<class T, class... Keys, class... Args>
|
| 432 |
|
auto emplace(Args&&... args) ->
|
432 |
|
auto emplace(Args&&... args) ->
|
| 433 |
|
typename std::enable_if<! get_key<T>::value, T&>::type
|
433 |
|
typename std::enable_if<! get_key<T>::value, T&>::type
|
| 434 |
|
|
434 |
|
|
| 435 |
|
// T& must be convertible to each of Keys&
|
435 |
|
// T& must be convertible to each of Keys&
|
| 436 |
|
BOOST_CORE_STATIC_ASSERT((std::is_convertible_v<T&, Keys&> && ...));
|
436 |
|
BOOST_CORE_STATIC_ASSERT((std::is_convertible_v<T&, Keys&> && ...));
|
| 437 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
437 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
| 438 |
|
keyset<T, Keys...> ks(*static_cast<T*>(p->get()));
|
438 |
|
keyset<T, Keys...> ks(*static_cast<T*>(p->get()));
|
| 439 |
|
return *static_cast<T*>(insert_impl(
|
439 |
|
return *static_cast<T*>(insert_impl(
|
| 440 |
|
std::move(p), ks.kn, ks.N));
|
440 |
|
std::move(p), ks.kn, ks.N));
|
| 441 |
|
|
441 |
|
|
| 442 |
|
|
442 |
|
|
| 443 |
|
/** Return an existing object, creating it if necessary
|
443 |
|
/** Return an existing object, creating it if necessary
|
| 444 |
|
|
444 |
|
|
| 445 |
|
If an object of the exact type `T` already exists in the container,
|
445 |
|
If an object of the exact type `T` already exists in the container,
|
| 446 |
|
a reference to that object is returned. Otherwise, a new object is
|
446 |
|
a reference to that object is returned. Otherwise, a new object is
|
| 447 |
|
constructed in place using the provided arguments, and a reference
|
447 |
|
constructed in place using the provided arguments, and a reference
|
| 448 |
|
to the newly created object is returned. The type `T` must not
|
448 |
|
to the newly created object is returned. The type `T` must not
|
| 449 |
|
already exist in the container, nor may any of the additional key
|
449 |
|
already exist in the container, nor may any of the additional key
|
| 450 |
|
types refer to an existing object. The type `T` must be convertible
|
450 |
|
types refer to an existing object. The type `T` must be convertible
|
| 451 |
|
to a reference to each additional key type.
|
451 |
|
to a reference to each additional key type.
|
| 452 |
|
|
452 |
|
|
| 453 |
|
|
453 |
|
|
| 454 |
|
|
454 |
|
|
| 455 |
|
|
455 |
|
|
| 456 |
|
|
456 |
|
|
| 457 |
|
|
457 |
|
|
| 458 |
|
|
458 |
|
|
| 459 |
|
@throws std::invalid_argument On duplicate insertion.
|
459 |
|
@throws std::invalid_argument On duplicate insertion.
|
| 460 |
|
@tparam T The type of object to return or create.
|
460 |
|
@tparam T The type of object to return or create.
|
| 461 |
|
@tparam Keys Optional key types associated with the object.
|
461 |
|
@tparam Keys Optional key types associated with the object.
|
| 462 |
|
@param args Arguments forwarded to the constructor of `T`.
|
462 |
|
@param args Arguments forwarded to the constructor of `T`.
|
| 463 |
|
@return A reference to the existing or newly created object.
|
463 |
|
@return A reference to the existing or newly created object.
|
| 464 |
|
|
464 |
|
|
| 465 |
|
template<class T, class... Keys, class... Args>
|
465 |
|
template<class T, class... Keys, class... Args>
|
| 466 |
|
auto try_emplace(Args&&... args) ->
|
466 |
|
auto try_emplace(Args&&... args) ->
|
| 467 |
|
typename std::enable_if<get_key<T>::value, T&>::type
|
467 |
|
typename std::enable_if<get_key<T>::value, T&>::type
|
| 468 |
|
|
468 |
|
|
| 469 |
|
// Can't have Keys with nested key_type
|
469 |
|
// Can't have Keys with nested key_type
|
| 470 |
|
BOOST_CORE_STATIC_ASSERT(sizeof...(Keys) == 0);
|
470 |
|
BOOST_CORE_STATIC_ASSERT(sizeof...(Keys) == 0);
|
| 471 |
|
// T& must be convertible to key_type&
|
471 |
|
// T& must be convertible to key_type&
|
| 472 |
|
BOOST_CORE_STATIC_ASSERT(std::is_convertible<
|
472 |
|
BOOST_CORE_STATIC_ASSERT(std::is_convertible<
|
| 473 |
|
T&, typename get_key<T>::type&>::value);
|
473 |
|
T&, typename get_key<T>::type&>::value);
|
| 474 |
|
|
474 |
|
|
| 475 |
|
|
475 |
|
|
| 476 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
476 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
| 477 |
|
keyset<T, typename get_key<T>::type> ks(
|
477 |
|
keyset<T, typename get_key<T>::type> ks(
|
| 478 |
|
*static_cast<T*>(p->get()));
|
478 |
|
*static_cast<T*>(p->get()));
|
| 479 |
|
return *static_cast<T*>(insert_impl(
|
479 |
|
return *static_cast<T*>(insert_impl(
|
| 480 |
|
std::move(p), ks.kn, ks.N));
|
480 |
|
std::move(p), ks.kn, ks.N));
|
| 481 |
|
|
481 |
|
|
| 482 |
|
|
482 |
|
|
| 483 |
|
/** Return an existing object, creating it if necessary
|
483 |
|
/** Return an existing object, creating it if necessary
|
| 484 |
|
|
484 |
|
|
| 485 |
|
If an object of the exact type `T` already exists in the container,
|
485 |
|
If an object of the exact type `T` already exists in the container,
|
| 486 |
|
a reference to that object is returned. Otherwise, a new object is
|
486 |
|
a reference to that object is returned. Otherwise, a new object is
|
| 487 |
|
constructed in place using the provided arguments, and a reference
|
487 |
|
constructed in place using the provided arguments, and a reference
|
| 488 |
|
to the newly created object is returned. The type `T` must not
|
488 |
|
to the newly created object is returned. The type `T` must not
|
| 489 |
|
already exist in the container, nor may any of the additional key
|
489 |
|
already exist in the container, nor may any of the additional key
|
| 490 |
|
types refer to an existing object. The type `T` must be convertible
|
490 |
|
types refer to an existing object. The type `T` must be convertible
|
| 491 |
|
to a reference to each additional key type.
|
491 |
|
to a reference to each additional key type.
|
| 492 |
|
|
492 |
|
|
| 493 |
|
|
493 |
|
|
| 494 |
|
|
494 |
|
|
| 495 |
|
|
495 |
|
|
| 496 |
|
|
496 |
|
|
| 497 |
|
`const` member function calls are thread-safe.
|
497 |
|
`const` member function calls are thread-safe.
|
| 498 |
|
Calls to non-`const` member functions must not run concurrently
|
498 |
|
Calls to non-`const` member functions must not run concurrently
|
| 499 |
|
with other member functions on the same object.
|
499 |
|
with other member functions on the same object.
|
| 500 |
|
|
500 |
|
|
| 501 |
|
@throws std::invalid_argument On duplicate insertion.
|
501 |
|
@throws std::invalid_argument On duplicate insertion.
|
| 502 |
|
@tparam T The type of object to return or create.
|
502 |
|
@tparam T The type of object to return or create.
|
| 503 |
|
@tparam Keys Optional key types associated with the object.
|
503 |
|
@tparam Keys Optional key types associated with the object.
|
| 504 |
|
@param args Arguments forwarded to the constructor of `T`.
|
504 |
|
@param args Arguments forwarded to the constructor of `T`.
|
| 505 |
|
@return A reference to the existing or newly created object.
|
505 |
|
@return A reference to the existing or newly created object.
|
| 506 |
|
|
506 |
|
|
| 507 |
|
template<class T, class... Keys, class... Args>
|
507 |
|
template<class T, class... Keys, class... Args>
|
| 508 |
|
auto try_emplace(Args&&... args) ->
|
508 |
|
auto try_emplace(Args&&... args) ->
|
| 509 |
|
typename std::enable_if<! get_key<T>::value, T&>::type
|
509 |
|
typename std::enable_if<! get_key<T>::value, T&>::type
|
| 510 |
|
|
510 |
|
|
| 511 |
|
// T& must be convertible to each of Keys&
|
511 |
|
// T& must be convertible to each of Keys&
|
| 512 |
|
BOOST_CORE_STATIC_ASSERT((std::is_convertible_v<T&, Keys&> && ...));
|
512 |
|
BOOST_CORE_STATIC_ASSERT((std::is_convertible_v<T&, Keys&> && ...));
|
| 513 |
|
|
513 |
|
|
| 514 |
|
|
514 |
|
|
| 515 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
515 |
|
auto p = make_any<T>(std::forward<Args>(args)...);
|
| 516 |
|
keyset<T, Keys...> ks(*static_cast<T*>(p->get()));
|
516 |
|
keyset<T, Keys...> ks(*static_cast<T*>(p->get()));
|
| 517 |
|
return *static_cast<T*>(insert_impl(
|
517 |
|
return *static_cast<T*>(insert_impl(
|
| 518 |
|
std::move(p), ks.kn, ks.N));
|
518 |
|
std::move(p), ks.kn, ks.N));
|
| 519 |
|
|
519 |
|
|
| 520 |
|
|
520 |
|
|
| 521 |
|
/** Insert an object by moving or copying it into the container
|
521 |
|
/** Insert an object by moving or copying it into the container
|
| 522 |
|
|
522 |
|
|
| 523 |
|
If an object of the same type `T` already exists in the container,
|
523 |
|
If an object of the same type `T` already exists in the container,
|
| 524 |
|
or if any of the additional key types would refer to an existing
|
524 |
|
or if any of the additional key types would refer to an existing
|
| 525 |
|
object, an exception is thrown. Otherwise, the object is inserted
|
525 |
|
object, an exception is thrown. Otherwise, the object is inserted
|
| 526 |
|
by move or copy construction, and a reference to the stored object
|
526 |
|
by move or copy construction, and a reference to the stored object
|
| 527 |
|
is returned. The type `T` must be convertible to a reference to each
|
527 |
|
is returned. The type `T` must be convertible to a reference to each
|
| 528 |
|
|
528 |
|
|
| 529 |
|
|
529 |
|
|
| 530 |
|
|
530 |
|
|
| 531 |
|
|
531 |
|
|
| 532 |
|
|
532 |
|
|
| 533 |
|
|
533 |
|
|
| 534 |
|
|
534 |
|
|
| 535 |
|
|
535 |
|
|
| 536 |
|
@throws std::invalid_argument On duplicate insertion.
|
536 |
|
@throws std::invalid_argument On duplicate insertion.
|
| 537 |
|
@tparam T The type of object to insert.
|
537 |
|
@tparam T The type of object to insert.
|
| 538 |
|
@tparam Keys Optional key types associated with the object.
|
538 |
|
@tparam Keys Optional key types associated with the object.
|
| 539 |
|
@param t The object to insert.
|
539 |
|
@param t The object to insert.
|
| 540 |
|
@return A reference to the inserted object.
|
540 |
|
@return A reference to the inserted object.
|
| 541 |
|
|
541 |
|
|
| 542 |
|
template<class T, class... Keys>
|
542 |
|
template<class T, class... Keys>
|
| 543 |
|
|
543 |
|
|
| 544 |
|
|
544 |
|
|
| 545 |
|
|
545 |
|
|
| 546 |
|
std::remove_cv<T>::type, Keys...>(
|
546 |
|
std::remove_cv<T>::type, Keys...>(
|
| 547 |
|
|
547 |
|
|
| 548 |
|
|
548 |
|
|
| 549 |
|
|
549 |
|
|
| 550 |
|
/** Return an existing object or create a new one
|
550 |
|
/** Return an existing object or create a new one
|
| 551 |
|
|
551 |
|
|
| 552 |
|
If an object of the exact type `T` already exists in the container,
|
552 |
|
If an object of the exact type `T` already exists in the container,
|
| 553 |
|
a reference to that object is returned. Otherwise, a new object of
|
553 |
|
a reference to that object is returned. Otherwise, a new object of
|
| 554 |
|
type `T` is default-constructed in the container, and a reference
|
554 |
|
type `T` is default-constructed in the container, and a reference
|
| 555 |
|
to the newly created object is returned. This function ignores
|
555 |
|
to the newly created object is returned. This function ignores
|
| 556 |
|
nested key types and cannot be used to specify additional keys.
|
556 |
|
nested key types and cannot be used to specify additional keys.
|
| 557 |
|
|
557 |
|
|
| 558 |
|
|
558 |
|
|
| 559 |
|
`T` must be default-constructible.
|
559 |
|
`T` must be default-constructible.
|
| 560 |
|
|
560 |
|
|
| 561 |
|
|
561 |
|
|
| 562 |
|
|
562 |
|
|
| 563 |
|
|
563 |
|
|
| 564 |
|
|
564 |
|
|
| 565 |
|
|
565 |
|
|
| 566 |
|
|
566 |
|
|
| 567 |
|
@tparam T The type of object to retrieve or create.
|
567 |
|
@tparam T The type of object to retrieve or create.
|
| 568 |
|
@return A reference to the stored object.
|
568 |
|
@return A reference to the stored object.
|
| 569 |
|
|
569 |
|
|
| 570 |
|
|
570 |
|
|
| 571 |
|
|
571 |
|
|
| 572 |
|
|
572 |
|
|
| 573 |
|
// T must be default constructible
|
573 |
|
// T must be default constructible
|
| 574 |
|
BOOST_CORE_STATIC_ASSERT(
|
574 |
|
BOOST_CORE_STATIC_ASSERT(
|
| 575 |
|
std::is_default_constructible<T>::value);
|
575 |
|
std::is_default_constructible<T>::value);
|
| 576 |
|
|
576 |
|
|
| 577 |
|
|
577 |
|
|
| 578 |
|
|
578 |
|
|
| 579 |
|
|
579 |
|
|
| 580 |
|
|
580 |
|
|
| 581 |
|
|
581 |
|
|
| 582 |
|
|
582 |
|
|
| 583 |
|
|
583 |
|
|
| 584 |
|
|
584 |
|
|
| 585 |
|
/** Remove and destroy all objects in the container.
|
585 |
|
/** Remove and destroy all objects in the container.
|
| 586 |
|
|
586 |
|
|
| 587 |
|
All stored objects are destroyed in the reverse order
|
587 |
|
All stored objects are destroyed in the reverse order
|
| 588 |
|
of construction. The container is left empty.
|
588 |
|
of construction. The container is left empty.
|
| 589 |
|
|
589 |
|
|
| 590 |
|
|
590 |
|
|
| 591 |
|
|
591 |
|
|
| 592 |
|
|
592 |
|
|
| 593 |
|
|
593 |
|
|
| 594 |
|
/** Return a range of all stored elements
|
594 |
|
/** Return a range of all stored elements
|
| 595 |
|
|
595 |
|
|
| 596 |
|
`const` member function calls are thread-safe.
|
596 |
|
`const` member function calls are thread-safe.
|
| 597 |
|
Calls to non-`const` member functions must not run concurrently
|
597 |
|
Calls to non-`const` member functions must not run concurrently
|
| 598 |
|
with other member functions on the same object.
|
598 |
|
with other member functions on the same object.
|
| 599 |
|
@return An object representing the range of stored elements.
|
599 |
|
@return An object representing the range of stored elements.
|
| 600 |
|
|
600 |
|
|
| 601 |
|
|
601 |
|
|
| 602 |
|
|
602 |
|
|
| 603 |
|
|
603 |
|
|
| 604 |
|
|
604 |
|
|
| 605 |
|
|
605 |
|
|
| 606 |
|
template<class T, class = void>
|
606 |
|
template<class T, class = void>
|
| 607 |
|
struct has_start : std::false_type {};
|
607 |
|
struct has_start : std::false_type {};
|
| 608 |
|
|
608 |
|
|
| 609 |
|
|
609 |
|
|
| 610 |
|
struct has_start<T, typename std::enable_if<
|
610 |
|
struct has_start<T, typename std::enable_if<
|
| 611 |
|
std::is_same<decltype(std::declval<T>().start()),
|
611 |
|
std::is_same<decltype(std::declval<T>().start()),
|
| 612 |
|
void>::value>::type> : std::true_type {};
|
612 |
|
void>::value>::type> : std::true_type {};
|
| 613 |
|
|
613 |
|
|
| 614 |
|
template<class T, class = void>
|
614 |
|
template<class T, class = void>
|
| 615 |
|
struct has_stop : std::false_type {};
|
615 |
|
struct has_stop : std::false_type {};
|
| 616 |
|
|
616 |
|
|
| 617 |
|
|
617 |
|
|
| 618 |
|
struct has_stop<T, typename std::enable_if<
|
618 |
|
struct has_stop<T, typename std::enable_if<
|
| 619 |
|
std::is_same<decltype(std::declval<T>().stop()),
|
619 |
|
std::is_same<decltype(std::declval<T>().stop()),
|
| 620 |
|
void>::value>::type> : std::true_type {};
|
620 |
|
void>::value>::type> : std::true_type {};
|
| 621 |
|
|
621 |
|
|
| 622 |
|
|
622 |
|
|
| 623 |
|
|
623 |
|
|
| 624 |
|
|
624 |
|
|
| 625 |
|
detail::typeindex(BOOST_CORE_TYPEID(void));
|
625 |
|
detail::typeindex(BOOST_CORE_TYPEID(void));
|
| 626 |
|
|
626 |
|
|
| 627 |
|
|
627 |
|
|
| 628 |
|
|
628 |
|
|
| 629 |
|
key(detail::typeindex const& ti_,
|
629 |
|
key(detail::typeindex const& ti_,
|
| 630 |
|
void* p_) noexcept : ti(ti_) , p(p_) {}
|
630 |
|
void* p_) noexcept : ti(ti_) , p(p_) {}
|
| 631 |
|
|
631 |
|
|
| 632 |
|
|
632 |
|
|
| 633 |
|
template<class T, class... Key>
|
633 |
|
template<class T, class... Key>
|
| 634 |
|
|
634 |
|
|
| 635 |
|
|
635 |
|
|
| 636 |
|
|
636 |
|
|
| 637 |
|
|
637 |
|
|
| 638 |
|
|
638 |
|
|
| 639 |
|
static constexpr std::size_t N = 1;
|
639 |
|
static constexpr std::size_t N = 1;
|
| 640 |
|
|
640 |
|
|
| 641 |
|
|
641 |
|
|
| 642 |
|
explicit keyset(T& t) noexcept
|
642 |
|
explicit keyset(T& t) noexcept
|
| 643 |
|
: kn{ key(detail::typeindex(BOOST_CORE_TYPEID(T)), &t) }
|
643 |
|
: kn{ key(detail::typeindex(BOOST_CORE_TYPEID(T)), &t) }
|
| 644 |
|
|
644 |
|
|
| 645 |
|
|
645 |
|
|
| 646 |
|
|
646 |
|
|
| 647 |
|
|
647 |
|
|
| 648 |
|
template<class T, class... Keys>
|
648 |
|
template<class T, class... Keys>
|
| 649 |
|
|
649 |
|
|
| 650 |
|
|
650 |
|
|
| 651 |
|
static constexpr std::size_t N = 1 + sizeof...(Keys);
|
651 |
|
static constexpr std::size_t N = 1 + sizeof...(Keys);
|
| 652 |
|
|
652 |
|
|
| 653 |
|
|
653 |
|
|
| 654 |
|
explicit keyset(T& t) noexcept
|
654 |
|
explicit keyset(T& t) noexcept
|
| 655 |
|
|
655 |
|
|
| 656 |
|
key(detail::typeindex(BOOST_CORE_TYPEID(T)),
|
656 |
|
key(detail::typeindex(BOOST_CORE_TYPEID(T)),
|
| 657 |
|
|
657 |
|
|
| 658 |
|
key(detail::typeindex(BOOST_CORE_TYPEID(Keys)),
|
658 |
|
key(detail::typeindex(BOOST_CORE_TYPEID(Keys)),
|
| 659 |
|
&static_cast<Keys&>(t))..., }
|
659 |
|
&static_cast<Keys&>(t))..., }
|
| 660 |
|
|
660 |
|
|
| 661 |
|
|
661 |
|
|
| 662 |
|
|
662 |
|
|
| 663 |
|
|
663 |
|
|
| 664 |
|
template<class T> struct any_impl;
|
664 |
|
template<class T> struct any_impl;
|
| 665 |
|
|
665 |
|
|
| 666 |
|
using any_ptr = std::unique_ptr<any>;
|
666 |
|
using any_ptr = std::unique_ptr<any>;
|
| 667 |
|
|
667 |
|
|
| 668 |
|
template<class T, class... Args>
|
668 |
|
template<class T, class... Args>
|
| 669 |
|
|
669 |
|
|
| 670 |
|
make_any(Args&&... args) ->
|
670 |
|
make_any(Args&&... args) ->
|
| 671 |
|
std::unique_ptr<any_impl<T>>
|
671 |
|
std::unique_ptr<any_impl<T>>
|
| 672 |
|
|
672 |
|
|
| 673 |
|
return std::unique_ptr<any_impl<T>>(new
|
673 |
|
return std::unique_ptr<any_impl<T>>(new
|
| 674 |
|
any_impl<T>(std::forward<Args>(args)...));
|
674 |
|
any_impl<T>(std::forward<Args>(args)...));
|
| 675 |
|
|
675 |
|
|
| 676 |
|
|
676 |
|
|
| 677 |
|
|
677 |
|
|
| 678 |
|
BOOST_HTTP_DECL any& get(std::size_t i);
|
678 |
|
BOOST_HTTP_DECL any& get(std::size_t i);
|
| 679 |
|
BOOST_HTTP_DECL void* find(
|
679 |
|
BOOST_HTTP_DECL void* find(
|
| 680 |
|
core::typeinfo const& ti) const noexcept;
|
680 |
|
core::typeinfo const& ti) const noexcept;
|
| 681 |
|
BOOST_HTTP_DECL void* insert_impl(any_ptr,
|
681 |
|
BOOST_HTTP_DECL void* insert_impl(any_ptr,
|
| 682 |
|
key const* = nullptr, std::size_t = 0);
|
682 |
|
key const* = nullptr, std::size_t = 0);
|
| 683 |
|
|
683 |
|
|
| 684 |
|
|
684 |
|
|
| 685 |
|
|
685 |
|
|
| 686 |
|
detail::typeindex, void*> m_;
|
686 |
|
detail::typeindex, void*> m_;
|
| 687 |
|
|
687 |
|
|
| 688 |
|
|
688 |
|
|
| 689 |
|
//------------------------------------------------
|
689 |
|
//------------------------------------------------
|
| 690 |
|
|
690 |
|
|
| 691 |
|
|
691 |
|
|
| 692 |
|
|
692 |
|
|
| 693 |
|
|
693 |
|
|
| 694 |
|
virtual ~any() = default;
|
694 |
|
virtual ~any() = default;
|
| 695 |
|
virtual void start() = 0;
|
695 |
|
virtual void start() = 0;
|
| 696 |
|
|
696 |
|
|
| 697 |
|
|
697 |
|
|
| 698 |
|
|
698 |
|
|
| 699 |
|
virtual void* get() noexcept = 0;
|
699 |
|
virtual void* get() noexcept = 0;
|
| 700 |
|
|
700 |
|
|
| 701 |
|
|
701 |
|
|
| 702 |
|
//------------------------------------------------
|
702 |
|
//------------------------------------------------
|
| 703 |
|
|
703 |
|
|
| 704 |
|
class polystore::elements
|
704 |
|
class polystore::elements
|
| 705 |
|
|
705 |
|
|
| 706 |
|
|
706 |
|
|
| 707 |
|
std::size_t size() const noexcept
|
707 |
|
std::size_t size() const noexcept
|
| 708 |
|
|
708 |
|
|
| 709 |
|
|
709 |
|
|
| 710 |
|
|
710 |
|
|
| 711 |
|
|
711 |
|
|
| 712 |
|
|
712 |
|
|
| 713 |
|
|
713 |
|
|
| 714 |
|
|
714 |
|
|
| 715 |
|
|
715 |
|
|
| 716 |
|
|
716 |
|
|
| 717 |
|
|
717 |
|
|
| 718 |
|
|
718 |
|
|
| 719 |
|
|
719 |
|
|
| 720 |
|
|
720 |
|
|
| 721 |
|
|
721 |
|
|
| 722 |
|
|
722 |
|
|
| 723 |
|
|
723 |
|
|
| 724 |
|
|
724 |
|
|
| 725 |
|
|
725 |
|
|
| 726 |
|
|
726 |
|
|
| 727 |
|
|
727 |
|
|
| 728 |
|
|
728 |
|
|
| 729 |
|
|
729 |
|
|
| 730 |
|
|
730 |
|
|
| 731 |
|
|
731 |
|
|
| 732 |
|
|
732 |
|
|
| 733 |
|
//------------------------------------------------
|
733 |
|
//------------------------------------------------
|
| 734 |
|
|
734 |
|
|
| 735 |
|
|
735 |
|
|
| 736 |
|
struct polystore::any_impl : polystore::any
|
736 |
|
struct polystore::any_impl : polystore::any
|
| 737 |
|
|
737 |
|
|
| 738 |
|
|
738 |
|
|
| 739 |
|
|
739 |
|
|
| 740 |
|
|
740 |
|
|
| 741 |
|
explicit any_impl(Args&&... args)
|
741 |
|
explicit any_impl(Args&&... args)
|
| 742 |
|
: t(std::forward<Args>(args)...)
|
742 |
|
: t(std::forward<Args>(args)...)
|
| 743 |
|
|
743 |
|
|
| 744 |
|
|
744 |
|
|
| 745 |
|
void* get() noexcept override { return std::addressof(t); }
|
745 |
|
void* get() noexcept override { return std::addressof(t); }
|
| 746 |
|
void start() override { do_start(has_start<T>{}); }
|
746 |
|
void start() override { do_start(has_start<T>{}); }
|
| 747 |
|
void stop() override { do_stop(has_stop<T>{}); }
|
747 |
|
void stop() override { do_stop(has_stop<T>{}); }
|
| 748 |
|
void do_start(std::true_type) { t.start(); }
|
748 |
|
void do_start(std::true_type) { t.start(); }
|
| 749 |
|
void do_start(std::false_type) {}
|
749 |
|
void do_start(std::false_type) {}
|
| 750 |
|
void do_stop(std::true_type) { t.stop(); }
|
750 |
|
void do_stop(std::true_type) { t.stop(); }
|
| 751 |
|
void do_stop(std::false_type) {}
|
751 |
|
void do_stop(std::false_type) {}
|
| 752 |
|
|
752 |
|
|
| 753 |
|
|
753 |
|
|
| 754 |
|
//------------------------------------------------
|
754 |
|
//------------------------------------------------
|
| 755 |
|
|
755 |
|
|
| 756 |
|
|
756 |
|
|
| 757 |
|
|
757 |
|
|
| 758 |
|
template<class T> struct arg;
|
758 |
|
template<class T> struct arg;
|
| 759 |
|
template<class T> struct arg<T const&> : arg<T&> {};
|
759 |
|
template<class T> struct arg<T const&> : arg<T&> {};
|
| 760 |
|
template<class T> struct arg<T const*> : arg<T*> {};
|
760 |
|
template<class T> struct arg<T const*> : arg<T*> {};
|
| 761 |
|
template<class T> struct arg<T&>
|
761 |
|
template<class T> struct arg<T&>
|
| 762 |
|
|
762 |
|
|
| 763 |
|
T& operator()(polystore& ps) const
|
763 |
|
T& operator()(polystore& ps) const
|
| 764 |
|
|
764 |
|
|
| 765 |
|
|
765 |
|
|
| 766 |
|
|
766 |
|
|
| 767 |
|
|
767 |
|
|
| 768 |
|
template<class T> struct arg<T*>
|
768 |
|
template<class T> struct arg<T*>
|
| 769 |
|
|
769 |
|
|
| 770 |
|
T* operator()(polystore& ps) const
|
770 |
|
T* operator()(polystore& ps) const
|
| 771 |
|
|
771 |
|
|
| 772 |
|
|
772 |
|
|
| 773 |
|
|
773 |
|
|
| 774 |
|
|
774 |
|
|
| 775 |
|
|
775 |
|
|
| 776 |
|
template<class F, class... Args>
|
776 |
|
template<class F, class... Args>
|
| 777 |
|
|
777 |
|
|
| 778 |
|
invoke(polystore& ps, F&& f,
|
778 |
|
invoke(polystore& ps, F&& f,
|
| 779 |
|
type_list<Args...> const&) ->
|
779 |
|
type_list<Args...> const&) ->
|
| 780 |
|
typename call_traits<std::decay_t<F>>::return_type
|
780 |
|
typename call_traits<std::decay_t<F>>::return_type
|
| 781 |
|
|
781 |
|
|
| 782 |
|
return std::forward<F>(f)(arg<Args>()(ps)...);
|
782 |
|
return std::forward<F>(f)(arg<Args>()(ps)...);
|
| 783 |
|
|
783 |
|
|
| 784 |
|
|
784 |
|
|
| 785 |
|
|
785 |
|
|
| 786 |
|
|
786 |
|
|
| 787 |
|
/** Invoke a callable, injecting stored objects as arguments
|
787 |
|
/** Invoke a callable, injecting stored objects as arguments
|
| 788 |
|
The callable is invoked with zero or more arguments.
|
788 |
|
The callable is invoked with zero or more arguments.
|
| 789 |
|
For each argument type, if an object of that type
|
789 |
|
For each argument type, if an object of that type
|
| 790 |
|
(or key type) is stored in the container, a reference
|
790 |
|
(or key type) is stored in the container, a reference
|
| 791 |
|
to that object is passed to the callable.
|
791 |
|
to that object is passed to the callable.
|
| 792 |
|
|
792 |
|
|
| 793 |
|
|
793 |
|
|
| 794 |
|
|
794 |
|
|
| 795 |
|
|
795 |
|
|
| 796 |
|
|
796 |
|
|
| 797 |
|
ps.invoke([](A& a){ assert(a.i == 1; });
|
797 |
|
ps.invoke([](A& a){ assert(a.i == 1; });
|
| 798 |
|
|
798 |
|
|
| 799 |
|
@param f The callable to invoke.
|
799 |
|
@param f The callable to invoke.
|
| 800 |
|
@return The result of the invocation.
|
800 |
|
@return The result of the invocation.
|
| 801 |
|
@throws std::bad_typeid if any reference argument
|
801 |
|
@throws std::bad_typeid if any reference argument
|
| 802 |
|
types are not found in the container.
|
802 |
|
types are not found in the container.
|
| 803 |
|
|
803 |
|
|
| 804 |
|
|
804 |
|
|
| 805 |
|
|
805 |
|
|
| 806 |
|
invoke(polystore& ps, F&& f) ->
|
806 |
|
invoke(polystore& ps, F&& f) ->
|
| 807 |
|
typename detail::call_traits<std::decay_t<F>>::return_type
|
807 |
|
typename detail::call_traits<std::decay_t<F>>::return_type
|
| 808 |
|
|
808 |
|
|
| 809 |
|
return detail::invoke(ps, std::forward<F>(f),
|
809 |
|
return detail::invoke(ps, std::forward<F>(f),
|
| 810 |
|
typename detail::call_traits<std::decay_t<F>>::arg_types{});
|
810 |
|
typename detail::call_traits<std::decay_t<F>>::arg_types{});
|
| 811 |
|
|
811 |
|
|
| 812 |
|
|
812 |
|
|
| 813 |
|
|
813 |
|
|
| 814 |
|
|
814 |
|
|
| 815 |
|
|
815 |
|
|
| 816 |
|
|
816 |
|
|