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