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 ctor 15 16 #include <memory> 17 #include <utility> 18 #include <cassert> 19 20 // test move ctor. Can't copy from const lvalue 21 22 struct A 23 { 24 static int count; 25 A() {++count;} 26 A(const A&) {++count;} 27 ~A() {--count;} 28 }; 29 30 int A::count = 0; 31 32 class Deleter 33 { 34 int state_; 35 36 public: 37 38 Deleter() : state_(5) {} 39 40 int state() const {return state_;} 41 42 void operator()(A* p) {delete p;} 43 }; 44 45 int main() 46 { 47 { 48 const 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