From Jason Turner

[util.smartptr.shared.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpifhxol8c/{from.md → to.md} +116 -0
tmp/tmpifhxol8c/{from.md → to.md} RENAMED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##### General <a id="util.smartptr.shared.general">[[util.smartptr.shared.general]]</a>
2
+
3
+ The `shared_ptr` class template stores a pointer, usually obtained via
4
+ `new`. `shared_ptr` implements semantics of shared ownership; the last
5
+ remaining owner of the pointer is responsible for destroying the object,
6
+ or otherwise releasing the resources associated with the stored pointer.
7
+ A `shared_ptr` is said to be empty if it does not own a pointer.
8
+
9
+ ``` cpp
10
+ namespace std {
11
+ template<class T> class shared_ptr {
12
+ public:
13
+ using element_type = remove_extent_t<T>;
14
+ using weak_type = weak_ptr<T>;
15
+
16
+ // [util.smartptr.shared.const], constructors
17
+ constexpr shared_ptr() noexcept;
18
+ constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
19
+ template<class Y>
20
+ explicit shared_ptr(Y* p);
21
+ template<class Y, class D>
22
+ shared_ptr(Y* p, D d);
23
+ template<class Y, class D, class A>
24
+ shared_ptr(Y* p, D d, A a);
25
+ template<class D>
26
+ shared_ptr(nullptr_t p, D d);
27
+ template<class D, class A>
28
+ shared_ptr(nullptr_t p, D d, A a);
29
+ template<class Y>
30
+ shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
31
+ template<class Y>
32
+ shared_ptr(shared_ptr<Y>&& r, element_type* p) noexcept;
33
+ shared_ptr(const shared_ptr& r) noexcept;
34
+ template<class Y>
35
+ shared_ptr(const shared_ptr<Y>& r) noexcept;
36
+ shared_ptr(shared_ptr&& r) noexcept;
37
+ template<class Y>
38
+ shared_ptr(shared_ptr<Y>&& r) noexcept;
39
+ template<class Y>
40
+ explicit shared_ptr(const weak_ptr<Y>& r);
41
+ template<class Y, class D>
42
+ shared_ptr(unique_ptr<Y, D>&& r);
43
+
44
+ // [util.smartptr.shared.dest], destructor
45
+ ~shared_ptr();
46
+
47
+ // [util.smartptr.shared.assign], assignment
48
+ shared_ptr& operator=(const shared_ptr& r) noexcept;
49
+ template<class Y>
50
+ shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
51
+ shared_ptr& operator=(shared_ptr&& r) noexcept;
52
+ template<class Y>
53
+ shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
54
+ template<class Y, class D>
55
+ shared_ptr& operator=(unique_ptr<Y, D>&& r);
56
+
57
+ // [util.smartptr.shared.mod], modifiers
58
+ void swap(shared_ptr& r) noexcept;
59
+ void reset() noexcept;
60
+ template<class Y>
61
+ void reset(Y* p);
62
+ template<class Y, class D>
63
+ void reset(Y* p, D d);
64
+ template<class Y, class D, class A>
65
+ void reset(Y* p, D d, A a);
66
+
67
+ // [util.smartptr.shared.obs], observers
68
+ element_type* get() const noexcept;
69
+ T& operator*() const noexcept;
70
+ T* operator->() const noexcept;
71
+ element_type& operator[](ptrdiff_t i) const;
72
+ long use_count() const noexcept;
73
+ explicit operator bool() const noexcept;
74
+ template<class U>
75
+ bool owner_before(const shared_ptr<U>& b) const noexcept;
76
+ template<class U>
77
+ bool owner_before(const weak_ptr<U>& b) const noexcept;
78
+ };
79
+
80
+ template<class T>
81
+ shared_ptr(weak_ptr<T>) -> shared_ptr<T>;
82
+ template<class T, class D>
83
+ shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>;
84
+ }
85
+ ```
86
+
87
+ Specializations of `shared_ptr` shall be *Cpp17CopyConstructible*,
88
+ *Cpp17CopyAssignable*, and *Cpp17LessThanComparable*, allowing their use
89
+ in standard containers. Specializations of `shared_ptr` shall be
90
+ contextually convertible to `bool`, allowing their use in boolean
91
+ expressions and declarations in conditions.
92
+
93
+ The template parameter `T` of `shared_ptr` may be an incomplete type.
94
+
95
+ [*Note 1*: `T` can be a function type. — *end note*]
96
+
97
+ [*Example 1*:
98
+
99
+ ``` cpp
100
+ if (shared_ptr<X> px = dynamic_pointer_cast<X>(py)) {
101
+ // do something with px
102
+ }
103
+ ```
104
+
105
+ — *end example*]
106
+
107
+ For purposes of determining the presence of a data race, member
108
+ functions shall access and modify only the `shared_ptr` and `weak_ptr`
109
+ objects themselves and not objects they refer to. Changes in
110
+ `use_count()` do not reflect modifications that can introduce data
111
+ races.
112
+
113
+ For the purposes of subclause [[smartptr]], a pointer type `Y*` is said
114
+ to be *compatible with* a pointer type `T*` when either `Y*` is
115
+ convertible to `T*` or `Y` is `U[N]` and `T` is cv `U[]`.
116
+