• 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 {
21     int state_;
22 
23     Deleter(Deleter&);
24     Deleter& operator=(Deleter&);
25 
26 public:
Deleter()27     Deleter() : state_(0) {}
28 
state() const29     int state() const {return state_;}
30 
operator ()(void *)31     void operator()(void*) {++state_;}
32 };
33 
main()34 int main()
35 {
36     Deleter d;
37     assert(d.state() == 0);
38     {
39     std::unique_ptr<int[], Deleter&> p(0, d);
40     assert(p.get() == 0);
41     assert(&p.get_deleter() == &d);
42     }
43     assert(d.state() == 0);
44 }
45