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 converting move assignment 15 16 // Can't assign from lvalue 17 18 #include <memory> 19 #include <cassert> 20 21 #include "../deleter.h" 22 23 struct A 24 { 25 static int count; 26 A() {++count;} 27 A(const A&) {++count;} 28 virtual ~A() {--count;} 29 }; 30 31 int A::count = 0; 32 33 struct B 34 : public A 35 { 36 static int count; 37 B() {++count;} 38 B(const B&) {++count;} 39 virtual ~B() {--count;} 40 }; 41 42 int B::count = 0; 43 44 int main() 45 { 46 { 47 Deleter<B> db(5); 48 boost::unique_ptr<B[], Deleter<B>&> s(new B, db); 49 A* p = s.get(); 50 Deleter<A> da(6); 51 boost::unique_ptr<A[], Deleter<A>&> s2(new A, da); 52 s2 = s; 53 assert(s2.get() == p); 54 assert(s.get() == 0); 55 assert(A::count == 1); 56 assert(B::count == 1); 57 assert(s2.get_deleter().state() == 5); 58 } 59 assert(A::count == 0); 60 assert(B::count == 0); 61 } 62