www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Function overload pointers

reply Daniel Ribeiro Maciel <daniel.maciel gmail.com> writes:
I'm having a problem to pass function overload pointers. I have the following
situation:

void foo() { writefln( "hello" ); }
void foo(int i) { writefln( "hello 1 int ", i ); }
void foo(int i, int j) { writefln( "hello 2 int ", i, " ", j ); }

I need to be able to build a tuple of all "foo"'s overloads such in as
__traits( getVirtualFunctions, ... ), but "foo" is not virtual. Is it possible?

Best regards,
Daniel
Nov 06 2008
parent reply Christopher Wright <dhasenan gmail.com> writes:
Daniel Ribeiro Maciel wrote:
 I'm having a problem to pass function overload pointers. I have the following
situation:
 
 void foo() { writefln( "hello" ); }
 void foo(int i) { writefln( "hello 1 int ", i ); }
 void foo(int i, int j) { writefln( "hello 2 int ", i, " ", j ); }
 
 I need to be able to build a tuple of all "foo"'s overloads such in as
__traits( getVirtualFunctions, ... ), but "foo" is not virtual. Is it possible?
Yes, because __traits(getVirtualFunctions) returns final functions. Once that bug is fixed, it won't be nearly as possible.
 Best regards,
 Daniel
Nov 07 2008
parent Daniel Ribeiro Maciel <daniel.maciel gmail.com> writes:
Oh, sorry, I did not express myself correctly.

What I actually meant was, I need to enumerate all "foo"'s overloads, but "foo"
is not class methods, its a set of standalone functions.

I need to do that in order to properly bind those overloads automatically to a
scripting language. My final goal is to be able to write something like:

export!( foo );

... and be able to call any overload of "foo" from my scripting language, all
detected automatically using compile time reflection.

Is it possible?

I understand that __traits( getVirtualFunctions ... ) needs a class and a
method as argument and returns a tuple containing all virtual overloads of that
method.

That allows me to automatically bind all VIRTUAL methods of a class and it
works great.
Now I need a way to do the same for non-member functions and non-virtual
functions.

You said that there's a bug that allows me to reflect non-virtual member
functions. 

How can I reflect non-member functions?

Best Regards,
Daniel

Christopher Wright Wrote:

 Daniel Ribeiro Maciel wrote:
 I'm having a problem to pass function overload pointers. I have the following
situation:
 
 void foo() { writefln( "hello" ); }
 void foo(int i) { writefln( "hello 1 int ", i ); }
 void foo(int i, int j) { writefln( "hello 2 int ", i, " ", j ); }
 
 I need to be able to build a tuple of all "foo"'s overloads such in as
__traits( getVirtualFunctions, ... ), but "foo" is not virtual. Is it possible?
Yes, because __traits(getVirtualFunctions) returns final functions. Once that bug is fixed, it won't be nearly as possible.
 Best regards,
 Daniel
Nov 07 2008