1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <memory>
10 
11 // weak_ptr
12 
13 // void swap(weak_ptr& r);
14 
15 #include <memory>
16 #include <cassert>
17 
18 struct A
19 {
20     static int count;
21 
22     A() {++count;}
23     A(const A&) {++count;}
24     ~A() {--count;}
25 };
26 
27 int A::count = 0;
28 
29 int main(int, char**)
30 {
31     {
32         std::shared_ptr<A> p1(new A);
33         std::weak_ptr<A> w1(p1);
34         assert(w1.use_count() == 1);
35         w1.reset();
36         assert(w1.use_count() == 0);
37         assert(p1.use_count() == 1);
38     }
39     assert(A::count == 0);
40 
41   return 0;
42 }
43