I want to cast the const-ness out of a boost::shared_ptr
, but I boost::const_pointer_cast
is not the answer. boost::const_pointer_cast
wants a const boost::shared_ptr<T>
, not a boost::shared_ptr<const T>
. Let's forego the obligatory "you shouldn't be doing that". I know... but I need to do it... so what's the best/easiest way to do it?
For clarity sake:
boost::shared_ptr<const T> orig_ptr( new T() );
boost::shared_ptr<T> new_ptr = magic_incantation(orig_ptr);
I need to know the magic_incantation()
boost::const_pointer_cast
is the function you want to use:
boost::shared_ptr<const int> ci(new int(42));
boost::shared_ptr<int> i(boost::const_pointer_cast<int>(ci));
Does that not work for you? I tested that with both Boost 1.43 and the Visual C++2010 C++0x implementation--no issues with either.
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