Referencing an overloaded function

John nospam at unavailable.com
Sat Mar 24 08:24:29 PDT 2012


On Saturday, 24 March 2012 at 13:59:30 UTC, Philippe Sigaud wrote:
> module pack.mod; // needs to be XXX.YYY for __traits to work
>
> void foo() {}
> void foo(int x) {}
>
> template Alias(A...) { alias A Alias;}
>
> void main()
> {
>     // The Alias!( ) trick is needed to work around a 
> limitation in
> alias X Y grammar
>     // __traits() is not accepted in an alias: alias
> __traits(getOverloads, X, "Y") OV_XY; does not work
>     alias Alias!(__traits(getOverloads, pack.mod, "foo")) OV;
>
>     // OV is a tuple holding all the different foo's
>
>     foreach(i, ov; OV)
>         writefln("overload #%s: %s", i, typeof(ov).stringof);
>
>     alias OV[1] intFoo; // void foo(int x) {}
>
>     intFoo(1); // calls void foo(int x) {}
> }

That's exactly what I was looking for.  Thanks.



More information about the Digitalmars-d-learn mailing list