struct opCmp confustion
Era Scarecrow
rtcvb32 at yahoo.com
Sun Aug 26 14:06:41 PDT 2012
On Sunday, 26 August 2012 at 19:23:10 UTC, Charles Hixson wrote:
> Thank you.
>
> So string doesn't respond to opCmp. Pity.
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");
}
More information about the Digitalmars-d-learn
mailing list