1 module imports.std15030algo; 2 filter(alias pred)3template filter(alias pred) 4 { 5 auto filter(R)(R r) 6 { 7 return FilterResult!(pred, R)(r); 8 } 9 } 10 FilterResult(alias pred,R)11private struct FilterResult(alias pred, R) 12 { 13 R _input; 14 15 this(R r) 16 { 17 _input = r; 18 while (_input.length != 0 && !pred(_input[0])) 19 { 20 _input = _input[1..$]; 21 } 22 } 23 24 @property bool empty() { return _input.length == 0; } 25 26 @property auto ref front() { return _input[0]; } 27 28 void popFront() 29 { 30 do 31 { 32 _input = _input[1..$]; 33 } while (_input.length != 0 && !pred(_input[0])); 34 } 35 } 36