Skip to content

Commit b985003

Browse files
author
msebolt
committed
memory touchups
1 parent 9ce35b7 commit b985003

6 files changed

Lines changed: 216 additions & 11 deletions

File tree

docs/standard-library/allocator-class.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,21 @@ The modified vector v is:
10481048
( 150 200 300 400 500 600 700 ).
10491049
```
10501050

1051+
## Helpers
1052+
1053+
### <a name="allocator_arg_t"></a> allocator_arg_t
1054+
1055+
```cpp
1056+
struct allocator_arg_t { explicit allocator_arg_t() = default; };
1057+
inline constexpr allocator_arg_t allocator_arg{};
1058+
```
1059+
1060+
### <a name="uses_allocator"></a> uses_allocator
1061+
1062+
```cpp
1063+
template <class T, class Alloc> struct uses_allocator;
1064+
```
1065+
10511066
## See also
10521067

10531068
[Thread Safety in the C++ Standard Library](../standard-library/thread-safety-in-the-cpp-standard-library.md)<br/>

docs/standard-library/enable-shared-from-this-class.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public:
1717
shared_ptr<Ty>
1818
shared_from_this();
1919
shared_ptr<const Ty> shared_from_this() const;
20+
weak_ptr<T> weak_from_this() noexcept;
21+
weak_ptr<T const> weak_from_this() const noexcept;
2022
protected:
2123
enable_shared_from_this();
2224
enable_shared_from_this(const enable_shared_from_this&);
@@ -91,6 +93,13 @@ int main()
9193
sp2->val == 3
9294
```
9395

96+
## <a name="weak_from_this"></a> weak_from_this
97+
98+
```cpp
99+
weak_ptr<T> weak_from_this() noexcept;
100+
weak_ptr<T const> weak_from_this() const noexcept;
101+
```
102+
94103
## See also
95104

