opIndexCall
Dan
murpsoft at hotmail.com
Sun Mar 25 10:52:36 PDT 2007
Jarrett Billingsley Wrote:
> "Dan" <murpsoft at hotmail.com> wrote in message
> news:eu4man$1cs3$1 at digitalmars.com...
> >
> > Heh...
> >
> > the code was a sample, not my actual code (obviously) I was trying to
> > only show enough to represent what I was trying to suggest.
> >
> > That said, I was hoping we could do:
> >
> > myAssocStruct[myCharArray](params)
> >
> > Which I've never seen done before in D in any examples or source online,
> > or in the guide. I haven't actually tried a minimal test case, I just
> > didn't know the feature existed at all and was suggesting we ought to be
> > able to do so.
> >
> > If we can, then hey... I'll try to figure it out then. : p
>
> Uhh, well:
>
> struct FuncHolder
> {
> void function(int)[char[]] funcs;
>
> void function(int) opIndex(char[] name)
> {
> return funcs[name];
> }
>
> void opIndexAssign(void function(int) func, char[] name)
> {
> funcs[name] = func;
> }
> }
>
> void foo(int x)
> {
> writefln("foo: ", x);
> }
>
> void bar(int x)
> {
> writefln("bar: ", x);
> }
>
> void main()
> {
> FuncHolder fh;
> fh["foo"] = &foo;
> fh["bar"] = &bar;
>
> fh["foo"](3);
> fh["bar"](4);
> }
>
>
> Unless you're getting at something else?
>
>
Okay, yeah. I wrote it out and it works. : p
Guess there's no need for an opIndexCall then. Maybe just perhaps having something about this in documentation for the next guy.
More information about the Digitalmars-d
mailing list