//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr& operator=(const shared_ptr& r);
#include<memory>#include<type_traits>#include<cassert>structB{staticintcount;B(){++count;}B(constB&){++count;}virtual~B(){--count;}};intB::count=0;structA:publicB{staticintcount;A(){++count;}A(constA&){++count;}~A(){--count;}};intA::count=0;intmain(){{conststd::shared_ptr<A>pA(newA);A*ptrA=pA.get();{std::shared_ptr<A>pB(newA);pB=pA;assert(B::count==1);assert(A::count==1);assert(pB.use_count()==2);assert(pA.use_count()==2);assert(pA.get()==pB.get());assert(pB.get()==ptrA);}assert(pA.use_count()==1);assert(B::count==1);assert(A::count==1);}assert(B::count==0);assert(A::count==0);{conststd::shared_ptr<A>pA;A*ptrA=pA.get();{std::shared_ptr<A>pB(newA);pB=pA;assert(B::count==0);assert(A::count==0);assert(pB.use_count()==0);assert(pA.use_count()==0);assert(pA.get()==pB.get());assert(pB.get()==ptrA);}assert(pA.use_count()==0);assert(B::count==0);assert(A::count==0);}assert(B::count==0);assert(A::count==0);{conststd::shared_ptr<A>pA(newA);A*ptrA=pA.get();{std::shared_ptr<A>pB;pB=pA;assert(B::count==1);assert(A::count==1);assert(pB.use_count()==2);assert(pA.use_count()==2);assert(pA.get()==pB.get());assert(pB.get()==ptrA);}assert(pA.use_count()==1);assert(B::count==1);assert(A::count==1);}assert(B::count==0);assert(A::count==0);{conststd::shared_ptr<A>pA;A*ptrA=pA.get();{std::shared_ptr<A>pB;pB=pA;assert(B::count==0);assert(A::count==0);assert(pB.use_count()==0);assert(pA.use_count()==0);assert(pA.get()==pB.get());assert(pB.get()==ptrA);}assert(pA.use_count()==0);assert(B::count==0);assert(A::count==0);}assert(B::count==0);assert(A::count==0);}