boost::openmethod::initialize

Initialize a registry.

Synopsis

template<
    class Registry = boost::openmethod::default_registry,
    class... Options>
auto
initialize(Options...&&... options);

Description

Initialize the registry passed as an explicit function template argument, or default_registry if the registry is not specified. The default can be changed by defining BOOST_OPENMETHOD_DEFAULT_REGISTRY. Option objects can be passed to change the behavior of the function. Currently two options exist:

  • trace Enable tracing of the initialization process.

  • n2216 Enable resolution of ambiguities according to the N2216 paper.

initialize must be called, typically at the beginning of main, before using any of the methods in a registry. It sets up the v‐tables, multi‐method dispatch tables, and any other data required by the policies.

The function returns an object of an unspecified type that contains a report member, itself an object of an unspecified type, thatcontains the following members:

  • `std::size_t cells`: The number of cells in all multi‐method dispatch tables.

  • `std::size_t not_implemented`: The number of multi‐method dispatch tables that contain at least one not implemented entry.

  • `std::size_t ambiguous`: The number of multi‐method dispatch tables that contain at least one ambiguous entry.

A translation unit that calls initialize must include the <boost/openmethod/initialize.hpp> header.

Errors

  • missing_class: A class used in a virtual parameter was not registered.

  • The registry's policies may report additional errors.

Example

Initialize the default registry with tracing enabled, and exit with an error message if there were any possibility of a bad_call error. User may run the program again after setting environment variable BOOST_OPENMETHOD_TRACE to 1 to troubleshoot.

#include <iostream>

#include <boost/openmethod.hpp>
#include <boost/openmethod/initialize.hpp>

int main() {
    namespace bom = boost::openmethod;
    auto report = bom::initialize(bom::trace::from_env()).report;

    if (report.not_implemented != 0 || report.ambiguous != 0) {
        std::cerr << "missing overriders or ambiguous methods\n";
        return 1;
    }

    // ...
}

Return Value

An object of an unspecified type.

Template Parameters

Name Description

Registry

The registry to initialize.

Options...

Zero or more option types, deduced from the function arguments.

Parameters

Name Description

options

Zero or more option objects.

Created with MrDocs