__traits(getDelegate, ...)

Steven Schveighoffer schveiguy at yahoo.com
Sun Feb 3 21:32:02 PST 2013


On Mon, 04 Feb 2013 00:20:22 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 2/4/13 12:14 AM, Steven Schveighoffer wrote:
>> Turns out, it's somewhat possible to specify, but it can be
>> painful/uintuitive:
>>
>> auto dg = cast(void delegate(string))&s.foo; // oops, what if I use the
>> wrong delegate signature, or S.foo is changed later!
>
> void delegate(string) dg = &s.foo;

That seems, ... odd.  How does the lhs dictate the rhs expression type?

Trying to think of a case where an expression is more handy than assigning  
to a variable first...

Possibly this?  Kind of a stretch.

void delayedCall(D)(D dg)
{
    // put dg as a delegate onto a message queue to call later...
}

-Steve


More information about the Digitalmars-d mailing list