mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
Add syntax sugar for resolving overloaded functions (#541)
This commit is contained in:
committed by
Wenzel Jakob
parent
ae185b7f19
commit
4e959c9af4
@@ -23,6 +23,9 @@ std::string test_function3(int i) {
|
||||
return "test_function(" + std::to_string(i) + ")";
|
||||
}
|
||||
|
||||
py::str test_function4(int, float) { return "test_function(int, float)"; }
|
||||
py::str test_function4(float, int) { return "test_function(float, int)"; }
|
||||
|
||||
py::bytes return_bytes() {
|
||||
const char *data = "\x01\x00\x02\x00";
|
||||
return std::string(data, 4);
|
||||
@@ -45,6 +48,14 @@ test_initializer constants_and_functions([](py::module &m) {
|
||||
m.def("test_function", &test_function2);
|
||||
m.def("test_function", &test_function3);
|
||||
|
||||
#if defined(PYBIND11_OVERLOAD_CAST)
|
||||
m.def("test_function", py::overload_cast<int, float>(&test_function4));
|
||||
m.def("test_function", py::overload_cast<float, int>(&test_function4));
|
||||
#else
|
||||
m.def("test_function", static_cast<py::str (*)(int, float)>(&test_function4));
|
||||
m.def("test_function", static_cast<py::str (*)(float, int)>(&test_function4));
|
||||
#endif
|
||||
|
||||
py::enum_<MyEnum>(m, "MyEnum")
|
||||
.value("EFirstEntry", EFirstEntry)
|
||||
.value("ESecondEntry", ESecondEntry)
|
||||
|
||||
Reference in New Issue
Block a user