Phobos strings versus C++ Boost

Jakob Ovrum jakobovrum at gmail.com
Sat Jan 11 00:25:38 PST 2014


On Saturday, 11 January 2014 at 07:50:56 UTC, Brad Anderson wrote:
> The recent discussion got me wondering how Phobos stacked up
> against the C++ Boost String Algorithms library.
>
> Some background on the design of the Boost library:
> http://www.boost.org/doc/libs/1_55_0/doc/html/string_algo/design.html
>
> TL;DR: It works somewhat like ranges.
>
> Google Spreadsheet with the comparison: http://goo.gl/Wmotu4

Some comments:

  * `empty` is a property - do not append parentheses/call syntax
  * `!find().empty` => `canFind` or `any`
  * `ifind_first/last` can use `find!((a, b) => a.toLower() == 
b.toLower())`
  * I think the Phobos equivalent of `find_tail` needs a second 
`retro`?
  * I don't like the idea of adding a predicate to joiner, I think 
using filter is better

> 1. They have case-insensitive versions of pretty much 
> everything.
> It's not hard to do a map!toLower/toUpper in D but it's also not
> obvious (nor do I know if that's actually correct in languages
> outside of english).

There are two pairs of toLower/toUpper - the ones in std.ascii 
and std.uni (the std.string pair aliases to std.uni). The latter 
pair works correctly for all scripts.

> 2. Replace and erase options a very slim. Doing something like a
> chain() on the results of findSplit() and what you want to 
> inject
> I guess would work for replacing but that's really not very
> elegant. remove() is simply way too cumbersome to use. I guess
> you could use indexOf, then indexOf again with a slice with the
> first result, then pass both two a tuple in remove. That's
> terrible though.

I think the mutation algorithms in std.algorithm can handle most 
of these when used in conjunction with other algorithms, except 
that narrow strings do not have the property of assignable 
elements, which is kind of a fatal blow.


More information about the Digitalmars-d mailing list