|
welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
|
Classes | |
| struct | rod |
| The pybind11 rod: a stateless policy type satisfying welder::rod. More... | |
Functions | |
| template<auto Fn, typename Self, typename BaseCall, typename... Args> | |
| decltype(auto) | override_dispatch (const Self &self, BaseCall &&base_call, Args &&... args) |
| Dispatch a captured virtual call to its Python override, else to the C++ base. | |
| decltype(auto) welder::rods::pybind11::override_dispatch | ( | const Self & | self, |
| BaseCall && | base_call, | ||
| Args &&... | args ) |
Dispatch a captured virtual call to its Python override, else to the C++ base.
The reflection-driven replacement for PYBIND11_OVERRIDE/PYBIND11_OVERRIDE_PURE: the method name (for the Python lookup), the return type, and whether the method is pure are all read from Fn — a reflection of the base virtual — rather than spelled by hand.
self is the trampoline instance viewed as the welded type it is bound under (welder_py_base), not the virtual's declaring class. pybind11's get_override(const T*, name) keys the Python-object lookup off typeid(T) — the static pointer type — so T must be the type the instance is registered as (class_<T, Trampoline, …>). For a virtual type inherits from a base, the declaring class differs from the registered type; casting to the declaring class would look the instance up under the wrong registration and miss the override (C++ would silently see the base implementation). The caller (WELDER_PY_OVERRIDE) casts *this to welder_py_base for exactly this reason.
The base-class fallback is passed in as base_call rather than derived from Fn: splicing a member function into a member access (self.[:Fn:]()) performs a virtual call, which would re-enter the override and recurse. The caller supplies a lambda doing a textually qualified Base::method(...) call, which is non-virtual — matching what PYBIND11_OVERRIDE's cname::fn(...) tail does.
| Fn | a reflection of the base virtual member function. |
| self | the trampoline instance as its registered welded type (for the get_override lookup). |
| base_call | an invocable performing the qualified base-class call. |
| args | the forwarded call arguments. |
Definition at line 64 of file trampoline.hpp.