//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // shared_ptr // template shared_ptr dynamic_pointer_cast(const shared_ptr& r); #include #include #include struct B { static int count; B() {++count;} B(const B&) {++count;} virtual ~B() {--count;} }; int B::count = 0; struct A : public B { static int count; A() {++count;} A(const A&) {++count;} ~A() {--count;} }; int A::count = 0; int main() { { const std::shared_ptr pB(new A); std::shared_ptr pA = std::dynamic_pointer_cast(pB); assert(pA.get() == pB.get()); assert(!pB.owner_before(pA) && !pA.owner_before(pB)); } { const std::shared_ptr pB(new B); std::shared_ptr pA = std::dynamic_pointer_cast(pB); assert(pA.get() == 0); assert(pA.use_count() == 0); } }