recursive delegate declaration

kris foo at bar.com
Tue Jun 20 15:50:37 PDT 2006


I have a situation whereby a delegate should return an instance of 
itself, to enable call chaining. Here's my attempt, which compiles and 
appears to work with dmd 161:

--------------
alias Consume delegate(char[]) Bar;
typedef Bar delegate (char[]) Consume;

void emit (Consume consume)
{
     consume ("1") ("2") ("3") ("4");
}

void main ()
{
    Bar consumer (char[] v)
    {
         return cast(Bar) &consumer;
    }

    emit (&consumer);
}
--------------

The above seems like a tad too much of a hack. Can anyone come up with a 
cleaner approach?




More information about the Digitalmars-d mailing list