summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/imports/std15030algo.d
blob: eb54c592f461e0262a6ce730fc745f96774333a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module imports.std15030algo;

template filter(alias pred)
{
    auto filter(R)(R r)
    {
        return FilterResult!(pred, R)(r);
    }
}

private struct FilterResult(alias pred, R)
{
    R _input;

    this(R r)
    {
        _input = r;
        while (_input.length != 0 && !pred(_input[0]))
        {
            _input = _input[1..$];
        }
    }

    @property bool empty() { return _input.length == 0; }

    @property auto ref front() { return _input[0]; }

    void popFront()
    {
        do
        {
            _input = _input[1..$];
        } while (_input.length != 0 && !pred(_input[0]));
    }
}