questions: remove from SList
Steven Schveighoffer
schveiguy at yahoo.com
Wed Oct 12 08:20:49 PDT 2011
On Tue, 11 Oct 2011 13:29:02 -0400, kennytm <kennytm at gmail.com> wrote:
> "Steven Schveighoffer" <schveiguy at yahoo.com> wrote:
>
>> Yes, I'd agree either remove's implementation or its constraint
>> specification are buggy. It should not specify that it needs a forward
>> range and then use bi-directional range primitives.
>>
>
> I think remove's constraint is fine. With a SList you don't really want
> to
> remove the current node, but the 'next' node. SList should provide the
> O(1)
> removeNext and insertNext functions (c.f. C++11's std::forward_list).
See the definition of std.algorithm.remove here:
https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L5927
And see line 5956 which uses popBack on the range which is determined not
to be a bidirectional range.
Looking at the code, I'd say the bug is simply that remove is overloaded
for forward ranges. I'd remove this whole overload.
But your points on SList are valid -- a linked list of any kind that does
not support O(1) removal or insertion is DOA.
-Steve
More information about the Digitalmars-d
mailing list