Address of overloaded functions

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jul 3 12:02:49 PDT 2013


On Wed, Jul 03, 2013 at 06:52:56PM +0200, Artur Skawina wrote:
> On 07/03/13 18:24, H. S. Teoh wrote:
> > On Wed, Jul 03, 2013 at 06:07:07PM +0200, Artur Skawina wrote:
> >> The context dependence isn't ideal, but what's the alternative?...
> > [...]
> > 
> > Explicit syntax for specifying overloads? ;-) Not like that would
> > happen in D, though.
> 
> Real Programmers need no special syntax :)
> 
>    import std.stdio;
> 
>    void foo(int a){ writeln("overload int"); }
>    void foo(long b){ writeln("overload long"); }
> 
>    auto pickOverload(alias FP, A...)() @property { typeof(FP(A.init)) function(A) fp = &FP; return fp;}

Wow. I didn't know you could use A.init for variadic A... !

That's amazing. D rawkz!!


>    void main()
>    {
>        auto b = pickOverload!(foo, long);

Now *that's* what I call coolness. Self-documenting and convenient to
use (though in this case it's arguable whether it's actually better than
native syntax).


>        b(2);
>    }
[...]


T

-- 
What doesn't kill me makes me stranger.


More information about the Digitalmars-d-learn mailing list