On 12/30/19 6:15 PM, JN wrote:
On Sunday, 29 December 2019 at 08:31:13 UTC, mipri wrote:

int i = a.countUntil!(v => v == 55);
assert(i == 2);

I also had to ask because I couldn't find it. In other languages it's named "index()", "indexOf()" or "find()". D is the only language I know which uses the "countUntil" scheme. And even so it's not obvious from the name if it's the index of the element or number of preceding elements.


indexOf used to be in std.algorithm I believe. It was nixed for having too simple an implementation I believe.

I have also created a bufref library [1] which is intended to help with using phobos algorithms and not losing the positional information.

import std.stdio;
import std.algorithm;
import bufref;

void main()
{
    string x = "hello, world!";
    writeln(x.bwin.find('o').bufRef.pos);
}

-Steve

[1] http://code.dlang.org/packages/bufref

Reply via email to