[ELF] Internalize computeCacheDirectedSortOrder. NFC
[llvm-project.git] / libcxx / test / std / utilities / memory / util.smartptr / util.smartptr.weak / util.smartptr.weak.obs / expired.pass.cpp
blobbc0eb6e1a481c6f5c32fe990ad1c3f193281a72f
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 // bool expired() const;
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 std::weak_ptr<A> wp;
35 assert(wp.use_count() == 0);
36 assert(wp.expired() == (wp.use_count() == 0));
39 std::shared_ptr<A> sp0(new A);
40 std::weak_ptr<A> wp(sp0);
41 assert(wp.use_count() == 1);
42 assert(wp.expired() == (wp.use_count() == 0));
43 sp0.reset();
44 assert(wp.use_count() == 0);
45 assert(wp.expired() == (wp.use_count() == 0));
48 return 0;