Thread overview
SList: How do I use linearRemove?
Jun 26, 2014
Lemonfiend
Jun 26, 2014
bearophile
Jun 26, 2014
Lemonfiend
Jun 26, 2014
sigod
Jun 26, 2014
Lemonfiend
Jun 26, 2014
sigod
Jun 28, 2014
sigod
June 26, 2014
---
module main;

void main()
{
	struct Tree { int apples; }

	import std.container;
	SList!Tree list;

	Tree tree = Tree(5);
	list.insert(tree);
	//list.linearRemove(tree); // <-- Error. What is the correct way?
}
---
June 26, 2014
Lemonfiend:

> 	//list.linearRemove(tree); // <-- Error. What is the correct way?
> }
> ---

linearRemove is linear, so I think it accepts a range. Perhaps the "once" range is enough.

Bye,
bearophile
June 26, 2014
> linearRemove is linear, so I think it accepts a range. Perhaps the "once" range is enough.
I cannot find once in the docs. Did you mean std.range.only?

Error: function std.container.SList!(Tree).SList.linearRemove (Range r) is not callable using argument types (OnlyResult!(Tree, 1u))
June 26, 2014
Take a look at unittests in [std.container.slist][0]:

```
unittest
{
    auto s = SList!int(1, 2, 3, 4, 5);
    auto r = s[];
    popFrontN(r, 3);
    auto r1 = s.linearRemove(r);
    assert(s == SList!int(1, 2, 3));
    assert(r1.empty);
}

unittest
{
    auto s = SList!int(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    auto r = s[];
    popFrontN(r, 3);
    auto r1 = take(r, 4);
    assert(equal(r1, [4, 5, 6, 7]));
    auto r2 = s.linearRemove(r1);
    assert(s == SList!int(1, 2, 3, 8, 9, 10));
    assert(equal(r2, [8, 9, 10]));
}
```

[0]: https://github.com/D-Programming-Language/phobos/blob/master/std/container/slist.d#L575
June 26, 2014
> unittest
> {
>     auto s = SList!int(1, 2, 3, 4, 5);
>     auto r = s[];
>     popFrontN(r, 3);
>     auto r1 = s.linearRemove(r);
>     assert(s == SList!int(1, 2, 3));
>     assert(r1.empty);
> }

This works:
auto s = SList!int(1, 2, 3, 4, 5);
auto r = s[];
popFrontN(r, 1);
auto r1 = s.linearRemove(r);

This doesn't (why?):
auto s = SList!int(1, 2, 3, 4, 5);
auto r = s[];
auto r1 = s.linearRemove(r);

This doesn't (why?):
auto s = SList!int(1, 2, 3, 4, 5);
auto s2 = SList!int(1, 2, 3, 4, 5);
auto r = s2[];
popFrontN(r, 1);
auto r1 = s.linearRemove(r);

I am at a loss..
June 26, 2014
First case is a bug. I'll make pull request.
Not sure about second.
June 28, 2014
On Thursday, 26 June 2014 at 16:50:38 UTC, Lemonfiend wrote:
> This doesn't (why?):
> auto s = SList!int(1, 2, 3, 4, 5);
> auto s2 = SList!int(1, 2, 3, 4, 5);
> auto r = s2[];
> popFrontN(r, 1);
> auto r1 = s.linearRemove(r);

This is intended behavior: https://issues.dlang.org/show_bug.cgi?id=12999