From 0dd3285d5668ca25da0858ca9cce80a972a5d6dd Mon Sep 17 00:00:00 2001
From: Darin Adler
template<typename T, typename U> - shared_ptr<T> shared_static_cast(shared_ptr<U> const & r); // never throws+ shared_ptr<T> shared_static_cast(shared_ptr<U> const & r); // never throws
Perform a static_cast on the stored pointer, returning another shared_ptr. The resulting smart pointer will share its use count with the original pointer.
Note that the seemingly equivalent expression
@@ -253,7 +257,7 @@ The resulting smart pointer will share its use count with the original pointer.<template<typename T, typename U> - shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r);+ shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r);
Perform a dynamic_cast on the stored pointer, returning another shared_ptr. The resulting smart pointer will share its use count with the original pointer unless the result of the cast is 0. The only exception which may be thrown is std::bad_alloc, which may be thrown during the @@ -263,6 +267,22 @@ cast has no effect.
shared_ptr<T>(dynamic_cast<T*>(r.get()))
will eventually result in undefined behavior, attempting to delete the same object twice.
+template<typename T, typename U> + shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r);+
Perform a polymorphic_cast on the stored pointer, +returning another shared_ptr. +The resulting smart pointer will share its use count with the original pointer. +The only exception which may be thrown is std::bad_cast, if the pointer type can not be converted. +If an exception is thrown, the cast has no effect.
+ +template<typename T, typename U> + shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r); // never throws+
Perform a polymorphic_downcast on the stored pointer, +returning another shared_ptr. +The resulting smart pointer will share its use count with the original pointer.
+See shared_ptr_example.cpp for a complete example program. diff --git a/weak_ptr.htm b/weak_ptr.htm index a28232b..ccedf19 100644 --- a/weak_ptr.htm +++ b/weak_ptr.htm @@ -71,6 +71,10 @@ pointed to. T must meet the smart pointer weak_ptr<T> shared_static_cast(weak_ptr<U> const & r); // never throws template<typename T, typename U> weak_ptr<T> shared_dynamic_cast(weak_ptr<U> const & r); + template<typename T, typename U> + weak_ptr<T> shared_polymorphic_cast(weak_ptr<U> const & r); + template<typename T, typename U> + weak_ptr<T> shared_polymorphic_downcast(weak_ptr<U> const & r); // never throws } @@ -192,19 +196,35 @@ Provided as an aid to generic programming.
template<typename T, typename U> - weak_ptr<T> shared_static_cast(weak_ptr<U> const & r); // never throws+ weak_ptr<T> shared_static_cast(weak_ptr<U> const & r); // never throws
Perform a static_cast on the stored pointer, returning another weak_ptr. The resulting smart pointer will share its use count with the original pointer.
template<typename T, typename U> - weak_ptr<T> shared_dynamic_cast(weak_ptr<U> const & r);+ weak_ptr<T> shared_dynamic_cast(weak_ptr<U> const & r);
Perform a dynamic_cast on the stored pointer, returning another weak_ptr. The resulting smart pointer will share its use count with the original pointer unless the result of the cast is 0. The only exception which may be thrown is std::bad_alloc, which may be thrown during the construction of the new weak_ptr if the result of the cast is 0. If an exception is thrown, the cast has no effect.
+template<typename T, typename U> + weak_ptr<T> shared_polymorphic_cast(weak_ptr<U> const & r);+
Perform a polymorphic_cast on the stored pointer, +returning another weak_ptr. +The resulting smart pointer will share its use count with the original pointer. +The only exception which may be thrown is std::bad_cast, if the pointer type can not be converted. +If an exception is thrown, the cast has no effect.
+ +template<typename T, typename U> + weak_ptr<T> shared_polymorphic_downcast(weak_ptr<U> const & r); // never throws+
Perform a polymorphic_downcast on the stored pointer, +returning another weak_ptr. +The resulting smart pointer will share its use count with the original pointer.
+Revised 1 February 2002