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