Bugs in template constraints

Philippe Sigaud philippe.sigaud at gmail.com
Tue Aug 3 14:27:44 PDT 2010


On Tue, Aug 3, 2010 at 23:07, Andrej Mitrovic <andrej.mitrovich at gmail.com>wrote:

>
> If I understood everything, this code in the constraint:
>
> is(typeof({x = fun(x, range.front);}() )))
>
> creates an anonymous function, the compiler sees it's trying to access x so
> it makes it a delegate, and it infers that the function takes no arguments
> and the return type is void. Did I get this right?
>

Yes, that's it. If the enclosed statements are OK, then the whole delegate
compiles, gets a type (void delegate() ), and so on, though is(typeof()).

So, using it as a way to get template constraints to work on many statements
was not planned that way, I think. But it works :)

Basically any D block statement: { statements;} can be seen as a void
delegate().

see http://www.digitalmars.com/d/2.0/lazy-evaluation.html
and http://www.digitalmars.com/d/2.0/statement.html#ScopeStatement for an
example of this.

Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100803/710d9d6a/attachment.html>


More information about the Digitalmars-d mailing list