Will the D GC be awesome?
Marco Leise
Marco.Leise at gmx.de
Wed Oct 10 05:24:08 PDT 2012
Am Thu, 04 Oct 2012 16:12:43 +0200
schrieb "Simen Kjaeraas" <simen.kjaras at gmail.com>:
> On 2012-27-04 07:10, Walter Bright <newshound1 at digitalmars.com> wrote:
>
> >> * OpCmp returning an int is fugly I r sad
> >
> > How else would you return a 3 state value?
>
> enum Comparison {
> Before = -1,
> Same = 0,
> After = 1,
> Unordered = NaN,
> }
>
> I'm not saying it should be done, but it would be more readable
> (and more cmoplex to write).
a) There is no integer NaN and floating point is a no-go.
b) If you mix sortable and unsortable most algorithms fail.
Otherwise an enum solution is good, but a bit longer in
code:
auto rel = a.OpCmp(b);
if (rel < 0) ...;
else if (rel > 0) ...;
else ...;
vs.
if (rel == Comparison.Before) ...;
else if (rel == Comparison.After) ...;
else ...;
And in many cases right now you can just "return a - b";
--
Marco
More information about the Digitalmars-d
mailing list