Safer casts

Janice Caron caron800 at googlemail.com
Mon May 12 12:42:11 PDT 2008


On 12/05/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>  I prefer:
>  sort!((int a, int b) {return a.member > b.member;})(array);

ints don't have a member variable called .member, so presumably, you
must have meant something like

    class C { int member; }
    C[] array;
    sort!(C a, C b){return a.member > b.member;})(array);


>  this is ... more readable.

No it isn't. ;-)


>  but in the future that other programmer will have no
>  idea what those "a" and "b" are. especially since you didn't write the
>  types of them.

Incorrect. "a" and "b" are the placeholders for the things being
compared. This is well documented in the documentation for sort. The
only way anyone could not know what the "a" and "b" were would be if
they hadn't RTFM.

The type of a is the type of the array element. This is obvious.



>  there is no benefit in making it a template, IMO.

The benefit is choice.



More information about the Digitalmars-d mailing list