Pybind11 intrinsically supports the binding of overloaded functions.
Nonetheless, several predicaments may arise:
- Pybind11 internally scrutinizes overloaded functions sequentially, employing the first viable function. Please refer to this Documentation for further details.
- Certain discrepancies exist between Python and C++ types, such as Python's bool being a subclass of int.
Consequently, when generating an overload solely reliant on the builtin type, potential complications could emerge. For instance:
Should you bind void Foo(int, float) prior to void Foo(bool, float), the Python call mod.foo(False, 8) would align with void Foo(int, float), a situation incongruous with the C++ overloading mechanism.
In the face of such circumstances, it would be prudent to issue appropriate warnings when generating binding code.
Pybind11 intrinsically supports the binding of overloaded functions.
Nonetheless, several predicaments may arise:
Consequently, when generating an overload solely reliant on the builtin type, potential complications could emerge. For instance:
Should you bind
void Foo(int, float)prior tovoid Foo(bool, float), the Python callmod.foo(False, 8)would align withvoid Foo(int, float), a situation incongruous with the C++ overloading mechanism.In the face of such circumstances, it would be prudent to issue appropriate warnings when generating binding code.