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