Re: SList: How do I use linearRemove?

2014-06-28 Thread sigod via Digitalmars-d-learn

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


SList: How do I use linearRemove?

2014-06-26 Thread Lemonfiend via Digitalmars-d-learn

---
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?
}
---


Re: SList: How do I use linearRemove?

2014-06-26 Thread bearophile via Digitalmars-d-learn

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


Re: SList: How do I use linearRemove?

2014-06-26 Thread Lemonfiend via Digitalmars-d-learn
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?

2014-06-26 Thread sigod via Digitalmars-d-learn

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?

2014-06-26 Thread Lemonfiend via Digitalmars-d-learn

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?

2014-06-26 Thread sigod via Digitalmars-d-learn

First case is a bug. I'll make pull request.
Not sure about second.