The rfind challenge

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jan 15 04:56:42 PST 2013


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. The 
challenge is indeed implementing rfind for bidirectional ranges that are 
not random (e.g. strings).


Andrei


More information about the Digitalmars-d mailing list