digitalmars.D.learn - SList: How do I use linearRemove?
- Lemonfiend (12/12) Jun 26 2014 ---
- bearophile (5/9) Jun 26 2014 linearRemove is linear, so I think it accepts a range. Perhaps
- Lemonfiend (4/6) Jun 26 2014 I cannot find once in the docs. Did you mean std.range.only?
- sigod (25/25) Jun 26 2014 Take a look at unittests in [std.container.slist][0]:
- Lemonfiend (16/25) Jun 26 2014 This works:
---
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?
}
---
Jun 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
Jun 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))
Jun 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
Jun 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..
Jun 26 2014
First case is a bug. I'll make pull request. Not sure about second.
Jun 26 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
Jun 28 2014









"Lemonfiend" <lemon fie.nd> 