boost::openmethod::final_virtual_ptr

Create a virtual_ptr for an object of a known exact class.

Synopsis

Declared in <boost/openmethod/core.hpp>

template<
    class Registry,
    typename Arg>
auto
final_virtual_ptr(Arg&& obj);

Description

Creates a virtual_ptr to an object, setting its v‐table pointer according to the declared type of its argument. Assumes that the static and dynamic types are the same. Sets the v‐table pointer to the registry::static_vptr for the class.

Class is not required to be polymorphic.

Nothing is looked up at runtime. Constructing a virtual_ptr from a reference or a pointer reads the object's dynamic type through the registry's rtti policy, then finds the v‐table through its vptr policy; here the v‐table pointer is a static variable, read directly. It is also the only way to create a virtual_ptr in a registry that uses policies::static_rtti, which has no dynamic type to consult and disables the constructors that would need one.

If runtime checks are enabled, and the argument is polymorphic, checks if the static and dynamic types are the same. If not, calls the error handler with a final_error value, then terminates the program with abort.

Errors

  • final_error The static and dynamic types of the object are different.

Example

See the default‐registry overload for an example.

Return Value

A virtual_ptr<Class, Registry> pointing to obj.

Template Parameters

Name

Description

Registry

A registry.

Arg

The type of the argument.

Parameters

Name

Description

obj

A reference to an object.

Created with MrDocs