opCmp on a struct keyed by an array of bytes

Charles Hixson charleshixsn at earthlink.net
Tue Nov 12 13:06:10 PST 2013


Is there any better way to write the method than:
(cmp doesn't seem to work, and byte arrays don't have an opCmp method.)

  int opCmp(ref const B24 b) const
{    for    (int i = 0;    i < 24;    i++)
       {    if    (bytes[i] < b.bytes[i])    return    -1;
             if    (bytes[i] > b.bytes[i])    return    1;
        }
        return    0;
}    //    opCmp

FWIW, the key is a fixed length array of ubyte, but similar structs have 
differing lengths.   If it's not supported by the system I don't want to 
do something like casting the pieces
to ulongs and comparing those rather than the bytes.  The added 
complexity isn't worth it.

-- 
Charles Hixson



More information about the Digitalmars-d-learn mailing list