pywrap icon indicating copy to clipboard operation
pywrap copied to clipboard

Methods returning non const references

Open mnesarco opened this issue 2 years ago • 0 comments

Hi Friends,

As mentioned in this issue: https://github.com/CadQuery/OCP/issues/121 Some OCCT methods return a read-write refererence, if it is an object it is ok, but when the reference is to a primitive type there is a problem to use that in python.

I need to use math_Matrix in an algorithm in python, but the c++ object is updated using non const references returned by auto operator(int, int) -> double&.

In C++:

void something(math_Matrix& m) {
  m(1,5) = 0.5;
}

In python this has no sense:

from OCP.math import math_Matrix

def something(m: math_Matrix):
  m(1,5) = 0.5

Same problem with math_Vector

Maybe methods like:

auto method(int i, int j) -> double&;

can be wraped as two methods like:

def method(i: int, j: int) -> float: ...
def method_s(i: int, j: int, f: float): ...

mnesarco avatar Sep 08 '23 16:09 mnesarco