Documentation Home >> Headers >> <jss/experimental_atomic.hpp> Header >> std::experimental::shared_ptr >> std::experimental::dynamic_pointer_cast non-member function

Casts the pointer stored in the supplied std::experimental::shared_ptr instance to the specified type using dynamic_cast and returns a std::experimental::shared_ptr instance holding the result which shares ownership with the source.

template<typename Target,typename Source)
shared_ptr<Target> dynamic_pointer_cast(shared_ptr<Source> const& source);

Preconditions:

dynamic_cast<Target*>(source.get()) is well-formed.

Returns:

If dynamic_cast<Target*>(source.get())!=nullptr returns a shared_ptr<Target> that holds the value of dynamic_cast<Target*>(source.get()) and shares ownership with source. Otherwise returns a default-constructed shared_ptr<Target>.

Postconditions:

result.get()==dynamic_cast<Target*>(source.get()). If result.get()==nullptr, result.use_count()==0, otherwise result.use_count()==source.use_count(), source.use_count() is increased by 1, !result.owner_before(source), !source.owner_before(result).

Throws:

Nothing.

Header

#include <experimental/atomic>

See Also