opIndexCall

Chris Nicholson-Sauls ibisbasenji at gmail.com
Sat Mar 24 12:16:11 PDT 2007


Dan wrote:
> I've recently discovered the want for an opIndexCall override in D.
> 
> For this:
> 
> struct Y {
>   ...
>   Y function() f;
> }
> 
> struct X {
>   char[][] keys;
>   Y[] values;
>   opIndex()
>   opIndexAssign()
> }
> 
> Y myF(){
>   Y y;
>   return y;
> }
> 
> 
> X z;
> 
> z["hello"] = &myF;
> 
> z["hello"](); // <-- can't do that.

I'm not sure, but it would help muchly to know the actual signatures/implementations of 
opIndex and opIndexAssign.  In my own little test, this worked with no issues.  What error 
messages were you getting?  And with what compiler version?

> Y function() a; // have to do this?
> a = z["hello"];  // and this
> a();                 // and this?

Actually, you could simplify it somewhat using auto.  But in general this shouldn't be 
neccessary.

auto a = z["hello"];
a();

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list