Update synposis in <memory> to show move semantics for weak_ptr; add tests for already existing move semantics. Mark LWG issues #2315 (no changes needed), 2316 (move semantics for weak_ptr), 2252 (previous commit) and 2271 (previous commit) as complete.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@202931 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
// weak_ptr
|
||||
|
||||
// weak_ptr(const weak_ptr& r);
|
||||
// weak_ptr(weak_ptr &&r)
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
@@ -51,6 +52,12 @@ struct C
|
||||
|
||||
int C::count = 0;
|
||||
|
||||
template <class T>
|
||||
std::weak_ptr<T> source (std::shared_ptr<T> p) { return std::weak_ptr<T>(p); }
|
||||
|
||||
template <class T>
|
||||
void sink (std::weak_ptr<T> &&) {}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -90,4 +97,14 @@ int main()
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
|
||||
{
|
||||
std::shared_ptr<A> ps(new A);
|
||||
std::weak_ptr<A> pA = source(ps);
|
||||
assert(pA.use_count() == 1);
|
||||
assert(A::count == 1);
|
||||
sink(std::move(pA)); // kill off the weak pointer
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user