Phobos strings versus C++ Boost
Brad Anderson
eco at gnuk.net
Sat Jan 11 10:47:02 PST 2014
On Saturday, 11 January 2014 at 08:25:39 UTC, Jakob Ovrum wrote:
> Some comments:
>
> * `empty` is a property - do not append parentheses/call syntax
*Nod*
> * `!find().empty` => `canFind` or `any`
The documentation needs to be improved for canFind then. It takes
an `E needle` so I assumed it was an element type only. The
other overload of canFind takes `Ranges needles` and stops when
it finds just one of them so I assumed it'd be called in the case
assert("123".canFind("321")) and would be true (>0). Looks like
the first overload just hands off to find() which can do either
element type or a subrange but that's not clear from the
documentation.
any() needs some examples. I'm not sure how it'd be used for this
purpose.
I'll try to make some pull requests to fix both of these doc
issues.
> * `ifind_first/last` can use `find!((a, b) => a.toLower() ==
> b.toLower())`
Yeah, but as Michael pointed out this isn't really a valid way to
do case-insensitive comparison anyway.
> * I think the Phobos equivalent of `find_tail` needs a second
> `retro`?
Yeah, very ugly.
> * I don't like the idea of adding a predicate to joiner, I
> think using filter is better
I just figured for consistency since so much of std.algorithm
accepts a predicate. I'm not opposed to sticking with filter
though.
>> 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.
Something needs to be done about this. I'm not sure what.
More information about the Digitalmars-d
mailing list