Home | History | Annotate | Download | only in unique.ptr.single.ctor
      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(pointer) ctor
     15 
     16 #include <memory>
     17 #include <cassert>
     18 
     19 // template <class U> explicit unique_ptr(auto_ptr<U>&);
     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 struct Deleter
     43 {
     44     template <class T>
     45         void operator()(T*) {}
     46 };
     47 
     48 int main()
     49 {
     50     {
     51     B* p = new B;
     52     std::auto_ptr<B> ap(p);
     53     std::unique_ptr<A, Deleter> up(ap);
     54     assert(up.get() == p);
     55     assert(ap.get() == 0);
     56     assert(A::count == 1);
     57     assert(B::count == 1);
     58     }
     59     assert(A::count == 0);
     60     assert(B::count == 0);
     61 }
     62