struct opCmp confustion
Namespace
rswhite4 at googlemail.com
Sun Aug 26 14:45:37 PDT 2012
> A string is an array of chars. Structs and Classes have opCmp.
> You could make a wrapper for the string to include the opCmp
> then, but that seems irrelevant.
>
> Although another option is to make a separate opCmp function
> that would do it. Tested and works :)
>
> import std.algorithm;
>
> //simple wrapper
> int opCmp(string a, string b) {
> return cmp(a,b);
> }
>
> unittest {
> assert("abc" < "efg");
> assert("efg" > "abc");
> assert("abc" == "abc");
> }
Maybe I'm wrong but this method is never called by one of these
compares. Or is this the point?
I wished many times that something like this work, even for other
constructs. That would be a way to avoid nasty opCmp, opEquals
and so on in the object.d.
More information about the Digitalmars-d-learn
mailing list