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; AA22 A() {++count;} AA23 A(const A&) {++count;} ~AA24 ~A() {--count;} 25 }; 26 27 int A::count = 0; 28 main()29int main() 30 { 31 { 32 std::unique_ptr<A[]> p(new A[3]); 33 assert(A::count == 3); 34 A* i = p.get(); 35 assert(i != nullptr); 36 p.reset(); 37 assert(A::count == 0); 38 assert(p.get() == 0); 39 } 40 assert(A::count == 0); 41 { 42 std::unique_ptr<A[]> p(new A[4]); 43 assert(A::count == 4); 44 A* i = p.get(); 45 assert(i != nullptr); 46 p.reset(new A[5]); 47 assert(A::count == 5); 48 } 49 assert(A::count == 0); 50 } 51