* Simply has_kw_only_args handling
This simplifies tracking the number of kw-only args by instead tracking
the number of positional arguments (which is really what we care about
everywhere this is used).
* Allow keyword-only arguments to follow py::args
This removes the constraint that py::args has to be last (or
second-last, with py::kwargs) and instead makes py::args imply
py::kw_only for any remaining arguments, allowing you to bind a function
that works the same way as a Python function such as:
def f(a, *args, b):
return a * b + sum(args)
f(10, 1, 2, 3, b=20) # == 206
With this change, you can bind such a function using:
m.def("f", [](int a, py::args args, int b) { /* ... */ },
"a"_a, "b"_a);
Or, to be more explicit about the keyword-only arguments:
m.def("g", [](int a, py::args args, int b) { /* ... */ },
"a"_a, py::kw_only{}, "b"_a);
(The only difference between the two is that the latter will fail at
binding time if the `kw_only{}` doesn't match the `py::args` position).
This doesn't affect backwards compatibility at all because, currently,
you can't have a py::args anywhere except the end/2nd-last.
* Take args/kwargs by const lvalue ref
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| _static | Loading commit data... | |
| advanced | Loading commit data... | |
| cmake | Loading commit data... | |
| Doxyfile | Loading commit data... | |
| Makefile | Loading commit data... | |
| basics.rst | Loading commit data... | |
| benchmark.py | Loading commit data... | |
| benchmark.rst | Loading commit data... | |
| changelog.rst | Loading commit data... | |
| classes.rst | Loading commit data... | |
| compiling.rst | Loading commit data... | |
| conf.py | Loading commit data... | |
| faq.rst | Loading commit data... | |
| index.rst | Loading commit data... | |
| installing.rst | Loading commit data... | |
| limitations.rst | Loading commit data... | |
| pybind11-logo.png | Loading commit data... | |
| pybind11_vs_boost_python1.png | Loading commit data... | |
| pybind11_vs_boost_python1.svg | Loading commit data... | |
| pybind11_vs_boost_python2.png | Loading commit data... | |
| pybind11_vs_boost_python2.svg | Loading commit data... | |
| reference.rst | Loading commit data... | |
| release.rst | Loading commit data... | |
| requirements.txt | Loading commit data... | |
| upgrade.rst | Loading commit data... |