From Jason Turner

[util.smartptr.weak]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp9gl8d4z0/{from.md → to.md} +30 -30
tmp/tmp9gl8d4z0/{from.md → to.md} RENAMED
@@ -6,27 +6,27 @@ can be converted to a `shared_ptr` using the member function `lock`.
6
 
7
  ``` cpp
8
  namespace std {
9
  template<class T> class weak_ptr {
10
  public:
11
- typedef T element_type;
12
 
13
  // [util.smartptr.weak.const], constructors
14
  constexpr weak_ptr() noexcept;
15
- template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
16
- weak_ptr(weak_ptr const& r) noexcept;
17
- template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
18
  weak_ptr(weak_ptr&& r) noexcept;
19
  template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
20
 
21
  // [util.smartptr.weak.dest], destructor
22
  ~weak_ptr();
23
 
24
  // [util.smartptr.weak.assign], assignment
25
- weak_ptr& operator=(weak_ptr const& r) noexcept;
26
- template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
27
- template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
28
  weak_ptr& operator=(weak_ptr&& r) noexcept;
29
  template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
30
 
31
  // [util.smartptr.weak.mod], modifiers
32
  void swap(weak_ptr& r) noexcept;
@@ -34,17 +34,20 @@ namespace std {
34
 
35
  // [util.smartptr.weak.obs], observers
36
  long use_count() const noexcept;
37
  bool expired() const noexcept;
38
  shared_ptr<T> lock() const noexcept;
39
- template<class U> bool owner_before(shared_ptr<U> const& b) const;
40
- template<class U> bool owner_before(weak_ptr<U> const& b) const;
41
  };
42
 
 
 
 
43
  // [util.smartptr.weak.spec], specialized algorithms
44
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
45
- } // namespace std
46
  ```
47
 
48
  Specializations of `weak_ptr` shall be `CopyConstructible` and
49
  `CopyAssignable`, allowing their use in standard containers. The
50
  template parameter `T` of `weak_ptr` may be an incomplete type.
@@ -53,41 +56,41 @@ template parameter `T` of `weak_ptr` may be an incomplete type.
53
 
54
  ``` cpp
55
  constexpr weak_ptr() noexcept;
56
  ```
57
 
58
- *Effects:* Constructs an *empty* `weak_ptr` object.
59
 
60
  *Postconditions:* `use_count() == 0`.
61
 
62
  ``` cpp
63
  weak_ptr(const weak_ptr& r) noexcept;
64
  template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
65
  template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
66
  ```
67
 
68
- The second and third constructors shall not participate in overload
69
- resolution unless `Y*` is implicitly convertible to `T*`.
70
 
71
- *Effects:* If `r` is *empty*, constructs an *empty* `weak_ptr` object;
72
- otherwise, constructs a `weak_ptr` object that *shares ownership* with
73
- `r` and stores a copy of the pointer stored in `r`.
74
 
75
  *Postconditions:* `use_count() == r.use_count()`.
76
 
77
  ``` cpp
78
  weak_ptr(weak_ptr&& r) noexcept;
79
  template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
80
  ```
81
 
82
- The second constructor shall not participate in overload resolution
83
- unless `Y*` is implicitly convertible to `T*`.
84
 
85
- *Effects:* Move-constructs a `weak_ptr` instance from `r`.
86
 
87
  *Postconditions:* `*this` shall contain the old value of `r`. `r` shall
88
- be *empty*. `r.use_count() == 0`.
89
 
90
  ##### `weak_ptr` destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
91
 
92
  ``` cpp
93
  ~weak_ptr();
@@ -138,33 +141,29 @@ void reset() noexcept;
138
 
139
  ``` cpp
140
  long use_count() const noexcept;
141
  ```
142
 
143
- *Returns:* `0` if `*this` is *empty*; otherwise, the number of
144
- `shared_ptr` instances that *share ownership* with `*this`.
145
-
146
- `use_count()` is not necessarily efficient.
147
 
148
  ``` cpp
149
  bool expired() const noexcept;
150
  ```
151
 
152
  *Returns:* `use_count() == 0`.
153
 
154
- `expired()` may be faster than `use_count()`.
155
-
156
  ``` cpp
157
  shared_ptr<T> lock() const noexcept;
158
  ```
159
 
160
- *Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`,
161
  executed atomically.
162
 
163
  ``` cpp
164
- template<class U> bool owner_before(shared_ptr<U> const& b) const;
165
- template<class U> bool owner_before(weak_ptr<U> const& b) const;
166
  ```
167
 
168
  *Returns:* An unspecified value such that
169
 
170
  - `x.owner_before(y)` defines a strict weak ordering as defined
@@ -175,10 +174,11 @@ template<class U> bool owner_before(weak_ptr<U> const& b) const;
175
  ownership or are both empty.
176
 
177
  ##### `weak_ptr` specialized algorithms <a id="util.smartptr.weak.spec">[[util.smartptr.weak.spec]]</a>
