Thread overview | |||||
---|---|---|---|---|---|
|
September 23, 2015 BidirectionalRange switching direction | ||||
---|---|---|---|---|
| ||||
Trying to implement a bi directional range and it is slightly unclear what the semantics are supposed to be and just wanted some clarification. Are bidirectional ranges supposed to be able to support switching direction mid iteration? Like if I do popFront popFront popBack should that be equal to just a single popFront? Or once you start on a direction should switching be considered an error? Or is popFront and popBack supposed to consume from both ends of the range and the range is empty when they meet? -tofu |
September 23, 2015 Re: BidirectionalRange switching direction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Wednesday, 23 September 2015 at 02:10:22 UTC, Tofu Ninja wrote:
> Trying to implement a bi directional range and it is slightly unclear what the semantics are supposed to be and just wanted some clarification.
>
> Are bidirectional ranges supposed to be able to support switching direction mid iteration? Like if I do popFront popFront popBack should that be equal to just a single popFront? Or once you start on a direction should switching be considered an error? Or is popFront and popBack supposed to consume from both ends of the range and the range is empty when they meet?
>
> -tofu
The last one. E.g. for arrays (except narrow strings... ugh)
auto popFront(T)(ref T[] a)
{
a = a[1 .. $];
}
auto popBack(T)(ref T[] a)
{
a = a[0 .. $-1];
}
|
September 25, 2015 Re: BidirectionalRange switching direction | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Wednesday, 23 September 2015 at 03:26:29 UTC, John Colvin wrote:
> On Wednesday, 23 September 2015 at 02:10:22 UTC, Tofu Ninja wrote:
>> Trying to implement a bi directional range and it is slightly unclear what the semantics are supposed to be and just wanted some clarification.
>>
>> Are bidirectional ranges supposed to be able to support switching direction mid iteration? Like if I do popFront popFront popBack should that be equal to just a single popFront? Or once you start on a direction should switching be considered an error? Or is popFront and popBack supposed to consume from both ends of the range and the range is empty when they meet?
>>
>> -tofu
>
> The last one. E.g. for arrays (except narrow strings... ugh)
>
> auto popFront(T)(ref T[] a)
> {
> a = a[1 .. $];
> }
>
> auto popBack(T)(ref T[] a)
> {
> a = a[0 .. $-1];
> }
Ok cool, that's what I ended up doing.
|
Copyright © 1999-2021 by the D Language Foundation