std.range.primitives.pop_front - multiple declarations
- Function popFront
- Function popFrontN
Function popFront
Implements the range interface primitive for built-in
arrays. Due to the fact that nonmember functions can be called with
the first argument using the dot notation, popFrontarray.popFront is
equivalent to . For narrow strings,
popFront(array) automatically advances to the next code
point.
popFront
Prototype
void popFront(T)( T[] a ) pure nothrow @nogc @safe if (!isNarrowString!(T[]) && !is(T[] == void[]));
Example
auto a = [ 1, 2, 3 ]; a.popFront(); assert(a == [ 2, 3 ]);
Function popFrontN
Eagerly advances itself (not a copy) up to r times (by
calling nr.popFront). takes popFrontN by rref,
so it mutates the original range. Completes in Ο(1) steps for ranges
that support slicing and have length.
Completes in Ο() time for all other ranges.
n
Prototype
size_t popFrontN(Range)( Range r, size_t n ) if (isInputRange!Range);
Returns
How much was actually advanced, which may be less than r if
n did not have at least r elements.
n
will behave the same but instead removes elements from
the popBackNback of the (bidirectional) range instead of the front.
Example
int[] a = [ 1, 2, 3, 4, 5 ]; a.popFrontN(2); assert(a == [ 3, 4, 5 ]); a.popFrontN(7); assert(a == [ ]);
Example
import std.algorithm : equal; import std.range : iota; auto LL = iota(1L, 7L); auto r = popFrontN(LL, 2); assert(equal(LL, [3L, 4L, 5L, 6L])); assert(r == 2);
Example
int[] a = [ 1, 2, 3, 4, 5 ]; a.popBackN(2); assert(a == [ 1, 2, 3 ]); a.popBackN(7); assert(a == [ ]);
Example
import std.algorithm : equal; import std.range : iota; auto LL = iota(1L, 7L); auto r = popBackN(LL, 2); assert(equal(LL, [1L, 2L, 3L, 4L])); assert(r == 2);
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.