Comment #0 by verylonglogin.reg — 2013-06-16T07:29:05Z
Currently associative arrays are compared by comparing its `impl` pointers e.g. `aa1 < aa2` is rewritten as `cast(void*) aa1 > cast(void*) aa2` instead of calling a runtime function.
---
void main()
{
int[int] aa1 = [0: 1];
int[int] aa2 = [0: 1];
assert(aa1 == aa2); // Passes
assert(!(aa1 < aa2) && !(aa1 > aa2)); // Fails, different `impl`-s
}
---
And yes, there is not such function in druntime so this is druntime's issue too.
Comment #1 by hsteoh — 2013-07-08T15:12:06Z
IMO, comparing AA's with < should be a compile-time error. AA's are unordered so it makes no sense to use < to compare them.
Comment #2 by bearophile_hugs — 2013-07-08T15:58:43Z
(In reply to comment #1)
> IMO, comparing AA's with < should be a compile-time error. AA's are unordered
> so it makes no sense to use < to compare them.
There are some meaningful (and occasionally useful) operations done on whole associative arrays, like testing if the keys of an associative array are a subset (or strict subset) of the keys of another associative array. But probably it's not the best idea to use < to perform similar set comparisons...
(In reply to comment #2)
> There are some meaningful (and occasionally useful) operations done on whole
> associative arrays, like testing if the keys of an associative array are a
> subset (or strict subset) of the keys of another associative array.
Yes, interesting but too complex/specialized for built-in functionality IMHO.
Comment #5 by hsteoh — 2013-09-20T13:31:02Z
(In reply to comment #4)
> (In reply to comment #2)
> > There are some meaningful (and occasionally useful) operations done on whole
> > associative arrays, like testing if the keys of an associative array are a
> > subset (or strict subset) of the keys of another associative array.
>
> Yes, interesting but too complex/specialized for built-in functionality IMHO.
FWIW, using == on AA's already does (a superset of) what an AA subset operation would do (iterate over AA keys and check for existence in the other AA).
But I agree that it shouldn't be built-in functionality. Maybe a nice library wrapper in std.array, but not much beyond that.
Comment #6 by github-bugzilla — 2013-09-24T10:06:18Z