On 04/23/2012 04:44 AM, Steven Schveighoffer wrote:
On Sat, 21 Apr 2012 15:46:29 -0400, Mehrdad <[email protected]> wrote:
alias int delegate(out ItemGetter next) ItemGetter;
We currently can't do the above^ in D, but what do people think about
allowing it?
i.e. More specifically, I think an alias expression should be able to
refer to the identifier (unless it doesn't make sense, like including
a struct inside itself).
(It would require a look-ahead.)
It doesn't work.
If I do this:
alias int delegate() dtype;
alias int delegate(dtype d) ddtype;
pragma(msg, ddtype.stringof);
I get:
int delegate(int delegate() d)
Note how it's not:
int delegate(dtype d)
Why? Because alias does not create a new type. It's a new symbol that
*links* to the defined type.
The only problem is that the text representation of the type contains
it's self as a proper sub-string. As far as the compiler is concerned,
this should be no harder to handle than a linked list node or the
curiously recurring template pattern.
Another use for it would be one of the cleaner state machine
implementations I've ever seen:
alias foo delegate() foo;
foo = start();
while ((foo = foo())) {}