From Jason Turner

[util.smartptr.shared.cast]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp_5iayqb9/{from.md → to.md} +40 -16
tmp/tmp_5iayqb9/{from.md → to.md} RENAMED
@@ -1,77 +1,101 @@
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
 
 
1
+ #### 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
+ template<class T, class U>
7
+ shared_ptr<T> static_pointer_cast(shared_ptr<U>&& r) noexcept;
8
  ```
9
 
10
+ *Mandates:* The expression `static_cast<T*>((U*)nullptr)` is
11
+ well-formed.
12
 
13
  *Returns:*
14
 
15
  ``` cpp
16
+ shared_ptr<T>(R, static_cast<typename shared_ptr<T>::element_type*>(r.get()))
17
  ```
18
 
19
+ where *`R`* is `r` for the first overload, and `std::move(r)` for the
20
+ second.
21
+
22
+ [*Note 1*: The seemingly equivalent expression
23
  `shared_ptr<T>(static_cast<T*>(r.get()))` will eventually result in
24
  undefined behavior, attempting to delete the same object
25
  twice. — *end note*]
26
 
27
  ``` cpp
28
  template<class T, class U>
29
  shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
30
+ template<class T, class U>
31
+ shared_ptr<T> dynamic_pointer_cast(shared_ptr<U>&& r) noexcept;
32
  ```
33
 
34
+ *Mandates:* The expression `dynamic_cast<T*>((U*)nullptr)` is
35
+ well-formed. The expression
36
+ `dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())` is well
37
+ formed.
38
+
39
+ *Preconditions:* The expression
40
+ `dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())` has
41
+ well-defined behavior.
42
 
43
  *Returns:*
44
 
45
  - When `dynamic_cast<typename shared_ptr<T>::element_type*>(r.get())`
46
+ returns a non-null value `p`, `shared_ptr<T>(`*`R`*`, p)`, where *`R`*
47
+ is `r` for the first overload, and `std::move(r)` for the second.
48
  - Otherwise, `shared_ptr<T>()`.
49
 
50
+ [*Note 2*: The seemingly equivalent expression
51
  `shared_ptr<T>(dynamic_cast<T*>(r.get()))` will eventually result in
52
  undefined behavior, attempting to delete the same object
53
  twice. — *end note*]
54
 
55
  ``` cpp
56
  template<class T, class U>
57
  shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
58
+ template<class T, class U>
59
+ shared_ptr<T> const_pointer_cast(shared_ptr<U>&& r) noexcept;
60
  ```
61
 
62
+ *Mandates:* The expression `const_cast<T*>((U*)nullptr)` is well-formed.
63
 
64
  *Returns:*
65
 
66
  ``` cpp
67
+ shared_ptr<T>(R, const_cast<typename shared_ptr<T>::element_type*>(r.get()))
68
  ```
69
 
70
+ where *`R`* is `r` for the first overload, and `std::move(r)` for the
71
+ second.
72
+
73
+ [*Note 3*: The seemingly equivalent expression
74
  `shared_ptr<T>(const_cast<T*>(r.get()))` will eventually result in
75
  undefined behavior, attempting to delete the same object
76
  twice. — *end note*]
77
 
78
  ``` cpp
79
  template<class T, class U>
80
  shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;
81
+ template<class T, class U>
82
+ shared_ptr<T> reinterpret_pointer_cast(shared_ptr<U>&& r) noexcept;
83
  ```
84
 
85
+ *Mandates:* The expression `reinterpret_cast<T*>((U*)nullptr)` is
86
+ well-formed.
87
 
88
  *Returns:*
89
 
90
  ``` cpp
91
+ shared_ptr<T>(R, reinterpret_cast<typename shared_ptr<T>::element_type*>(r.get()))
92
  ```
93
 
94
+ where *`R`* is `r` for the first overload, and `std::move(r)` for the
95
+ second.
96
+
97
+ [*Note 4*: The seemingly equivalent expression
98
  `shared_ptr<T>(reinterpret_cast<T*>(r.get()))` will eventually result in
99
  undefined behavior, attempting to delete the same object
100
  twice. — *end note*]
101