Property rewriting; I feel it's important. Is there still time?

Chad J chadjoan at __spam.is.bad__gmail.com
Thu Mar 11 15:30:05 PST 2010


Andrei Alexandrescu wrote:
> On 03/10/2010 09:14 PM, Chad J wrote:
>> ...
>> Indexing seems to be the general case of properties: an indexed
>> expression can be a getter/setter pair identified by both an identifier
>> (the property's name: opIndex in this case) and some runtime variables
>> (the indices).  The properties are a getter/setter pair identified by
>> only the property's name alone.  This isn't much harder to deal with:
>>
>>      foo[i]++;
>>
>> ->
>>
>>      {auto t = foo.opIndex(i);
>>       t++;
>>       foo.opIndex(i,t) }()
> 
> I considered and rejected that design because it has a number of
> important practical drawbacks, such as unsuitability for certain
> containers (hashes, sparse vectors) and inefficiency.
> 
> 
> Andrei

Oh.

What would those drawbacks be?

Note that I made a typo and wrote opIndex instead of opIndexAssign.
I really meant
>>      {auto t = foo.opIndex(i);
>>       t++;
>>       foo.opIndexAssign(i,t) }()
I'm assuming that the "design" you speak of is the getting/setting
through indexing ops and not the overloading of opIndex to be a setter
as well as a getter.  Correct me if I'm wrong.

- Chad



More information about the Digitalmars-d mailing list