Static Functions and pointers

Chris Nicholson-Sauls ibisbasenji at gmail.com
Tue Apr 3 16:23:40 PDT 2007



Dan wrote:
> Kirk McDonald Wrote:
>> No, it means you *can* use that. 
> ...
> 
> The rest didn't make sense.  : p  Classes are still little black boxes to me, I think well in terms of instructions, pointers, structs and arrays.
> 
> So that means I can now go:
> 
> static int f1(int x){..}
> static int f2(int x){..}
> static int f3(int x){..}
> 
> static int function(int x)[3] foo = [ &f1, &f2, &f3 ];
> 
> ???
> 
> If that's true, then that will dramatically improve startup performance and legibility of my Walnut 2.x scripting engine!  : D

Even better, you can do it like this:

int f1 (int x) {..}
int f2 (int x) {..}
int f3 (int x) {..}

auto foo = [&f1, &f2, &f3];

And replace the 'auto' with 'const' if you want it so...  Except when D's new const'ness 
concept goes live, then replace it with 'final'... and possibly 'final invariant' 
depending on your needs.  Man.  I have to admit the transitional period for that is going 
to be awkward.

-- Chris Nicholson-Sauls


More information about the Digitalmars-d-learn mailing list