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 // Test unique_ptr move assignment
15 
16 #include <memory>
17 #include <utility>
18 #include <cassert>
19 
20 // Can't copy from lvalue
21 
22 struct A
23 {
24     static int count;
AA25     A() {++count;}
AA26     A(const A&) {++count;}
~AA27     ~A() {--count;}
28 };
29 
30 int A::count = 0;
31 
32 class Deleter
33 {
34     int state_;
35 
36 public:
37 
Deleter()38     Deleter() : state_(5) {}
39 
state() const40     int state() const {return state_;}
41 
operator ()(A * p)42     void operator()(A* p) {delete p;}
43 };
44 
main()45 int main()
46 {
47     {
48     std::unique_ptr<A, Deleter> s(new A);
49     A* p = s.get();
50     std::unique_ptr<A, Deleter> s2;
51     s2 = s;
52     assert(s2.get() == p);
53     assert(s.get() == 0);
54     assert(A::count == 1);
55     }
56     assert(A::count == 0);
57 }
58