typeof(SortedRange) and is operator

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 8 05:59:19 PST 2016


On Tuesday, 8 November 2016 at 13:22:35 UTC, RazvanN wrote:
> Sorry, I accidentally posted the above message and I don't know 
> how to erase it.

You can't, this is a mailing list not a forum.

> The following post is the complete one:
>
> Given the following code:
>
> int[] arr = [1, 2, 9, 4, 10, 6];
> auto r    = sort(arr);
>
> if(is(typeof(r) == SortedRange!(int[], "a<b")))
>     writeln("first if");
>
> if(is(typeof(r) == SortedRange!(int[], "a < b")))
>     writeln("second if");
>
> The program outputs only "second if". I assumed that it should 
> have printed both
> ifs. Is this a bug?
>

equality of lambdas are fickle. String lambdas are comparable, 
because strings are comparable. Comparison of 
`(args){...body...}`  or `() => expression` lambdas don't work at 
all in template expressions.

`SortedRange!(int[], "a<b") == SortedRange!(int[], "a < b")` is 
false because the arguments to the templates differ i.e. "a<b" != 
"a < b".

Is this a bug? no. is it weird, confusing and unintuitive? yes.





More information about the Digitalmars-d-learn mailing list