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