welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
welder::rods::nanobind Namespace Reference

Classes

struct  rod
 The nanobind rod: a stateless policy type satisfying welder::rod. More...

Functions

template<auto Fn, std::size_t N, typename BaseCall, typename... Args>
decltype(auto) override_dispatch (const nb::detail::trampoline< N > &tr, BaseCall &&base_call, Args &&... args)
 Dispatch a captured virtual call to its Python override, else to the C++ base.

Function Documentation

◆ override_dispatch()

template<auto Fn, std::size_t N, typename BaseCall, typename... Args>
decltype(auto) welder::rods::nanobind::override_dispatch ( const nb::detail::trampoline< N > & tr,
BaseCall && base_call,
Args &&... args )

Dispatch a captured virtual call to its Python override, else to the C++ base.

The reflection-driven replacement for NB_OVERRIDE/NB_OVERRIDE_PURE: the method name (for the Python attribute 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.

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 (WELDER_PY_OVERRIDE) supplies a lambda doing a textually qualified Base::method(...) call, which is non-virtual — matching what NB_OVERRIDE's NBBase::func(...) does.

Template Parameters
Fna reflection of the base virtual member function.
Nthe trampoline's slot count.
Parameters
trthe nanobind trampoline storage (a const ref: it is accessed from const overrides and its cache is mutable).
base_callan invocable performing the qualified base-class call.
argsthe forwarded call arguments.

Definition at line 55 of file trampoline.hpp.