boost::openmethod::inplace_vptr_base
Embed a v‐table pointer in a class.
Synopsis
Declared in <boost/openmethod/inplace_vptr.hpp>
template<
class Class,
class Registry = boost::openmethod::default_registry>
class inplace_vptr_base
: protected /* implementation-defined */
Description
inplace_vptr_base is a CRTP mixin that embeds a v‐table pointer at the root of a class hierarchy. It also declares a boost_openmethod_vptr free function that returns the v‐table pointer stored in the object.
inplace_vptr_base registers the class in Registry. It is not necessary to register the class with use_class or BOOST_OPENMETHOD_REGISTER.
The v‐table pointer is obtained directly from the Registry's static_vptr variable. No hashing is involved. If all the classes in Registry inherit from inplace_vptr_base, the registry needs not have a policies::vptr policy, nor any policy it depends on (like policies::type_hash).
If Registry contains the has_indirect_vptr policy, the v‐table pointer is stored as a pointer to a pointer, and remains valid after a call to initialize.
The default value of Registry can be changed by defining BOOST_OPENMETHOD_DEFAULT_REGISTRY.
Example
struct Animal : inplace_vptr_base<Animal> {};
struct Cat : Animal, inplace_vptr_derived<Cat, Animal> {};
struct Dog : Animal, inplace_vptr_derived<Dog, Animal> {};
BOOST_OPENMETHOD(trick, (virtual_<Animal&> animal), std::string);
BOOST_OPENMETHOD_OVERRIDE(trick, (Cat&), std::string) {
return "sulk";
}
BOOST_OPENMETHOD_OVERRIDE(trick, (Dog&), std::string) {
return "spin";
}
initialize();
std::unique_ptr<Animal> a = std::make_unique<Cat>();
std::unique_ptr<Animal> b = std::make_unique<Dog>();
std::cout << trick(*a) << "\n"; // sulk
std::cout << trick(*b) << "\n"; // spin
Protected Member Functions
Name |
Description |
|
Set the vptr to |
|
Set the vptr to |
Template Parameters
Name |
Description |
Class |
The class in which to embed the v‐table pointer. |
Registry |
The |
See Also
Created with MrDocs