On Tuesday, 15 January 2013 at 12:56:43 UTC, Andrei Alexandrescu wrote:
On 1/15/13 2:20 AM, monarch_dodra wrote:
On Tuesday, 15 January 2013 at 05:51:16 UTC, Andrei Alexandrescu wrote:
R rfind(R, E)(R range, E element)
{
for (;;)
{
auto ahead = range.save.find(element);
if (ahead.empty) return range;
range = ahead;
}
}

I'd hardly call that an ideal solution >:( The point of rfind is to not
start the search from the start of the string.

I may reply to the rest, but let me destroy this quickly: this is the implementation for a forward range that's not bidirectional.

I'd argue against providing rfind at all if R is not bidirectional. But that's not the thread's main issue, so let's not focus on this.

The challenge is indeed implementing rfind for bidirectional ranges that are not random (e.g. strings).

Andrei

Agreed.

On a side note, it would be very easy if we agreed to return the subrange starting at the beginning of range, and ending after the last element.

But that's really just avoiding the problem.

Reply via email to