PageRenderTime 23ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/ct.d

http://github.com/baryluk/cords
D | 71 lines | 53 code | 14 blank | 4 comment | 0 complexity | 8424c624bc863ffd90d59ed98ceb0af3 MD5 | raw file
 1module ct;
 2
 3import RBt : RB;
 4
 5class C {
 6	const int a;
 7	private const C b;
 8
 9	this(int a_) {
10		a = a_;
11		b = null;
12	}
13
14	this(int a_, in const(C) b_) {
15		a = a_;
16		b = b_;
17	}
18	const(C) m() const {
19		return b;
20	}
21
22//	const(C) opCast() {
23//	    return this;
24//	}
25
26	const(C) merge(in const(C) b2) const {
27	    return new C(a, b2);
28	}
29}
30
31import std.stdio;
32
33alias RB!(const C) CC;
34
35CC CCC(int i) {
36    return CC(new C(i));
37}
38CC CCC(int i, CC b) {
39    return CC(new C(i, b.opDot()));
40}
41
42int something(in C a) {
43    return a.a;
44}
45
46int something(CC a) {
47    return something(a.opDot());
48}
49
50const(C) something2(in C a) {
51	return a;
52}
53
54CC something2(CC a) {
55	//return CC(something2(a.opDot()));
56	return CC(something2(cast(const(C))a));
57}
58
59void main() {
60	auto c1 = CCC(1);
61	auto c2 = CCC(2, c1);
62	CC c3 = CCC(2, c1);
63	writefln("%d", c2.a);
64	c2 = c2.m();
65	writefln("%d", c2.a);
66	writefln("%d", something(c2));
67	CC c4 = something2(c3);
68	c4 = c3.opDot();
69	c4 = c3 = c2;
70	c3 = c1.merge(c2.opDot());
71}