Understanding isInfinite(Range)

Stanislav Blinov stanislav.blinov at gmail.com
Mon Sep 6 12:38:01 PDT 2010


Andrej Mitrovic wrote:
> Apparently I can't post to D.learn from gmail without waiting for a review? What the..?
> 
> Anyway, I've posted this:
> 
> On a related note, I always wanted to make a template to replace the
> dreaded is(typeof('delegate literal'())); calls.
> 
> For example, instead of this:
> 
> 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
> }()));
> 
> We'd have a much cleaner call like so:
> 
> enum bool isInputRange = validate!(
> {
>    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
> });
> 
> But I haven't found a way to do it properly. If I call validate on a
> type R range which doesn't feature the empty() method, then no matter
> what the definition of validate is the compiler will error out because
> it sees the call to r.empty() in the function literal, and 'r' doesn't
> have an empty method.
> 

What about __traits(compiles) ?


More information about the Digitalmars-d-learn mailing list