tmp/tmp66v9ty4n/{from.md → to.md}
RENAMED
|
@@ -1,58 +1,77 @@
|
|
| 1 |
##### `shared_ptr` casts <a id="util.smartptr.shared.cast">[[util.smartptr.shared.cast]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
-
template<class T, class U>
|
|
|
|
| 5 |
```
|
| 6 |
|
| 7 |
-
*Requires:* The expression `static_cast<T*>(
|
| 8 |
formed.
|
| 9 |
|
| 10 |
-
*Returns:*
|
| 11 |
-
`shared_ptr<T>` object that stores `static_cast<T*>(r.get())` and
|
| 12 |
-
*shares ownership* with `r`.
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
The seemingly equivalent expression
|
| 18 |
`shared_ptr<T>(static_cast<T*>(r.get()))` will eventually result in
|
| 19 |
-
undefined behavior, attempting to delete the same object
|
|
|
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
-
template<class T, class U>
|
|
|
|
| 23 |
```
|
| 24 |
|
| 25 |
-
*Requires:* The expression `dynamic_cast<T*>(
|
| 26 |
formed and shall have well defined behavior.
|
| 27 |
|
| 28 |
*Returns:*
|
| 29 |
|
| 30 |
-
- When `dynamic_cast<T*>(r.get())`
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
- Otherwise, an *empty* `shared_ptr<T>` object.
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
The seemingly equivalent expression
|
| 38 |
`shared_ptr<T>(dynamic_cast<T*>(r.get()))` will eventually result in
|
| 39 |
-
undefined behavior, attempting to delete the same object
|
|
|
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
-
template<class T, class U>
|
|
|
|
| 43 |
```
|
| 44 |
|
| 45 |
-
*Requires:* The expression `const_cast<T*>(
|
| 46 |
-
formed.
|
| 47 |
|
| 48 |
-
*Returns:*
|
| 49 |
-
`shared_ptr<T>` object that stores `const_cast<T*>(r.get())` and shares
|
| 50 |
-
ownership with `r`.
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
-
The seemingly equivalent expression
|
| 56 |
`shared_ptr<T>(const_cast<T*>(r.get()))` will eventually result in
|
| 57 |
-
undefined behavior, attempting to delete the same object
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
|
|
|
| 1 |
##### `shared_ptr` casts <a id="util.smartptr.shared.cast">[[util.smartptr.shared.cast]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
+
template<class T, class U>
|
| 5 |
+
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 6 |
```
|
| 7 |
|
| 8 |
+
*Requires:* The expression `static_cast<T*>((U*)0)` shall be well
|
| 9 |
formed.
|
| 10 |
|
| 11 |
+
*Returns:*
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
``` cpp
|
| 14 |
+
shared_ptr<T>(r, static_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 15 |
+
```
|
| 16 |
|
| 17 |
+
[*Note 10*: The seemingly equivalent expression
|
| 18 |
`shared_ptr<T>(static_cast<T*>(r.get()))` will eventually result in
|
| 19 |
+
undefined behavior, attempting to delete the same object
|
| 20 |
+
twice. — *end note*]
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
+
template<class T, class U>
|
| 24 |
+
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 25 |
```
|
| 26 |
|
| 27 |
+
*Requires:* The expression `dynamic_cast<T*>((U*)0)` shall be well
|
| 28 |
formed and shall have well defined behavior.
|
| 29 |
|
| 30 |
*Returns:*
|
| 31 |
|
| 32 |
+
- When `dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())`
|
| 33 |
+
returns a nonzero value `p`, `shared_ptr<T>(r, p)`.
|
| 34 |
+
- Otherwise, `shared_ptr<T>()`.
|
|
|
|
| 35 |
|
| 36 |
+
[*Note 11*: The seemingly equivalent expression
|
|
|
|
|
|
|
| 37 |
`shared_ptr<T>(dynamic_cast<T*>(r.get()))` will eventually result in
|
| 38 |
+
undefined behavior, attempting to delete the same object
|
| 39 |
+
twice. — *end note*]
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
+
template<class T, class U>
|
| 43 |
+
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 44 |
```
|
| 45 |
|
| 46 |
+
*Requires:* The expression `const_cast<T*>((U*)0)` shall be well formed.
|
|
|
|
| 47 |
|
| 48 |
+
*Returns:*
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
``` cpp
|
| 51 |
+
shared_ptr<T>(r, const_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 52 |
+
```
|
| 53 |
|
| 54 |
+
[*Note 12*: The seemingly equivalent expression
|
| 55 |
`shared_ptr<T>(const_cast<T*>(r.get()))` will eventually result in
|
| 56 |
+
undefined behavior, attempting to delete the same object
|
| 57 |
+
twice. — *end note*]
|
| 58 |
+
|
| 59 |
+
``` cpp
|
| 60 |
+
template<class T, class U>
|
| 61 |
+
shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
*Requires:* The expression `reinterpret_cast<T*>((U*)0)` shall be well
|
| 65 |
+
formed.
|
| 66 |
+
|
| 67 |
+
*Returns:*
|
| 68 |
+
|
| 69 |
+
``` cpp
|
| 70 |
+
shared_ptr<T>(r, reinterpret_cast<typename shared_ptr<T>::element_type*>(r.get()))
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
[*Note 13*: The seemingly equivalent expression
|
| 74 |
+
`shared_ptr<T>(reinterpret_cast<T*>(r.get()))` will eventually result in
|
| 75 |
+
undefined behavior, attempting to delete the same object
|
| 76 |
+
twice. — *end note*]
|
| 77 |
|