A case for opImplicitCast: making string search work better
Christopher Wright
dhasenan at gmail.com
Fri May 15 15:26:13 PDT 2009
downs wrote:
> 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.
Just use two functions: find and contains.
More information about the Digitalmars-d
mailing list