typeof(SortedRange) and is operator
RazvanN via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 8 07:06:02 PST 2016
On Tuesday, 8 November 2016 at 13:59:19 UTC, Nicholas Wilson
wrote:
> 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.
I think that lambda comparison should be done logically (by that
I mean: what the function actually computes) not literally. For
example: it is a mistake to consider the 2 two lambda functions
different just because one expression has more white spaces. Also
"a < b" is the same lambda function as "e < d"; considering these
2 functions to not be equal is a mistake.
More information about the Digitalmars-d-learn
mailing list