boost::openmethod::virtual_ptr<SmartPtr, Registry>::virtual_ptr
Construct‐move from a virtual pointer to a derived class
Synopsis
Declared in <boost/openmethod/core.hpp>
template<class Other>
requires SameSmartPtr<SmartPtr, Other, Registry> &&
std::is_constructible_v<SmartPtr, Other&&>
virtual_ptr(virtual_ptr<Other, Registry>&& other);
Description
Move the object pointer from other to this. Copy the v‐table pointer from other.
Other is not required to be a pointer to a polymorphic class.
Examples
Move‐constructing from a shared virtual_ptr:
// classes not required to be polymorphic
struct Animal {};
struct Cat : Animal {};
struct Dog : Animal {};
BOOST_OPENMETHOD_CLASSES(Animal, Cat, Dog);
virtual_ptr<std::shared_ptr<Dog>> snoopy = make_shared_virtual<Dog>();
Dog* dog = snoopy.get();
virtual_ptr<std::shared_ptr<Animal>> p = std::move(snoopy);
BOOST_TEST(p.get() == dog);
BOOST_TEST(p.vptr() == default_registry::static_vptr<Dog>);
BOOST_TEST(snoopy.get() == nullptr);
Move‐constructing from a unique virtual_ptr:
unique_virtual_ptr<Dog> snoopy = make_unique_virtual<Dog>();
Dog* moving = snoopy.get();
unique_virtual_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
-
SmartPtrandOthermust be instantiated from the same template ‐ e.g. bothstd::shared_ptror bothstd::unique_ptr. -
Othermust be a smart pointer to a class derived fromelement_type. -
SmartPtrmust be constructible fromOther&&.
Created with MrDocs