std.v2020.algorithm etc[ WAS: Is run.d going to be expand for runtime and the phobos library?]
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Jun 21 00:11:24 UTC 2020
On 6/20/20 2:34 PM, Johannes Loher wrote:
> On Saturday, 20 June 2020 at 13:07:41 UTC, Paul Backus wrote:
>> On Saturday, 20 June 2020 at 12:42:01 UTC, Stanislav Blinov wrote:
>>> On Saturday, 20 June 2020 at 10:43:41 UTC, Paul Backus wrote:
>>>
>>>> Also, switch from `void popFront()` to `typeof(this) rest`, so that
>>>> we can have `const` and `immutable` ranges.
>>>
>>> *Switch* is probably too restrictive. For a given range a `popFront`
>>> may be more efficient than a `range = range.rest`. Making `rest` a
>>> valid range primitive though, and using where appropriate - that'd be
>>> awesome.
>>
>> For non-forward ranges, there's no promise that the original range (or
>> any copies of it) will remain valid after calling `rest`, so you can
>> always implement `rest` like this:
>>
>> auto rest() {
>> this.popFront;
>> return this;
>> }
>
> Can’t make it const then... also some ranges probably cannot bee const
> by design, e.g. byLine etc.
That function would be a fallback. Ranges that are const would implement
it as a primitive not expressible with popFront.
Consider:
immutable List(T) {
private T payload;
private List next;
public List tail() { return next; }
...
}
You can't implement popFront for this structure.
More information about the Digitalmars-d
mailing list