boost::shared_polymorphic_downcast
disappeared between boost 1.52.0 and 1.53.0. Nothing is mentioned about this in the release notes, and the commit (r81463) contains only the cryptic log message "Update shared_ptr casts."
It is not clear to me what I should be using now instead, or why this functionality was removed. Can anybody help?
EDIT: Thanks everyone for the insightful comments. I find myself a bit frustrated that boost will make backwards-incompatible changes in a release without any justification or notice, and I also find it frustrating that they remove useful features. But based on the responses, I can do what I want in two lines of code instead of one, so I think that will suffice. Still, I am leaving this question "unanswered" because nobody has provided a simple way to get the old behavior of boost::shared_polymorphic_downcast
; that is, to use a dynamic_cast
when debugging is enabled and a static_cast
when it is not.
Use boost::dynamic_pointer_cast
.
The update it talks about is to match the design of C++11. In C++11 the pointer casts are generalized as the functions std::dynamic_pointer_cast
(and friends) to allow us to write:
template <typename PointerToBase> // models Base* in some way
void foo(PointerToBase ptr)
{
auto ptrToDerived = std::dynamic_pointer_cast<Derived>(ptr);
}
So that PointerToBase
could be a raw Base*
or a std::shared_ptr<Base>
, without us writing cases.
Boost of course simply wants to match C++ as much as possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With