Range with an alias parameter
Steven Schveighoffer
schveiguy at gmail.com
Thu Jan 31 02:41:00 UTC 2019
On 1/30/19 3:56 PM, Alex wrote:
> Ok... strange... it doesn't in fact... as this works:
>
> ´´´
> import std.experimental.all;
>
> void main()
> {
> S!42 s;
> auto res = s[];
> static assert(isInputRange!(typeof(res)));
> res.front.writeln;
> }
>
> //static assert(isInputRange!(ReturnType!(produceS!(42))[]));
Apples and oranges :)
ReturnType!(produceS!(42)) is a TYPE, not a variable. When you apply the
brackets, it's not calling your opindex, but rather changing it to an
array. So let's make it clearer by saying:
alias T = ReturnType!(produceS!(42));
So now, your assert becomes:
static assert(isInputRange!(T[]));
Which, is not coming up as a valid range, because you can't copy the
front value (this(this) is disabled).
In the other expression, you are first calling the index operator on an
instance of the type, which returns a DIFFERENT type, and then asserting
the type of that is an input range.
The equivalent (still using T) is:
static assert(isInputRange!(typeof(T.init[])));
replacing T with the original is:
static assert(isInputRange!(typeof(ReturnType!(produceS!(42)).init[])));
-Steve
More information about the Digitalmars-d-learn
mailing list