boost::openmethod::virtual_ptr<SmartPtr, Registry>::virtual_ptr
Move‐construct from a 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, Other&&>
virtual_ptr(Other&& other);
Description
Move object pointer from other to this. Set the v‐table pointer according to the dynamic type of *other.
Example
struct Animal { virtual ~Animal() { } }; // polymorphic
struct Dog : Animal {}; // polymorphic
BOOST_OPENMETHOD_CLASSES(Animal, Dog);
initialize();
std::shared_ptr<Dog> snoopy = std::make_shared<Dog>();
Dog* moving = snoopy.get();
virtual_ptr<std::shared_ptr<Animal>> p = std::move(snoopy);
BOOST_TEST(p.get() == moving);
BOOST_TEST(p.vptr() == default_registry::static_vptr<Dog>);
BOOST_TEST(snoopy.get() == nullptr);
Requirements
-
`SmartPtr` and `Other` must be instantiated from the same template ‐ e.g. both `std::shared_ptr` or both `std::unique_ptr`.
-
`Other` must be a smart pointer to a polymorphic class derived from `element_type`.
-
`SmartPtr` must be constructible from `Other&&`.
Created with MrDocs