Re: std.range.interfaces : InputRange moveFront

2017-12-08 Thread Andrei Alexandrescu via Digitalmars-d-learn
On 12/03/2017 12:42 AM, Johan Engelen wrote: On Friday, 1 December 2017 at 18:33:09 UTC, Ali Çehreli wrote: On 12/01/2017 07:21 AM, Steven Schveighoffer wrote: > On 12/1/17 4:29 AM, Johan Engelen wrote: >> (Also, I would expect "popFront" to return the element popped, but it >> doesn't, OK... >

Re: std.range.interfaces : InputRange moveFront

2017-12-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/3/17 12:42 AM, Johan Engelen wrote: On Friday, 1 December 2017 at 18:33:09 UTC, Ali Çehreli wrote: On 12/01/2017 07:21 AM, Steven Schveighoffer wrote: > On 12/1/17 4:29 AM, Johan Engelen wrote: >> (Also, I would expect "popFront" to return the element popped, but it >> doesn't, OK... > >

Re: std.range.interfaces : InputRange moveFront

2017-12-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 December 2017 at 18:55:53 UTC, Steven Schveighoffer wrote: Once you popFront a byLine range, the element that was at front is now possibly invalid (the buffer may be reused). So in order to return the line from popFront, you have to store it somewhere. This means allocating anoth

Re: std.range.interfaces : InputRange moveFront

2017-12-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 December 2017 at 18:33:09 UTC, Ali Çehreli wrote: On 12/01/2017 07:21 AM, Steven Schveighoffer wrote: > On 12/1/17 4:29 AM, Johan Engelen wrote: >> (Also, I would expect "popFront" to return the element popped, but it >> doesn't, OK... > > pop removes the front element, but if getti

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/1/17 1:33 PM, Ali Çehreli wrote: On 12/01/2017 07:21 AM, Steven Schveighoffer wrote: > On 12/1/17 4:29 AM, Johan Engelen wrote: >> (Also, I would expect "popFront" to return the element popped, but it >> doesn't, OK... > > pop removes the front element, but if getting the front elemen

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Ali Çehreli via Digitalmars-d-learn
On 12/01/2017 07:21 AM, Steven Schveighoffer wrote: > On 12/1/17 4:29 AM, Johan Engelen wrote: >> (Also, I would expect "popFront" to return the element popped, but it >> doesn't, OK... > > pop removes the front element, but if getting the front element is > expensive (say if it's a map with a co

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Ali Çehreli via Digitalmars-d-learn
On 12/01/2017 01:11 AM, Johan Engelen wrote: I tested it and it works like you wrote, but the behavior is different for an array of integers...: auto a = [ 1,2,3 ]; writeln(a.front); // 1 auto b = a.moveFront(); writeln(b); // 1 writeln(a.length); // still 3 writeln(a.front); // still 1 -Joha

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/1/17 4:29 AM, Johan Engelen wrote: On Friday, 1 December 2017 at 09:11:40 UTC, Johan Engelen wrote: I tested it and it works like you wrote, but the behavior is different for an array of integers...: Hmm, I guess I misread what Ali meant. But the documentation is wrong/very confusing

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 December 2017 at 09:11:40 UTC, Johan Engelen wrote: I tested it and it works like you wrote, but the behavior is different for an array of integers...: Hmm, I guess I misread what Ali meant. But the documentation is wrong/very confusing for moveFront: It says "moveFront -- Remov

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 30 November 2017 at 06:36:12 UTC, Ali Çehreli wrote: import std.range; struct S { int i; bool is_a_copy = false; this(this) { is_a_copy = true; } } void main() { auto r = [S(1)]; auto a = r.front; assert(a.is_a_copy); // yes, a is a copy

Re: std.range.interfaces : InputRange moveFront

2017-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/30/2017 07:31 AM, Tony wrote: On Thursday, 30 November 2017 at 09:50:37 UTC, Tony wrote: On Thursday, 30 November 2017 at 09:47:14 UTC, Tony wrote: Thanks for the reply. Probably just missing it, but in poking around dlang.org (Language Reference and Library Reference) I am having troub

Re: std.range.interfaces : InputRange moveFront

2017-11-30 Thread Tony via Digitalmars-d-learn
On Thursday, 30 November 2017 at 09:50:37 UTC, Tony wrote: On Thursday, 30 November 2017 at 09:47:14 UTC, Tony wrote: Thanks for the reply. Probably just missing it, but in poking around dlang.org (Language Reference and Library Reference) I am having trouble finding out about the move(), fron

Re: std.range.interfaces : InputRange moveFront

2017-11-30 Thread Tony via Digitalmars-d-learn
On Thursday, 30 November 2017 at 09:47:14 UTC, Tony wrote: Thanks for the reply. Probably just missing it, but in poking around dlang.org (Language Reference and Library Reference) I am having trouble finding out about the move(), front() and moveFront() functions, as is used here on a dynamic

Re: std.range.interfaces : InputRange moveFront

2017-11-30 Thread Tony via Digitalmars-d-learn
On Thursday, 30 November 2017 at 06:36:12 UTC, Ali Çehreli wrote: move is an operation that transfers the state of the source to the destination. The front element becomes its .init value and its previous values is returned by moveFront(). The important bit is that, the element is *not* cop

Re: std.range.interfaces : InputRange moveFront

2017-11-29 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/2017 08:31 PM, Tony wrote: What does the moveFront() method do in the InputRange interface? std.range.interfaces : InputRange.moveFront() move is an operation that transfers the state of the source to the destination. The front element becomes its .init value and its previous values

std.range.interfaces : InputRange moveFront

2017-11-29 Thread Tony via Digitalmars-d-learn
What does the moveFront() method do in the InputRange interface? std.range.interfaces : InputRange.moveFront()