-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
link14834a.d
57 lines (48 loc) · 924 Bytes
/
link14834a.d
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module link14834a;
struct DirIterator
{
int i = 1;
@property bool empty() { return i == 0; }
@property int front() { return 10; }
void popFront() { --i; }
}
auto dirEntries(string path)
{
bool f(int x)
{
assert(path == "."); // should pass
return true;
}
return filter!f(DirIterator());
}
template filter(alias pred)
{
auto filter(R)(R range)
{
return FilterResult!(pred, R)(range);
}
}
struct FilterResult(alias pred, R)
{
R input;
this(R r)
{
input = r;
while (!input.empty && !pred(input.front))
{
input.popFront();
}
}
@property bool empty() { return input.empty; }
@property auto ref front()
{
return input.front;
}
void popFront()
{
do
{
input.popFront();
} while (!input.empty && !pred(input.front));
}
}