8 Oct
2015
8 Oct
'15
2:08 a.m.
Hi Karolin, On 2015/10/06 19:19, Karolin Varner wrote:
There is the family of boost pointer cast (boost::static_pointer_cast, boost::dynamic_pointer_cast, ...) that allow a developer to write generic code by casting pointers regardless of whether they are some smart pointer (e.g. shared_ptr) or plain pointers.
However, those functions have not been implemented for unique_ptr, because they create a copy of their pointer and unique_pointers can not be copied. I disagree this option because user can write unsafe code easily, see http://melpon.org/wandbox/permlink/x6Fj1QSwdD9fBAfA . It based on your dynamic_cast version, but it is also dangerous for other casts (static, const, ...).
Best, Kohei Takahashi