function pointer bug?

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 27 18:36:01 PDT 2014


>> besides, you can use CTFE to build wrapper code. Adam Ruppe 
>> has that in
>> his jsvar.d, and i have that in my cong.d (cmdcon-ng) too.

I have actually found a work around as well, which was to wrap 
the actual retrieval of the function address in a lambda, and 
pass the lambda by template parameter instead:

auto getMethod = function() {
     return &__traits(getMember, SCOPE, member);
};

this is later assigned to a delegate when called:

delegate_type dg;
dg.ptr = instance;
dg.funcptr = getMethod();
dg();

The above works for global or static functions too. This seems to 
me like an unnecessary workaround though..

my current project can be viewed here:
https://github.com/bitwise-github/D-Reflection/blob/master/reflection.d#L796

It's been implemented based on Andrei's suggestions here:
http://forum.dlang.org/thread/juf7sk$16rl$1@digitalmars.com

as far as I could google, no one has attempted this yet. My 
prototype works pretty much as he has described, less a feature 
here and there.


More information about the Digitalmars-d mailing list