1 // RUNNABLE_PHOBOS_TEST
2 import std.stdio;
3
4 struct S {
5 int x = 3;
funS6 void fun(T)(T x) { writefln("S.fun(%s)(%s)",typeid(T),x); this.x += x; }
7 }
8
9 class Tst(TST, int v = 2) {
10 int x = 3;
11 int z = 4;
12
proc(int x)13 final private void proc(int x) { writefln("proc(%s) -> %s",x,this.x); }
fun(T)14 void fun(T)(T x) { writefln("fun(%s)(%s) -> %s",typeid(T),x,this.x);}
fun()15 void fun()() { writefln("fun()() -> %s",this.x); }
fun2()16 void fun2()() { writefln("fun2"); }
17
18 class Inner {
19 int y = 99;
20 Tst outer;
f3()21 void f3() { z = 55; }
22 // Make sure the correct this-ptr is used
f1()23 void f1() { writefln("Inner.f1"); proc(-11); outer.proc(-11); }
f2()24 void f2() { writefln("Inner.f2"); fun(-17); outer.fun(-17); }
25 }
26 Inner inner;
27
this()28 this() {
29 inner = new Inner;
30 inner.outer = this;
31 }
32
callInnerf1()33 void callInnerf1() { writefln("callInnerf1"); inner.f1(); }
callInnerf2()34 void callInnerf2() { writefln("callInnerf2"); inner.f2(); }
35
36
37 //
opAdd(T)38 void opAdd(T)(T x) { this.x += x; writefln("opAdd(%s)",x); }
opPos()39 void opPos()() { writefln("opPos()"); }
40 //void opPos() { writefln("xxx"); }
opIndex(T)41 void opIndex(T)(T x) { writefln("opIndex[%s]",x); }
42
opIndex(A,B,C)43 void opIndex(A,B,C)(A a, B b, C c) {
44 writefln("opIndex[(%s)%s,(%s)%s,(%s)%s]",typeid(A),a,
45 typeid(B),b,typeid(C),c);
46 }
47
48
49 static if (v > 1) {
50 void opCall(A = int, B = float)(A a = 1, B b = 8.2) { writefln("opCall(%s,%s)",a,b); this.x++; }
51
52 }
opSlice(A,B)53 void opSlice(A,B)(A a, B b) { writefln("opSlice(%s,%s)",a,b); }
opSlice()54 void opSlice()() { writefln("opSlice()"); }
55
opIndexAssign(A,B)56 void opIndexAssign(A,B)(A a, B b) {
57 writefln("opIndexAssign((%s)%s,(%s)%s)",typeid(A),a,typeid(B),b);
58 }
59
opSliceAssign(A,B,C)60 void opSliceAssign(A,B,C)(A a, B b, C c) {
61 writefln("opSliceAssign(%s,%s,%s)",a,b,c);
62 }
63
opEquals(A)64 bool opEquals(A)(A x) { writefln("opEquals((%s))",typeid(A));return true; }
65
opApply(T)66 int opApply(T)(int delegate(ref T)dg) {
67 for (int i = 0; i < 5; i++) {
68 T d = cast(T)(i+0.1);
69 if (auto result = dg(d))
70 return result;
71 }
72 return 0;
73 }
74 }
75
76 class Y : Tst!(float) {}
77
main()78 void main() {
79 Tst!(int) t = new Tst!(int);
80 Y u = new Y;
81 S s;
82 t.x = 7;
83 t.proc(5);
84 t.fun(5);
85 t.fun();
86 t.callInnerf1();
87 t.callInnerf2();
88 u.fun(5);
89 u.fun();
90 u.callInnerf1();
91 u.callInnerf2();
92 s.fun(5);
93 t.fun2();
94
95 +t;
96 t+5;
97 t[55];
98 t[1,2,3.0];
99 u[1,2,3.0];
100 t(1,2.5);
101 t(2);
102 t();
103 t[];
104 t[1..2];
105 u[1..2.5];
106 t[1i] = 5;
107 t[-4.5..7i] = "hello";
108 t == t;
109 auto b = t != t; // without assignment -> "! has no effect in expression"
110 t == u;
111 u == t;
112 u == u;
113 b = u != u;
114 foreach(int i;t) {
115 writefln("%s",i);
116 }
117 foreach(double i;t) {
118 writefln("%s",i);
119 }
120
121 }
122