A case for opImplicitCast: making string search work better
downs
default_357-line at yahoo.de
Fri May 15 03:07:10 PDT 2009
Consider this type:
struct StringPosition {
size_t pos;
void opImplicitCast(out size_t sz) {
sz = pos;
}
void opImplicitCast(out bool b) {
b = pos != -1;
}
}
Wouldn't that effectively sidestep most problems people have with find returning -1?
Or am I missing something?
Of course, this would require a way to resolve ambiguities, i.e. functions/statements with preferences - for instance, if() would "prefer" bool over int. I don't know if this is possible.
More information about the Digitalmars-d
mailing list