The rfind challenge

deadalnix deadalnix at gmail.com
Tue Jan 15 18:16:44 PST 2013


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.


More information about the Digitalmars-d mailing list