boost::openmethod::boost_openmethod_registry

Return the registry a class belongs to (ADL customization point).

Synopsis

Declared in <boost/openmethod/core.hpp>

void
boost_openmethod_registry(...);

Description

This declaration is a catch‐all that matches any argument list. It returns a placeholder that denotes the absence of customization, which registry_affinity reads as BOOST_OPENMETHOD_DEFAULT_REGISTRY. If an overload beats it for a given class, that class declares an affinity for the overload's return type, and that registry becomes the default for every construct that mentions the class: virtual_ptr and the smart pointer aliases, and the methods that take it as a virtual parameter.

An affinity declared for a class extends to its derived classes, because the derived‐to‐base pointer conversion makes the base's overload viable. An overload on the derived class itself is a better match, and wins.

A class can also declare its affinity with a member typedef, `using boost_openmethod_registry = Registry;`. It is looked up first, and it is inherited like any member ‐ a derived class's typedef hides the base's. Being visible from the point it is declared, it is the spelling for a class that mentions virtual_ptr of itself in its own body ‐ which a class that declares no affinity may do freely.

Requirements

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

  • The single parameter is a pointer to the class. Its role is to carry the class to the overload. It must not be dereferenced ‐ the function is never called, only its return type is used.

  • The return type is a registry, possibly cv‐qualified.

The declaration must precede the first construct that mentions the class without naming a registry: a virtual_ptr of it, or a method that takes it as a virtual parameter. The answer is remembered for the rest of the translation unit, and a class mentioned before it is complete ‐ as a member of itself, or through a forward declaration ‐ is asked before a declaration further down can be seen. Declaring none is fine, and is the common case; declaring one too late is an error, reported where the class is complete and its affinity matters: a virtual parameter of a method, or a class registration.

Example

namespace zoo {

class Animal {
  public:
    virtual ~Animal() = default;

  private:
    friend auto boost_openmethod_registry(Animal*) -> zoo_registry;
};

class Dog : public Animal {};
class Cat : public Animal {};

} // namespace zoo