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