The rfind challenge

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jan 15 18:56:21 PST 2013


On 1/15/13 9:16 PM, deadalnix wrote:
> On Tuesday, 15 January 2013 at 12:54:12 UTC, Andrei Alexandrescu wrote:
>> On 1/15/13 1:31 AM, H. S. Teoh wrote:
>>> Hmm. What about introducing a new primitive takeUntil, that returns the
>>> initial segment of the range until a given predicate becomes true? Then
>>> you could implement rfind thus:
>>>
>>> auto rfind(alias pred, R)(R range)
>>> if (isBidirectionalRange!R)
>>> {
>>> return range.retro()
>>> .takeUntil!pred()
>>> .retro();
>>> }
>>
>> That works, but returns a different type. Ideally rfind would return
>> the same type as the initial range, R.
>>
>> Andrei
>
> Retro of retro is supposed to give back the original range, so I don't
> think it does.

There's a takeUntil in the middle.

Andrei


More information about the Digitalmars-d mailing list