Request for "indexOf" undeprecation.

monarch_dodra monarchdodra at gmail.com
Fri Nov 16 06:02:00 PST 2012


On Friday, 16 November 2012 at 13:49:57 UTC, Sönke Ludwig wrote:
>
> Fully agree about the fix of countUntil - I can imagine that 
> there is a non-trivial amount of code
> that blindly uses countUntil instead of indexOf because of the 
> deprecation (I know I also did this
> before).
>
> But there is still std.string.indexOf, which should do the 
> right thing here...

Yeah... I just noticed that exists. Still, the deprecation 
comment is not very clear. I think there should be a clearer 
message of indexOf vs countUntil.

As a matter of fact, I found that in path, we are going out of 
our way to use "std.algorithm.countUntil", probably because of a 
forced migration, without considering using std.string.indexOf 
instead.

Still, if we have a RA range of chars, I think it needs to be 
possible to call indexOf on that range. std.utf can decode input 
ranges of chars, why can't we get an indexOf for RA ranges too 
then ?

> wait, no, that one
> also screws up and returns based on the ASCII state of the 
> search character!

It doesn't screw up the result, it is meant for slicing your 
string.

> However this all is fixed, it will probably cause a good amount 
> of breakage, but there is no way
> around it.
>
> Btw. is 'string' actually considered a RA range? After all it 
> provides no useful invariants apart
> from str[0] == str.front - str[1] could be different from 
> str.popFront(); str.front.

No! String is not an RA range. It can be indexed, but 
isRandomAccessRange!string is false. This is a fundamental aspect 
of string, to avoid accidently breaking it.

dstring, however, is random access. You should always take this 
into account for considering whether or not it is worth 
converting to before operating on it. For example: sorting the 
chars in a dstring: Easy as pie. Doing it on a string: Not sure 
if even possible.


More information about the Digitalmars-d mailing list