pybind11/docs/advanced
Jason Rhinelander abc29cad02 Add support for non-converting arguments
This adds support for controlling the `convert` flag of arguments
through the py::arg annotation.  This then allows arguments to be
flagged as non-converting, which the type_caster is able to use to
request different behaviour.

Currently, AFAICS `convert` is only used for type converters of regular
pybind11-registered types; all of the other core type_casters ignore it.
We can, however, repurpose it to control internal conversion of
converters like Eigen and `array`: most usefully to give callers a way
to disable the conversion that would otherwise occur when a
`Eigen::Ref<const Eigen::Matrix>` argument is passed a numpy array that
requires conversion (either because it has an incompatible stride or the
wrong dtype).

Specifying a noconvert looks like one of these:

    m.def("f1", &f, "a"_a.noconvert() = "default"); // Named, default, noconvert
    m.def("f2", &f, "a"_a.noconvert()); // Named, no default, no converting
    m.def("f3", &f, py::arg().noconvert()); // Unnamed, no default, no converting

(The last part--being able to declare a py::arg without a name--is new:
previous py::arg() only accepted named keyword arguments).

Such an non-convert argument is then passed `convert = false` by the
type caster when loading the argument.  Whether this has an effect is up
to the type caster itself, but as mentioned above, this would be
extremely helpful for the Eigen support to give a nicer way to specify
a "no-copy" mode than the custom wrapper in the current PR, and
moreover isn't an Eigen-specific hack.
2017-02-03 20:18:15 -05:00
..
cast Automate generation of reference docs with doxygen and breathe (#598) 2017-01-31 16:54:08 +01:00
pycpp Minor fixes (#613) 2017-01-31 17:28:29 +01:00
classes.rst Add support for non-converting arguments 2017-02-03 20:18:15 -05:00
exceptions.rst Reorganize documentation 2016-10-20 15:21:34 +02:00
functions.rst Add support for non-converting arguments 2017-02-03 20:18:15 -05:00
misc.rst Documentation: explicitly call out that the GIL is held (#615) 2017-01-31 17:06:13 +01:00
smart_ptrs.rst Improve custom holder support (#607) 2017-01-31 17:05:44 +01:00