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