popBackWhile

Pops back an input range while a predicate is true. Consumes the input argument.

void
popBackWhile
(
alias pred
Range
)
(
ref Range range
)
if (
isBidirectionalRange!Range &&
is(typeof(unaryFun!pred))
&&
isImplicitlyConvertible!(typeof(unaryFun!pred((ElementType!Range).init)), bool)
)

Parameters

pred

the predicate.

range Range

an input range, must be a lvalue.

Examples

1 string r0 = "bcdaaaa";
2 r0.popBackWhile!"a == 'a'";
3 assert(r0 == "bcd");
4 
5 static bool lessTwo(T)(T t)
6 {
7     return t < 2;
8 }
9 int[] r1 = [0,1,2,2,1,0];
10 r1.popBackWhile!lessTwo;
11 assert(r1 == [0,1,2,2]);
12 
13 static bool posLessFive(T)(T t)
14 {
15     return t < 5 && t > 0;
16 }
17 int[] r3 = [-1,2,3,4];
18 r3.popBackWhile!posLessFive;
19 assert(r3 == [-1]);
20 int[] r4 = [5,2,3,4];
21 r4.popBackWhile!posLessFive;
22 assert(r4 == [5]);

Meta