1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <memory>
11 
12 // unique_ptr
13 
14 // test reset
15 
16 #include <memory>
17 #include <cassert>
18 
19 struct A
20 {
21     static int count;
22     A() {++count;}
23     A(const A&) {++count;}
24     ~A() {--count;}
25 };
26 
27 int A::count = 0;
28 
29 int main()
30 {
31     {
32     std::unique_ptr<A> p(new A);
33     assert(A::count == 1);
34     A* i = p.get();
35     p.reset();
36     assert(A::count == 0);
37     assert(p.get() == 0);
38     }
39     assert(A::count == 0);
40     {
41     std::unique_ptr<A> p(new A);
42     assert(A::count == 1);
43     A* i = p.get();
44     p.reset(new A);
45     assert(A::count == 1);
46     }
47     assert(A::count == 0);
48 }
49