6 alias TypeTuple(T...) = T;
8 /*******************************************/
33 mixin typeof(b).Def!(int);
45 /*******************************************/
60 assert(C2.x2 == long.sizeof);
61 // assert(x2 == int.sizeof);
64 /*******************************************/
68 int func() { printf("Foo3.func()\n"); return 1; }
78 override int func() { printf("Code3.func()\n"); return 2; }
94 /*******************************************/
98 int func() { printf("Foo4.func()\n"); return 1; }
115 /*******************************************/
119 int func() { printf("Foo5.func()\n"); return 1; }
136 /*******************************************/
155 assert(b.sizeof == int.sizeof);
158 /*******************************************/
177 printf("b.x = %d\n", b.x);
181 /*******************************************/
186 int bar() { return 7; }
192 printf("x = %d\n", x);
197 /*******************************************/
201 int abc() { return y; }
211 /*******************************************/
213 template Foo10(alias b)
215 typeof(b) abc() { return b; }
226 /*******************************************/
228 template Foo11(alias b)
230 int abc() { return b; }
237 assert(B.abc() == 8);
240 /*******************************************/
242 template duff_for(alias id1, alias id2, alias s)
247 printf("duff_for(%d, %d)\n", id1, id2);
248 typeof(id1) id = id1;
249 printf("fid = %d, %d\n", id, (id2 - id) % 8);
250 switch ((id2 - id) % 8)
255 printf("wid = %d\n", id);
258 case 7: s(); ++id; goto case;
259 case 6: s(); ++id; goto case;
260 case 5: s(); ++id; goto case;
261 case 4: s(); ++id; goto case;
262 case 3: s(); ++id; goto case;
263 case 2: s(); ++id; goto case;
272 void foo12() { printf("foo12\n"); }
279 mixin duff_for!(i, j, delegate void() { foo12(); });
283 /*******************************************/
285 template duff(alias id1, alias id2, alias s)
297 printf("foo13 j = %d\n", j);
306 mixin duff!(i, j, delegate { foo13(i); });
310 /*******************************************/
321 printf("x14 = %d\n", x14);
325 /*******************************************/
331 int bar15() { return x15; }
340 printf("x15 = %d\n", x15);
341 printf("bar15() = %d\n", bar15());
343 assert(bar15() == 5);
346 /*******************************************/
352 int bar() { return x16; }
362 printf("x16 = %d\n", x16);
363 printf("bar() = %d\n", A16.bar());
365 assert(A16.x16 == 5);
366 assert(B16.x16 == 5);
367 assert(A16.bar() == 5);
368 assert(B16.bar() == 5);
371 /*******************************************/
387 printf("x17 = %d\n", x17); // prints 5
392 printf("b.x17 = %d\n", b.x17); // prints 5
394 printf("x17 = %d\n", x17); // prints 3
398 printf("x17 = %d\n", x17); // prints 5
401 printf("x17 = %d\n", x17); // prints 4
404 printf("x17 = %d\n", x17); // prints 3
407 printf("x17 = %d\n", x17); // prints 5
411 /*******************************************/
413 template Foo18() { int z = 3; }
415 struct Bar18(alias Tmpl)
427 /*******************************************/
431 int foo19(T a) { return 2*a; }
438 int bar19(T a) { return foo19(a); }
451 /*******************************************/
453 interface A20 { int f(); }
459 printf("in C20.f()\n");
467 // void f() { printf("in C20.f()\n"); }
477 /*******************************************/
479 template Mix21() { this(int x) { printf("mix1\n"); }}
484 mixin Mix21; // wouldn't compile
488 // mixin Mix21; // placing it here compiles
493 Bar21 bar = new Bar21();
496 /*******************************************/
510 int foo() { printf("B22.foo()\n"); return 67; }
524 /*******************************************/
545 printf("%d\n",c.F.x);
550 printf("%d\n",d.F.x);
554 /*******************************************/
558 void foo24() { return cast(void)0; }
559 // alias foo24 foo24;
570 /*******************************************/
574 this() { this(null); }
585 Foo25 foo = new Foo25();
589 /*******************************************/
601 mixin Get26!(byte) bar;
603 mixin Get26!(int) beq;
609 Reader r = new Reader;
616 /*******************************************/
618 template Template(int L)
621 int foo(int b = Template!(9).i) {
629 int foo(int b = Template!(9).i) {
635 /*******************************************/
637 template Blah28(int a, alias B)
639 mixin Blah28!(a-1, B);
640 //mixin Blah28!(0, B);
643 template Blah28(int a:0, alias B)
651 printf("a = %d\n", a);
654 /*******************************************/
667 const S29 s29 = { x:2, y:3 };
675 /*******************************************/
683 foreach(Type v; arr) writeln(typeid(typeof(v)));
692 static int[] ints = [0,1,2,3];
693 A30 a = new A30(ints);
696 /*******************************************/
699 const bool opEquals(ref const T x) { return true; }
704 //int opEquals(List31 x) { return 0; }
705 mixin Share!(List31);
716 /*******************************************/
718 template Blah(int a, alias B)
723 template Blah(int a:0, alias B)
738 /*******************************************/
740 template T33( int i )
744 printf("foo %d\n", i );
749 printf("opCall %d\n", i );
776 /*******************************************/
783 printf( "%d %d\n", i, j );
795 //printf( "%i\n", i );
798 /*******************************************/
812 /*******************************************/
828 printf("f.sizeof = %d\n", f.sizeof);
829 assert(f.sizeof == 12);
840 /*******************************************/
859 auto i = b.bar.func!()();
861 i = (new Baz37).bar.func!()();
865 /*******************************************/
899 Outer38 o = new Outer38();
901 assert(Outer38.c == 3);
904 /*******************************************/
910 printf("Mixed-in dtor\n");
918 printf("Base39 dtor\n");
922 class Class39 : Base39
929 printf("Class39 dtor\n");
935 auto test = new Class39;
939 /*******************************************/
948 union { mixin Mix40; }
957 /*******************************************/
976 /*******************************************/
979 template TCALL2245a(ARGS...)
981 int makecall(ARGS args)
987 template TCALL2245b(int n)
989 int makecall2(ARGS...)(ARGS args) if (ARGS.length == n)
998 mixin TCALL2245a!(int);
999 mixin TCALL2245a!(int,int);
1001 mixin TCALL2245b!(0);
1002 mixin TCALL2245b!(1);
1003 mixin TCALL2245b!(2);
1008 mixin TCALL2245a!();
1009 mixin TCALL2245a!(int);
1010 mixin TCALL2245a!(int,int);
1012 mixin TCALL2245b!(0);
1013 mixin TCALL2245b!(1);
1014 mixin TCALL2245b!(2);
1020 assert(c.makecall() == 0);
1021 assert(c.makecall(0) == 1);
1022 assert(c.makecall(0,1) == 2);
1024 assert(c.makecall2() == 0);
1025 assert(c.makecall2(0) == 1);
1026 assert(c.makecall2(0,1) == 2);
1028 assert(c.makecall2!()() == 0);
1029 assert(c.makecall2!(int)(0) == 1);
1030 assert(c.makecall2!(int, int)(0,1) == 2);
1033 assert(s.makecall() == 0);
1034 assert(s.makecall(0) == 1);
1035 assert(s.makecall(0,1) == 2);
1037 assert(s.makecall2() == 0);
1038 assert(s.makecall2(0) == 1);
1039 assert(s.makecall2(0,1) == 2);
1041 assert(s.makecall2!()() == 0);
1042 assert(s.makecall2!(int)(0) == 1);
1043 assert(s.makecall2!(int, int)(0,1) == 2);
1046 /*******************************************/
1049 template M2481() { int i; }
1050 class Z2481a { struct { mixin M2481!(); } }
1051 class Z2481b { struct { int i; } }
1057 static assert(z1.i.offsetof == z2.i.offsetof);
1060 /*******************************************/
1063 interface IFooable2740
1067 abstract class CFooable2740
1072 mixin template MFoo2740()
1074 override bool foo() { return true; }
1077 class Foo2740i1 : IFooable2740
1079 override bool foo() { return false; }
1082 class Foo2740i2 : IFooable2740
1085 override bool foo() { return false; }
1088 class Foo2740c1 : CFooable2740
1090 override bool foo() { return false; }
1093 class Foo2740c2 : CFooable2740
1096 override bool foo() { return false; }
1102 auto p = new Foo2740i1();
1104 assert(p.foo() == false);
1105 assert(i.foo() == false);
1108 auto p = new Foo2740i2();
1110 assert(p.foo() == false);
1111 assert(i.foo() == false);
1115 auto p = new Foo2740c1();
1117 assert(p.foo() == false);
1118 assert(i.foo() == false);
1121 auto p = new Foo2740c2();
1123 assert(p.foo() == false);
1124 assert(i.foo() == false);
1128 /*******************************************/
1130 mixin template MTestFoo()
1132 int foo(){ return 2; }
1136 mixin MTestFoo!() test;
1137 int foo(){ return 1; }
1141 auto p = new TestFoo();
1142 assert(p.foo() == 1);
1143 assert(p.test.foo() == 2);
1146 /*******************************************/
1149 class ZeroOrMore7744(Expr)
1151 enum name = "ZeroOrMore7744!("~Expr.name~")";
1153 class Range7744(char begin, char end)
1155 enum name = "Range7744!("~begin~","~end~")";
1159 class RubySource7744 : ZeroOrMore7744!(DecLiteral7744)
1162 class DecLiteral7744 : Range7744!('0','9')
1167 /*******************************************/
1170 mixin template T8032()
1177 mixin T8032; // Named mixin causes the error too
1180 class B8032a : A8032a
1182 override void f() { }
1188 mixin T8032; // Named mixin causes the error too
1190 class B8032b : A8032b
1192 override void f() { }
1195 /*********************************************/
1198 mixin template Foo9417()
1211 /*******************************************/
1222 static assert(is(typeof(c.front) == void));
1225 template Mix(alias R)
1228 @property front() inout {}
1238 /*******************************************/
1241 mixin template M11767()
1246 mixin M11767!(); // OK
1247 static assert(!__traits(compiles, S11767));
1256 static assert(!is(S1 == S2));
1257 static assert(S1.mangleof == "S6mixin19test11767FZ8__mixin16S11767");
1258 static assert(S2.mangleof == "S6mixin19test11767FZ8__mixin26S11767");
1261 static assert(!__traits(compiles, S11767));
1264 /*******************************************/
1267 void Delete12023(Object obj) {}
1269 template MessageCode12023()
1271 alias typeof(this) C;
1273 struct MessageDeinitHelper
1279 m_outer.DoDeinitMessaging();
1283 CToClient toClient = null;
1284 TypeTuple!(CToClient) toClients;
1288 void DoDeinitMessaging()
1290 Delete12023(toClient);
1291 Delete12023(toClients);
1295 class TurretCannon12023(ProjectileClass)
1297 mixin MessageCode12023;
1302 auto tc = new TurretCannon12023!Object();
1305 /*******************************************/
1308 mixin template Mix14243a(int n)
1310 static assert(n > 0);
1311 import core.stdc.stdio;
1312 enum { enumMember = 1 }
1317 mixin template Mix14243b(int n)
1325 template foo14243(alias v) { auto bar() { return &v; } }
1326 mixin template Mix14243c(alias v)
1328 // instantiate template in TemplateMixin
1329 auto c = foo14243!v.bar();
1332 mixin template Mix14243d(int n)
1334 // Type declaration in TemplateMixin
1335 struct NS { int x = n; }
1336 mixin("auto d" ~ ('0' + n) ~ " = NS();");
1339 mixin template Mix14243e(int n)
1343 int foo() { return var; }
1346 struct S { int x; void f() {} }
1347 int bar() { return n; }
1357 this(int x) { ctor ~= x; this.x = x; }
1358 ~this() { dtor ~= x; }
1363 assert(ctor == [] && dtor == []); mixin Mix14243a!(1);
1364 assert(ctor == [1] && dtor == []); mixin Mix14243b!(12) b1;
1365 assert(ctor == [1,12] && dtor == []); mixin Mix14243b!(24) b2;
1366 assert(ctor == [1,12,24] && dtor == []);
1368 static assert(!__traits(compiles, b > 0)); // ambiguous symbol access
1369 assert(b1.b.x == 12);
1370 assert(b2.b.x == 24);
1373 mixin Mix14243c!(x);
1376 mixin Mix14243d!(1);
1377 mixin Mix14243d!(2);
1378 static assert(!is(typeof(d1) == typeof(d2)));
1382 assert(ctor == [1,12,24] && dtor == []);
1384 assert(ctor == [1,12,24] && dtor == [24,12,1]);
1389 static assert(is(typeof(&foo) == int delegate() @safe nothrow pure @nogc));
1390 static assert(is(typeof(&bar) == int function() @safe nothrow pure @nogc));
1391 static assert(S.sizeof == int.sizeof); // s is static struct
1393 assert(bar() == 12);
1397 static assert(test14243()); // changed to be workable
1399 /*******************************************/
1402 class TestClass10492 {}
1404 mixin template mix10492(string name)
1406 mixin("scope " ~ name ~ " = new TestClass10492;" );
1411 mixin mix10492!("var");
1414 /*******************************************/
1468 printf("Success\n");