Re: [pygccxml-development] __getitem__ / __setitem__
Brought to you by:
mbaas,
roman_yakovenko
From: Matthias B. <ba...@ir...> - 2006-09-28 13:11:57
|
Roman Yakovenko wrote: >> Py++ turns index operators into a __getitem__() method. Now I was just >> wondering if it should also create a __setitem__() method when there's >> an operator that returns a reference? >> [...] > > double& operator[]( unsinged i ) > > ==> > > void __setitem__( unsigned i, double value ){ > this->operator[]( i ) = value; > } > > This is what you mean, right? Yes. > It could be done, it should not be a problem. > If you write test code I can spend few hours on adding this functionality. > Test cases ( instead of double ): > 1. fundamental type ( double is good ) > 2. pointer to some struct > 3. reference to some struct > 4. reference to noncopyable object ( in this case __setitem__ > should not be generated ) > 5. other use cases I missed :-) Well, my own use-cases are of the first type, so they are among the easier ones. I'm not so sure about the other cases when the values are actual objects. Has anybody else here had to wrap index operators? Did you do it manually and have there been any special situations? What are your thoughts about such a feature? - Matthias - |