| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
|
2 |
|
// Copyright (c) 2019 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/boostorg/json
|
7 |
|
// Official repository: https://github.com/boostorg/json
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_JSON_STORAGE_PTR_HPP
|
10 |
|
#ifndef BOOST_JSON_STORAGE_PTR_HPP
|
| 11 |
|
#define BOOST_JSON_STORAGE_PTR_HPP
|
11 |
|
#define BOOST_JSON_STORAGE_PTR_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/core/detail/static_assert.hpp>
|
13 |
|
#include <boost/core/detail/static_assert.hpp>
|
| 14 |
|
#include <boost/container/pmr/polymorphic_allocator.hpp>
|
14 |
|
#include <boost/container/pmr/polymorphic_allocator.hpp>
|
| 15 |
|
#include <boost/json/detail/config.hpp>
|
15 |
|
#include <boost/json/detail/config.hpp>
|
| 16 |
|
#include <boost/json/detail/shared_resource.hpp>
|
16 |
|
#include <boost/json/detail/shared_resource.hpp>
|
| 17 |
|
#include <boost/json/detail/default_resource.hpp>
|
17 |
|
#include <boost/json/detail/default_resource.hpp>
|
| 18 |
|
#include <boost/json/is_deallocate_trivial.hpp>
|
18 |
|
#include <boost/json/is_deallocate_trivial.hpp>
|
| 19 |
|
|
19 |
|
|
| 20 |
|
|
20 |
|
|
| 21 |
|
|
21 |
|
|
| 22 |
|
|
22 |
|
|
| 23 |
|
|
23 |
|
|
| 24 |
|
|
24 |
|
|
| 25 |
|
|
25 |
|
|
| 26 |
|
/** A smart pointer to a memory resource.
|
26 |
|
/** A smart pointer to a memory resource.
|
| 27 |
|
|
27 |
|
|
| 28 |
|
This class is used to hold a pointer to a memory resource. The pointed-to
|
28 |
|
This class is used to hold a pointer to a memory resource. The pointed-to
|
| 29 |
|
resource is always valid. Depending on the means of construction, the
|
29 |
|
resource is always valid. Depending on the means of construction, the
|
| 30 |
|
ownership will be either:
|
30 |
|
ownership will be either:
|
| 31 |
|
|
31 |
|
|
| 32 |
|
@li Non-owning, when constructing from a raw pointer to
|
32 |
|
@li Non-owning, when constructing from a raw pointer to
|
| 33 |
|
@ref boost::container::pmr::memory_resource or from a
|
33 |
|
@ref boost::container::pmr::memory_resource or from a
|
| 34 |
|
@ref boost::container::pmr::polymorphic_allocator. In this case the caller
|
34 |
|
@ref boost::container::pmr::polymorphic_allocator. In this case the caller
|
| 35 |
|
is responsible for ensuring that the lifetime of the memory resource
|
35 |
|
is responsible for ensuring that the lifetime of the memory resource
|
| 36 |
|
extends until there are no more calls to allocate or deallocate.
|
36 |
|
extends until there are no more calls to allocate or deallocate.
|
| 37 |
|
|
37 |
|
|
| 38 |
|
@li Owning, when constructing using the function @ref make_shared_resource.
|
38 |
|
@li Owning, when constructing using the function @ref make_shared_resource.
|
| 39 |
|
In this case ownership is shared; the lifetime of the memory resource
|
39 |
|
In this case ownership is shared; the lifetime of the memory resource
|
| 40 |
|
extends until the last copy of the `storage_ptr` is destroyed.
|
40 |
|
extends until the last copy of the `storage_ptr` is destroyed.
|
| 41 |
|
|
41 |
|
|
| 42 |
|
|
42 |
|
|
| 43 |
|
These statements create a memory resource on the stack and construct
|
43 |
|
These statements create a memory resource on the stack and construct
|
| 44 |
|
a pointer from it without taking ownership:
|
44 |
|
a pointer from it without taking ownership:
|
| 45 |
|
|
45 |
|
|
| 46 |
|
|
46 |
|
|
| 47 |
|
monotonic_resource mr; // Create our memory resource on the stack
|
47 |
|
monotonic_resource mr; // Create our memory resource on the stack
|
| 48 |
|
storage_ptr sp( &mr ); // Construct a non-owning pointer to the resource
|
48 |
|
storage_ptr sp( &mr ); // Construct a non-owning pointer to the resource
|
| 49 |
|
|
49 |
|
|
| 50 |
|
|
50 |
|
|
| 51 |
|
This function creates a pointer to a memory resource using shared ownership
|
51 |
|
This function creates a pointer to a memory resource using shared ownership
|
| 52 |
|
and returns it. The lifetime of the memory resource extends until the last
|
52 |
|
and returns it. The lifetime of the memory resource extends until the last
|
| 53 |
|
copy of the pointer is destroyed:
|
53 |
|
copy of the pointer is destroyed:
|
| 54 |
|
|
54 |
|
|
| 55 |
|
|
55 |
|
|
| 56 |
|
// Create a counted memory resource and return it
|
56 |
|
// Create a counted memory resource and return it
|
| 57 |
|
storage_ptr make_storage()
|
57 |
|
storage_ptr make_storage()
|
| 58 |
|
|
58 |
|
|
| 59 |
|
return make_shared_resource< monotonic_resource >();
|
59 |
|
return make_shared_resource< monotonic_resource >();
|
| 60 |
|
|
60 |
|
|
| 61 |
|
|
61 |
|
|
| 62 |
|
|
62 |
|
|
| 63 |
|
|
63 |
|
|
| 64 |
|
Instances of this type provide the default level of thread safety for all
|
64 |
|
Instances of this type provide the default level of thread safety for all
|
| 65 |
|
C++ objects. Specifically, it conforms to
|
65 |
|
C++ objects. Specifically, it conforms to
|
| 66 |
|
[16.4.6.10 Data race avoidance](http://eel.is/c++draft/res.on.data.races).
|
66 |
|
[16.4.6.10 Data race avoidance](http://eel.is/c++draft/res.on.data.races).
|
| 67 |
|
|
67 |
|
|
| 68 |
|
|
68 |
|
|
| 69 |
|
@ref make_shared_resource,
|
69 |
|
@ref make_shared_resource,
|
| 70 |
|
@ref boost::container::pmr::polymorphic_allocator,
|
70 |
|
@ref boost::container::pmr::polymorphic_allocator,
|
| 71 |
|
@ref boost::container::pmr::memory_resource.
|
71 |
|
@ref boost::container::pmr::memory_resource.
|
| 72 |
|
|
72 |
|
|
| 73 |
|
|
73 |
|
|
| 74 |
|
|
74 |
|
|
| 75 |
|
|
75 |
|
|
| 76 |
|
|
76 |
|
|
| 77 |
|
// VFALCO doc toolchain shows this when it shouldn't
|
77 |
|
// VFALCO doc toolchain shows this when it shouldn't
|
| 78 |
|
friend struct detail::shared_resource;
|
78 |
|
friend struct detail::shared_resource;
|
| 79 |
|
|
79 |
|
|
| 80 |
|
|
80 |
|
|
| 81 |
|
|
81 |
|
|
| 82 |
|
|
82 |
|
|
| 83 |
|
|
83 |
|
|
| 84 |
|
detail::default_resource;
|
84 |
|
detail::default_resource;
|
| 85 |
|
|
85 |
|
|
| 86 |
|
|
86 |
|
|
| 87 |
|
|
87 |
|
|
| 88 |
|
|
88 |
|
|
| 89 |
|
get_shared() const noexcept
|
89 |
|
get_shared() const noexcept
|
| 90 |
|
|
90 |
|
|
| 91 |
|
return static_cast<shared_resource*>(
|
91 |
|
return static_cast<shared_resource*>(
|
| 92 |
|
reinterpret_cast<container::pmr::memory_resource*>(
|
92 |
|
reinterpret_cast<container::pmr::memory_resource*>(
|
| 93 |
|
|
93 |
|
|
| 94 |
|
|
94 |
|
|
| 95 |
|
|
95 |
|
|
| 96 |
|
|
96 |
|
|
| 97 |
|
|
97 |
|
|
| 98 |
|
|
98 |
|
|
| 99 |
|
|
99 |
|
|
| 100 |
|
get_shared()->refs.fetch_add(
|
100 |
|
get_shared()->refs.fetch_add(
|
| 101 |
|
1, std::memory_order_relaxed);
|
101 |
|
1, std::memory_order_relaxed);
|
| 102 |
|
|
102 |
|
|
| 103 |
|
|
103 |
|
|
| 104 |
|
|
104 |
|
|
| 105 |
|
|
105 |
|
|
| 106 |
|
|
106 |
|
|
| 107 |
|
|
107 |
|
|
| 108 |
|
|
108 |
|
|
| 109 |
|
auto const p = get_shared();
|
109 |
|
auto const p = get_shared();
|
| 110 |
|
|
110 |
|
|
| 111 |
|
std::memory_order_acq_rel) == 1)
|
111 |
|
std::memory_order_acq_rel) == 1)
|
| 112 |
|
|
112 |
|
|
| 113 |
|
|
113 |
|
|
| 114 |
|
|
114 |
|
|
| 115 |
|
|
115 |
|
|
| 116 |
|
|
116 |
|
|
| 117 |
|
|
117 |
|
|
| 118 |
|
detail::shared_resource_impl<T>* p) noexcept
|
118 |
|
detail::shared_resource_impl<T>* p) noexcept
|
| 119 |
|
: i_(reinterpret_cast<std::uintptr_t>(
|
119 |
|
: i_(reinterpret_cast<std::uintptr_t>(
|
| 120 |
|
static_cast<container::pmr::memory_resource*>(p)) + 1 +
|
120 |
|
static_cast<container::pmr::memory_resource*>(p)) + 1 +
|
| 121 |
|
(json::is_deallocate_trivial<T>::value ? 2 : 0))
|
121 |
|
(json::is_deallocate_trivial<T>::value ? 2 : 0))
|
| 122 |
|
|
122 |
|
|
| 123 |
|
|
123 |
|
|
| 124 |
|
|
124 |
|
|
| 125 |
|
|
125 |
|
|
| 126 |
|
|
126 |
|
|
| 127 |
|
|
127 |
|
|
| 128 |
|
|
128 |
|
|
| 129 |
|
If the pointer has shared ownership of the resource, the shared
|
129 |
|
If the pointer has shared ownership of the resource, the shared
|
| 130 |
|
ownership is released. If this is the last owned copy, the memory
|
130 |
|
ownership is released. If this is the last owned copy, the memory
|
| 131 |
|
|
131 |
|
|
| 132 |
|
|
132 |
|
|
| 133 |
|
|
133 |
|
|
| 134 |
|
|
134 |
|
|
| 135 |
|
|
135 |
|
|
| 136 |
|
|
136 |
|
|
| 137 |
|
|
137 |
|
|
| 138 |
|
|
138 |
|
|
| 139 |
|
|
139 |
|
|
| 140 |
|
|
140 |
|
|
| 141 |
|
|
141 |
|
|
| 142 |
|
|
142 |
|
|
| 143 |
|
|
143 |
|
|
| 144 |
|
|
144 |
|
|
| 145 |
|
|
145 |
|
|
| 146 |
|
@li **(1)** constructs a non-owning pointer that refers to the
|
146 |
|
@li **(1)** constructs a non-owning pointer that refers to the
|
| 147 |
|
\<\<default_memory_resource,default memory resource\>\>.
|
147 |
|
\<\<default_memory_resource,default memory resource\>\>.
|
| 148 |
|
|
148 |
|
|
| 149 |
|
@li **(2)** constructs a non-owning pointer that points to the memory
|
149 |
|
@li **(2)** constructs a non-owning pointer that points to the memory
|
| 150 |
|
|
150 |
|
|
| 151 |
|
|
151 |
|
|
| 152 |
|
@li **(3)** constructs a non-owning pointer that points to the same
|
152 |
|
@li **(3)** constructs a non-owning pointer that points to the same
|
| 153 |
|
memory resource as `alloc`, obtained by calling `alloc.resource()`.
|
153 |
|
memory resource as `alloc`, obtained by calling `alloc.resource()`.
|
| 154 |
|
|
154 |
|
|
| 155 |
|
@li **(4)**, **(5)** construct a pointer to the same memory resource as
|
155 |
|
@li **(4)**, **(5)** construct a pointer to the same memory resource as
|
| 156 |
|
`other`, with the same ownership.
|
156 |
|
`other`, with the same ownership.
|
| 157 |
|
|
157 |
|
|
| 158 |
|
After **(4)** and **(5)** if `other` was owning, then the constructed
|
158 |
|
After **(4)** and **(5)** if `other` was owning, then the constructed
|
| 159 |
|
pointer is also owning. In particular, **(4)** transfers ownership to
|
159 |
|
pointer is also owning. In particular, **(4)** transfers ownership to
|
| 160 |
|
the constructed pointer while **(5)** causes it to share ownership with
|
160 |
|
the constructed pointer while **(5)** causes it to share ownership with
|
| 161 |
|
`other`. Otherwise, and with other overloads the constructed pointer
|
161 |
|
`other`. Otherwise, and with other overloads the constructed pointer
|
| 162 |
|
doesn't own its memory resource and the caller is responsible for
|
162 |
|
doesn't own its memory resource and the caller is responsible for
|
| 163 |
|
maintaining the lifetime of the pointed-to
|
163 |
|
maintaining the lifetime of the pointed-to
|
| 164 |
|
@ref boost::container::pmr::memory_resource.
|
164 |
|
@ref boost::container::pmr::memory_resource.
|
| 165 |
|
|
165 |
|
|
| 166 |
|
After **(4)**, `other` will point to the default memory resource.
|
166 |
|
After **(4)**, `other` will point to the default memory resource.
|
| 167 |
|
|
167 |
|
|
| 168 |
|
|
168 |
|
|
| 169 |
|
|
169 |
|
|
| 170 |
|
std::is_convertible< T*, boost::container::pmr::memory_resource* >::value == true
|
170 |
|
std::is_convertible< T*, boost::container::pmr::memory_resource* >::value == true
|
| 171 |
|
|
171 |
|
|
| 172 |
|
|
172 |
|
|
| 173 |
|
|
173 |
|
|
| 174 |
|
|
174 |
|
|
| 175 |
|
|
175 |
|
|
| 176 |
|
|
176 |
|
|
| 177 |
|
|
177 |
|
|
| 178 |
|
|
178 |
|
|
| 179 |
|
|
179 |
|
|
| 180 |
|
|
180 |
|
|
| 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 |
|
@tparam T The type of memory resource.
|
193 |
|
@tparam T The type of memory resource.
|
| 194 |
|
@param r A non-null pointer to the memory resource to use.
|
194 |
|
@param r A non-null pointer to the memory resource to use.
|
| 195 |
|
|
195 |
|
|
| 196 |
|
|
196 |
|
|
| 197 |
|
|
197 |
|
|
| 198 |
|
, class = typename std::enable_if<
|
198 |
|
, class = typename std::enable_if<
|
| 199 |
|
|
199 |
|
|
| 200 |
|
container::pmr::memory_resource*>::value>::type
|
200 |
|
container::pmr::memory_resource*>::value>::type
|
| 201 |
|
|
201 |
|
|
| 202 |
|
|
202 |
|
|
| 203 |
|
storage_ptr(T* r) noexcept
|
203 |
|
storage_ptr(T* r) noexcept
|
| 204 |
|
: i_(reinterpret_cast<std::uintptr_t>(
|
204 |
|
: i_(reinterpret_cast<std::uintptr_t>(
|
| 205 |
|
static_cast<container::pmr::memory_resource *>(r)) +
|
205 |
|
static_cast<container::pmr::memory_resource *>(r)) +
|
| 206 |
|
(json::is_deallocate_trivial<T>::value ? 2 : 0))
|
206 |
|
(json::is_deallocate_trivial<T>::value ? 2 : 0))
|
| 207 |
|
|
207 |
|
|
| 208 |
|
|
208 |
|
|
| 209 |
|
|
209 |
|
|
| 210 |
|
|
210 |
|
|
| 211 |
|
|
211 |
|
|
| 212 |
|
|
212 |
|
|
| 213 |
|
|
213 |
|
|
| 214 |
|
@param alloc A @ref boost::container::pmr::polymorphic_allocator to
|
214 |
|
@param alloc A @ref boost::container::pmr::polymorphic_allocator to
|
| 215 |
|
|
215 |
|
|
| 216 |
|
|
216 |
|
|
| 217 |
|
|
217 |
|
|
| 218 |
|
|
218 |
|
|
| 219 |
|
container::pmr::polymorphic_allocator<V> const& alloc) noexcept
|
219 |
|
container::pmr::polymorphic_allocator<V> const& alloc) noexcept
|
| 220 |
|
: i_(reinterpret_cast<std::uintptr_t>(
|
220 |
|
: i_(reinterpret_cast<std::uintptr_t>(
|
| 221 |
|
|
221 |
|
|
| 222 |
|
|
222 |
|
|
| 223 |
|
|
223 |
|
|
| 224 |
|
|
224 |
|
|
| 225 |
|
|
225 |
|
|
| 226 |
|
|
226 |
|
|
| 227 |
|
@param other Another pointer.
|
227 |
|
@param other Another pointer.
|
| 228 |
|
|
228 |
|
|
| 229 |
|
|
229 |
|
|
| 230 |
|
storage_ptr&& other) noexcept
|
230 |
|
storage_ptr&& other) noexcept
|
| 231 |
|
: i_(detail::exchange(other.i_, 0))
|
231 |
|
: i_(detail::exchange(other.i_, 0))
|
| 232 |
|
|
232 |
|
|
| 233 |
|
|
233 |
|
|
| 234 |
|
|
234 |
|
|
| 235 |
|
|
235 |
|
|
| 236 |
|
|
236 |
|
|
| 237 |
|
|
237 |
|
|
| 238 |
|
|
238 |
|
|
| 239 |
|
|
239 |
|
|
| 240 |
|
storage_ptr const& other) noexcept
|
240 |
|
storage_ptr const& other) noexcept
|
| 241 |
|
|
241 |
|
|
| 242 |
|
|
242 |
|
|
| 243 |
|
|
243 |
|
|
| 244 |
|
|
244 |
|
|
| 245 |
|
|
245 |
|
|
| 246 |
|
|
246 |
|
|
| 247 |
|
/** Assignment operators.
|
247 |
|
/** Assignment operators.
|
| 248 |
|
|
248 |
|
|
| 249 |
|
This function assigns a pointer that points to the same memory resource
|
249 |
|
This function assigns a pointer that points to the same memory resource
|
| 250 |
|
as `other`, with the same ownership:
|
250 |
|
as `other`, with the same ownership:
|
| 251 |
|
|
251 |
|
|
| 252 |
|
@li If `other` is non-owning, then the assigned-to pointer will be be
|
252 |
|
@li If `other` is non-owning, then the assigned-to pointer will be be
|
| 253 |
|
|
253 |
|
|
| 254 |
|
|
254 |
|
|
| 255 |
|
@li If `other` has shared ownership, then **(1)** transfers ownership
|
255 |
|
@li If `other` has shared ownership, then **(1)** transfers ownership
|
| 256 |
|
to the assigned-to pointer, while after **(2)** it shares the ownership
|
256 |
|
to the assigned-to pointer, while after **(2)** it shares the ownership
|
| 257 |
|
|
257 |
|
|
| 258 |
|
|
258 |
|
|
| 259 |
|
If the assigned-to pointer previously had shared ownership, it is
|
259 |
|
If the assigned-to pointer previously had shared ownership, it is
|
| 260 |
|
released before the function returns.
|
260 |
|
released before the function returns.
|
| 261 |
|
|
261 |
|
|
| 262 |
|
After **(1)**, `other` will point to the
|
262 |
|
After **(1)**, `other` will point to the
|
| 263 |
|
\<\<default_memory_resource,default memory resource\>\>.
|
263 |
|
\<\<default_memory_resource,default memory resource\>\>.
|
| 264 |
|
|
264 |
|
|
| 265 |
|
|
265 |
|
|
| 266 |
|
|
266 |
|
|
| 267 |
|
|
267 |
|
|
| 268 |
|
|
268 |
|
|
| 269 |
|
|
269 |
|
|
| 270 |
|
|
270 |
|
|
| 271 |
|
@param other Another pointer.
|
271 |
|
@param other Another pointer.
|
| 272 |
|
|
272 |
|
|
| 273 |
|
|
273 |
|
|
| 274 |
|
|
274 |
|
|
| 275 |
|
|
275 |
|
|
| 276 |
|
|
276 |
|
|
| 277 |
|
storage_ptr&& other) noexcept
|
277 |
|
storage_ptr&& other) noexcept
|
| 278 |
|
|
278 |
|
|
| 279 |
|
|
279 |
|
|
| 280 |
|
i_ = detail::exchange(other.i_, 0);
|
280 |
|
i_ = detail::exchange(other.i_, 0);
|
| 281 |
|
|
281 |
|
|
| 282 |
|
|
282 |
|
|
| 283 |
|
|
283 |
|
|
| 284 |
|
|
284 |
|
|
| 285 |
|
|
285 |
|
|
| 286 |
|
storage_ptr const& other) noexcept
|
286 |
|
storage_ptr const& other) noexcept
|
| 287 |
|
|
287 |
|
|
| 288 |
|
|
288 |
|
|
| 289 |
|
|
289 |
|
|
| 290 |
|
|
290 |
|
|
| 291 |
|
|
291 |
|
|
| 292 |
|
|
292 |
|
|
| 293 |
|
|
293 |
|
|
| 294 |
|
|
294 |
|
|
| 295 |
|
/** Check if ownership of the memory resource is shared.
|
295 |
|
/** Check if ownership of the memory resource is shared.
|
| 296 |
|
|
296 |
|
|
| 297 |
|
This function returns true for memory resources created using @ref
|
297 |
|
This function returns true for memory resources created using @ref
|
| 298 |
|
|
298 |
|
|
| 299 |
|
|
299 |
|
|
| 300 |
|
|
300 |
|
|
| 301 |
|
is_shared() const noexcept
|
301 |
|
is_shared() const noexcept
|
| 302 |
|
|
302 |
|
|
| 303 |
|
|
303 |
|
|
| 304 |
|
|
304 |
|
|
| 305 |
|
|
305 |
|
|
| 306 |
|
/** Check if calling `deallocate` on the memory resource has no effect.
|
306 |
|
/** Check if calling `deallocate` on the memory resource has no effect.
|
| 307 |
|
|
307 |
|
|
| 308 |
|
This function is used to determine if the deallocate function of the
|
308 |
|
This function is used to determine if the deallocate function of the
|
| 309 |
|
pointed to memory resource is trivial. The value of @ref
|
309 |
|
pointed to memory resource is trivial. The value of @ref
|
| 310 |
|
is_deallocate_trivial is evaluated and saved when the memory resource
|
310 |
|
is_deallocate_trivial is evaluated and saved when the memory resource
|
| 311 |
|
is constructed and the type is known, before the type is erased.
|
311 |
|
is constructed and the type is known, before the type is erased.
|
| 312 |
|
|
312 |
|
|
| 313 |
|
|
313 |
|
|
| 314 |
|
is_deallocate_trivial() const noexcept
|
314 |
|
is_deallocate_trivial() const noexcept
|
| 315 |
|
|
315 |
|
|
| 316 |
|
|
316 |
|
|
| 317 |
|
|
317 |
|
|
| 318 |
|
|
318 |
|
|
| 319 |
|
/** Check if ownership of the memory resource is not shared and deallocate is trivial.
|
319 |
|
/** Check if ownership of the memory resource is not shared and deallocate is trivial.
|
| 320 |
|
|
320 |
|
|
| 321 |
|
This function is used to determine if calls to deallocate can
|
321 |
|
This function is used to determine if calls to deallocate can
|
| 322 |
|
effectively be skipped. Equivalent to `! is_shared() &&
|
322 |
|
effectively be skipped. Equivalent to `! is_shared() &&
|
| 323 |
|
is_deallocate_trivial()`.
|
323 |
|
is_deallocate_trivial()`.
|
| 324 |
|
|
324 |
|
|
| 325 |
|
|
325 |
|
|
| 326 |
|
is_not_shared_and_deallocate_is_trivial() const noexcept
|
326 |
|
is_not_shared_and_deallocate_is_trivial() const noexcept
|
| 327 |
|
|
327 |
|
|
| 328 |
|
|
328 |
|
|
| 329 |
|
|
329 |
|
|
| 330 |
|
|
330 |
|
|
| 331 |
|
/** Return a pointer to the memory resource.
|
331 |
|
/** Return a pointer to the memory resource.
|
| 332 |
|
|
332 |
|
|
| 333 |
|
This function returns a pointer to the
|
333 |
|
This function returns a pointer to the
|
| 334 |
|
referenced @ref boost::container::pmr::memory_resource.
|
334 |
|
referenced @ref boost::container::pmr::memory_resource.
|
| 335 |
|
|
335 |
|
|
| 336 |
|
|
336 |
|
|
| 337 |
|
|
337 |
|
|
| 338 |
|
|
338 |
|
|
| 339 |
|
|
339 |
|
|
| 340 |
|
|
340 |
|
|
| 341 |
|
|
341 |
|
|
| 342 |
|
container::pmr::memory_resource*
|
342 |
|
container::pmr::memory_resource*
|
| 343 |
|
|
343 |
|
|
| 344 |
|
|
344 |
|
|
| 345 |
|
|
345 |
|
|
| 346 |
|
|
346 |
|
|
| 347 |
|
container::pmr::memory_resource*>(i_ & ~3);
|
347 |
|
container::pmr::memory_resource*>(i_ & ~3);
|
| 348 |
|
return default_resource::get();
|
348 |
|
return default_resource::get();
|
| 349 |
|
|
349 |
|
|
| 350 |
|
|
350 |
|
|
| 351 |
|
/** Return a pointer to the memory resource.
|
351 |
|
/** Return a pointer to the memory resource.
|
| 352 |
|
|
352 |
|
|
| 353 |
|
This function returns a pointer to the referenced @ref
|
353 |
|
This function returns a pointer to the referenced @ref
|
| 354 |
|
boost::container::pmr::memory_resource.
|
354 |
|
boost::container::pmr::memory_resource.
|
| 355 |
|
|
355 |
|
|
| 356 |
|
|
356 |
|
|
| 357 |
|
|
357 |
|
|
| 358 |
|
|
358 |
|
|
| 359 |
|
|
359 |
|
|
| 360 |
|
|
360 |
|
|
| 361 |
|
|
361 |
|
|
| 362 |
|
container::pmr::memory_resource*
|
362 |
|
container::pmr::memory_resource*
|
| 363 |
|
operator->() const noexcept
|
363 |
|
operator->() const noexcept
|
| 364 |
|
|
364 |
|
|
| 365 |
|
|
365 |
|
|
| 366 |
|
|
366 |
|
|
| 367 |
|
|
367 |
|
|
| 368 |
|
/** Return a reference to the memory resource.
|
368 |
|
/** Return a reference to the memory resource.
|
| 369 |
|
|
369 |
|
|
| 370 |
|
This function returns a reference to the pointed-to @ref
|
370 |
|
This function returns a reference to the pointed-to @ref
|
| 371 |
|
boost::container::pmr::memory_resource.
|
371 |
|
boost::container::pmr::memory_resource.
|
| 372 |
|
|
372 |
|
|
| 373 |
|
|
373 |
|
|
| 374 |
|
|
374 |
|
|
| 375 |
|
|
375 |
|
|
| 376 |
|
|
376 |
|
|
| 377 |
|
|
377 |
|
|
| 378 |
|
|
378 |
|
|
| 379 |
|
|
379 |
|
|
| 380 |
|
|
380 |
|
|
| 381 |
|
container::pmr::memory_resource&
|
381 |
|
container::pmr::memory_resource&
|
| 382 |
|
operator*() const noexcept
|
382 |
|
operator*() const noexcept
|
| 383 |
|
|
383 |
|
|
| 384 |
|
|
384 |
|
|
| 385 |
|
|
385 |
|
|
| 386 |
|
|
386 |
|
|
| 387 |
|
template<class U, class... Args>
|
387 |
|
template<class U, class... Args>
|
| 388 |
|
|
388 |
|
|
| 389 |
|
|
389 |
|
|
| 390 |
|
make_shared_resource(Args&&... args);
|
390 |
|
make_shared_resource(Args&&... args);
|
| 391 |
|
|
391 |
|
|
| 392 |
|
|
392 |
|
|
| 393 |
|
|
393 |
|
|
| 394 |
|
|
394 |
|
|
| 395 |
|
# if !defined(__clang__) && _MSC_VER <= 1900
|
395 |
|
# if !defined(__clang__) && _MSC_VER <= 1900
|
| 396 |
|
# pragma warning( disable : 4702 )
|
396 |
|
# pragma warning( disable : 4702 )
|
| 397 |
|
|
397 |
|
|
| 398 |
|
|
398 |
|
|
| 399 |
|
|
399 |
|
|
| 400 |
|
/** Return a pointer that owns a new, dynamically allocated memory resource.
|
400 |
|
/** Return a pointer that owns a new, dynamically allocated memory resource.
|
| 401 |
|
|
401 |
|
|
| 402 |
|
This function dynamically allocates a new memory resource as if by
|
402 |
|
This function dynamically allocates a new memory resource as if by
|
| 403 |
|
`operator new` that uses shared ownership. The lifetime of the memory
|
403 |
|
`operator new` that uses shared ownership. The lifetime of the memory
|
| 404 |
|
resource will be extended until the last @ref storage_ptr which points to
|
404 |
|
resource will be extended until the last @ref storage_ptr which points to
|
| 405 |
|
|
405 |
|
|
| 406 |
|
|
406 |
|
|
| 407 |
|
|
407 |
|
|
| 408 |
|
|
408 |
|
|
| 409 |
|
std::is_base_of< boost::container::pmr::memory_resource, U >::value == true
|
409 |
|
std::is_base_of< boost::container::pmr::memory_resource, U >::value == true
|
| 410 |
|
|
410 |
|
|
| 411 |
|
|
411 |
|
|
| 412 |
|
|
412 |
|
|
| 413 |
|
Same as `new U( std::forward<Args>(args)... )`.
|
413 |
|
Same as `new U( std::forward<Args>(args)... )`.
|
| 414 |
|
|
414 |
|
|
| 415 |
|
|
415 |
|
|
| 416 |
|
|
416 |
|
|
| 417 |
|
|
417 |
|
|
| 418 |
|
@tparam U The type of memory resource to create.
|
418 |
|
@tparam U The type of memory resource to create.
|
| 419 |
|
|
419 |
|
|
| 420 |
|
@param args Parameters forwarded to the constructor of `U`.
|
420 |
|
@param args Parameters forwarded to the constructor of `U`.
|
| 421 |
|
|
421 |
|
|
| 422 |
|
template<class U, class... Args>
|
422 |
|
template<class U, class... Args>
|
| 423 |
|
|
423 |
|
|
| 424 |
|
make_shared_resource(Args&&... args)
|
424 |
|
make_shared_resource(Args&&... args)
|
| 425 |
|
|
425 |
|
|
| 426 |
|
// If this generates an error, it means that
|
426 |
|
// If this generates an error, it means that
|
| 427 |
|
// `T` is not a memory resource.
|
427 |
|
// `T` is not a memory resource.
|
| 428 |
|
BOOST_CORE_STATIC_ASSERT((
|
428 |
|
BOOST_CORE_STATIC_ASSERT((
|
| 429 |
|
std::is_base_of<container::pmr::memory_resource, U>::value));
|
429 |
|
std::is_base_of<container::pmr::memory_resource, U>::value));
|
| 430 |
|
|
430 |
|
|
| 431 |
|
detail::shared_resource_impl<U>(
|
431 |
|
detail::shared_resource_impl<U>(
|
| 432 |
|
std::forward<Args>(args)...));
|
432 |
|
std::forward<Args>(args)...));
|
| 433 |
|
|
433 |
|
|
| 434 |
|
|
434 |
|
|
| 435 |
|
|
435 |
|
|
| 436 |
|
|
436 |
|
|
| 437 |
|
|
437 |
|
|
| 438 |
|
|
438 |
|
|
| 439 |
|
|
439 |
|
|
| 440 |
|
|
440 |
|
|
| 441 |
|
|
441 |
|
|
| 442 |
|
|
442 |
|
|
| 443 |
|
storage_ptr const& rhs) noexcept
|
443 |
|
storage_ptr const& rhs) noexcept
|
| 444 |
|
|
444 |
|
|
| 445 |
|
return lhs.get() == rhs.get();
|
445 |
|
return lhs.get() == rhs.get();
|
| 446 |
|
|
446 |
|
|
| 447 |
|
|
447 |
|
|
| 448 |
|
|
448 |
|
|
| 449 |
|
|
449 |
|
|
| 450 |
|
|
450 |
|
|
| 451 |
|
|
451 |
|
|
| 452 |
|
|
452 |
|
|
| 453 |
|
storage_ptr const& rhs) noexcept
|
453 |
|
storage_ptr const& rhs) noexcept
|
| 454 |
|
|
454 |
|
|
| 455 |
|
return lhs.get() != rhs.get();
|
455 |
|
return lhs.get() != rhs.get();
|
| 456 |
|
|
456 |
|
|
| 457 |
|
|
457 |
|
|
| 458 |
|
|
458 |
|
|
| 459 |
|
|
459 |
|
|
| 460 |
|
|
460 |
|
|
| 461 |
|
|
461 |
|
|