https://issues.dlang.org/show_bug.cgi?id=21109
--- Comment #6 from Andrej Mitrovic <[email protected]> --- (In reply to Boris Carvajal from comment #5) > There is no 'opCmp' defined for the struct so the runtime just use a memcmp > for the comparison. > The code itself calls '__cmp' from core/internal/array/comparison.d (because > the element are an array '[S(2, [0, 0])]') and there the 3 'static if' > conditions fail but if you define 'opCmp' the second path is taken. > > So the following works: > > struct S > { > int[] arr; > int opCmp(ref const S s) const { return arr < s.arr; } > } > > There is a comment on clone.d file that says: > > "Essentially, a struct which does not define opCmp is not comparable." > > This concise phrase should be on the spec. Hmm. In the past the compiler would also do memcmp when a struct didn't define `opEquals`, but we changed it so it does member-by-member `==` comparison. I wonder if we can do something similar for opCmp, or if that wouldn't make sense.. --
