Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Support for cdef of C++ object references #1695
Comments
netheril96
commented
May 21, 2017
|
Why not just take the address and reference the return value as a pointer? |
|
References are just pointers that must be assigned at declaration time, which ties in strongly to C++'s scoping (which is at odds with Python/Cython's scoping) which means supporting this would be non-trivial (as well as require other changes, e.g. allowing a cdef definition to occur anywhere). In particular, legal constructions like
simply wouldn't work (or require interesting gymnastics). Instead, write |
robertwb
added a commit
that referenced
this issue
May 21, 2017
|
|
robertwb |
bfd1aa7
|
ferdonline
commented
Jul 3, 2017
•
|
Another side effect is that will invoke the copy assignment operator... without warnings. With arrays the problem goes from performance penalty to compile errors (like when using boost::multi_array) |
ferdonline
commented
Jul 3, 2017
I was wondering if cython was specially handling that case, but no, it doesn't work. |
|
The |
ferdonline commentedMay 3, 2017
When a C++ function returns a reference we are forced to workaround: typically make the call inside a function accepting references
It would be desirable to support
cdef Foo & obj = func_bar()Cython apparently declares the reference and assigns to it in different steps, which obviously doesn't compile.