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 //===----------------------------------------------------------------------===// 8 9 // <memory> 10 11 // unique_ptr 12 13 // test reset 14 15 #include <memory> 16 #include <cassert> 17 18 #include "unique_ptr_test_helper.h" 19 20 int main(int, char**) { 21 { 22 std::unique_ptr<A> p(new A); 23 assert(A::count == 1); 24 assert(B::count == 0); 25 A* i = p.get(); 26 assert(i != nullptr); 27 p.reset(new B); 28 assert(A::count == 1); 29 assert(B::count == 1); 30 } 31 assert(A::count == 0); 32 assert(B::count == 0); 33 { 34 std::unique_ptr<A> p(new B); 35 assert(A::count == 1); 36 assert(B::count == 1); 37 A* i = p.get(); 38 assert(i != nullptr); 39 p.reset(new B); 40 assert(A::count == 1); 41 assert(B::count == 1); 42 } 43 assert(A::count == 0); 44 assert(B::count == 0); 45 46 return 0; 47 } 48