std.range.interfaces : InputRange moveFront
Tony
tonytdominguez at aol.com
Thu Nov 30 09:47:14 UTC 2017
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* copied:
>
> 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
> assert(a.i == 1); // as expected, 1
> assert(r.front.i == 1); // front is still 1
>
> auto b = r.moveFront();
> assert(!b.is_a_copy); // no, b is not a copy
> assert(b.i == 1); // state is transferred
> assert(r.front.i == 0); // front is int.init
> }
>
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 array.
More information about the Digitalmars-d-learn
mailing list