boost::openmethod::boost_openmethod_vptr

Return the v‐table pointer of an object (ADL customization point).

Synopsis

Declared in <boost/openmethod/core.hpp>

void
boost_openmethod_vptr(...);

Description

This declaration is a catch‐all that matches any argument list and returns void, denoting the absence of customization. If an overload beats it for a given argument type and registry, that overload is used to acquire a v‐table pointer instead of the registry's policies::vptr policy.

The library uses boost_openmethod_vptr (if found):

  • when dispatching via a virtual_ parameter (not a virtual_ptr);

  • when a virtual_ptr is constructed from, or assigned, a reference or a pointer to an object (not by the "final" constructs).

Requirements

The library uses argument‐dependent lookup to find an overload that satisfies the following requirements:

  • The first parameter is a const lvalue reference to the virtual argument.

  • The second parameter is a pointer to a registry. Its role is to pass the registry's class to the overload. It must not be dereferenced ‐ its value is nullptr. It may instead be void* if the overload does not need the registry.

  • The return type is vptr_type.

Example

Animal carries its v‐table pointer, and is registry‐agnostic:

class Animal {
  protected:
    boost::openmethod::vptr_type vptr;

    friend auto boost_openmethod_vptr(const Animal& a, void*) {
        return a.vptr;
    }

  public:
    Animal() {
        vptr = boost::openmethod::default_registry::static_vptr<Animal>;
    }
};

class Cat : public Animal {
  public:
    Cat() {
        vptr = boost::openmethod::default_registry::static_vptr<Cat>;
    }
};

BOOST_OPENMETHOD(poke, (std::ostream&, virtual_<Animal&>), void);

BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream & os, Cat& /*cat*/), void) {
    os << "hiss\n";
}

BOOST_OPENMETHOD_CLASSES(Animal, Cat);