178
 
179
  ``` cpp
180
- template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
 
181
  ```
182
 
183
  *Effects:* Equivalent to `a.swap(b)`.
184
 
 
6
 
7
  ``` cpp
8
  namespace std {
9
  template<class T> class weak_ptr {
10
  public:
11
+ using element_type = T;
12
 
13
  // [util.smartptr.weak.const], constructors
14
  constexpr weak_ptr() noexcept;
15
+ template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
16
+ weak_ptr(const weak_ptr& r) noexcept;
17
+ template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
18
  weak_ptr(weak_ptr&& r) noexcept;
19
  template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
20
 
21
  // [util.smartptr.weak.dest], destructor
22
  ~weak_ptr();
23
 
24
  // [util.smartptr.weak.assign], assignment
25
+ weak_ptr& operator=(const weak_ptr& r) noexcept;
26
+ template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
27
+ template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
28
  weak_ptr& operator=(weak_ptr&& r) noexcept;
29
  template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
30
 
31
  // [util.smartptr.weak.mod], modifiers
32
  void swap(weak_ptr& r) noexcept;
 
34
 
35
  // [util.smartptr.weak.obs], observers
36
  long use_count() const noexcept;
37
  bool expired() const noexcept;
38
  shared_ptr<T> lock() const noexcept;
39
+ template<class U> bool owner_before(const shared_ptr<U>& b) const;
40
+ template<class U> bool owner_before(const weak_ptr<U>& b) const;
41
  };
42
 
43
+ template<class T> weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
44
+
45
+
46
  // [util.smartptr.weak.spec], specialized algorithms
47
  template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
48
+ }
49
  ```
50
 
51
  Specializations of `weak_ptr` shall be `CopyConstructible` and
52
  `CopyAssignable`, allowing their use in standard containers. The
53
  template parameter `T` of `weak_ptr` may be an incomplete type.
 
56
 
57
  ``` cpp
58
  constexpr weak_ptr() noexcept;
59
  ```
60
 
61
+ *Effects:* Constructs an empty `weak_ptr` object.
62
 
63
  *Postconditions:* `use_count() == 0`.
64
 
65
  ``` cpp
66
  weak_ptr(const weak_ptr& r) noexcept;
67
  template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
68
  template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
69
  ```
70
 
71
+ *Remarks:* The second and third constructors shall not participate in
72
+ overload resolution unless `Y*` is compatible with `T*`.
73
 
74
+ *Effects:* If `r` is empty, constructs an empty `weak_ptr` object;
75
+ otherwise, constructs a `weak_ptr` object that shares ownership with `r`
76
+ and stores a copy of the pointer stored in `r`.
77
 
78
  *Postconditions:* `use_count() == r.use_count()`.
79
 
80
  ``` cpp
81
  weak_ptr(weak_ptr&& r) noexcept;
82
  template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
83
  ```
84
 
85
+ *Remarks:* The second constructor shall not participate in overload
86
+ resolution unless `Y*` is compatible with `T*`.
87
 
88
+ *Effects:* Move constructs a `weak_ptr` instance from `r`.
89
 
90
  *Postconditions:* `*this` shall contain the old value of `r`. `r` shall
91
+ be empty. `r.use_count() == 0`.
92
 
93
  ##### `weak_ptr` destructor <a id="util.smartptr.weak.dest">[[util.smartptr.weak.dest]]</a>
94
 
95
  ``` cpp
96
  ~weak_ptr();
 
141
 
142
  ``` cpp
143
  long use_count() const noexcept;
144
  ```
145
 
146
+ *Returns:* `0` if `*this` is empty; otherwise, the number of
147
+ `shared_ptr` instances that share ownership with `*this`.
 
 
148
 
149
  ``` cpp
150
  bool expired() const noexcept;
151
  ```
152
 
153
  *Returns:* `use_count() == 0`.
154
 
 
 
155
  ``` cpp
156
  shared_ptr<T> lock() const noexcept;
157
  ```
158
 
159
+ *Returns:* `expired() ? shared_ptr<T>() : shared_ptr<T>(*this)`,
160
  executed atomically.
161
 
162
  ``` cpp
163
+ template<class U> bool owner_before(const shared_ptr<U>& b) const;
164
+ template<class U> bool owner_before(const weak_ptr<U>& b) const;
165
  ```
166
 
167
  *Returns:* An unspecified value such that
168
 
169
  - `x.owner_before(y)` defines a strict weak ordering as defined
 
174
  ownership or are both empty.
175
 
176
  ##### `weak_ptr` specialized algorithms <a id="util.smartptr.weak.spec">[[util.smartptr.weak.spec]]</a>
177
 
178
  ``` cpp
179
+ template<class T>
180
+ void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
181
  ```
182
 
183
  *Effects:* Equivalent to `a.swap(b)`.
184