
# BOOST_OPENMETHOD_OVERRIDE

## Synopsis

Defined in link:{{BASE_URL}}/include/boost/openmethod/macros.hpp[<boost/openmethod/macros.hpp>].

```c++
BOOST_OPENMETHOD_OVERRIDE(ID, (PARAMETERS...), RETURN_TYPE) {
    // body
}
```

## Description

`BOOST_OPENMETHOD_OVERRIDE` adds an overrider to a method.

`ID` is the identifier of the method to which the overrider is added.

NOTE: `ID` must be an *identifier*. Qualified names are not allowed.

`PARAMETERS` is a comma-separated list of types, possibly followed by parameter
names, just like in a function declaration.

The macro tries to locate a method that can be called with the same argument
list as the overrider, possibly via argument dependent lookup.

Each `virtual_ptr<T>` in the method's parameter list must have a corresponding
`virtual_ptr<U>` parameter in the same position in the overrider's parameter
list, such that `U` is the same as `T`, or has `T` as an accessible unambiguous
base.

Each `virtual_<T>` in the method's parameter list must have a corresponding `U`
parameter in the same position in the overrider's parameter list, such that `U`
is the same as `T`, or has `T` as an accessible unambiguous base.

The following names are available inside the overrider's body:

* `fn`: a pointer to a function, the overrider itself. Can be used for recursion.

* `next`: a function with the same signature as the method (minus the
`virtual_<>` decorators). It forwards to the next most specialized overrider, if
it exists and it is unique. If the next overrider does not exist, or is
ambiguous, calling `next` reports a cpp:no_overrider[] or a cpp:ambiguous_call[]
and terminates the program.

* `has_next()`: returns `true` if the next most specialized overrider exists.

## Implementation Notes

The macro creates additional entities in the current scope.

* A class template declaration that acts as a container for the method's
overriders in the current scope:

```c++
template<typename...> struct BOOST_OPENMETHOD_OVERRIDERS(NAME);
```

* A specialization of the container for the overrider:
+
--
```c++
struct BOOST_OPENMETHOD_OVERRIDERS(ID)<RETURN_TYPE(PARAMETERS...)> {
    static auto fn(PARAMETERS...) -> RETURN_TYPE;
    static auto has_next() -> bool;
    template<typename... Args>
    static auto next(typename... Args) -> RETURN_TYPE;
};
```

[]

* A xref:BOOST_OPENMETHOD_REGISTER.adoc[registrar] adding the overrider to the
method.

* Finally, the macro starts the definition of the overrider function:
--
```c++
auto BOOST_OPENMETHOD_OVERRIDERS(ID)<RETURN_TYPE(PARAMETERS...)>::fn(
    PARAMETERS...) -> RETURN_TYPE
```
--

{empty}

The `{}` block following the call to the macro is the body of the function.
