January 16, 2013 Re: The rfind challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | 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
|
January 16, 2013 Re: The rfind challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 15 January 2013 at 22:49:45 UTC, Andrei Alexandrescu wrote:
> On 1/15/13 4:57 PM, monarch_dodra wrote:
>> On Tuesday, 15 January 2013 at 20:59:17 UTC, Andrei Alexandrescu wrote:
> [snip]
>> But the goal was having a range that start at needle, and ends at
>> haystackEnd. Your implementation doesn't do that. It would have to use a
>> "after" instead of a "before".
>
> Sorry, got ahead of myself. r.retro.before would be needed, which requires r.after. I'd like to only add one primitive if at all possible, or have a solid proof that two are needed. Back to the drawing board...
>
> Andrei
I think the whole point of reverse is to avoid duplicating before/after front/back popFront/popBack etc . . .
|
January 16, 2013 Re: The rfind challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Solution: add a "subtraction" operator/method, which, when given a sub-range of a super-range, returns the portion of the super-range before and after the sub-range. |
Copyright © 1999-2021 by the D Language Foundation