Home | History | Annotate | Download | only in unique.ptr.runtime.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 move ctor
     15 
     16 // test move ctor.  Can't copy from lvalue
     17 
     18 #include <memory>
     19 #include <cassert>
     20 
     21 struct A
     22 {
     23     static int count;
     24     A() {++count;}
     25     A(const A&) {++count;}
     26     ~A() {--count;}
     27 };
     28 
     29 int A::count = 0;
     30 
     31 class Deleter
     32 {
     33     int state_;
     34 
     35 public:
     36 
     37     Deleter() : state_(5) {}
     38 
     39     int state() const {return state_;}
     40 
     41     void operator()(A* p) {delete [] p;}
     42 };
     43 
     44 int main()
     45 {
     46     {
     47     std::unique_ptr<A[], Deleter> s(new A[3]);
     48     A* p = s.get();
     49     std::unique_ptr<A[], Deleter> s2 = s;
     50     assert(s2.get() == p);
     51     assert(s.get() == 0);
     52     assert(A::count == 1);
     53     }
     54     assert(A::count == 0);
     55 }
     56