-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbug.d
51 lines (43 loc) · 975 Bytes
/
bug.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
// from ng Martin Kinkelin
import std.stdio;
void main() {}
struct A
{
int[3] _data;
string _name;
this(string name) { writeln("A.__ctor() for ", name); _name = name; }
~this() { writeln("A.__dtor() for ", _name); }
this(this) { _name ~= "2"; writeln("Postblit constructor for ", _name); }
A dup()
{
A r = A(_name ~ ".dup");
r._data[] = _data[];
return r;
}
int opApply(int delegate(ref int) dg)
{
int r = 0;
for (int i = 0; i < _data.length; i++)
{
r = dg(_data[i]);
if (r)
break;
}
return r;
}
}
unittest
{
A a = A("a");
a._data = [ 1, 2, 3 ];
writeln("Iterating through a:");
foreach (ref e; a)
writeln(e);
writeln("\nIterating through a.dup:");
{
foreach (ref e; a.dup)
writeln(e);
writeln("ending inner scope");
}
writeln("inner scope ended");
}