[mlir][scf]: Add value bound between scf for loop yield and result (#123200)
[llvm-project.git] / libcxx / test / std / utilities / memory / util.smartptr / util.smartptr.weak / util.smartptr.weak.mod / swap.pass.cpp
blob73453d20ee807977edcc8f6ba692b368e9474d12
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 //===----------------------------------------------------------------------===//
9 // <memory>
11 // weak_ptr
13 // void swap(weak_ptr& r);
15 #include <memory>
16 #include <cassert>
18 #include "test_macros.h"
20 struct A
22 static int count;
24 A() {++count;}
25 A(const A&) {++count;}
26 ~A() {--count;}
29 int A::count = 0;
31 int main(int, char**)
34 A* ptr1 = new A;
35 A* ptr2 = new A;
36 std::shared_ptr<A> p1(ptr1);
37 std::weak_ptr<A> w1(p1);
39 std::shared_ptr<A> p2(ptr2);
40 std::weak_ptr<A> w2(p2);
41 w1.swap(w2);
42 assert(w1.use_count() == 1);
43 assert(w1.lock().get() == ptr2);
44 assert(w2.use_count() == 1);
45 assert(w2.lock().get() == ptr1);
46 assert(A::count == 2);
49 assert(A::count == 0);
51 return 0;