std.string and std.algorithm: what to do?

Steven Schveighoffer schveiguy at yahoo.com
Thu May 14 09:58:05 PDT 2009


On Thu, 14 May 2009 09:55:08 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> I'm not sure what needs to be done about the combo string + algorithm.  
> There's quite some overlap, and also functions that have the same name  
> in both modules (e.g. find()), which forces you to disambiguate.
>
> Should std.algorithm automatically recognize strings and proceed  
> accordingly, should it just consider them straight arrays and leave  
> everything else to std.string (risky!), or refuse to handle strings?
>
> 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!)
>
> So I want to rename std.string.find() into something like findIndex or  
> indexOf. But then we also have ifind, rfind, irfind. Ideas for renaming?

find -> indexOf
rfind -> lastIndexOf

This is consistent with C# and Java.

ifind, irfind -> do we care about renaming?  They kind of seem niche  
anyways.

another alternative, leave ifind and irfind deprecated for a while and  
redefine indexOf to be e.g.:

indexOf(string s, dchar d, bool caseSensitive = true)

-Steve



More information about the Digitalmars-d mailing list