Skip to content

Bind functions with mutable references

Hi all, I'm currently playing with autopybind11 to automatize the process of creating Python bindings from a c++ library.

When writing a function in c++ it is common to pass mutable references. However, in python, some types are immutables (e.g. int, float, ...)

As a consequence, the following function cannot one-to-one converted into a Python

void foo(int &i)
{
   i++;
}

As explained in pybind11 documentation, a possible solution is to create a lambda function that returns a tuple with all output arguments.

I was wondering if there is a way to guide autopybind11 to automatically create the lambda function.

cc @traversaro

Edited by Giulio Romualdi