45 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// weak_ptr12 13// void swap(weak_ptr& r);14 15#include <memory>16#include <cassert>17 18#include "test_macros.h"19 20struct A21{22 static int count;23 24 A() {++count;}25 A(const A&) {++count;}26 ~A() {--count;}27};28 29int A::count = 0;30 31int main(int, char**)32{33 {34 std::shared_ptr<A> p1(new A);35 std::weak_ptr<A> w1(p1);36 assert(w1.use_count() == 1);37 w1.reset();38 assert(w1.use_count() == 0);39 assert(p1.use_count() == 1);40 }41 assert(A::count == 0);42 43 return 0;44}45