BOOST_OPENMETHOD_REGISTER_CLASSES

Find the classes taking part in dispatch by reflection, and register them.

Synopsis

Declared in <boost/openmethod/macros.hpp>

#define BOOST_OPENMETHOD_REGISTER_CLASSES(…​)

Description

Does its work only with C++26 reflection (P2996): a compiler that implements it, and the flag that turns it on ‐ ‐freflection with GCC 16. Without it ‐ in C++17, or in C++26 without the flag ‐ the macro expands to a no‐op, so a file that also calls BOOST_OPENMETHOD_CLASSES builds under either standard.

It makes BOOST_OPENMETHOD_CLASSES unnecessary in most cases.

This macro is a wrapper around boost::openmethod::register_classes; see its documentation for the meaning of the arguments, which are passed through verbatim: groups of reflections, each written in braces ‐ or, for a group of one, as the reflection itself ‐ holding the namespaces to scan, the classes to register, and the registries; each group optional, in that order. With no namespace group, the global namespace is scanned.

The scan sees the whole translation unit on current compilers, but the standard promises less: a class or a method it would select, declared after the macro in the same translation unit, makes the program ill‐formed, no diagnostic required. Put the macro after the declarations it is meant to find, at the bottom of the file:

struct Animal { virtual ~Animal() = default; };
struct Cat : Animal {};
struct Dog : Animal {};
struct Bulldog : Dog {};

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

BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream& os, Dog&), void) {
    os << "bark";
}

BOOST_OPENMETHOD_REGISTER_CLASSES(); // registers all four classes

Parameters

Name

Description

...

Braced groups: namespaces, classes, registries ‐ see above.

See Also