Re: SList: How do I use linearRemove?
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
Re: SList: How do I use linearRemove?
First case is a bug. I'll make pull request. Not sure about second.
Re: SList: How do I use linearRemove?
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..
Re: SList: How do I use linearRemove?
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
Re: SList: How do I use linearRemove?
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))
Re: SList: How do I use linearRemove?
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
SList: How do I use linearRemove?
--- 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? } ---