swig
swig copied to clipboard
Accessing data in std::vector<double>
In my C++ code, I sometimes return std::vector
Sounds like it's not implemented properly. In CasADi we have a output typemap for it. So the user never works directly with it - it gets converted to a MATLAB row vector.
Well, it does seem that you can index into the DoubleVector using x(3)
for instance, but I keep getting random crashes that I can't debug. I return a struct that holds std::vector
OK, it's probably a reference counting thing. It needs to keep a reference to the original vector<double>
in order to do things like mystruct.x(3) = 3
.
How fixable is this? At the moment I have a non-swig-based MATLAB wrapper working, so it's not the end of the world, but it is quite annoying that I can can't have vectors in returned structs.
It's probably fixable with a moderate effort. But someone has to do it.