> I did not submit an enhancement ticket for the "left-value assignment > problems" yet, because I wanted to make some things clear first. To > recap, there are actually two problems, I think: > 1- If foo_iterator is an iterator, operator.dereference(foo_iterator) > is not an l-value for cython. Therefore it is not possible to do the > equivalent of " *foo_iterator=bar " in cython (except if foo_iterator > is a pointer and not a general iterator) > 2- functions returning references are not l-values for cython. > Therefore, for example, it is not possible to use the ".at" method of > std::vectors to assign a value.
I had not read the parallel thread between Stefan Behnel , Dag Sverre Seljebotn and Sturla Molden. If I understand correctly, they advocate that the return value of functions declared as returning a reference should be automatically converted to a pointer (to the returned referenced object). It makes sense. All things being equal, I would have prefered a "set_lvalue" operator, but I am not the one doing the implementation (nor do I understand the possible implementation difficulties). This solve however only a part of the problem. More precisely, if we want to apply the same idea to operator.dereference, we need to change its definition so that dereference(foo) produce the c++ code " &(*foo) ". Then, it is indeed possible to do all the necessary operations in cython: *foo ---> "dereference(foo)[0]" *foo=bar ---> "dereference(foo)[0]=bar" bar=&(*foo) ---> "bar=dereference(foo)" But this might lead to many errors by the users: when doing "bar=dereference(foo)", many people will expect that bar will be equal to *foo, and not &(*foo). Unfortunately, the problem is the same for functions returning references: if a user write: foo=vect.at(4)+10, he might be expecting to add 10 to the value at index 4 of vect, but in reality he will add 10 to the address of this value. Or is there something I do not understand? Toki _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
