A possible solution for the opIndexXxxAssign morass

Jason House jason.james.house at gmail.com
Wed Oct 14 07:42:27 PDT 2009


Andrei Alexandrescu Wrote:

> Right now we're in trouble with operators: opIndex and opIndexAssign 
> don't seem to be up to snuff because they don't catch operations like
> 
> a[b] += c;
> 
> with reasonable expressiveness and efficiency.

I would hope that *= += /= and friends could all be handled efficiently with one function written by the programmer. As I see it, there are 3 basic steps:
1. Look up a value by index
2. Mutate the value
3. Store the result

it's possible to use opIndex for #1 and opIndexAssign for #3, but that's not efficient. #1 and #3 should be part of the same function, but I think #2 shouldnot be. What about defining an opIndexOpOpAssign that accepts a delegate for #2 and then use compiler magic to specialize/inline it? 



More information about the Digitalmars-d mailing list