A couple of questions

BCS none at anon.com
Tue May 12 20:34:05 PDT 2009


Hello Sam,

> Hello,
> 
> For the given example below,
> 
> E1:
> template Chain(R...) if (allSatisfy!(isInputRange, R))
> {
> static if (R.length > 1)
> alias ChainImpl!(R) Chain;
> else
> alias R[0] Chain;
> }
> Q1: What's *if* statement doing right after the template definite?I
> can guess what the purpose is but I can not find the answer from the
> spec.
> 
> E2:
> 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
> }()));
> }
> Q2:What's the logic inside the enum...{} blocks?

That is an odd construct and not an enum block, breaking it into pieces:

enum bool isInputRange = SomeBoolExp;

SomeBoolExp:  // true if SomeExp is a valid expression
    is(typeof(SomeExp))

SomeExp:  // a function call
    SomeFnExp()

SomeFnExp: // a delegate literal
    {
       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
    }


> Q3:The *typeof* expression here. is it an anonymous function/delegate
> which return a bool value?If not,how come there is a () pairs appeared
> right after the enum{}blocks?If yes,shouldn't the () pairs appear
> before the last *)* ?
> It would be grateful if anybody can help.

see above

> 
> Regards,
> Sam




More information about the Digitalmars-d-learn mailing list