| 1 |
//import std.array, std.range; |
| 2 |
module imports.a11850; |
| 3 |
|
| 4 |
|
| 5 |
template filter(alias pred) |
| 6 |
{ |
| 7 |
auto filter(Range)(Range rs) |
| 8 |
{ |
| 9 |
return FilterResult!(pred, Range)(rs); |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
private struct FilterResult(alias pred, Range) |
| 15 |
{ |
| 16 |
alias Range R; |
| 17 |
R _input; |
| 18 |
|
| 19 |
|
| 20 |
this(R r) |
| 21 |
{ |
| 22 |
_input = r; |
| 23 |
while (_input.length != 0 && !pred(_input[0])) |
| 24 |
{ |
| 25 |
_input = _input[1..$]; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
auto opSlice() { return this; } |
| 31 |
|
| 32 |
|
| 33 |
@property bool empty() { return _input.length == 0; } |
| 34 |
|
| 35 |
|
| 36 |
void popFront() |
| 37 |
{ |
| 38 |
do |
| 39 |
{ |
| 40 |
_input = _input[1..$]; |
| 41 |
} while (_input.length != 0 && !pred(_input[0])); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
@property auto ref front() |
| 46 |
{ |
| 47 |
return _input[0]; |
| 48 |
} |
| 49 |
} |