reset.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===//
2//
3// ��������������������The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <memory>
11
12// weak_ptr
13
14// void swap(weak_ptr& r);
15
16#include <memory>
17#include <cassert>
18
19struct A
20{
21    static int count;
22
23    A() {++count;}
24    A(const A&) {++count;}
25    ~A() {--count;}
26};
27
28int A::count = 0;
29
30int main()
31{
32    {
33        std::shared_ptr<A> p1(new A);
34        std::weak_ptr<A> w1(p1);
35        assert(w1.use_count() == 1);
36        w1.reset();
37        assert(w1.use_count() == 0);
38        assert(p1.use_count() == 1);
39    }
40    assert(A::count == 0);
41}
42