On Thu, Oct 25, 2012 at 06:34:32PM -0700, Ellery Newcomer wrote: > On 10/24/2012 01:16 PM, Mehrdad wrote: > >On Wednesday, 24 October 2012 at 20:03:44 UTC, H. S. Teoh wrote: > >>What's wrong with RedBlackTree? You can just do something like: > >> > >> RedBlackTree!(RedBlackTree!MySet) setOfSets; > > > >The last time I checked two RedBlackTrees for equality, they seemed > >to have reference semantics... > > > > Dang. > > import std.container; > import std.stdio; > > void main() { > auto a = make!(RedBlackTree!int)(1,2,3,4); > auto b = make!(RedBlackTree!int)(1,2,3,4); > writeln(a == b); > } > > prints > > false > > > Explanation: RedBlackTree doesn't override opEquals. Either file an > enhancement request or use equal(a[], b[]), depending on whether > opEquals *should* have reference semantics.
Hmph. This is what I don't like about the built-in ==. Its semantics are inconsistent once you leave the realm of ints and floats and other numerical types. I think this one is worthy of a bug report. > Actually, it shouldn't, since that would differ from array/string > opEquals semantics. Yeah, Jonathan is right, "==" should *always* do a deep compare, and leave "is" to do a shallow compare. Anything else is inconsistent, and leads to all kinds of pathological bugs. T -- Любишь кататься - люби и саночки возить.