https://issues.dlang.org/show_bug.cgi?id=21109

Boris Carvajal <boris...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |boris...@gmail.com

--- Comment #5 from Boris Carvajal <boris...@gmail.com> ---
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.

--

Reply via email to