Home | History | Annotate | Download | only in unique.ptr.single.asgn
      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 struct A
     20 {
     21     static int count;
     22     A() {++count;}
     23     A(const A&) {++count;}
     24     virtual ~A() {--count;}
     25 };
     26 
     27 int A::count = 0;
     28 
     29 struct B
     30     : public A
     31 {
     32     static int count;
     33     B() {++count;}
     34     B(const B&) {++count;}
     35     virtual ~B() {--count;}
     36 };
     37 
     38 int B::count = 0;
     39 
     40 int main()
     41 {
     42     {
     43     std::unique_ptr<B> s(new B);
     44     A* p = s.get();
     45     std::unique_ptr<A> s2(new A);
     46     assert(A::count == 2);
     47     s2 = std::move(s);
     48     assert(s2.get() == p);
     49     assert(s.get() == 0);
     50     assert(A::count == 1);
     51     assert(B::count == 1);
     52     }
     53     assert(A::count == 0);
     54     assert(B::count == 0);
     55 }
     56