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 // The deleter is not called if get() == 0 14 15 #include <memory> 16 #include <cassert> 17 18 class Deleter { 19 int state_; 20 21 Deleter(Deleter&); 22 Deleter& operator=(Deleter&); 23 24 public: 25 Deleter() : state_(0) {} 26 27 int state() const { return state_; } 28 29 void operator()(void*) { ++state_; } 30 }; 31 32 template <class T> 33 void test_basic() { 34 Deleter d; 35 assert(d.state() == 0); 36 { 37 std::unique_ptr<T, Deleter&> p(nullptr, d); 38 assert(p.get() == nullptr); 39 assert(&p.get_deleter() == &d); 40 } 41 assert(d.state() == 0); 42 } 43 44 int main(int, char**) { 45 test_basic<int>(); 46 test_basic<int[]>(); 47 48 return 0; 49 } 50