opIndexCall
Bill Baxter
dnewsgroup at billbaxter.com
Sat Mar 24 11:37:41 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.
>
> Y function() a; // have to do this?
> a = z["hello"]; // and this
> a(); // and this?
Does it work if you use a plain method instead of indexing? I.e. if you
add a get_elem(char[] key), does get_elem("hello")() work?
It sounds more like a bug to me than a need for an opIndexCall.
Something seems fishy about your code, though. You have a Y[] array,
but no array of Y function() anywhere.
--bb
More information about the Digitalmars-d
mailing list