how does isInputRange(T) actually work?

kevin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 22 09:58:04 PDT 2015


On Tuesday, 21 April 2015 at 19:42:42 UTC, anonymous wrote:
> On Tuesday, 21 April 2015 at 19:17:56 UTC, kevin wrote:
>> On Tuesday, 21 April 2015 at 19:13:34 UTC, Meta wrote:
>>> On Tuesday, 21 April 2015 at 19:11:43 UTC, John Colvin wrote:
>>>> On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote:
>>>>> enum bool isInputRange = is(typeof(
>>>>> (inout int = 0)
>>>>> {
>>>>>     R r = R.init;     // can define a range object
>>>>>     if (r.empty) {}   // can test for empty
>>>>>     r.popFront();     // can invoke popFront()
>>>>>     auto h = r.front; // can get the front of the range
>>>>> }));
>> [...]
>> Also, what is the purpose of typeof? I would have expected a 
>> simple is() to work just fine.
>
> (In this most simple form,) `is` evaluates to true if the 
> argument is a valid type. A function/delegate literal isn't a 
> type.
>
> If you passed the lambda expression itself to `is`, the result 
> would always be false. As it is, the result is true when the 
> lambda expression compiles (so it has a valid type).
>
> More about the IsExpression: 
> http://dlang.org/expression.html#IsExpression

That makes sense. It seems to me that D has very... special but 
effective syntax. I'm having a hard time remembering all the 
keywords and expression forms (especially of IsExpression) but 
it's definitely a vast improvement over C++'s half baked pile of 
whatever. Thanks for the help, everyone.


More information about the Digitalmars-d-learn mailing list