From Jason Turner

[util.smartptr.shared.cast]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp66v9ty4n/{from.md → to.md} +48 -29
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> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
 
5
  ```
6
 
7
- *Requires:* The expression `static_cast<T*>(r.get())` shall be well
8
  formed.
9
 
10
- *Returns:* If `r` is *empty*, an *empty* `shared_ptr<T>`; otherwise, a
11
- `shared_ptr<T>` object that stores `static_cast<T*>(r.get())` and
12
- *shares ownership* with `r`.
13
 
14
- *Postconditions:* `w.get() == static_cast<T*>(r.get())` and
15
- `w.use_count() == r.use_count()`, where `w` is the return value.
 
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 twice.
 
20
 
21
  ``` cpp
22
- template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
 
23
  ```
24
 
25
- *Requires:* The expression `dynamic_cast<T*>(r.get())` shall be well
26
  formed and shall have well defined behavior.
27
 
28
  *Returns:*
29
 
30
- - When `dynamic_cast<T*>(r.get())` returns a nonzero value, a
31
- `shared_ptr<T>` object that stores a copy of it and *shares ownership*
32
- with `r`;
33
- - Otherwise, an *empty* `shared_ptr<T>` object.
34
 
35
- `w.get() == dynamic_cast<T*>(r.get())`, where `w` is the return value.
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 twice.
 
40
 
41
  ``` cpp
42
- template<class T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
 
43
  ```
44
 
45
- *Requires:* The expression `const_cast<T*>(r.get())` shall be well
46
- formed.
47
 
48
- *Returns:* If `r` is empty, an empty `shared_ptr<T>`; otherwise, a
49
- `shared_ptr<T>` object that stores `const_cast<T*>(r.get())` and shares
50
- ownership with `r`.
51
 
52
- *Postconditions:* `w.get() == const_cast<T*>(r.get())` and
53
- `w.use_count() == r.use_count()`, where `w` is the return value.
 
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 twice.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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