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// shared_ptr 13 14// template<class T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r); 15 16#include <memory> 17#include <type_traits> 18#include <cassert> 19 20struct B 21{ 22 static int count; 23 24 B() {++count;} 25 B(const B&) {++count;} 26 virtual ~B() {--count;} 27}; 28 29int B::count = 0; 30 31struct A 32 : public B 33{ 34 static int count; 35 36 A() {++count;} 37 A(const A&) {++count;} 38 ~A() {--count;} 39}; 40 41int A::count = 0; 42 43int main() 44{ 45 { 46 const std::shared_ptr<A> pA(new A); 47 std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA); 48 assert(pB.get() == pA.get()); 49 assert(!pB.owner_before(pA) && !pA.owner_before(pB)); 50 } 51 { 52 const std::shared_ptr<B> pA(new A); 53 std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA); 54 assert(pB.get() == pA.get()); 55 assert(!pB.owner_before(pA) && !pA.owner_before(pB)); 56 } 57 { 58 const std::shared_ptr<A> pA; 59 std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA); 60 assert(pB.get() == pA.get()); 61 assert(!pB.owner_before(pA) && !pA.owner_before(pB)); 62 } 63 { 64 const std::shared_ptr<B> pA; 65 std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA); 66 assert(pB.get() == pA.get()); 67 assert(!pB.owner_before(pA) && !pA.owner_before(pB)); 68 } 69} 70