96105
[enable_shared_from_this::shared_from_this](#shared_from_this)<br/>

docs/standard-library/memory-functions.md

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ helpviewer_keywords: ["std::addressof [C++]", "std::align [C++]", "std::allocate
1010
||||
1111
|-|-|-|
1212
|[addressof](#addressof)|[align](#align)|[allocate_shared](#allocate_shared)|
13-
|[const_pointer_cast](#const_pointer_cast)|[declare_no_pointers](#declare_no_pointers)|[declare_reachable](#declare_reachable)|
14-
|[default_delete](#default_delete)|[destroy_at](../standard-library/memory-functions.md#destroy_at)|[destroy](../standard-library/memory-functions.md#destroy)|
15-
|[destroy_n](../standard-library/memory-functions.md#destroy_n)|[dynamic_pointer_cast](#dynamic_pointer_cast)|[get_deleter](#get_deleter)|
16-
|[get_pointer_safety](#get_pointer_safety)|[get_temporary_buffer](#get_temporary_buffer)|[make_shared](#make_shared)|
17-
|[make_unique](#make_unique)|[owner_less](#owner_less)|[return_temporary_buffer](#return_temporary_buffer)|
18-
|[static_pointer_cast](#static_pointer_cast)|[swap (C++ Standard Library)](#swap)|[undeclare_no_pointers](#undeclare_no_pointers)|
19-
|[undeclare_reachable](#undeclare_reachable)|[uninitialized_copy](#uninitialized_copy)|[uninitialized_copy_n](#uninitialized_copy_n)|
20-
|[uninitialized_default_construct](../standard-library/memory-functions.md#uninitialized_default_construct)|[uninitialized_default_construct_n](../standard-library/memory-functions.md#uninitialized_default_construct_n)|[uninitialized_fill](#uninitialized_fill)|
21-
|[uninitialized_fill_n](#uninitialized_fill_n)|[uninitialized_move](../standard-library/memory-functions.md#uninitialized_move)|[uninitialized_move_n](../standard-library/memory-functions.md#uninitialized_move_n)|
22-
|[uninitialized_value_construct](../standard-library/memory-functions.md#uninitialized_value_construct)|[uninitialized_value_construct_n](../standard-library/memory-functions.md#uninitialized_value_construct_n)||
13+
|[atomic_compare_exchange_strong](#atomic_compare_exchange_strong)|[atomic_compare_exchange_weak](#atomic_compare_exchange_weak)|[atomic_compare_exchange_strong_explicit](#atomic_compare_exchange_strong_explicit)|
14+
|[atomic_compare_exchange_weak_explicit](#atomic_compare_exchange_weak_explicit)|[atomic_exchange](#atomic_exchange)|[atomic_exchange_explicit](#atomic_exchange_explicit)|
15+
|[atomic_is_lock_free](#atomic_is_lock_free)|[atomic_load](#atomic_load)|[atomic_load_explicit](#atomic_load_explicit)|
16+
|[atomic_store](#atomic_store)|[atomic_store_explicit](#atomic_store_explicit)|[const_pointer_cast](#const_pointer_cast)|
17+
|[declare_no_pointers](#declare_no_pointers)|[declare_reachable](#declare_reachable)|[default_delete](#default_delete)|
18+
|[destroy_at](#destroy_at)|[destroy](#destroy)|[destroy_n](#destroy_n)|
19+
|[dynamic_pointer_cast](#dynamic_pointer_cast)|[get_deleter](#get_deleter)|[get_pointer_safety](#get_pointer_safety)|
20+
|[get_temporary_buffer](#get_temporary_buffer)|[make_shared](#make_shared)|[make_unique](#make_unique)|
21+
|[owner_less](#owner_less)|[return_temporary_buffer](#return_temporary_buffer)|[static_pointer_cast](#static_pointer_cast)|
22+
|[swap (C++ Standard Library)](#swap)|[undeclare_no_pointers](#undeclare_no_pointers)|[undeclare_reachable](#undeclare_reachable)|
23+
|[uninitialized_copy](#uninitialized_copy)|[uninitialized_copy_n](#uninitialized_copy_n)|[uninitialized_default_construct](#uninitialized_default_construct)|
24+
|[uninitialized_default_construct_n](#uninitialized_default_construct_n)|[uninitialized_fill](#uninitialized_fill)|[uninitialized_fill_n](#uninitialized_fill_n)|
25+
|[uninitialized_move](#uninitialized_move)|[uninitialized_move_n](#uninitialized_move_n)|[uninitialized_value_construct](#uninitialized_value_construct)|
26+
|[uninitialized_value_construct_n](#uninitialized_value_construct_n)|[uses_allocator_v](#uses_allocator_v)||
2327

2428
## <a name="addressof"></a> addressof
2529

@@ -123,6 +127,89 @@ The zero or more arguments that become the objects.
123127
124128
The function creates the object `shared_ptr<Type>`, a pointer to `Type(Args...)` as allocated and constructed by *Alloc*.
125129
130+
## <a name="atomic_compare_exchange_strong"></a> atomic_compare_exchange_strong
131+
132+
```cpp
133+
template<class T>
134+
bool atomic_compare_exchange_strong(
135+
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
136+
```
137+
138+
## <a name="atomic_compare_exchange_weak"></a> atomic_compare_exchange_weak
139+
140+
```cpp
141+
template<class T>
142+
bool atomic_compare_exchange_weak(
143+
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
144+
```
145+
146+
## <a name="atomic_compare_exchange_strong_explicit"></a> atomic_compare_exchange_strong_explicit
147+
148+
```cpp
149+
template<class T>
150+
bool atomic_compare_exchange_strong_explicit(
151+
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
152+
memory_order success, memory_order failure);
153+
```
154+
155+
## <a name="atomic_compare_exchange_weak_explicit"></a> atomic_compare_exchange_weak_explicit
156+
157+
```cpp
158+
template<class T>
159+
bool atomic_compare_exchange_weak_explicit(
160+
shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
161+
memory_order success, memory_order failure);
162+
```
163+
164+
## <a name="atomic_exchange"></a> atomic_exchange
165+
166+
```cpp
167+
template<class T>
168+
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
169+
```
170+
171+
## <a name="atomic_exchange_explicit"></a> atomic_exchange_explicit
172+
173+
```cpp
174+
template<class T>
175+
shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
176+
```
177+
178+
## <a name="atomic_is_lock_free"></a> atomic_is_lock_free
179+
180+
```cpp
181+
template<class T>
182+
bool atomic_is_lock_free(const shared_ptr<T>* p);
183+
```
184+
185+
## <a name="atomic_load"></a> atomic_load
186+
187+
```cpp
188+
template<class T>
189+
shared_ptr<T> atomic_load(const shared_ptr<T>* p);
190+
```
191+
192+
## <a name="atomic_load_explicit"></a> atomic_load_explicit
193+
194+
```cpp
195+
template<class T>
196+
shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
197+
```
198+
199+
## <a name="atomic_store"></a> atomic_store
200+
201+
```cpp
202+
template<class T>
203+
void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
204+
```
205+
206+
## <a name="atomic_store_explicit"></a> atomic_store_explicit
207+
208+
```cpp
209+
template<class T>
210+
void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
211+
```
212+
126213
## <a name="const_pointer_cast"></a> const_pointer_cast
127214

128215
Const cast to shared_ptr.
@@ -1281,6 +1368,13 @@ for (; n>0; (void)++first, --n)
12811368
typename iterator_traits<ForwardIterator>::value_type(); return first;
12821369
```
12831370

1371+
## <a name="uses_allocator_v"></a> uses_allocator_v
1372+
1373+
```cpp
1374+
template <class T, class Alloc>
1375+
inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
1376+
```
1377+
12841378
## See also
12851379
12861380
[\<memory>](../standard-library/memory.md)<br/>

docs/standard-library/memory.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ Defines a class, an operator, and several templates that help allocate and free
2323
|[addressof](../standard-library/memory-functions.md#addressof)|Gets the true address of an object.|
2424
|[align](../standard-library/memory-functions.md#align)|Returns a pointer to a range of a given size, based on the provided alignment and starting address.|
2525
|[allocate_shared](../standard-library/memory-functions.md#allocate_shared)|Creates a `shared_ptr` to objects that are allocated and constructed for a given type with a specified allocator.|
26+
|[atomic_compare_exchange_strong](../standard-library/memory-functions.md#atomic_compare_exchange_strong)||
27+
|[atomic_compare_exchange_weak](../standard-library/memory-functions.md#atomic_compare_exchange_weak)||
28+
|[atomic_compare_exchange_strong_explicit](../standard-library/memory-functions.md#atomic_compare_exchange_strong_explicit)||
29+
|[atomic_compare_exchange_weak_explicit](../standard-library/memory-functions.md#atomic_compare_exchange_weak_explicit)||
30+
|[atomic_exchange](../standard-library/memory-functions.md#atomic_exchange)||
31+
|[atomic_exchange_explicit](../standard-library/memory-functions.md#atomic_exchange_explicit)||
32+
|[atomic_is_lock_free](../standard-library/memory-functions.md#atomic_is_lock_free)||
33+
|[atomic_load](../standard-library/memory-functions.md#atomic_load)||
34+
|[atomic_load_explicit](../standard-library/memory-functions.md#atomic_load_explicit)||
35+
|[atomic_store](../standard-library/memory-functions.md#atomic_store)||
36+
|[atomic_store_explicit](../standard-library/memory-functions.md#atomic_store_explicit)||
2637
|[const_pointer_cast](../standard-library/memory-functions.md#const_pointer_cast)|Const cast to `shared_ptr`.|
2738
|[declare_no_pointers](../standard-library/memory-functions.md#declare_no_pointers)|Informs a garbage collector that the characters starting at a specified address and falling within the indicated block size contain no traceable pointers.|
2839
|[declare_reachable](../standard-library/memory-functions.md#declare_reachable)|Informs garbage collection that the indicated address is to allocated storage and is reachable.|
@@ -52,6 +63,7 @@ Defines a class, an operator, and several templates that help allocate and free
5263
|[uninitialized_move_n](../standard-library/memory-functions.md#uninitialized_move_n)|Shorthand `uninitialized_move` method.|
5364
|[uninitialized_value_construct](../standard-library/memory-functions.md#uninitialized_value_construct)|Shorthand `uninitialized_value_construct` method.|
5465
|[uninitialized_value_construct_n](../standard-library/memory-functions.md#uninitialized_value_construct_n)|Shorthand `uninitialized_value_construct` method.|
66+
|[uses_allocator_v](../standard-library/memory-functions.md#uses_allocator_v)||
5567

5668
### Operators
5769

@@ -84,8 +96,11 @@ Defines a class, an operator, and several templates that help allocate and free
8496

8597
|Structure|Description|
8698
|-|-|
99+
|[allocator_arg_t](../standard-library/allocator-class.md#allocator_arg_t)||
87100
|[default_delete](../standard-library/default-delete-struct.md)||
101+
|[hash]()||
88102
|[owner_less](../standard-library/memory-functions.md#owner_less)|Allows ownership-based mixed comparisons of shared and weak pointers.|
103+
|[uses_allocator](../standard-library/allocator-class.md#uses_allocator)||
89104

90105
### Specializations
91106

docs/standard-library/shared-ptr-class.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,16 @@ Multiple threads can read and write different `shared_ptr` objects at the same t
111111
112112
|Function|Description|
113113
|-|-|
114+
|[allocate_shared](#allocate_shared)||
115+
|[const_pointer_cast](#const_pointer_cast)||
116+
|[dynamic_pointer_cast](#dynamic_pointer_cast)||
114117
|[get](#get)|Gets address of owned resource.|
118+
|[get_deleter](#get_deleter)||
119+
|[make_shared](#make_shared)||
115120
|[owner_before](#owner_before)|Returns true if this `shared_ptr` is ordered before (or less than) the provided pointer.|
121+
|[reinterpret_pointer_cast](#reinterpret_pointer_cast)||
116122
|[reset](#reset)|Replace owned resource.|
123+
|[static_pointer_cast](#static_pointer_cast)||
117124
|[swap](#swap)|Swaps two `shared_ptr` objects.|
118125
|[unique](#unique)|Tests if owned resource is unique.|
119126
|[use_count](#use_count)|Counts numbers of resource owners.|
@@ -126,13 +133,35 @@ Multiple threads can read and write different `shared_ptr` objects at the same t
126133
|[shared_ptr::operator*](#op_star)|Gets the designated value.|
127134
|[shared_ptr::operator=](#op_eq)|Replaces the owned resource.|
128135
|[shared_ptr::operator-&gt;](#op_arrow)|Gets a pointer to the designated value.|
136+
|[shared_ptr::operator&lt;&lt;](#op_arrowarrow)||
129137
130138
## Requirements
131139
132140
**Header:** \<memory>
133141
134142
**Namespace:** std
135143
144+
## <a name="allocate_shared"></a> allocate_shared
145+
146+
```cpp
147+
template<class T, class A, class... Args>
148+
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
149+
```
150+
151+
## <a name="const_pointer_cast"></a> const_pointer_cast
152+
153+
```cpp
154+
template<class T, class U>
155+
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
156+
```
157+
158+
## <a name="dynamic_pointer_cast"></a> dynamic_pointer_cast
159+
160+
```cpp
161+
template<class T, class U>
162+
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
163+
```
164+
136165
## <a name="element_type"></a> shared_ptr::element_type
137166

138167
The type of an element.
@@ -206,6 +235,20 @@ sp0.get() == 0 == true
206235
*sp1.get() == 5
207236
```
208237

238+
## <a name="get_deleter"></a> get_deleter
239+
240+
```cpp
241+
template<class D, class T>
242+
D* get_deleter(const shared_ptr<T>& p) noexcept;
243+
```
244+
245+
## <a name="make_shared"></a> make_shared
246+
247+
```cpp
248+
template<class T, class... Args>
249+
shared_ptr<T> make_shared(Args&&... args);
250+
```
251+
209252
## <a name="op_bool"></a> shared_ptr::operator bool
210253

211254
Tests if an owned resource exists.
@@ -380,6 +423,13 @@ sp0->first == 1
380423
sp0->second == 2
381424
```
382425

426+
## <a name="op_arrowarrow"></a> shared_ptr::operator&lt;&lt;
427+
428+
```cpp
429+
template<class E, class T, class Y>
430+
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const shared_ptr<Y>& p);
431+
```
432+
383433
## <a name="owner_before"></a> shared_ptr::owner_before
384434
385435
Returns true if this `shared_ptr` is ordered before (or less than) the provided pointer.
@@ -401,6 +451,13 @@ An `lvalue` reference to either a `shared_ptr` or a `weak_ptr`.
401451

402452
The template member function returns true if `*this` is `ordered before` `ptr`.
403453

454+
## <a name="reinterpret_pointer_cast"></a> reinterpret_pointer_cast
455+
456+
```cpp
457+
template<class T, class U>
458+
shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;
459+
```
460+
404461
## <a name="reset"></a> shared_ptr::reset
405462
406463
Replace owned resource.
@@ -678,6 +735,13 @@ use count == 2
678735
use count == 1
679736
```
680737

738+
## <a name="static_pointer_cast"></a> static_pointer_cast
739+
740+
```cpp
741+
template<class T, class U>
742+
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
743+
```
744+
681745
## <a name="swap"></a> shared_ptr::swap
682746
683747
Swaps two `shared_ptr` objects.

docs/standard-library/weak-ptr-class.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ Swaps two `weak_ptr` objects.
364364
void swap(weak_ptr& wp);
365365
```
366366
367+
Also includes the specialization.
368+
369+
```cpp
370+
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
371+
```
372+
367373
### Parameters
368374

369375
*wp*<br/>
@@ -468,7 +474,7 @@ wp.use_count() == 2
468474

469475
## <a name="weak_ptr"></a> weak_ptr
470476

471-
Constructs a `weak_ptr`.
477+
Constructs a `weak_ptr`. Also includes a destructor.
472478

473479
```cpp
474480
weak_ptr();
@@ -480,6 +486,8 @@ weak_ptr(const weak_ptr<Other>& wp);
480486

481487
template <class Other>
482488
weak_ptr(const shared_ptr<Other>& sp);
489+
490+
~weak_ptr();
483491
```
484492
485493
### Parameters

0 commit comments

Comments
 (0)