1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // void swap(shared_ptr& r);
18 #include "test_macros.h"
25 A(const A
&) {++count
;}
36 std::shared_ptr
<A
> p1(ptr1
);
38 std::shared_ptr
<A
> p2(ptr2
);
40 assert(p1
.use_count() == 1);
41 assert(p1
.get() == ptr2
);
42 assert(p2
.use_count() == 1);
43 assert(p2
.get() == ptr1
);
44 assert(A::count
== 2);
46 assert(p1
.use_count() == 1);
47 assert(p1
.get() == ptr2
);
48 assert(A::count
== 1);
50 assert(A::count
== 0);
54 std::shared_ptr
<A
> p1(ptr1
);
56 std::shared_ptr
<A
> p2
;
58 assert(p1
.use_count() == 0);
59 assert(p1
.get() == ptr2
);
60 assert(p2
.use_count() == 1);
61 assert(p2
.get() == ptr1
);
62 assert(A::count
== 1);
64 assert(p1
.use_count() == 0);
65 assert(p1
.get() == ptr2
);
66 assert(A::count
== 0);
68 assert(A::count
== 0);
72 std::shared_ptr
<A
> p1
;
74 std::shared_ptr
<A
> p2(ptr2
);
76 assert(p1
.use_count() == 1);
77 assert(p1
.get() == ptr2
);
78 assert(p2
.use_count() == 0);
79 assert(p2
.get() == ptr1
);
80 assert(A::count
== 1);
82 assert(p1
.use_count() == 1);
83 assert(p1
.get() == ptr2
);
84 assert(A::count
== 1);
86 assert(A::count
== 0);
90 std::shared_ptr
<A
> p1
;
92 std::shared_ptr
<A
> p2
;
94 assert(p1
.use_count() == 0);
95 assert(p1
.get() == ptr2
);
96 assert(p2
.use_count() == 0);
97 assert(p2
.get() == ptr1
);
98 assert(A::count
== 0);
100 assert(p1
.use_count() == 0);
101 assert(p1
.get() == ptr2
);
102 assert(A::count
== 0);
104 assert(A::count
== 0);