boost::openmethod::virtual_ptr<SmartPtr, Registry>::virtual_ptr
Construct from a (const) smart pointer to a derived class
Synopsis
Declared in <boost/openmethod/core.hpp>
template<class Other>
requires SameSmartPtr<SmartPtr, Other, Registry> &&
IsPolymorphic<typename Other::element_type, Registry> &&
std::is_constructible_v<SmartPtr, const Other&>
virtual_ptr(Other const& other);
Description
Set the object pointer with a copy of other. Set the v‐table pointer according to the dynamic type of *other.
Examples
Constructing from a std::shared_ptr:
const std::shared_ptr<Dog> snoopy = std::make_shared<Dog>();
virtual_ptr<std::shared_ptr<Animal>> p = snoopy;
BOOST_TEST(p.get() == snoopy.get());
BOOST_TEST(p.vptr() == default_registry::static_vptr<Dog>);
A move‐only smart pointer cannot be copied from. Use the move constructor instead:
static_assert(
std::is_constructible_v<
unique_virtual_ptr<Animal>, const std::unique_ptr<Dog>&> ==
false);
Requirements
-
SmartPtrandOthermust be instantiated from the same template ‐ e.g. bothstd::shared_ptror bothstd::unique_ptr. -
Othermust be a smart pointer to a polymorphic class derived fromelement_type. -
SmartPtrmust be constructible fromconstOther&.
Created with MrDocs