Range with an alias parameter

Alex sascha.orlov at gmail.com
Thu Jan 31 10:07:57 UTC 2019


On Thursday, 31 January 2019 at 02:41:00 UTC, Steven 
Schveighoffer wrote:
> 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

Yeah... maybe, it was too much code for a single day yesterday... 
:P



More information about the Digitalmars-d-learn mailing list