typeof and block statements

Stanislav Blinov blinov at loniir.ru
Thu Aug 12 06:38:53 PDT 2010


  12.08.2010 17:13, simendsjo wrote:
> The spec doesn't mention anything about block statements in typeof 
> declarations.
>
>     //typeof({1}) a; // found } expecting ;
>     //typeof({1}()) b; // same as a
>     typeof(1) c; // int
>
> I'm asking because isInputRange from std.range the idom from the b test:
>
> template isInputRange(R)
> {
>     enum bool isInputRange = is(typeof(
>     {
>         R r;             // can define a range object
>         if (r.empty) {}  // can test for empty
>         r.popFront;          // can invoke next
>         auto h = r.front; // can get the front of the range
>     }()));
> }
>
This looks like a parameterless delegate to me :) Seems something akin 
to __traits(compiles).
>
> Also... The unittest contains
>     static assert(isInputRange!(int[]));
>     static assert(isInputRange!(char[]));
>
> But arrays doesn't include these methods.. I don't understand a thing :(
They don't, but std.array imported in std.range defines the methods for 
them.

-- 
*
* 	
**

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100812/ff02ac08/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list