std.string and std.algorithm: what to do?
Daniel Keep
daniel.keep.lists at gmail.com
Thu May 14 08:02:27 PDT 2009
Steven Schveighoffer wrote:
> On Thu, 14 May 2009 09:55:08 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> Also, I dislike the signature int find() that returns -1 if not found.
>> Time and again experience shows that find() returning a range is much
>> better in real code because it works seamlessly when the
>> substring/element was not found (no more need for an extra test!)
>
> Ech, returning -1 is the bane of Java and C#. The return value should
> be the end of the string, regardless of whether it is a range or index.
> I could never understand the mentality of returning -1 versus end of
> string.
>
> -Steve
int idx = find(str);
if( idx == -1 ) doStuff;
- or -
if( idx == str.length ) doStuff;
-- Daniel
More information about the Digitalmars-d
mailing list