forked from OSchip/llvm-project
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.
llvm-svn: 202931
This commit is contained in:
parent
acb842d523
commit
4703f76376
|
@ -479,6 +479,8 @@ public:
|
|||
template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
|
||||
weak_ptr(weak_ptr const& r) noexcept;
|
||||
template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
|
||||
weak_ptr(weak_ptr&& r) noexcept; // C++14
|
||||
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
|
||||
|
||||
// destructor
|
||||
~weak_ptr();
|
||||
|
@ -487,6 +489,8 @@ public:
|
|||
weak_ptr& operator=(weak_ptr const& r) noexcept;
|
||||
template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
|
||||
template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
|
||||
weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
|
||||
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
|
||||
|
||||
// modifiers
|
||||
void swap(weak_ptr& r) noexcept;
|
||||
|
|
|
@ -59,4 +59,20 @@ int main()
|
|||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
|
||||
{
|
||||
const std::shared_ptr<A> ps(new A);
|
||||
std::weak_ptr<A> pA(ps);
|
||||
{
|
||||
std::weak_ptr<A> pB;
|
||||
pB = std::move(pA);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 1);
|
||||
}
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
|
|
@ -59,4 +59,20 @@ int main()
|
|||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
|
||||
{
|
||||
const std::shared_ptr<A> ps(new A);
|
||||
std::weak_ptr<A> pA(ps);
|
||||
{
|
||||
std::weak_ptr<B> pB;
|
||||
pB = std::move(pA);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 1);
|
||||
}
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
// weak_ptr
|
||||
|
||||
// template<class Y> weak_ptr(const weak_ptr<Y>& r);
|
||||
// template<class Y> weak_ptr(weak_ptr<Y> &&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()
|
||||
{
|
||||
static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), "");
|
||||
|
@ -92,4 +99,13 @@ int main()
|
|||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
|
||||
{
|
||||
std::shared_ptr<A> ps(new A);
|
||||
std::weak_ptr<A> pA = source(ps);
|
||||
std::weak_ptr<B> pB(std::move(pA));
|
||||
assert(pB.use_count() == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
|
|
@ -217,10 +217,10 @@
|
|||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2291">2291</a></td><td>std::hash is vulnerable to collision DoS attack</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2142">2142</a></td><td>packaged_task::operator() synchronization too broad?</td><td>Issaquah</td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2240">2240</a></td><td>Probable misuse of term "function scope" in [thread.condition]</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2252">2252</a></td><td>Strong guarantee on vector::push_back() still broken with C++11?</td><td>Issaquah</td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2252">2252</a></td><td>Strong guarantee on vector::push_back() still broken with C++11?</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2257">2257</a></td><td>Simplify container requirements with the new algorithms</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2268">2268</a></td><td>Setting a default argument in the declaration of a member function assign of std::basic_string</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2271">2271</a></td><td>regex_traits::lookup_classname specification unclear</td><td>Issaquah</td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2271">2271</a></td><td>regex_traits::lookup_classname specification unclear</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2272">2272</a></td><td>quoted should use char_traits::eq for character comparison</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2278">2278</a></td><td>User-defined literals for Standard Library types</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2280">2280</a></td><td>begin / end for arrays should be constexpr and noexcept</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
|
@ -247,8 +247,8 @@
|
|||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2308">2308</a></td><td>Clarify container destructor requirements w.r.t. std::array</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2313">2313</a></td><td>tuple_size should always derive from integral_constant<size_t, N></td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2314">2314</a></td><td>apply() should return decltype(auto) and use decay_t before tuple_size</td><td>Issaquah</td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2315">2315</a></td><td>weak_ptr should be movable</td><td>Issaquah</td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2316">2316</a></td><td>weak_ptr::lock() should be atomic</td><td>Issaquah</td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2315">2315</a></td><td>weak_ptr should be movable</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2316">2316</a></td><td>weak_ptr::lock() should be atomic</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2317">2317</a></td><td>The type property queries should be UnaryTypeTraits returning size_t</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2320">2320</a></td><td>select_on_container_copy_construction() takes allocators, not containers</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2322">2322</a></td><td>Associative(initializer_list, stuff) constructors are underspecified</td><td>Issaquah</td><td>Complete</td></tr>
|
||||
|
|
Loading…
Reference in New Issue