Home | History | Annotate | Download | only in util.smartptr.weak.mod
      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 // weak_ptr
     13 
     14 // void swap(weak_ptr& r);
     15 
     16 #include <memory>
     17 #include <cassert>
     18 
     19 struct A
     20 {
     21     static int count;
     22 
     23     A() {++count;}
     24     A(const A&) {++count;}
     25     ~A() {--count;}
     26 };
     27 
     28 int A::count = 0;
     29 
     30 int main()
     31 {
     32     {
     33         std::shared_ptr<A> p1(new A);
     34         std::weak_ptr<A> w1(p1);
     35         assert(w1.use_count() == 1);
     36         w1.reset();
     37         assert(w1.use_count() == 0);
     38         assert(p1.use_count() == 1);
     39     }
     40     assert(A::count == 0);
     41 }
     42