January 28, 2012 [Issue 7389] New: Disallow or implement correct SortedRange equality | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=7389 Summary: Disallow or implement correct SortedRange equality Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2012-01-28 06:10:59 PST --- Given two small unsorted arrays 'a1' and 'a2', a common natural idiom to test that they have the same items is: a1.sort() == a2.sort() But currently in D2 it's a trap: import std.algorithm: sort; void main() { auto a1 = [1, 2]; auto a2 = [2, 1]; assert(a1.sort() == a2.sort()); // AssertError assert(a1.sort().release() == a2.sort().release()); // OK } To avoid such bugs I suggest to statically forbid the == operation among two SortedRange; or _better_ to implement it correctly, and allow that testing idiom. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 28, 2012 [Issue 7389] Disallow or implement correct SortedRange equality | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=7389 --- Comment #1 from bearophile_hugs@eml.cc 2012-01-28 06:19:26 PST --- Another workaround: import std.algorithm: sort, equal; void main() { auto a1 = [1, 2]; auto a2 = [2, 1]; assert(equal(a1.sort(), a2.sort())); // OK } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation