tmp/tmpk1mlrwm5/{from.md → to.md}
RENAMED
|
@@ -11,64 +11,64 @@ struct X: public enable_shared_from_this<X> { };
|
|
| 11 |
|
| 12 |
int main() {
|
| 13 |
shared_ptr<X> p(new X);
|
| 14 |
shared_ptr<X> q = p->shared_from_this();
|
| 15 |
assert(p == q);
|
| 16 |
-
assert(
|
| 17 |
}
|
| 18 |
```
|
| 19 |
|
| 20 |
— *end example*]
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
namespace std {
|
| 24 |
template<class T> class enable_shared_from_this {
|
| 25 |
protected:
|
| 26 |
constexpr enable_shared_from_this() noexcept;
|
| 27 |
-
enable_shared_from_this(const enable_shared_from_this&) noexcept;
|
| 28 |
-
enable_shared_from_this& operator=(const enable_shared_from_this&) noexcept;
|
| 29 |
-
~enable_shared_from_this();
|
| 30 |
|
| 31 |
public:
|
| 32 |
-
shared_ptr<T> shared_from_this();
|
| 33 |
-
shared_ptr<T const> shared_from_this() const;
|
| 34 |
-
weak_ptr<T> weak_from_this() noexcept;
|
| 35 |
-
weak_ptr<T const> weak_from_this() const noexcept;
|
| 36 |
|
| 37 |
private:
|
| 38 |
-
mutable weak_ptr<T>
|
| 39 |
};
|
| 40 |
}
|
| 41 |
```
|
| 42 |
|
| 43 |
The template parameter `T` of `enable_shared_from_this` may be an
|
| 44 |
incomplete type.
|
| 45 |
|
| 46 |
``` cpp
|
| 47 |
constexpr enable_shared_from_this() noexcept;
|
| 48 |
-
enable_shared_from_this(const enable_shared_from_this<T>&) noexcept;
|
| 49 |
```
|
| 50 |
|
| 51 |
-
*Effects:* Value-initializes
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
-
enable_shared_from_this<T>& operator=(const enable_shared_from_this<T>&) noexcept;
|
| 55 |
```
|
| 56 |
|
| 57 |
*Returns:* `*this`.
|
| 58 |
|
| 59 |
-
[*Note 1*:
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
-
shared_ptr<T> shared_from_this();
|
| 63 |
-
shared_ptr<T const> shared_from_this() const;
|
| 64 |
```
|
| 65 |
|
| 66 |
-
*Returns:* `shared_ptr<T>(
|
| 67 |
|
| 68 |
``` cpp
|
| 69 |
-
weak_ptr<T> weak_from_this() noexcept;
|
| 70 |
-
weak_ptr<T const> weak_from_this() const noexcept;
|
| 71 |
```
|
| 72 |
|
| 73 |
-
*Returns:*
|
| 74 |
|
|
|
|
| 11 |
|
| 12 |
int main() {
|
| 13 |
shared_ptr<X> p(new X);
|
| 14 |
shared_ptr<X> q = p->shared_from_this();
|
| 15 |
assert(p == q);
|
| 16 |
+
assert(p.owner_equal(q)); // p and q share ownership
|
| 17 |
}
|
| 18 |
```
|
| 19 |
|
| 20 |
— *end example*]
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
namespace std {
|
| 24 |
template<class T> class enable_shared_from_this {
|
| 25 |
protected:
|
| 26 |
constexpr enable_shared_from_this() noexcept;
|
| 27 |
+
constexpr enable_shared_from_this(const enable_shared_from_this&) noexcept;
|
| 28 |
+
constexpr enable_shared_from_this& operator=(const enable_shared_from_this&) noexcept;
|
| 29 |
+
constexpr ~enable_shared_from_this();
|
| 30 |
|
| 31 |
public:
|
| 32 |
+
constexpr shared_ptr<T> shared_from_this();
|
| 33 |
+
constexpr shared_ptr<T const> shared_from_this() const;
|
| 34 |
+
constexpr weak_ptr<T> weak_from_this() noexcept;
|
| 35 |
+
constexpr weak_ptr<T const> weak_from_this() const noexcept;
|
| 36 |
|
| 37 |
private:
|
| 38 |
+
mutable weak_ptr<T> weak-this; // exposition only
|
| 39 |
};
|
| 40 |
}
|
| 41 |
```
|
| 42 |
|
| 43 |
The template parameter `T` of `enable_shared_from_this` may be an
|
| 44 |
incomplete type.
|
| 45 |
|
| 46 |
``` cpp
|
| 47 |
constexpr enable_shared_from_this() noexcept;
|
| 48 |
+
constexpr enable_shared_from_this(const enable_shared_from_this<T>&) noexcept;
|
| 49 |
```
|
| 50 |
|
| 51 |
+
*Effects:* Value-initializes *weak-this*.
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
+
constexpr enable_shared_from_this<T>& operator=(const enable_shared_from_this<T>&) noexcept;
|
| 55 |
```
|
| 56 |
|
| 57 |
*Returns:* `*this`.
|
| 58 |
|
| 59 |
+
[*Note 1*: *weak-this* is not changed. — *end note*]
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
+
constexpr shared_ptr<T> shared_from_this();
|
| 63 |
+
constexpr shared_ptr<T const> shared_from_this() const;
|
| 64 |
```
|
| 65 |
|
| 66 |
+
*Returns:* `shared_ptr<T>(`*`weak-this`*`)`.
|
| 67 |
|
| 68 |
``` cpp
|
| 69 |
+
constexpr weak_ptr<T> weak_from_this() noexcept;
|
| 70 |
+
constexpr weak_ptr<T const> weak_from_this() const noexcept;
|
| 71 |
```
|
| 72 |
|
| 73 |
+
*Returns:* *weak-this*.
|
| 74 |
|