Can you explain this?

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 20 13:12:58 PDT 2014


On Wed, 20 Aug 2014 20:01:03 +0000, Colin wrote:

> It looks very....hacky.
> 
> I see 3 distinct parts playing a role in my confusion:
> A) The 'is' keyword. What does it do when you have is(expression);
> B) typeof( expression ); whats this doing? Particularly when the
> expression its acting on is a closure that returns nothing? (at least as
> far as I can see)
> C) The closure expression:
> (inout int = 0) {
>     // Check to see if I can do InputRangy stuff...
> }
> Why is there a need for that inout int = 0 clause at the start of it?
> 
> Sorry for the long question!
> 
> Thanks,
> Colin

Before the introduction of __traits(compiles, ...), `is(typeof(...))` was used.
It works because the is expression evaluates to false if the contents don't have
a type or are semantically invalid.  So this code creates a delegate to test 
the various properties--if it would compile, the delegate has a type and `is`
returns true. 
The inout int parameter is very hacky, see this thread: 
http://forum.dlang.org/thread/opykgvxbqqeleuiktthp@forum.dlang.org#post-mailman.102.1396007039.25518.digitalmars-d-learn:40puremagic.com


More information about the Digitalmars-d-learn mailing list