5 import core.stdc.stdio, core.vararg;
7 /**********************************/
21 auto i = foo!(int)(2L);
22 // assert(i == 4); // now returns 3
25 /**********************************/
34 auto i = foo2!(int)(2L);
38 /**********************************/
51 int i = foo.bar!(int)(1.0);
56 /**********************************/
58 T* begin4(T)(T[] a) { return a.ptr; }
60 void copy4(string pred = "", Ranges...)(Ranges rs)
62 alias rs[$ - 1] target;
63 pragma(msg, typeof(target).stringof);
64 auto tb = begin4(target);//, te = end(target);
71 // comment the following line to prevent compiler from crashing
72 copy4!("a > 1")(a, b, c);
75 /**********************************/
77 import std.stdio:writefln;
82 writefln("typeof(T)=",typeid(T)," typeof(S)=",typeid(S));
89 writefln("typeof(T)=",typeid(T),"typeof(S)=",typeid(S));
97 bar5!(double,int)(33);
101 /**********************************/
103 int foo6(T...)(auto ref T x)
109 assert(__traits(isRef, x[i]));
111 assert(!__traits(isRef, x[i]));
132 /**********************************/
134 auto ref min(T, U)(auto ref T lhs, auto ref U rhs)
136 return lhs > rhs ? rhs : lhs;
149 static assert(!__traits(compiles, min(3, y) = 10));
150 static assert(!__traits(compiles, min(y, 3) = 10));
153 /**********************************/
158 int call(){ return this.g(); }
162 int f() { mixin TTest8!(); return call(); }
163 int g() { return 10; }
167 assert((new CTest8()).f() == 10);
170 /**********************************/
173 template TTest9(alias sym)
175 int call(){ return sym.g(); }
179 int f1() { mixin TTest9!(this); return call(); }
180 int f2() { mixin TTest9!this; return call(); }
181 int g() { return 10; }
185 assert((new CTest9()).f1() == 10);
186 assert((new CTest9()).f2() == 10);
189 /**********************************/
192 template Tuple1780(Ts ...) { alias Ts Tuple1780; }
194 template Decode1780( T ) { alias Tuple1780!() Types; }
195 template Decode1780( T : TT!(Us), alias TT, Us... ) { alias Us Types; }
199 struct S1780(T1, T2) {}
201 // should extract tuple (bool,short) but matches the first specialisation
202 alias Decode1780!( S1780!(bool,short) ).Types SQ1780; // --> SQ2 is empty tuple!
203 static assert(is(SQ1780 == Tuple1780!(bool, short)));
206 /**********************************/
210 class Bar1659 : Foo1659 { }
212 void f1659(T : Foo1659)() { }
213 void f1659(alias T)() { static assert(false); }
220 /**********************************/
226 template Foo2025(int i) { enum Foo2025 = 1; }
227 template Foo2025(TL...) { enum Foo2025 = 2; }
228 static assert(Foo2025!1 == 1);
229 static assert(Foo2025!int == 2);
230 static assert(Foo2025!S2025 == 2);
231 static assert(Foo2025!f2025 == 2);
233 template Bar2025(T) { enum Bar2025 = 1; }
234 template Bar2025(A...) { enum Bar2025 = 2; }
235 static assert(Bar2025!1 == 2);
236 static assert(Bar2025!int == 1); // 2 -> 1
237 static assert(Bar2025!S2025 == 1); // 2 -> 1
238 static assert(Bar2025!f2025 == 2);
240 template Baz2025(T) { enum Baz2025 = 1; }
241 template Baz2025(alias A) { enum Baz2025 = 2; }
242 static assert(Baz2025!1 == 2);
243 static assert(Baz2025!int == 1);
244 static assert(Baz2025!S2025 == 1); // 2 -> 1
245 static assert(Baz2025!f2025 == 2);
247 /**********************************/
250 template foo3608(T, U){}
252 template BaseTemplate3608(alias TTT : U!V, alias U, V...)
254 alias U BaseTemplate3608;
256 template TemplateParams3608(alias T : U!V, alias U, V...)
258 alias V TemplateParams3608;
261 template TyueTuple3608(T...) { alias T TyueTuple3608; }
265 alias foo3608!(int, long) Foo3608;
267 static assert(__traits(isSame, BaseTemplate3608!Foo3608, foo3608));
268 static assert(is(TemplateParams3608!Foo3608 == TyueTuple3608!(int, long)));
271 /**********************************/
276 static if (is(ElemType!(int))){}
278 template ElemType(T) {
279 alias _ElemType!(T).type ElemType;
282 template _ElemType(T) {
286 /**********************************/
293 C5185!(C5185!(int)) c;
299 C5185!(C5185!(int)) c;
302 /**********************************/
307 int concatAssign(C5893 other) { return 1; }
308 int concatAssign(int other) { return 2; } // to demonstrate overloading
310 template opOpAssign(string op) if (op == "~")
311 { alias concatAssign opOpAssign; }
313 int opOpAssign(string op)(int other) if (op == "+") { return 3; }
319 assert(c.opOpAssign!"~"(c) == 1); // works
320 assert(c.opOpAssign!"~"(1) == 2); // works
321 assert((c ~= 1) == 2);
322 assert((c += 1) == 3); // overload
325 /**********************************/
328 template Templ5988(alias T)
330 alias T!int Templ5988;
333 class C5988a(T) { Templ5988!C5988a foo; }
334 //Templ5988!C5988a foo5988a; // Commented version
335 void test5988a() { C5988a!int a; } // Was error, now works
337 class C5988b(T) { Templ5988!C5988b foo; }
338 Templ5988!C5988b foo5988b; // Uncomment version
339 void test5988b() { C5988b!int a; } // Works
341 /**********************************/
344 // receive only rvalue
345 void rvalue(T)(auto ref T x) if (!__traits(isRef, x)) {}
346 void rvalueVargs(T...)(auto ref T x) if (!__traits(isRef, x[0])) {}
348 // receive only lvalue
349 void lvalue(T)(auto ref T x) if ( __traits(isRef, x)) {}
350 void lvalueVargs(T...)(auto ref T x) if ( __traits(isRef, x[0])) {}
356 static assert(!__traits(compiles, rvalue(n)));
357 static assert( __traits(compiles, rvalue(0)));
359 static assert( __traits(compiles, lvalue(n)));
360 static assert(!__traits(compiles, lvalue(0)));
362 static assert(!__traits(compiles, rvalueVargs(n)));
363 static assert( __traits(compiles, rvalueVargs(0)));
365 static assert( __traits(compiles, lvalueVargs(n)));
366 static assert(!__traits(compiles, lvalueVargs(0)));
369 /**********************************/
380 class C2246(T,int rk){
384 template f2246(T:A2246!(U,d),U,d){
388 template f2246(T:B2246!(rank),int rank){
392 template f2246(T:C2246!(U,rank),U,int rank){
400 f2246!(A2246!(int,long))();
402 f2246!(C2246!(int,2))();
405 /**********************************/
408 void foo2296(size_t D)(int[D] i...){}
414 /**********************************/
417 template Test1684( uint memberOffset ){}
421 mixin Test1684!(cast(uint)flags2.offsetof) t1; // compiles ok
422 mixin Test1684!(cast(int)flags2.offsetof) t2; // compiles ok
423 mixin Test1684!(flags2.offsetof) t3; // Error: no property 'offsetof' for type 'int'
426 /**********************************/
428 void bug4984a(int n)() if (n > 0 && is(typeof(bug4984a!(n-1) ()))) {
431 void bug4984a(int n : 0)() {
434 void bug4984b(U...)(U args) if ( is(typeof( bug4984b(args[1..$]) )) ) {
437 void bug4984b(U)(U u) {
441 // Note: compiling this overflows the stack if dmd is build with DEBUG
444 bug4984b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
447 /***************************************/
450 void foo2579(T)(T delegate(in Object) dlg)
456 foo2579( (in Object o) { return 15; } );
459 /**********************************/
462 auto foo2803(T)(T t = 0) { return t; }
466 ref S2803 getS2803() { return s2803; }
467 auto fun2803(T, U)(T t, ref U u = getS2803)
469 static assert(is(U == S2803));
473 // from the past version of std.conv
474 template to2803(T) { T to2803(S)(S src) { return T.init; } }
475 auto toImpl2803a(T, S)(S s, in T left, in T sep = ", ", in T right = "]") {}
476 auto toImpl2803b(T, S)(S s, in T left = to2803!T(S.stringof~"("), in T right = ")") {}
477 auto toImpl2803c(T, S)(S s, in T left = S.stringof~"(" , in T right = ")") {} // combination with enh 13944
479 // from std.range.package in 2.067a.
480 auto enumerate2803(En = size_t, R)(R r, En start = 0)
482 // The type of 'start' should be size_t, it's the defaultArg of En,
483 // rather than the deduced type from its defualtArg '0'.
484 static assert(is(typeof(start) == size_t));
489 alias ElementType2803(R) = typeof(R.init[0].init);
490 void normalize2803(R)(R range, ElementType2803!R sum = 1)
492 // The type of 'sum' should be determined to ElementType!(double[]) == double
493 // before the type deduction from its defaultArg '1'.
494 static assert(is(typeof(sum) == double));
497 auto foo14468(T)(T[]...) { return 1; }
498 auto foo14468(bool flag, T)(T[]...) { return 2; }
502 assert(foo2803() == 0);
503 assert(foo2803(1) == 1);
506 assert(fun2803(1) is &s2803);
507 assert(fun2803(1, s) is &s);
511 toImpl2803a!string(1, "[");
513 toImpl2803b! string(1);
514 toImpl2803b!wstring(1);
515 toImpl2803b!dstring(1);
517 toImpl2803c! string(1);
518 toImpl2803c!wstring(1); // requires enhancement 13944
519 toImpl2803c!dstring(1); // requires enhancement 13944
526 assert(foo14468!int() == 1);
529 /**********************************/
532 alias Tuple6613(T...) = T;
534 void f6613(T...)(int x = 0, T xs = Tuple6613!())
537 static assert(T.length == 0);
545 /**********************************/
548 void bug4953(T = void)(short x) {}
549 static assert(is(typeof(bug4953(3))));
551 /**********************************/
554 mixin template Foo5886(T)
556 void foo(U : T, this X)() const { static assert(is(X == const K5886)); }
561 void get1(this T)() const
565 void get2(int N=4, this T)() const
567 pragma(msg, N, " ; ", T);
570 mixin Foo5886!double;
571 mixin Foo5886!string;
596 km.get2!(1, K5886); // Ugly
597 kc.get2!(2, const(K5886)); // Ugly
598 ki.get2!(3, immutable(K5886)); // Ugly
610 void opDispatch (string name, this T) () { }
619 /**********************************/
624 T opCast(T)(){ return 1; }
625 const T opCast(T)(){ return 2; }
626 immutable T opCast(T)(){ return 3; }
627 shared T opCast(T)(){ return 4; }
628 const shared T opCast(T)(){ return 5; }
633 auto xc = const(X5896) ();
634 auto xi = immutable(X5896) ();
635 auto xs = shared(X5896) ();
636 auto xcs= const(shared(X5896))();
637 assert(cast(int)xm == 1);
638 assert(cast(int)xc == 2);
639 assert(cast(int)xi == 3);
640 assert(cast(int)xs == 4);
641 assert(cast(int)xcs== 5);
644 /**********************************/
651 mixin wrap6312!h6312;
654 mixin template wrap6312(alias f)
656 void blub(alias g = f)()
664 Bla6312 b = new Bla6312();
668 /**********************************/
675 void write(S...)(S args) {}
678 void dump(void delegate(string) d) {}
681 dump(&o.write!string);
684 /**********************************/
687 template isStaticArray6789(T)
689 static if (is(T U : U[N], size_t N)) // doesn't match
691 pragma(msg, "> U = ", U, ", N:", typeof(N), " = ", N);
692 enum isStaticArray6789 = true;
695 enum isStaticArray6789 = false;
701 static assert(isStaticArray6789!T);
704 /**********************************/
707 struct ArrayWrapper2778(T)
713 void doStuffFunc2778(int[] data) {}
715 void doStuffTempl2778(T)(T[] data) {}
717 int doStuffTemplOver2778(T)(void* data) { return 1; }
718 int doStuffTemplOver2778(T)(ArrayWrapper2778!T w) { return 2; }
722 ArrayWrapper2778!(int) foo;
724 doStuffFunc2778(foo); // Works.
726 doStuffTempl2778!(int)(foo); // Works.
728 doStuffTempl2778(foo); // Error
730 assert(doStuffTemplOver2778(foo) == 2);
737 void foo(K, V)(V[K] aa){ pragma(msg, "K=", K, ", V=", V); }
747 SubTypeOf!(string[char]) aa2;
759 ubyte[] val = [1,2,3];
760 @property ref ubyte[] get(){ return val; }
767 /**********************************/
770 int getRefNonref(T)(ref T s){ return 1; }
771 int getRefNonref(T)( T s){ return 2; }
773 int getAutoRef(T)(auto ref T s){ return __traits(isRef, s) ? 1 : 2; }
775 void getOut(T)(out T s){ {} }
777 void getLazy1(T=int)(lazy void s){ s(), s(); }
778 void getLazy2(T)(lazy T s){ s(), s(); }
783 int rvalue(){ int t; return t; }
785 assert(getRefNonref(lvalue ) == 1);
786 assert(getRefNonref(rvalue()) == 2);
788 assert(getAutoRef(lvalue ) == 1);
789 assert(getAutoRef(rvalue()) == 2);
791 static assert( __traits(compiles, getOut(lvalue )));
792 static assert(!__traits(compiles, getOut(rvalue())));
794 int n1; getLazy1(++n1); assert(n1 == 2);
795 int n2; getLazy2(++n2); assert(n2 == 2);
799 int f(T)(auto ref T t){ return 1; }
800 int f(T)(auto ref T t, ...){ return -1; }
803 auto xc = const(X)();
805 assert(xm.f!int(n) == 1); // resolved 'auto ref'
806 assert(xm.f!int(0) == 1); // ditto
811 void foo(T)(const T value) if (!is(T == int)) {}
815 static assert(!__traits(compiles, foo(mn))); // OK -> OK
816 static assert(!__traits(compiles, foo(cn))); // NG -> OK
823 // Original test case.
824 int foo(V)(in V v) { return 1; }
825 int foo(Args...)(auto ref const Args args) { return 2; }
827 // Reduced test cases
829 int hoo(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst
830 int hoo(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst
831 // If deduction matching level is same, tuple parameter is less specialized than others.
833 int bar(V)(V v) { return 1; } // typeof(10) : V -> MATCHexact
834 int bar(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst
836 int baz(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst
837 int baz(Args...)(Args args) { return 2; } // typeof(10) : Args[0] -> MATCHexact
839 inout(int) war(V)(inout V v) { return 1; }
840 inout(int) war(Args...)(inout Args args){ return 2; }
842 inout(int) waz(Args...)(inout Args args){ return 0; } // wild deduction test
848 assert(s.foo(nm) == 1);
849 assert(s.hoo(nm) == 1);
850 assert(s.bar(nm) == 1);
851 assert(s.baz(nm) == 2);
852 assert(s.war(nm) == 1);
853 static assert(is(typeof(s.waz(nm)) == int));
856 assert(s.foo(nc) == 1);
857 assert(s.hoo(nc) == 1);
858 assert(s.bar(nc) == 1);
859 assert(s.baz(nc) == 1);
860 assert(s.war(nc) == 1);
861 static assert(is(typeof(s.waz(nc)) == const(int)));
863 immutable int ni = 10;
864 assert(s.foo(ni) == 1);
865 assert(s.hoo(ni) == 1);
866 assert(s.bar(ni) == 1);
867 assert(s.baz(ni) == 2);
868 assert(s.war(ni) == 1);
869 static assert(is(typeof(s.waz(ni)) == immutable(int)));
871 static assert(is(typeof(s.waz(nm, nm)) == int));
872 static assert(is(typeof(s.waz(nm, nc)) == const(int)));
873 static assert(is(typeof(s.waz(nm, ni)) == const(int)));
874 static assert(is(typeof(s.waz(nc, nm)) == const(int)));
875 static assert(is(typeof(s.waz(nc, nc)) == const(int)));
876 static assert(is(typeof(s.waz(nc, ni)) == const(int)));
877 static assert(is(typeof(s.waz(ni, nm)) == const(int)));
878 static assert(is(typeof(s.waz(ni, nc)) == const(int)));
879 static assert(is(typeof(s.waz(ni, ni)) == immutable(int)));
882 /**********************************/
887 template opDispatch(string name)
892 static assert(is(T6805.xxx.Type == int));
894 /**********************************/
901 @property int val()() { return _val; }
902 int get() { return val; } // fail
908 auto x = foo.val; // ok
910 assert(foo.get() == 10);
913 /**********************************/
916 template IndexMixin(){
917 void insert(T)(T value){ }
920 class MultiIndexContainer{
921 mixin IndexMixin!() index0;
924 this.outer.index0.insert(1);
929 /**********************************/
932 @property int foo6780()(){ return 10; }
935 @property void bar6780()(int n){ g6780 = n; }
946 /**********************************/
949 int f6810(int n)(int) { return 1;}
950 int f6810(U...)(U) { assert(0); }
951 int f6810(U...)(U a) { assert(0); }
952 int f6810(U...)(U) if (true) { assert(0); }
953 int f6810(U...)(U a) if (true) { assert(0); }
957 assert(f6810!0(0) == 1);
960 /**********************************/
963 struct S6891(int N, T)
965 void f(U)(S6891!(N, U) u) { }
970 alias S6891!(1, void) A;
974 /**********************************/
979 T get(T)(){ return T.init; }
982 if (__traits(compiles, get!T()))
986 if (__traits(compiles, this.get!T())) // add explicit 'this'
993 foo.func1!int(); // OK
994 foo.func2!int(); // NG
997 /**********************************/
1000 enum N6764 = 1; //use const for D1
1002 alias size_t[N6764] T6764; //workaround
1003 void f6764()(T6764 arr...) { }
1005 void g6764()(size_t[1] arr...) { }
1007 void h6764()(size_t[N6764] arr...) { }
1014 h6764(0); //Error: template main.f() does not match any function template declaration
1017 /**********************************/
1020 struct Foo3467( uint n )
1022 Foo3467!( n ) bar( ) {
1023 typeof( return ) result;
1027 struct Vec3467(size_t N)
1029 void opBinary(string op:"~", size_t M)(Vec3467!M) {}
1034 baz = baz.bar;// FAIL
1038 a1 ~ a2; // line 7, Error
1041 struct TS6806(size_t n) { pragma(msg, typeof(n)); }
1042 static assert(is(TS6806!(1u) == TS6806!(1)));
1044 /**********************************/
1049 alias typeof(this) typeof_this;
1050 void bar1(typeof_this other) {}
1051 void bar2()(typeof_this other) {}
1052 void bar3(typeof(this) other) {}
1053 void bar4()(typeof(this) other) {}
1065 /**********************************/
1068 template isNumeric(T)
1070 enum bool test1 = is(T : long); // should be hidden
1071 enum bool test2 = is(T : real); // should be hidden
1072 enum bool isNumeric = test1 || test2;
1076 static assert( isNumeric!int);
1077 static assert(!isNumeric!string);
1078 static assert(!__traits(compiles, isNumeric!int.test1)); // should be an error
1079 static assert(!__traits(compiles, isNumeric!int.test2)); // should be an error
1080 static assert(!__traits(compiles, isNumeric!int.isNumeric));
1083 /**********************************/
1088 T foo5525(T t) { return t; }
1089 T foo5525(T t, T u) { return t + u; }
1094 alias foo5525!int f;
1096 assert(f(1, 2) == 3);
1099 /**********************************/
1103 void bar5801(T = double)(typeof(a5801) i) {}
1104 void baz5801(T)(typeof(a5801) i, T t) {}
1107 bar5801(2); // Does not compile.
1108 baz5801(3, "baz"); // Does not compile.
1111 /**********************************/
1114 struct Bar5832(alias v) {}
1116 template isBar5832a(T)
1118 static if (is(T _ : Bar5832!(v), alias v))
1119 enum isBar5832a = true;
1121 enum isBar5832a = false;
1123 template isBar5832b(T)
1125 static if (is(T _ : Bar5832!(v), alias int v))
1126 enum isBar5832b = true;
1128 enum isBar5832b = false;
1130 template isBar5832c(T)
1132 static if (is(T _ : Bar5832!(v), alias string v))
1133 enum isBar5832c = true;
1135 enum isBar5832c = false;
1137 static assert( isBar5832a!(Bar5832!1234));
1138 static assert( isBar5832b!(Bar5832!1234));
1139 static assert(!isBar5832c!(Bar5832!1234));
1141 /**********************************/
1144 template pow10_2550(long n)
1146 const long pow10_2550 = 0;
1148 const long pow10_2550 = 0;
1150 const long pow10_2550 = 10 * pow10_2550!(n - 1);
1152 template pow10_2550(long n:0)
1154 const long pow10_2550 = 1;
1156 static assert(pow10_2550!(0) == 1);
1158 /**********************************/
1159 // [2.057] Remove top const in IFTI, 9198
1161 void foo10a(T )(T) { static assert(is(T == const(int)[])); }
1162 void foo10b(T...)(T) { static assert(is(T[0] == const(int)[])); }
1164 // ref parameter doesn't remove top const
1165 void boo10a(T )(ref T) { static assert(is(T == const(int[]))); }
1166 void boo10b(T...)(ref T) { static assert(is(T[0] == const(int[]))); }
1168 // auto ref with lvalue doesn't
1169 void goo10a(T )(auto ref T) { static assert(is(T == const(int[]))); }
1170 void goo10b(T...)(auto ref T) { static assert(is(T[0] == const(int[]))); }
1172 // auto ref with rvalue does
1173 void hoo10a(T )(auto ref T) { static assert(is(T == const(int)[])); }
1174 void hoo10b(T...)(auto ref T) { static assert(is(T[0] == const(int)[])); }
1176 void bar10a(T )(T) { static assert(is(T == const(int)*)); }
1177 void bar10b(T...)(T) { static assert(is(T[0] == const(int)*)); }
1182 static assert(is(typeof(a) == const(int[])));
1189 hoo10a(cast(const)[1,2,3]);
1190 hoo10b(cast(const)[1,2,3]);
1194 static assert(is(typeof(p) == const(int*)));
1199 /**********************************/
1202 template Foo3092(A...)
1206 static assert(is(Foo3092!(int, "foo") == int));
1208 /**********************************/
1212 struct Bar7037 { Foo7037 f; alias f this; }
1213 void works7037( T )( T value ) if ( is( T : Foo7037 ) ) {}
1214 void doesnotwork7037( T : Foo7037 )( T value ) {}
1220 doesnotwork7037( b );
1223 /**********************************/
1228 int opSlice(int, int) const { return 0; }
1229 int opSlice() const { return 0; }
1230 int opIndex(int, int) const { return 0; }
1231 int opIndex(int) const { return 0; }
1234 enum e7110 = S7110();
1236 template T7110(alias a) { } // or T7110(a...)
1238 alias T7110!( S7110 ) T71100; // passes
1239 alias T7110!((S7110)) T71101; // passes
1241 alias T7110!( S7110()[0..0] ) A0; // passes
1242 alias T7110!( (e7110[0..0]) ) A1; // passes
1243 alias T7110!( e7110[0..0] ) A2; // passes
1245 alias T7110!( S7110()[0, 0] ) B0; // passes
1246 alias T7110!( (e7110[0, 0]) ) B1; // passes
1247 alias T7110!( e7110[0, 0] ) B2; // passes
1249 alias T7110!( S7110()[] ) C0; // passes
1250 alias T7110!( (e7110[]) ) C1; // passes
1251 alias T7110!( e7110[] ) C2; // fails: e7110 is used as a type
1253 alias T7110!( S7110()[0] ) D0; // passes
1254 alias T7110!( (e7110[0]) ) D1; // passes
1255 alias T7110!( e7110[0] ) D2; // fails: e7110 must be an array or pointer type, not S7110
1257 /**********************************/
1260 template StaticArrayOf(T : E[dim], E, size_t dim)
1262 pragma(msg, "T = ", T, ", E = ", E, ", dim = ", dim);
1263 alias E[dim] StaticArrayOf;
1266 template DynamicArrayOf(T : E[], E)
1268 pragma(msg, "T = ", T, ", E = ", E);
1269 alias E[] DynamicArrayOf;
1272 template AssocArrayOf(T : V[K], K, V)
1274 pragma(msg, "T = ", T, ", K = ", K, ", V = ", V);
1275 alias V[K] AssocArrayOf;
1279 struct SA { int[5] sa; alias sa this; }
1280 static assert(is(StaticArrayOf!SA == int[5]));
1282 struct DA { int[] da; alias da this; }
1283 static assert(is(DynamicArrayOf!DA == int[]));
1285 struct AA { int[string] aa; alias aa this; }
1286 static assert(is(AssocArrayOf!AA == int[string]));
1289 /**********************************/
1292 bool foo7359(T)(T[] a ...)
1299 assert(foo7359(1,1,1,1,1,1)); // OK
1300 assert(foo7359("abc","abc","abc","abc")); // NG
1303 /**********************************/
1312 static assert(!__traits(compiles, t7363!().t7363 == 0)); // Assertion fails
1313 static assert(t7363!() == 0); // Error: void has no value
1324 static assert(!__traits(compiles, u7363!().u7363 == 0)); // Assertion fails
1325 static assert(u7363!() == 0); // Error: void has no value
1327 /**********************************/
1329 struct S4371(T ...) { }
1331 alias S4371!("hi!") t;
1333 static if (is(t U == S4371!(U))) { }
1335 /**********************************/
1338 void t7416(alias a)() if(is(typeof(a())))
1346 /**********************************/
1351 void test(T, bool a = true)(T t)
1359 auto test = new Test7563;
1360 pragma(msg, typeof(test.test!(int, true)).stringof);
1361 pragma(msg, typeof(test.test!(int)).stringof); // Error: expression (test.test!(int)) has no type
1364 /**********************************/
1369 Tr fn7572(Tr, T...)(T t) { return 1; }
1371 Tr Fn7572(Tr, T...)(T t) { return 2; }
1375 F7572 f = new F7572();
1376 int delegate() dg = &f.fn7572!int;
1379 int function() fn = &Fn7572!int;
1383 /**********************************/
1388 void opAssign()(T value) {}
1393 @property ref inout(T) get()() inout { return val; } // template
1399 @property ref auto get()() inout { return val; } // template + auto return
1411 shared(X7580!int) sx;
1412 static assert(!__traits(compiles, s = sx));
1415 /**********************************/
1418 extern(C) alias void function() Callback;
1420 template W7585a(alias dg)
1422 //pragma(msg, typeof(dg));
1423 extern(C) void W7585a() { dg(); }
1428 static void f7585a(){}
1429 Callback cb1 = &W7585a!(f7585a); // OK
1430 static assert(!__traits(compiles,
1433 Callback cb2 = &W7585a!(f7585b); // NG
1436 Callback cb3 = &W7585a!((){}); // NG -> OK
1437 Callback cb4 = &W7585a!(function(){}); // OK
1438 static assert(!__traits(compiles,
1440 Callback cb5 = &W7585a!(delegate(){}); // NG
1443 static int global; // global data
1444 Callback cb6 = &W7585a!((){return global;}); // NG -> OK
1445 static assert(!__traits(compiles,
1448 Callback cb7 = &W7585a!((){return n;}); // NG
1452 /**********************************/
1455 template T7643(A...){ alias A T7643; }
1457 alias T7643!(long, "x", string, "y") Specs7643;
1459 alias T7643!( Specs7643[] ) U7643; // Error: tuple A is used as a type
1461 /**********************************/
1464 inout(int)[3] id7671n1 ( inout(int)[3] );
1465 inout( U )[n] id7671x1(U, size_t n)( inout( U )[n] );
1467 shared(inout int)[3] id7671n2 ( shared(inout int)[3] );
1468 shared(inout U )[n] id7671x2(U, size_t n)( shared(inout U )[n] );
1472 static assert(is( typeof( id7671n1( (immutable(int)[3]).init ) ) == immutable(int[3]) ));
1473 static assert(is( typeof( id7671x1( (immutable(int)[3]).init ) ) == immutable(int[3]) ));
1475 static assert(is( typeof( id7671n2( (immutable(int)[3]).init ) ) == immutable(int[3]) ));
1476 static assert(is( typeof( id7671x2( (immutable(int)[3]).init ) ) == immutable(int[3]) ));
1479 /************************************/
1482 T foo7672(T)(T a){ return a; }
1484 void test7672(inout(int[]) a = null, inout(int*) p = null)
1486 static assert(is( typeof( a ) == inout(int[]) ));
1487 static assert(is( typeof(foo7672(a)) == inout(int)[] ));
1489 static assert(is( typeof( p ) == inout(int*) ));
1490 static assert(is( typeof(foo7672(p)) == inout(int)* ));
1493 /**********************************/
1496 U[] id7684(U)( U[] );
1497 shared(U[]) id7684(U)( shared(U[]) );
1502 static assert(is( typeof(id7684(x)) == shared(int)[] ));
1505 /**********************************/
1508 void match7694(alias m)()
1510 m.foo(); //removing this line suppresses ice in both cases
1518 //next line causes ice
1526 /**********************************/
1531 T to7755(A...)(A args)
1533 return toImpl7755!T(args);
1537 T toImpl7755(T, S)(S value)
1542 template Foo7755(T){}
1548 if (is(typeof(to7755!string(Foo7755!int)))){}
1552 /**********************************/
1554 U[] id11a(U)( U[] );
1555 inout(U)[] id11a(U)( inout(U)[] );
1556 inout(U[]) id11a(U)( inout(U[]) );
1557 inout(shared(U[])) id11a(U)( inout(shared(U[])) );
1559 void test11a(inout int _ = 0)
1561 shared(const(int))[] x;
1562 static assert(is( typeof(id11a(x)) == shared(const(int))[] ));
1565 static assert(is( typeof(id11a(y)) == shared(int)[] ));
1567 inout(U)[n] idz(U, size_t n)( inout(U)[n] );
1569 inout(shared(bool[1])) z;
1570 static assert(is( typeof(idz(z)) == inout(shared(bool[1])) ));
1573 inout(U[]) id11b(U)( inout(U[]) );
1577 alias const(shared(int)[]) T;
1578 static assert(is(typeof(id11b(T.init)) == const(shared(int)[])));
1581 /**********************************/
1584 void f7769(K)(inout(K) value){}
1590 /**********************************/
1593 template A7812(T...) {}
1595 template B7812(alias C) if (C) {}
1599 alias B7812!(A7812!(NonExistent!())) D7812;
1602 static assert(!__traits(compiles, D7812!()));
1604 /**********************************/
1607 inout(T)* foo(T)(inout(T)* t)
1609 static assert(is(T == int*));
1613 inout(T)* bar(T)(inout(T)* t)
1624 /**********************************/
1627 struct Boo7933(size_t dim){int a;}
1628 struct Baa7933(size_t dim)
1631 //Boo7933!1 a; //(1) This version causes no errors
1634 auto foo7933()(Boo7933!1 b){return b;}
1635 //auto fuu7933(Boo7933!1 b){return b;} //(2) This line neutralizes the error
1639 Baa7933!1 a; //(3) This line causes the error message
1640 auto b = foo7933(Boo7933!1(1));
1643 /**********************************/
1646 struct Tuple8094(T...) {}
1648 template getParameters8094(T, alias P)
1650 static if (is(T t == P!U, U...))
1651 alias U getParameters8094;
1653 static assert(false);
1658 alias getParameters8094!(Tuple8094!(int, string), Tuple8094) args;
1661 /**********************************/
1663 struct Tuple12(T...)
1668 static if (is(typeof(this) t == X!U, U...))
1669 alias U getParameters;
1671 static assert(false);
1677 Tuple12!(int, string) t;
1681 /**********************************/
1684 struct Foo14290(int i) {}
1685 alias Foo14290a = Foo14290!1;
1686 static assert(!is(Foo14290!2 == Foo14290a!T, T...));
1688 /**********************************/
1693 struct X8125(alias a) {}
1695 template Y8125a(T : A!f, alias A, alias f) {} //OK
1696 template Y8125b(T : A!foo8125, alias A) {} //NG
1700 alias Y8125a!(X8125!foo8125) y1;
1701 alias Y8125b!(X8125!foo8125) y2;
1704 /**********************************/
1707 struct B13(TT...) {}
1709 struct D13(T1, TT...) {}
1710 struct E13(T1, T2) {}
1711 struct F13(T1, T2, TT...) {}
1713 template Test13(alias X)
1715 static if (is(X x : P!U, alias P, U...))
1718 enum Test13 = false;
1723 static assert(Test13!( A13!() ));
1724 static assert(Test13!( B13!(int) ));
1725 static assert(Test13!( B13!(int, double) ));
1726 static assert(Test13!( B13!(int, double, string) ));
1727 static assert(Test13!( C13!(int) ));
1728 static assert(Test13!( D13!(int) ));
1729 static assert(Test13!( D13!(int, double) ));
1730 static assert(Test13!( D13!(int, double, string) ));
1731 static assert(Test13!( E13!(int, double) ));
1732 static assert(Test13!( F13!(int, double) ));
1733 static assert(Test13!( F13!(int, double, string) ));
1734 static assert(Test13!( F13!(int, double, string, bool) ));
1737 /**********************************/
1739 struct A14(T, U, int n = 1)
1743 template Test14(alias X)
1745 static if (is(X x : P!U, alias P, U...))
1753 alias A14!(int, double) Type;
1754 alias Test14!Type Params;
1755 static assert(Params.length == 3);
1756 static assert(is(Params[0] == int));
1757 static assert(is(Params[1] == double));
1758 static assert( Params[2] == 1);
1761 /**********************************/
1762 // test for evaluateConstraint assertion
1764 bool canSearchInCodeUnits15(C)(dchar c)
1773 auto b = canSearchInCodeUnits15!char(needle);
1776 /**********************************/
1781 class B8129 : A8129 {}
1783 int foo8129(T : A8129)(X8129 x) { return 1; }
1784 int foo8129(T : A8129)(X8129 x, void function (T) block) { return 2; }
1786 int bar8129(T, R)(R range, T value) { return 1; }
1788 int baz8129(T, R)(R range, T value) { return 1; }
1789 int baz8129(T, R)(R range, Undefined value) { return 2; }
1794 assert(x.foo8129!B8129() == 1);
1795 assert(x.foo8129!B8129((a){}) == 2);
1796 assert(foo8129!B8129(x) == 1);
1797 assert(foo8129!B8129(x, (a){}) == 2);
1798 assert(foo8129!B8129(x) == 1);
1799 assert(foo8129!B8129(x, (B8129 b){}) == 2);
1801 ubyte[] buffer = [0, 1, 2];
1802 assert(bar8129!ushort(buffer, 915) == 1);
1804 // While deduction, parameter type 'Undefined' shows semantic error.
1805 static assert(!__traits(compiles, {
1806 baz8129!ushort(buffer, 915);
1810 /**********************************/
1815 static struct S { template t(){ int t; } }
1818 assert(cast(void*)&s1 != cast(void*)&s2 );
1819 assert(cast(void*)&s1 != cast(void*)&s1.t!());
1820 assert(cast(void*)&s2 != cast(void*)&s2.t!());
1821 assert(cast(void*)&s1.t!() == cast(void*)&s2.t!());
1823 assert(s2.t!() == 256);
1826 /**********************************/
1833 static assert(is(typeof(this) == T));
1835 void cfoo(this T)() const
1837 static assert(is(typeof(this) == const(T)));
1839 void sfoo(this T)() shared
1841 static assert(is(typeof(this) == shared(T)));
1843 void scfoo(this T)() shared const
1845 static assert(is(typeof(this) == shared(const(T))));
1847 void ifoo(this T)() immutable
1849 static assert(is(typeof(this) == immutable(T)));
1859 shared const X8669 scx;
1873 static assert(!is(typeof( mx.sfoo() )));
1874 static assert(!is(typeof( cx.sfoo() )));
1879 static assert(!is(typeof( mx.scfoo() )));
1880 static assert(!is(typeof( cx.scfoo() )));
1885 static assert(!is(typeof( mx.ifoo() )));
1886 static assert(!is(typeof( cx.ifoo() )));
1888 static assert(!is(typeof( sx.ifoo() )));
1889 static assert(!is(typeof( scx.ifoo() )));
1892 /**********************************/
1895 template TypeTuple8833(T...) { alias TypeTuple = T; }
1897 void func8833(alias arg)() { }
1903 alias TypeTuple8833!(
1909 /**********************************/
1912 void f8976(ref int) { }
1925 static assert(! __traits(compiles, h8976!()() ) ); // causes error
1926 static assert(!is(typeof( h8976!()() )));
1930 static assert(! __traits(compiles, h8976!()() ) );
1931 static assert(!is(typeof( h8976!()() )));
1934 /****************************************/
1937 const int n8940; // or `immutable`
1938 static this() { n8940 = 3; }
1940 void f8940(T)(ref int val)
1946 static assert(!__traits(compiles, f8940!void(n8940))); // fails
1950 static assert(!__traits(compiles, f8940!void(n8940)));
1951 //assert(n8940 == 3); // may pass as compiler caches comparison result
1952 //assert(n8940 != 4); // may pass but likely will fail
1955 /**********************************/
1958 class A6969() { alias C6969!() C1; }
1959 class B6969 { alias A6969!() A1; }
1960 class C6969() : B6969 {}
1962 struct A8990(T) { T t; }
1963 struct B8990(T) { A8990!T* a; }
1964 struct C8990 { B8990!C8990* b; }
1966 /**********************************/
1969 template Inst9018(alias Template, T)
1971 alias Template!T Inst;
1974 template Template9018(T)
1976 enum Template9018 = T;
1979 static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert passes
1980 static assert(!__traits(compiles, Inst9018!(Template9018, int))); // Assert fails
1982 /**********************************/
1998 auto c = new C9022();
1999 auto d = new D9022();
2000 auto cx = C9022.X();
2001 auto dx = D9022.X();
2003 void foo1(T)(T, T.X) { static assert(is(T == C9022)); }
2004 void foo2(T)(T.X, T) { static assert(is(T == C9022)); }
2008 void hoo1(T)(T, T.B) { static assert(is(T == C9022)); }
2009 void hoo2(T)(T.B, T) { static assert(is(T == C9022)); }
2013 void bar1(alias A)(A.C9022, A.D9022) { static assert(A.stringof == "module breaker"); }
2014 void bar2(alias A)(A.D9022, A.C9022) { static assert(A.stringof == "module breaker"); }
2018 void var1(alias A)(A.C9022, A.D9022.X) { static assert(A.stringof == "module breaker"); }
2019 void var2(alias A)(A.D9022.X, A.C9022) { static assert(A.stringof == "module breaker"); }
2023 void baz(T)(T.X t, T.X u) { }
2024 static assert(!__traits(compiles, baz(cx, dx)));
2027 /**********************************/
2030 mixin template node9026()
2032 static if (is(this == struct))
2033 alias typeof(this)* E;
2035 alias typeof(this) E;
2039 struct list9026(alias N)
2051 list9026!(A9026.L1) g9026_l1;
2052 list9026!(A9026.L2) g9026_l2;
2056 list9026!(A9026.L1) l9026_l1;
2057 list9026!(A9026.L2) l9026_l2;
2060 /**********************************/
2063 mixin template Foo9038()
2065 string data = "default";
2074 void check_data9038(alias M, T)(T obj)
2076 //writeln(M.stringof);
2077 assert(obj.data == "Bar");
2078 assert(obj.f.data == "F");
2083 auto bar = new Bar9038;
2087 assert(bar.data == "Bar");
2088 assert(bar.f.data == "F");
2090 check_data9038!(Bar9038)(bar);
2091 check_data9038!(Bar9038.f)(bar);
2092 check_data9038!(bar.f)(bar);
2095 /**********************************/
2102 void f() { foo9050(A9050!int()); }
2105 auto foo9050()(A9050!int base) pure
2110 auto s9050 = foo9050(A9050!int());
2112 /**********************************/
2113 // 10936 (dup of 9050)
2115 struct Vec10936(string s)
2117 auto foo(string v)()
2119 return Vec10936!(v)();
2125 auto p = v.foo!"sup";
2131 /**********************************/
2134 template forward9076(args...)
2136 @property forward9076()(){ return args[0]; }
2143 assert(a == forward9076!b);
2146 /**********************************/
2149 template isFunction9083(X...) if (X.length == 1)
2151 enum isFunction9083 = true;
2156 static string func(alias Class)()
2158 foreach (m; __traits(allMembers, Class))
2160 pragma(msg, m); // prints "func"
2161 enum x1 = isFunction9083!(mixin(m)); //NG
2162 enum x2 = isFunction9083!(func); //OK
2167 enum nothing9083 = S9083.func!S9083();
2171 int x; // some class members
2175 void templateFunc(T)(const T obj)
2177 enum x1 = isFunction9083!(mixin("x")); // NG
2178 enum x2 = isFunction9083!(x); // NG
2184 /**********************************/
2187 template Id(alias A) { alias Id = A; }
2188 template ErrId(alias A) { static assert(0); }
2189 template TypeTuple9100(TL...) { alias TypeTuple9100 = TL; }
2195 int fun() { return value; }
2196 int tfun(T)() { return value; }
2197 TypeTuple9100!(int, long) field;
2202 auto c = new C9100();
2205 alias t1a = Id!(c.fun); // OK
2206 alias t1b = Id!(this.fun); // Prints weird error, bad
2207 // -> internally given TOKdotvar
2208 assert(t1a() == this.value);
2209 assert(t1b() == this.value);
2211 alias t2a = Id!(c.tfun); // OK
2212 static assert(!__traits(compiles, ErrId!(this.tfun)));
2213 alias t2b = Id!(this.tfun); // No error occurs, why?
2214 // -> internally given TOKdottd
2215 assert(t2a!int() == this.value);
2216 assert(t2b!int() == this.value);
2218 alias t3a = Id!(foo9100); // OK
2219 alias t3b = Id!(mixin("foo9100")); // Prints weird error, bad
2220 // -> internally given TOKtemplate
2221 assert(t3a() == 10);
2222 assert(t3b() == 10);
2224 assert(field[0] == 0);
2225 alias t4a = TypeTuple9100!(field); // NG
2226 alias t4b = TypeTuple9100!(GetField9100!()); // NG
2227 t4a[0] = 1; assert(field[0] == 1);
2228 t4b[0] = 2; assert(field[0] == 2);
2232 int foo9100()() { return 10; }
2233 template GetField9100() { alias GetField9100 = C9100.field[0]; }
2237 (new C9100()).test();
2240 /**********************************/
2245 template ForwardCtorNoId()
2247 this() {} // default constructor
2248 void foo() { 0 = 1; } // wrong code
2251 enum x9101 = __traits(compiles, Node9101.ForwardCtorNoId!());
2253 /**********************************/
2256 struct Foo9124a(N...)
2261 public void opAssign (T) (T other)
2262 if (is(T unused == Foo9124a!(_N), _N...))
2264 _val = other._val; // compile error
2265 this._val = other._val; // explicit this make it work
2268 public auto opUnary (string op) () if (op == "~") {
2269 Foo9124a!(SIZE) result = this;
2276 Foo9124a!(28) b = ~a;
2281 template Foo9124b(T, U, string OP)
2284 alias Foo9124b = Foo9124b!(false, true, N);
2286 struct Foo9124b(bool S, bool L, N...)
2290 void someFunction() const {
2291 auto data1 = _a; // Does not compile
2292 auto data2 = this._a; // <--- Compiles
2294 auto opBinary(string op, T)(T) {
2295 Foo9124b!(typeof(this), T, op) test;
2300 auto p = Foo9124b!(false, false, 5)();
2301 auto q = Foo9124b!(false, false, 5)();
2306 /**********************************/
2309 struct Foo9143a(bool S, bool L)
2312 Foo9143a!(S, false) x1; // compiles if this line commented
2313 static if(S) Foo9143a!(true, false) x2;
2314 else Foo9143a!(false, false) x2;
2316 this(T)(T other) // constructor
2317 if (is(T unused == Foo9143a!(P, Q), bool P, bool Q)) { }
2320 struct Foo9143b(bool L, size_t N)
2323 bar!(Foo9143b!(false, N))(); // line 7
2324 // -> move to before the baaz semantic
2327 bar!(Foo9143b!(false, 2LU))(); // line 3
2328 bar!(Foo9143b!(true, 2LU))(); // line 4
2329 bar!(Foo9143b!(L, N))(); // line 5
2330 bar!(Foo9143b!(true, N))(); // line 6
2331 bar!(Foo9143b!(false, N))(); // line 7
2334 if (is(T unused == Foo9143b!(_L, _N), bool _L, size_t _N))
2340 Foo9143a!(false, true) k = Foo9143a!(false, false)();
2342 auto p = Foo9143b!(true, 2LU)();
2345 /**********************************/
2348 template Foo9266(T...)
2354 alias Foo9266!int f;
2361 /**********************************/
2366 void butPleaseDontUseMe()()
2367 if (is(unitType9361!((this)))) // !
2371 template isUnit9361(alias T) if ( is(T)) {}
2372 template isUnit9361(alias T) if (!is(T)) {}
2374 template unitType9361(alias T) if (isUnit9361!T) {}
2379 static assert(!__traits(compiles, u.butPleaseDontUseMe())); // crashes
2382 /**********************************/
2387 static A foo(A)(A a)
2400 assert(s.bar() == 84);
2403 /**********************************/
2406 template t9578(alias f) { void tf()() { f(); } }
2408 void g9578a(alias f)() { f(); } // Error -> OK
2409 void g9578b(alias ti)() { ti.tf(); } // Error -> OK
2414 int m() { return i; }
2416 g9578a!(t9578!m.tf)();
2420 /**********************************/
2423 int foo9596a(K, V)(inout( V [K])) { return 1; }
2424 int foo9596a(K, V)(inout(shared(V) [K])) { return 2; }
2426 int foo9596b(K, V)(inout( V [K])) { return 1; }
2427 int foo9596b(K, V)(inout( const(V) [K])) { return 3; }
2429 int foo9596c(K, V)(inout(shared(V) [K])) { return 2; }
2430 int foo9596c(K, V)(inout( const(V) [K])) { return 3; }
2432 int foo9596d(K, V)(inout( V [K])) { return 1; }
2433 int foo9596d(K, V)(inout(shared(V) [K])) { return 2; }
2434 int foo9596d(K, V)(inout( const(V) [K])) { return 3; }
2436 int foo9596e(K, V)(inout(shared(V) [K])) { return 2; }
2437 int foo9596e(K, V)(inout( V [K])) { return 1; }
2438 int foo9596e(K, V)(inout( const(V) [K])) { return 3; }
2442 shared(int)[int] aa;
2443 static assert(!__traits(compiles, foo9596a(aa)));
2445 assert(foo9596b(aa) == 1);
2446 assert(foo9596c(aa) == 2);
2448 static assert(!__traits(compiles, foo9596d(aa)));
2449 static assert(!__traits(compiles, foo9596e(aa)));
2452 /******************************************/
2455 struct S9806a(alias x)
2459 enum expr9806a = 0 * 0;
2460 alias S9806a!expr9806a T9806a;
2464 struct S9806b(alias x)
2469 alias S9806b!expr Next;
2472 alias S9806b!1 One9806b;
2473 alias S9806b!0.Next!() OneAgain9806b;
2481 enum expr = x[0] + 1;
2482 alias S9806c!expr Next;
2485 alias S9806c!1 One9806c;
2486 alias S9806c!0.Next!() OneAgain9806c;
2488 /******************************************/
2493 enum DA : int[] { a = [1,2,3] }
2496 static assert(is(DA : int[]));
2497 void fda1(int[] a) {}
2498 void fda2(T)(T[] a) {}
2502 enum SA : int[3] { a = [1,2,3] }
2505 static assert(is(SA : int[3]));
2506 void fsa1(int[3] a) {}
2507 void fsa2(T)(T[3] a) {}
2508 void fsa3(size_t d)(int[d] a) {}
2509 void fsa4(T, size_t d)(T[d] a) {}
2515 enum AA : int[int] { a = null }
2518 static assert(is(AA : int[int]));
2519 void faa1(int[int] a) {}
2520 void faa2(V)(V[int] a) {}
2521 void faa3(K)(int[K] a) {}
2522 void faa4(K, V)(V[K] a) {}
2529 /******************************************/
2532 bool foo9874() { return true; }
2533 void bar9874(T)(T) if (foo9874()) {} // OK
2534 void baz9874(T)(T) if (foo9874) {} // error
2543 /******************************************/
2547 void foo(int[1][]) {}
2548 void boo()(int[1][]){}
2549 struct X(T...) { static void xoo(T){} }
2550 struct Y(T...) { static void yoo()(T){} }
2551 struct Z(T...) { static void zoo(U...)(T, U){} }
2553 struct V(T...) { static void voo()(T, ...){} }
2554 struct W(T...) { static void woo()(T...){} }
2556 struct R(T...) { static void roo(U...)(int, U, T){} }
2563 X!(int[1][]).xoo([[10]]);
2568 Y!(int, int[]).yoo(1, [10]);
2569 static assert(!__traits(compiles, Y!().yoo(1)));
2570 static assert(!__traits(compiles, Y!(int).yoo("a")));
2571 static assert(!__traits(compiles, Y!().yoo!(int)()));
2575 Z!().zoo([1], [1:1]);
2576 Z!(int, string).zoo(1, "a");
2577 Z!(int, string).zoo(1, "a", [1], [1:1]);
2579 static assert(!__traits(compiles, Z!().zoo!()(1))); // (none) <- 1
2580 static assert(!__traits(compiles, Z!(int).zoo!()())); // int <- (none)
2581 static assert(!__traits(compiles, Z!(int).zoo!()(""))); // int <- ""
2582 static assert(!__traits(compiles, Z!().zoo!(int)())); // int <- (none)
2583 static assert(!__traits(compiles, Z!().zoo!(int)(""))); // int <- ""
2587 V!(int, long).voo(1,2,3);
2588 static assert(!__traits(compiles, V!(int).voo())); // int <- (none)
2589 static assert(!__traits(compiles, V!(int, long).voo(1))); // long <- (none)
2590 static assert(!__traits(compiles, V!(int, string).voo(1,2,3))); // string <- 2
2593 //W!().woo(1, 2, 3); // Access Violation
2594 { // this behavior is consistent with:
2595 //alias TL = TypeTuple!();
2596 //void foo(TL...) {}
2597 //foo(1, 2, 3); // Access Violation
2598 //pragma(msg, typeof(foo)); // void(...) -> D-style variadic function?
2600 W!(int,int[]).woo(1,2,3);
2601 W!(int,int[2]).woo(1,2,3);
2602 static assert(!__traits(compiles, W!(int,int,int).woo(1,2,3))); // int... <- 2
2603 static assert(!__traits(compiles, W!(int,int).woo(1,2))); // int... <- 2
2604 static assert(!__traits(compiles, W!(int,int[2]).woo(1,2))); // int[2]... <- 2
2606 R!().roo(1, "", []);
2607 R!(int).roo(1, "", [], 1);
2608 R!(int, string).roo(1, "", [], 1, "");
2609 R!(int, string).roo(1, 2, "");
2610 static assert(!__traits(compiles, R!(int).roo(1, "", []))); // int <- []
2611 static assert(!__traits(compiles, R!(int, int).roo(1, "", []))); // int <- []
2612 static assert(!__traits(compiles, R!(int, string).roo(1, 2, 3))); // string <- 3
2615 struct Tuple(T...) { this()(T values) {} }
2616 alias T = Tuple!(int[1][]);
2620 /******************************************/
2633 static assert(is(typeof(g) == delegate));
2641 S9971.init.goo!()();
2644 /******************************************/
2649 struct S1(T) { T value; }
2650 auto func1(T)(T value) { return value; }
2651 static assert(is(S1!int == struct));
2652 assert(func1(10) == 10);
2654 template S2(T) { struct S2 { T value; } }
2655 template func2(T) { auto func2(T value) { return value; } }
2656 static assert(is(S2!int == struct));
2657 assert(func2(10) == 10);
2659 template X(T) { alias X = T[3]; }
2660 static assert(is(X!int == int[3]));
2663 template Y(T) { alias Y = T[typeof(a)]; }
2664 static assert(is(Y!double == double[int]));
2667 template Z() { alias Z = v; }
2673 /******************************************/
2675 enum T8848a(int[] a) = a;
2676 enum T8848b(int[int] b) = b;
2677 enum T8848c(void* c) = c;
2679 static assert(T8848a!([1,2,3]) == [1,2,3]);
2680 static assert(T8848b!([1:2,3:4]) == [1:2,3:4]);
2681 static assert(T8848c!(null) == null);
2683 /******************************************/
2686 auto initS9990() { return "hi"; }
2688 class C9990(alias init) {}
2690 alias SC9990 = C9990!(initS9990);
2692 /******************************************/
2695 struct assumeSize10067(alias F) {}
2697 template useItemAt10067(size_t idx, T)
2701 alias useItemAt10067 = assumeSize10067!(impl);
2704 useItemAt10067!(0, char) mapS10067;
2706 /******************************************/
2709 void bug4072(T)(T x)
2710 if (is(typeof(bug4072(x))))
2713 static assert(!is(typeof(bug4072(7))));
2715 /******************************************/
2718 template foo10074(F)
2720 enum foo10074 = false;
2722 bool foo10074(F)(F f)
2728 static assert(!is(typeof(foo10074(1))));
2730 /******************************************/
2733 // [a-c] IFTI can find syntactic eponymous member
2734 template foo10083a(T)
2736 int foo10083a(double) { return 1; }
2737 int foo10083a(T) { return 2; }
2739 template foo10083b(T)
2741 int foo10083b(T) { return 1; }
2742 int foo10083b(T, T) { return 2; }
2744 template foo10083c1(T)
2746 int foo10083c1(T) { return 1; }
2747 static if (true) { int x; }
2749 template foo10083c2(T)
2751 int foo10083c2(T) { return 1; }
2752 static if (true) { int x; } else { int y; }
2755 // [d-f] IFTI cannot find syntactic eponymous member
2756 template foo10083d1(T)
2760 int foo10083d1(T) { return 1; }
2766 template foo10083d2(T)
2773 int foo10083d2(T) { return 1; }
2776 template foo10083e(T)
2780 int foo10083e(double arg) { return 1; }
2782 int foo10083e(T arg) { return 2; }
2784 template foo10083f(T)
2788 int foo10083f(T) { return 1; }
2792 int foo10083f(T) { return 2; }
2798 assert(foo10083a(1) == 2);
2799 assert(foo10083a!int(1) == 2);
2800 assert(foo10083a!int(1.0) == 1);
2801 static assert(!__traits(compiles, foo10083a!double(1)));
2802 static assert(!__traits(compiles, foo10083a!double(1.0)));
2803 static assert(!__traits(compiles, foo10083a!real(1)));
2804 assert(foo10083a!real(1.0) == 1);
2805 assert(foo10083a!real(1.0L) == 2);
2807 assert(foo10083b(2) == 1);
2808 assert(foo10083b(3, 4) == 2);
2809 static assert(!__traits(compiles, foo10083b(2, "")));
2811 assert(foo10083c1(1) == 1);
2812 assert(foo10083c2(1) == 1);
2814 static assert(!__traits(compiles, foo10083d1(2)));
2815 static assert(!__traits(compiles, foo10083d2(2)));
2816 static assert(!__traits(compiles, foo10083e(3)));
2817 static assert(!__traits(compiles, foo10083f(3)));
2820 /******************************************/
2823 template ReturnType10134(alias func)
2825 static if (is(typeof(func) R == return))
2826 alias R ReturnType10134;
2831 struct Result10134(T) {}
2833 template getResultType10134(alias func)
2835 static if(is(ReturnType10134!(func.exec) _ == Result10134!(T), T))
2837 alias getResultType10134 = T;
2841 template f10134(alias func)
2843 Result10134!(getResultType10134!(func)) exec(int i)
2845 return typeof(return)();
2851 Result10134!(double) exec(int i)
2853 return b10134!().exec(i);
2859 Result10134!(double) exec(int i)
2861 return f10134!(a10134!()).exec(i);
2865 pragma(msg, getResultType10134!(a10134!()));
2867 /******************************************/
2874 this()(inout T value) inout {}
2877 struct S { S[] array; }
2879 auto ns = Nullable!S(s);
2881 class C { C[] array; }
2883 auto nc = Nullable!C(c);
2886 /******************************************/
2889 template triggerIssue10498a()
2891 enum triggerIssue10498a = __traits(compiles, { T10498a; });
2894 template PackedGenericTuple10498a(Args...)
2897 enum e = triggerIssue10498a!();
2904 alias PackedGenericTuple10498a!S10498a T10498a;
2910 static assert(is(t.Tuple[0])); // Fails -> OK
2915 template triggerIssue10498b(A...)
2917 enum triggerIssue10498b = __traits(compiles, { auto a = A[0]; });
2920 template PackedGenericTuple10498b(Args...)
2923 enum e = triggerIssue10498b!Args;
2928 struct S {} // The fact `S` is in `T` causes the problem
2929 alias PackedGenericTuple10498b!S T10498b;
2935 static assert(is(t.Tuple[0]));
2938 /******************************************/
2944 mixin Yield10537!q{ ; };
2947 auto skipStrings10537(T)(T source)
2952 mixin template Yield10537(dstring code)
2954 alias X = typeof({ enum x = rewriteCode10537(code); }());
2957 dstring rewriteCode10537(dstring code)
2959 skipStrings10537(code); // IFTI causes forward reference
2963 /******************************************/
2966 template Template10558() {}
2968 struct Struct10558(alias T){}
2970 alias bar10558 = foo10558!(Template10558!());
2972 template foo10558(alias T)
2974 alias foobar = Struct10558!T;
2978 alias a = foo10558!T;
2982 /******************************************/
2989 int put()(const(E)[] data)
2994 int put()(const(dchar)[] data) if (!is(E == dchar))
2999 int put(C)(const(C)[] data) if (!is(C == dchar) && !is(E == C))
3006 assert(x.put("abcde"c) == 1); // OK: hit 1
3007 assert(x.put("abcde"w) == 3); // NG: this should hit 3
3008 assert(x.put("abcde"d) == 2); // OK: hit 2
3011 /******************************************/
3014 inout(T[]) fromString11242(T)(inout(char[]) s, T[] dst)
3022 fromString11242(a, a);
3025 /******************************************/
3028 void foo10811a(R1, R2)(R1, R2) {}
3029 template foo10811a(alias pred) { void foo10811a(R1, R2)(R1, R2) {} }
3031 template foo10811b(alias pred) { void foo10811b(R1, R2)(R1, R2) {} }
3032 void foo10811b(R1, R2)(R1, R2) {}
3037 foo10811a!(a => a)(1, 2);
3040 foo10811b!(a => a)(1, 2);
3043 /******************************************/
3046 template A10969(T, U...) { alias A10969 = T; }
3047 void foo10969(T, U...)(A10969!(T, U) a) {}
3049 template B10969(T, U) { alias B10969 = T; }
3050 void bar10969(T, U...)(B10969!(T, U[0]) a) {}
3054 foo10969!(int, float)(3);
3055 bar10969!(int, float)(3);
3058 /******************************************/
3061 struct SmartPtr11271(T)
3064 void opAssign(U)(auto ref U rh) {}
3069 SmartPtr11271!Object a;
3070 a = SmartPtr11271!Object();
3073 /******************************************/
3080 void put(alias fun)() { fun!int(); }
3084 static void foo(T)() {}
3091 static void bar(alias fun)() { fun(); }
3098 static struct Foo(alias fun)
3100 auto call() { return fun(); }
3103 auto getVar() { return var; }
3105 assert(foo.call() == var);
3107 assert(foo.call() == var);
3124 /******************************************/
3127 struct Pack11553(T ...)
3130 enum length = T.length;
3133 template isPack11553(TList ...)
3135 static if (TList.length == 1 && is(Pack11553!(TList[0].Unpack) == TList[0]))
3137 enum isPack11553 = true;
3141 enum isPack11553 = false;
3145 template PartialApply11553(alias T, uint argLoc, Arg ...)
3146 if (Arg.length == 1)
3148 template PartialApply11553(L ...)
3150 alias PartialApply11553 = T!(L[0 .. argLoc], Arg, L[argLoc .. $]);
3154 template _hasLength11553(size_t len, T)
3156 static if (T.length == len)
3158 enum _hasLength11553 = true;
3162 enum _hasLength11553 = false;
3166 alias _hasLength11553(size_t len) = PartialApply11553!(._hasLength11553, 0, len);
3169 alias hl11553 = _hasLength11553!1;
3172 static if (!isPack11553!hl11553) { pragma(msg, "All good 1"); }
3175 static if ( hl11553!(Pack11553!(5))) { pragma(msg, "All good 2"); }
3177 static if (!hl11553!(Pack11553!( ))) { pragma(msg, "All good 3"); }
3179 /******************************************/
3182 enum E11818 { e0, e1 }
3184 struct SortedRange11818
3186 void fun(E11818 e = true ? E11818.e0 : E11818.e1)()
3197 /******************************************/
3207 struct Bar(alias foo) {}
3209 enum bar1 = Bar!(Foo(["a": 1]))();
3210 enum bar2 = Bar!(Foo(["a": 1]))();
3211 static assert(is(typeof(bar1) == typeof(bar2)));
3213 enum foo1 = Foo(["a": 1]);
3214 enum foo2 = Foo(["b": -1]);
3215 static assert(!__traits(isSame, foo1, foo2));
3216 enum bar3 = Bar!foo1();
3217 enum bar4 = Bar!foo2();
3218 static assert(!is(typeof(bar3) == typeof(bar4)));
3221 /******************************************/
3226 auto test(int v)() {}
3227 auto test(int v)(string) {}
3237 auto foo = new Foo11872();
3241 // ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti)
3242 foo.test!2(); // works
3243 test!2(); // works <- fails
3244 test!2; // works <- fails
3246 // ScopeExp(ti) -> DotTemplateInstanceExp(wthis, ti) -> DotExp(wthis, ScopeExp)
3247 foo.Bar!int.test(1); // works
3248 Bar!int.test(1); // works <- fails
3252 /******************************************/
3261 t = null; // CTFE error -> OK
3275 static assert(test12042());
3277 /******************************************/
3282 alias T12077(alias T : Base!Args, alias Base, Args...) = Base;
3283 static assert(__traits(isSame, T12077!(S12077!int), S12077));
3285 alias U12077(alias T : Base!Args, alias Base, Args...) = Base;
3286 alias U12077( T : Base!Args, alias Base, Args...) = Base;
3287 static assert(__traits(isSame, U12077!(S12077!int), S12077));
3289 /******************************************/
3292 template Inst12262(T) { int x; }
3294 enum fqnSym12262(alias a) = 1;
3295 enum fqnSym12262(alias a : B!A, alias B, A...) = 2;
3297 static assert(fqnSym12262!(Inst12262!(Object)) == 2);
3298 static assert(fqnSym12262!(Inst12262!(Object).x) == 1);
3300 /******************************************/
3305 template AX12264(alias A1) { enum AX12264 = 1; }
3306 template AX12264(alias A2 : B!A, alias B, A...) { enum AX12264 = 2; }
3307 template AY12264(alias A1) { enum AY12264 = 1; }
3308 template AY12264(alias A2 : B!int, alias B) { enum AY12264 = 2; }
3309 template AZ12264(alias A1) { enum AZ12264 = 1; }
3310 template AZ12264(alias A2 : S12264!T, T) { enum AZ12264 = 2; }
3311 static assert(AX12264!(S12264!int) == 2);
3312 static assert(AY12264!(S12264!int) == 2);
3313 static assert(AZ12264!(S12264!int) == 2);
3315 template TX12264(T1) { enum TX12264 = 1; }
3316 template TX12264(T2 : B!A, alias B, A...) { enum TX12264 = 2; }
3317 template TY12264(T1) { enum TY12264 = 1; }
3318 template TY12264(T2 : B!int, alias B) { enum TY12264 = 2; }
3319 template TZ12264(T1) { enum TZ12264 = 1; }
3320 template TZ12264(T2 : S12264!T, T) { enum TZ12264 = 2; }
3321 static assert(TX12264!(S12264!int) == 2);
3322 static assert(TY12264!(S12264!int) == 2);
3323 static assert(TZ12264!(S12264!int) == 2);
3325 /******************************************/
3330 void foo12122(T)(T[N12122]) if(is(T == int)) {}
3338 /******************************************/
3341 template map_front12186(fun...)
3343 auto map_front12186(Range)(Range r)
3345 return fun[0](r[0]);
3351 immutable int[][] mat;
3353 mat.map_front12186!((in r) => 0); // OK
3354 mat.map_front12186!((const r) => 0); // OK
3355 mat.map_front12186!((immutable int[] r) => 0); // OK
3356 mat.map_front12186!((immutable r) => 0); // OK <- Error
3359 /******************************************/
3366 static void f(T)(T) {}
3374 /******************************************/
3377 template A12263(alias a) { int x; }
3378 template B12263(alias a) { int x; }
3380 template fqnSym12263(alias T : B12263!A, alias B12263, A...)
3382 enum fqnSym12263 = true;
3385 static assert(fqnSym12263!(A12263!(Object)));
3386 static assert(fqnSym12263!(B12263!(Object)));
3388 /******************************************/
3402 auto func1a(E)(E[], E) { return E.init; }
3403 auto func1b(E)(E, E[]) { return E.init; }
3405 static assert(is(typeof(func1a(arrS, 1)) == short));
3406 static assert(is(typeof(func1b(1, arrS)) == short));
3407 static assert(is(typeof(func1a(arrF, 1.0)) == float));
3408 static assert(is(typeof(func1b(1.0, arrF)) == float));
3409 static assert(is(typeof(func1a(arrD, 1.0L)) == double));
3410 static assert(is(typeof(func1b(1.0L, arrD)) == double));
3411 static assert(is(typeof(func1a(arrR, 1)) == real));
3412 static assert(is(typeof(func1b(1, arrR)) == real));
3413 static assert(is(typeof(func1a("str" , 'a')) == immutable char));
3414 static assert(is(typeof(func1b('a', "str" )) == immutable char));
3415 static assert(is(typeof(func1a("str"c, 'a')) == immutable char));
3416 static assert(is(typeof(func1b('a', "str"c)) == immutable char));
3417 static assert(is(typeof(func1a("str"w, 'a')) == immutable wchar));
3418 static assert(is(typeof(func1b('a', "str"w)) == immutable wchar));
3419 static assert(is(typeof(func1a("str"d, 'a')) == immutable dchar));
3420 static assert(is(typeof(func1b('a', "str"d)) == immutable dchar));
3421 static assert(is(typeof(func1a([1,2,3], 1L)) == long));
3422 static assert(is(typeof(func1b(1L, [1,2,3])) == long));
3423 static assert(is(typeof(func1a([1,2,3], 1.5)) == double));
3424 static assert(is(typeof(func1b(1.5, [1,2,3])) == double));
3425 static assert(is(typeof(func1a(["a","b"], "s"c)) == string));
3426 static assert(is(typeof(func1b("s"c, ["a","b"])) == string));
3427 static assert(is(typeof(func1a(["a","b"], "s"w)) == wstring));
3428 static assert(is(typeof(func1b("s"w, ["a","b"])) == wstring));
3429 static assert(is(typeof(func1a(["a","b"], "s"d)) == dstring));
3430 static assert(is(typeof(func1b("s"d, ["a","b"])) == dstring));
3432 auto func2a(K, V)(V[K], K, V) { return V[K].init; }
3433 auto func2b(K, V)(V, K, V[K]) { return V[K].init; }
3435 static assert(is(typeof(func2a(aa, 1, 1)) == short[short]));
3436 static assert(is(typeof(func2b(1, 1, aa)) == short[short]));
3437 static assert(is(typeof(func2a([1:10,2:20,3:30], 1L, 10L)) == long[long]));
3438 static assert(is(typeof(func2b(1L, 10L, [1:20,2:20,3:30])) == long[long]));
3440 auto func3a(T)(T, T) { return T.init; }
3441 auto func3b(T)(T, T) { return T.init; }
3443 static assert(is(typeof(func3a(arrS, null)) == short[]));
3444 static assert(is(typeof(func3b(null, arrS)) == short[]));
3445 static assert(is(typeof(func3a(arrR, null)) == real[]));
3446 static assert(is(typeof(func3b(null, arrR)) == real[]));
3447 static assert(is(typeof(func3a(cstr, "str")) == string));
3448 static assert(is(typeof(func3b("str", cstr)) == string));
3449 static assert(is(typeof(func3a(wstr, "str")) == wstring));
3450 static assert(is(typeof(func3b("str", wstr)) == wstring));
3451 static assert(is(typeof(func3a(dstr, "str")) == dstring));
3452 static assert(is(typeof(func3b("str", dstr)) == dstring));
3453 static assert(is(typeof(func3a("str1" , "str2"c)) == string));
3454 static assert(is(typeof(func3b("str1"c, "str2" )) == string));
3455 static assert(is(typeof(func3a("str1" , "str2"w)) == wstring));
3456 static assert(is(typeof(func3b("str1"w, "str2" )) == wstring));
3457 static assert(is(typeof(func3a("str1" , "str2"d)) == dstring));
3458 static assert(is(typeof(func3b("str1"d, "str2" )) == dstring));
3460 inout(V) get(K, V)(inout(V[K]) aa, K key, lazy V defaultValue) { return V.init; }
3462 short[short] hash12220;
3463 short res12220 = get(hash12220, 1, 1);
3465 short[short] hash12221;
3466 enum Key12221 : short { a }
3467 get(hash12221, Key12221.a, Key12221.a);
3469 int[][string] mapping13026;
3470 int[] v = get(mapping13026, "test", []);
3473 /******************************************/
3478 void fun(T : string)(T data) {}
3481 static assert(!__traits(compiles, fun(sa)));
3482 static assert(!__traits(compiles, { alias f = fun!(ubyte[3]); }));
3485 /******************************************/
3488 static auto encode12376(size_t sz)(dchar ch) if (sz > 1)
3495 enum x = __traits(compiles, encode12376!2(x));
3498 /******************************************/
3501 enum test12447(string str) = str; // [1]
3502 string test12447(T...)(T args) if (T.length) { return args[0]; } // [2]
3504 // With [1]: The template parameter str cannot be be deduced -> no match
3505 // With [2]: T is deduced to a type tuple (string), then match to the function call.
3506 static assert(test12447("foo") == "foo");
3508 // With [1]: template parameter str is deduced to "bar", then match.
3509 // With [2]: T is deduced to an expression tuple ("bar"), but it will make invalid the function signature (T args).
3510 // The failure should be masked silently and prefer the 1st version.
3511 static assert(test12447!("bar") == "bar");
3513 /******************************************/
3516 alias TemplateArgsOf12651(alias T : Base!Args, alias Base, Args...) = Args;
3518 struct S12651(T) { }
3520 static assert(!__traits(compiles, TemplateArgsOf12651!(S12651!int, S, float)));
3522 /******************************************/
3535 auto v = B12719!T.init;
3541 enum canDoIt12719(R) = is(typeof(W12719!R));
3546 static if (canDoIt12719!R) {}
3551 /******************************************/
3558 static assert(!__traits(compiles, bar(1)));
3560 alias foo12746 = bar;
3570 foo12746(); // instantiate
3573 /******************************************/
3576 void foo12748(S, C : typeof(S.init[0]))(S s, C c)
3582 foo12748("abc", 'd');
3585 /******************************************/
3590 void f()(inout(Object)) inout {}
3599 /******************************************/
3602 void f12880(T)(in T value) { static assert(is(T == string)); }
3603 void test12880() { f12880(string.init); }
3605 /******************************************/
3611 void m() { auto n = component13087!(this, 'x'); }
3612 void c() const { auto n = component13087!(this, 'x'); }
3613 void w() inout { auto n = component13087!(this, 'x'); }
3614 void wc() inout const { auto n = component13087!(this, 'x'); }
3615 void s() shared { auto n = component13087!(this, 'x'); }
3616 void sc() shared const { auto n = component13087!(this, 'x'); }
3617 void sw() shared inout { auto n = component13087!(this, 'x'); }
3618 void swc() shared inout const { auto n = component13087!(this, 'x'); }
3619 void i() immutable { auto n = component13087!(this, 'x'); }
3622 template component13087(alias vec, char c)
3624 alias component13087 = vec.x;
3627 /******************************************/
3630 /+void test13127(inout int = 0)
3637 inout(const int)[] wca1;
3638 inout(const int[]) wca2;
3639 immutable(int)[] ia1;
3640 immutable(int[]) ia2;
3641 shared( int)[] sma1;
3642 shared( int[]) sma2;
3643 shared( const int)[] sca1;
3644 shared( const int[]) sca2;
3645 shared(inout int)[] swma1;
3646 shared(inout int[]) swma2;
3647 shared(inout const int)[] swca1;
3648 shared(inout const int[]) swca2;
3650 /* In all cases, U should be deduced to top-unqualified type.
3653 /* Parameter is (shared) mutable
3655 U f_m(U)( U) { return null; }
3656 U fsm(U)(shared U) { return null; }
3658 static assert(is(typeof(f_m( ma1)) == int []));
3659 static assert(is(typeof(f_m( ca1)) == const(int)[]));
3660 static assert(is(typeof(f_m( ca2)) == const(int)[]));
3661 static assert(is(typeof(f_m( wma1)) == inout( int)[]));
3662 static assert(is(typeof(f_m( wma2)) == inout( int)[]));
3663 static assert(is(typeof(f_m( wca1)) == inout(const int)[]));
3664 static assert(is(typeof(f_m( wca2)) == inout(const int)[]));
3665 static assert(is(typeof(f_m( ia1)) == immutable(int)[]));
3666 static assert(is(typeof(f_m( ia2)) == immutable(int)[]));
3667 static assert(is(typeof(f_m( sma1)) == shared( int)[]));
3668 static assert(is(typeof(f_m( sma2)) == shared( int)[])); // <- shared(int[])
3669 static assert(is(typeof(f_m( sca1)) == shared( const int)[]));
3670 static assert(is(typeof(f_m( sca2)) == shared( const int)[])); // <- shared(const(int)[])
3671 static assert(is(typeof(f_m(swma1)) == shared(inout int)[]));
3672 static assert(is(typeof(f_m(swma2)) == shared(inout int)[])); // <- shared(inout(int[]))
3673 static assert(is(typeof(f_m(swca1)) == shared(inout const int)[]));
3674 static assert(is(typeof(f_m(swca2)) == shared(inout const int)[])); // <- shared(inout(const(int))[])
3676 static assert(is(typeof(fsm( ma1))) == false);
3677 static assert(is(typeof(fsm( ca1))) == false);
3678 static assert(is(typeof(fsm( ca2))) == false);
3679 static assert(is(typeof(fsm( wma1))) == false);
3680 static assert(is(typeof(fsm( wma2))) == false);
3681 static assert(is(typeof(fsm( wca1))) == false);
3682 static assert(is(typeof(fsm( wca2))) == false);
3683 static assert(is(typeof(fsm( ia1))) == false);
3684 static assert(is(typeof(fsm( ia2))) == false);
3685 static assert(is(typeof(fsm( sma1)) == shared( int)[])); // <- NG
3686 static assert(is(typeof(fsm( sma2)) == shared( int)[]));
3687 static assert(is(typeof(fsm( sca1)) == shared( const int)[])); // <- NG
3688 static assert(is(typeof(fsm( sca2)) == shared( const int)[]));
3689 static assert(is(typeof(fsm(swma1)) == shared(inout int)[])); // <- NG
3690 static assert(is(typeof(fsm(swma2)) == shared(inout int)[]));
3691 static assert(is(typeof(fsm(swca1)) == shared(inout const int)[])); // <- NG
3692 static assert(is(typeof(fsm(swca2)) == shared(inout const int)[]));
3694 /* Parameter is (shared) const
3696 U f_c(U)( const U) { return null; }
3697 U fsc(U)(shared const U) { return null; }
3699 static assert(is(typeof(f_c( ma1)) == int []));
3700 static assert(is(typeof(f_c( ca1)) == const(int)[]));
3701 static assert(is(typeof(f_c( ca2)) == const(int)[]));
3702 static assert(is(typeof(f_c( wma1)) == inout( int)[]));
3703 static assert(is(typeof(f_c( wma2)) == inout( int)[]));
3704 static assert(is(typeof(f_c( wca1)) == inout(const int)[]));
3705 static assert(is(typeof(f_c( wca2)) == inout(const int)[]));
3706 static assert(is(typeof(f_c( ia1)) == immutable(int)[]));
3707 static assert(is(typeof(f_c( ia2)) == immutable(int)[]));
3708 static assert(is(typeof(f_c( sma1)) == shared( int)[]));
3709 static assert(is(typeof(f_c( sma2)) == shared( int)[])); // <- shared(int[])
3710 static assert(is(typeof(f_c( sca1)) == shared( const int)[]));
3711 static assert(is(typeof(f_c( sca2)) == shared( const int)[])); // <- shared(const(int)[])
3712 static assert(is(typeof(f_c(swma1)) == shared(inout int)[]));
3713 static assert(is(typeof(f_c(swma2)) == shared(inout int)[])); // shared(inout(int)[])
3714 static assert(is(typeof(f_c(swca1)) == shared(inout const int)[]));
3715 static assert(is(typeof(f_c(swca2)) == shared(inout const int)[])); // shared(inout(const(int))[])
3717 static assert(is(typeof(fsc( ma1))) == false);
3718 static assert(is(typeof(fsc( ca1))) == false);
3719 static assert(is(typeof(fsc( ca2))) == false);
3720 static assert(is(typeof(fsc( wma1))) == false);
3721 static assert(is(typeof(fsc( wma2))) == false);
3722 static assert(is(typeof(fsc( wca1))) == false);
3723 static assert(is(typeof(fsc( wca2))) == false);
3724 static assert(is(typeof(fsc( ia1)) == immutable(int)[])); // <- NG
3725 static assert(is(typeof(fsc( ia2)) == immutable(int)[])); // <- NG
3726 static assert(is(typeof(fsc( sma1)) == shared( int)[])); // <- NG
3727 static assert(is(typeof(fsc( sma2)) == shared( int)[]));
3728 static assert(is(typeof(fsc( sca1)) == shared( const int)[])); // <- NG
3729 static assert(is(typeof(fsc( sca2)) == shared( const int)[]));
3730 static assert(is(typeof(fsc(swma1)) == shared(inout int)[])); // <- NG
3731 static assert(is(typeof(fsc(swma2)) == shared(inout int)[]));
3732 static assert(is(typeof(fsc(swca1)) == shared(inout const int)[])); // <- NG
3733 static assert(is(typeof(fsc(swca2)) == shared(inout const int)[]));
3735 /* Parameter is immutable
3737 U fi(U)(immutable U) { return null; }
3739 static assert(is(typeof(fi( ma1))) == false);
3740 static assert(is(typeof(fi( ca1))) == false);
3741 static assert(is(typeof(fi( ca2))) == false);
3742 static assert(is(typeof(fi( wma1))) == false);
3743 static assert(is(typeof(fi( wma2))) == false);
3744 static assert(is(typeof(fi( wca1))) == false);
3745 static assert(is(typeof(fi( wca2))) == false);
3746 static assert(is(typeof(fi( ia1)) == immutable(int)[])); // <- NG
3747 static assert(is(typeof(fi( ia2)) == immutable(int)[])); // <- NG
3748 static assert(is(typeof(fi( sma1))) == false);
3749 static assert(is(typeof(fi( sma2))) == false);
3750 static assert(is(typeof(fi( sca1))) == false);
3751 static assert(is(typeof(fi( sca2))) == false);
3752 static assert(is(typeof(fi(swma1))) == false);
3753 static assert(is(typeof(fi(swma2))) == false);
3754 static assert(is(typeof(fi(swca1))) == false);
3755 static assert(is(typeof(fi(swca2))) == false);
3757 /* Parameter is (shared) inout
3759 U f_w(U)( inout U) { return null; }
3760 U fsw(U)(shared inout U) { return null; }
3762 static assert(is(typeof(f_w( ma1)) == int []));
3763 static assert(is(typeof(f_w( ca1)) == int [])); // <- const(int)[]
3764 static assert(is(typeof(f_w( ca2)) == int [])); // <- const(int)[]
3765 static assert(is(typeof(f_w( wma1)) == int [])); // <- inout(int)[]
3766 static assert(is(typeof(f_w( wma2)) == int [])); // <- inout(int)[]
3767 static assert(is(typeof(f_w( wca1)) == const(int)[])); // <- inout(const(int))[]
3768 static assert(is(typeof(f_w( wca2)) == const(int)[])); // <- inout(const(int))[]
3769 static assert(is(typeof(f_w( ia1)) == int [])); // <- immutable(int)[]
3770 static assert(is(typeof(f_w( ia2)) == int [])); // <- immutable(int)[]
3771 static assert(is(typeof(f_w( sma1)) == shared( int)[]));
3772 static assert(is(typeof(f_w( sma2)) == shared( int)[])); // <- shared(int[])
3773 static assert(is(typeof(f_w( sca1)) == shared( int)[])); // <- shared(const(int))[]
3774 static assert(is(typeof(f_w( sca2)) == shared( int)[])); // <- shared(const(int)[])
3775 static assert(is(typeof(f_w(swma1)) == shared( int)[])); // <- shared(inout(int))[]
3776 static assert(is(typeof(f_w(swma2)) == shared( int)[])); // <- shared(inout(int)[])
3777 static assert(is(typeof(f_w(swca1)) == shared(const int)[])); // <- shared(inout(const(int)))[]
3778 static assert(is(typeof(f_w(swca2)) == shared(const int)[])); // <- shared(inout(const(int))[])
3780 static assert(is(typeof(fsw( ma1))) == false);
3781 static assert(is(typeof(fsw( ca1))) == false);
3782 static assert(is(typeof(fsw( ca2))) == false);
3783 static assert(is(typeof(fsw( wma1))) == false);
3784 static assert(is(typeof(fsw( wma2))) == false);
3785 static assert(is(typeof(fsw( wca1))) == false);
3786 static assert(is(typeof(fsw( wca2))) == false);
3787 static assert(is(typeof(fsw( ia1)) == int [])); // <- NG
3788 static assert(is(typeof(fsw( ia2)) == int [])); // <- NG
3789 static assert(is(typeof(fsw( sma1)) == int [])); // <- NG
3790 static assert(is(typeof(fsw( sma2)) == int []));
3791 static assert(is(typeof(fsw( sca1)) == int [])); // <- NG
3792 static assert(is(typeof(fsw( sca2)) == int [])); // const(int)[]
3793 static assert(is(typeof(fsw(swma1)) == int [])); // <- NG
3794 static assert(is(typeof(fsw(swma2)) == int [])); // inout(int)[]
3795 static assert(is(typeof(fsw(swca1)) == const(int)[])); // <- NG
3796 static assert(is(typeof(fsw(swca2)) == const(int)[])); // <- inout(const(int))[]
3798 /* Parameter is (shared) inout const
3800 U f_wc(U)( inout const U) { return null; }
3801 U fswc(U)(shared inout const U) { return null; }
3803 static assert(is(typeof(f_wc( ma1)) == int []));
3804 static assert(is(typeof(f_wc( ca1)) == int [])); // <- const(int)[]
3805 static assert(is(typeof(f_wc( ca2)) == int [])); // <- const(int)[]
3806 static assert(is(typeof(f_wc( wma1)) == int [])); // <- inout(int)[]
3807 static assert(is(typeof(f_wc( wma2)) == int [])); // <- inout(int)[]
3808 static assert(is(typeof(f_wc( wca1)) == int [])); // <- inout(const(int))[]
3809 static assert(is(typeof(f_wc( wca2)) == int [])); // <- inout(const(int))[]
3810 static assert(is(typeof(f_wc( ia1)) == int [])); // <- immutable(int)[]
3811 static assert(is(typeof(f_wc( ia2)) == int [])); // <- immutable(int)[]
3812 static assert(is(typeof(f_wc( sma1)) == shared(int)[]));
3813 static assert(is(typeof(f_wc( sma2)) == shared(int)[])); // <- shared(int[])
3814 static assert(is(typeof(f_wc( sca1)) == shared(int)[])); // <- shared(const(int))[]
3815 static assert(is(typeof(f_wc( sca2)) == shared(int)[])); // <- shared(const(int)[])
3816 static assert(is(typeof(f_wc(swma1)) == shared(int)[])); // <- shared(inout(int))[]
3817 static assert(is(typeof(f_wc(swma2)) == shared(int)[])); // <- shared(inout(int)[])
3818 static assert(is(typeof(f_wc(swca1)) == shared(int)[])); // <- shared(inout(const(int)))[]
3819 static assert(is(typeof(f_wc(swca2)) == shared(int)[])); // <- shared(inout(const(int))[])
3821 static assert(is(typeof(fswc( ma1))) == false);
3822 static assert(is(typeof(fswc( ca1))) == false);
3823 static assert(is(typeof(fswc( ca2))) == false);
3824 static assert(is(typeof(fswc( wma1))) == false);
3825 static assert(is(typeof(fswc( wma2))) == false);
3826 static assert(is(typeof(fswc( wca1))) == false);
3827 static assert(is(typeof(fswc( wca2))) == false);
3828 static assert(is(typeof(fswc( ia1)) == int [])); // <- NG
3829 static assert(is(typeof(fswc( ia2)) == int [])); // <- NG
3830 static assert(is(typeof(fswc( sma1)) == int [])); // <- NG
3831 static assert(is(typeof(fswc( sma2)) == int []));
3832 static assert(is(typeof(fswc( sca1)) == int [])); // <- NG
3833 static assert(is(typeof(fswc( sca2)) == int [])); // <- const(int)[]
3834 static assert(is(typeof(fswc(swma1)) == int [])); // <- NG
3835 static assert(is(typeof(fswc(swma2)) == int [])); // <- inout(int)[]
3836 static assert(is(typeof(fswc(swca1)) == int [])); // <- NG
3837 static assert(is(typeof(fswc(swca2)) == int [])); // <- inout(const(int))[]
3842 void foo(T)(in T[] src, T[] dst) { static assert(is(T == int[])); }
3848 /******************************************/
3851 template maxSize13159(T...)
3853 static if (T.length == 1)
3855 enum size_t maxSize13159 = T[0].sizeof;
3859 enum size_t maxSize13159 =
3860 T[0].sizeof >= maxSize13159!(T[1 .. $])
3862 : maxSize13159!(T[1 .. $]);
3873 //alias Algebraic!(Node[], int) Value;
3874 enum n = maxSize13159!(Node13159[], int);
3877 /******************************************/
3882 inout(V) get1a(K, V)(inout(V[K]) aa, lazy inout(V) defaultValue)
3884 static assert(is(V == string));
3885 static assert(is(K == string));
3886 return defaultValue;
3888 inout(V) get1b(K, V)(lazy inout(V) defaultValue, inout(V[K]) aa)
3890 static assert(is(V == string));
3891 static assert(is(K == string));
3892 return defaultValue;
3895 inout(V) get2a(K, V)(inout(V)[K] aa, lazy inout(V) defaultValue)
3897 static assert(is(V == string));
3898 static assert(is(K == string));
3899 return defaultValue;
3901 inout(V) get2b(K, V)(lazy inout(V) defaultValue, inout(V)[K] aa)
3903 static assert(is(V == string));
3904 static assert(is(K == string));
3905 return defaultValue;
3909 string s1a = get1a(aa, def);
3910 string s1b = get1b(def, aa);
3911 string s2a = get2a(aa, def);
3912 string s2b = get2b(def, aa);
3915 /******************************************/
3918 struct A13204(uint v)
3920 alias whatever = A13204y;
3921 static assert(is(whatever == A13204));
3923 alias A13204x = A13204!1;
3924 alias A13204y = A13204x;
3926 struct B13204(uint v)
3928 alias whatever = B13204z;
3929 static assert(is(whatever == B13204));
3931 alias B13204x = B13204!1;
3932 alias B13204y = B13204x;
3933 alias B13204z = B13204y;
3937 static assert(is(A13204x == A13204!1));
3938 static assert(is(A13204x == A13204!1.whatever));
3939 static assert(is(A13204x == A13204y));
3941 static assert(is(B13204x == B13204!1));
3942 static assert(is(B13204x == B13204!1.whatever));
3943 static assert(is(B13204x == B13204y));
3944 static assert(is(B13204x == B13204z));
3947 /******************************************/
3948 // 8462 (dup of 13204)
3950 alias FP8462 = void function(C8462.Type arg);
3955 alias funcPtrPtr = FP8462*;
3958 /******************************************/
3961 template isCallable13218(T...)
3967 template ParameterTypeTuple13218(func...)
3968 if (func.length == 1 && isCallable13218!func)
3975 private static string mangleFuncPtr(ArgTypes...)()
3977 string result = "fnp_";
3978 foreach (T; ArgTypes)
3979 result ~= T.mangleof;
3982 void function(int) fnp_i;
3983 double delegate(double) fnp_d;
3985 void opAssign(FnT)(FnT func)
3987 mixin(mangleFuncPtr!( ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as TypeInstance
3988 //mixin(mangleFuncPtr!(.ParameterTypeTuple13218!FnT) ~ " = func;"); // parsed as DotTemplateInstanceExp -> works
3992 /******************************************/
3995 struct Map13219(V) {}
3997 void test13219a(alias F, VA, VB)(Map13219!VA a, Map13219!VB b)
3998 if (is(VA : typeof(F(VA.init, VB.init))))
4001 void test13219b(alias F)()
4003 test13219a!((a, b) => b)(Map13219!int.init, Map13219!int.init);
4012 /******************************************/
4017 T[] f1(T)(T[] a1, T[] a2)
4019 static assert(is(T == int));
4022 T[] f2(T)(T[] a1, T[] a2)
4024 static assert(is(T == int));
4028 static assert(is(typeof(f1(a, [])) == int[]));
4029 static assert(is(typeof(f2([], a)) == int[]));
4030 static assert(is(typeof(f1(a, null)) == int[]));
4031 static assert(is(typeof(f2(null, a)) == int[]));
4033 T[] f3(T)(T[] a) { return a; }
4034 static assert(is(typeof(f3([])) == void[]));
4035 static assert(is(typeof(f3(null)) == void[]));
4037 T f4(T)(T a) { return a; }
4038 static assert(is(typeof(f4([])) == void[]));
4039 static assert(is(typeof(f4(null)) == typeof(null)));
4041 T[][] f5(T)(T[][] a) { return a; }
4042 static assert(is(typeof(f5([])) == void[][]));
4043 static assert(is(typeof(f5(null)) == void[][]));
4045 void translate(C = immutable char)(const(C)[] toRemove)
4047 static assert(is(C == char));
4054 T f(T)(T, T) { return T.init; }
4061 static assert(is(typeof(f(i, i)) == immutable int));
4062 static assert(is(typeof(f(i, c)) == const int));
4063 static assert(is(typeof(f(c, i)) == const int));
4064 static assert(is(typeof(f(i, m)) == int));
4065 static assert(is(typeof(f(m, i)) == int));
4066 static assert(is(typeof(f(c, m)) == int));
4067 static assert(is(typeof(f(m, c)) == int));
4068 static assert(is(typeof(f(m, m)) == int));
4069 static assert(is(typeof(f(i, s)) == shared int));
4070 static assert(is(typeof(f(s, i)) == shared int));
4071 static assert(is(typeof(f(c, s)) == shared int));
4072 static assert(is(typeof(f(s, c)) == shared int));
4073 static assert(is(typeof(f(s, s)) == shared int));
4074 static assert(is(typeof(f(s, m)) == int));
4075 static assert(is(typeof(f(m, s)) == int));
4078 /******************************************/
4081 struct Tuple13235(T...)
4093 Tuple13235!(int, Foo13235)* foo;
4096 template Inst13235(T...)
4108 alias Inst13235 = Tuple*;
4112 Inst13235!(int, Bar13235) bar;
4117 alias Tup1 = Tuple13235!(int, Foo13235);
4118 assert(Tup1(1, Foo13235()).expand[0] == 1);
4120 alias Tup2 = typeof(*Inst13235!(int, Bar13235).init);
4121 assert(Tup2(1, Bar13235()).expand[0] == 1);
4124 /******************************************/
4127 alias TypeTuple13252(T...) = T;
4129 static assert(is(typeof(TypeTuple13252!(cast(int )1)[0]) == int ));
4130 static assert(is(typeof(TypeTuple13252!(cast(long)1)[0]) == long));
4132 static assert(is(typeof(TypeTuple13252!(cast(float )3.14)[0]) == float ));
4133 static assert(is(typeof(TypeTuple13252!(cast(double)3.14)[0]) == double));
4135 static assert(is(typeof(TypeTuple13252!(cast(cfloat )(1 + 2i))[0]) == cfloat ));
4136 static assert(is(typeof(TypeTuple13252!(cast(cdouble)(1 + 2i))[0]) == cdouble));
4138 static assert(is(typeof(TypeTuple13252!(cast(string )null)[0]) == string ));
4139 static assert(is(typeof(TypeTuple13252!(cast(string[])null)[0]) == string[])); // OK <- NG
4141 static assert(is(typeof(TypeTuple13252!(cast(wstring)"abc")[0]) == wstring));
4142 static assert(is(typeof(TypeTuple13252!(cast(dstring)"abc")[0]) == dstring));
4144 static assert(is(typeof(TypeTuple13252!(cast(int[] )[])[0]) == int[] ));
4145 static assert(is(typeof(TypeTuple13252!(cast(long[])[])[0]) == long[])); // OK <- NG
4148 static assert(is(typeof(TypeTuple13252!(const S13252())[0]) == const(S13252)));
4149 static assert(is(typeof(TypeTuple13252!(immutable S13252())[0]) == immutable(S13252))); // OK <- NG
4151 /******************************************/
4156 void f(T)(const ref T src, ref T dst)
4158 pragma(msg, "T = ", T);
4159 static assert(!is(T == const));
4173 T add(T)(in T x, in T y)
4179 const double a = 1.0;
4180 const double b = 2.0;
4185 /******************************************/
4190 Foo13299 opDispatch(string name)(int a, int[] b...)
4196 Foo13299 opDispatch(string name)()
4211 .opDispatch!"bar"(0)
4212 .opDispatch!"bar"(1)
4213 .opDispatch!"bar"(2);
4216 /******************************************/
4219 template AliasThisTypeOf13333(T)
4221 static assert(0, T.stringof); // T.stringof is important
4224 template StaticArrayTypeOf13333(T)
4226 static if (is(AliasThisTypeOf13333!T AT))
4227 alias X = StaticArrayTypeOf13333!AT;
4231 static if (is(X : E[n], E, size_t n))
4232 alias StaticArrayTypeOf13333 = X;
4234 static assert(0, T.stringof~" is not a static array type");
4237 enum bool isStaticArray13333(T) = is(StaticArrayTypeOf13333!T);
4239 struct VaraiantN13333(T)
4241 static if (isStaticArray13333!T)
4242 ~this() { static assert(0); }
4245 struct DummyScope13333
4247 alias A = VaraiantN13333!C;
4259 alias A = VaraiantN13333!C;
4268 /******************************************/
4271 int f13374(alias a)() { return 1; }
4272 int f13374(string s)() { return 2; }
4274 void x13374(int i) {}
4278 assert(f13374!x13374() == 1);
4281 /******************************************/
4284 string f14109() { return "a"; }
4285 string g14109()() { return "a"; }
4287 struct S14109(string s) { static assert(s == "a"); }
4289 alias X14109 = S14109!(f14109);
4290 alias Y14109 = S14109!(g14109!());
4291 static assert(is(X14109 == Y14109));
4293 /******************************************/
4296 struct Vec13378(size_t n, T, string as)
4301 void doSome13378(size_t n, T, string as)(Vec13378!(n,T,as) v) {}
4305 auto v = Vec13378!(3, float, "xyz")([1,2,3]);
4309 /******************************************/
4317 auto match13379(RegEx )(RegEx re)
4318 if (is(RegEx == Regex13379!char)) // #1 Regex!char (speculative && tinst == NULL)
4320 auto match13379(String)(String re)
4323 struct Regex13379(Char)
4325 ShiftOr13379!Char kickstart; // #2 ShiftOr!char (speculative && tinst == Regex!char)
4327 struct ShiftOr13379(Char)
4329 this(ref Regex13379!Char re) // #3 Regex!Char (speculative && tinst == ShiftOr!char)
4333 n_length = min13379(idx, n_length);
4337 template MinType13379(T...)
4339 alias MinType13379 = T[0];
4341 MinType13379!T min13379(T...)(T args) // #4 MinType!uint (speculative && thist == ShiftOr!char)
4344 alias b = args[$-1];
4345 return cast(typeof(return)) (a < b ? a : b);
4348 /******************************************/
4351 struct V13417(size_t N, E, alias string AS)
4355 auto f13417(E)(in V13417!(4, E, "ijka"))
4357 return V13417!(3, E, "xyz")();
4362 f13417(V13417!(4, float, "ijka")());
4365 /******************************************/
4368 int foo13484()(void delegate() hi) { return 1; }
4369 int foo13484(T)(void delegate(T) hi) { return 2; }
4373 assert(foo13484({}) == 1); // works
4374 assert(foo13484((float v){}) == 2); // works <- throws error
4377 /******************************************/
4382 bool foo13675(T : E13675)()
4389 if (foo13675!E13675)
4393 /******************************************/
4396 auto foo13694(T)(string A, T[] G ...) { return 1; }
4397 auto foo13694(T)(string A, long E, T[] G ...) { return 2; }
4404 assert(foo13694("A", v) == 1); // <- OK
4405 assert(foo13694("A", 0, v) == 2); // <- used to be OK but now fails
4406 assert(foo13694!S("A", 0, v) == 2); // <- workaround solution
4409 /******************************************/
4414 void func(K, V)(inout(V[K]) aa, inout(V) val) {}
4421 /******************************************/
4424 struct JSONValue13714
4429 this(T : JSONValue13714)(inout T arg) inout
4431 //store = arg.store;
4434 void opAssign(T)(T arg)
4441 enum DummyStringEnum
4446 JSONValue13714[string] aa;
4447 aa["A"] = DummyStringEnum.foo;
4450 /******************************************/
4453 T f13807(T)(inout(T)[] arr)
4460 static assert(is(typeof(f13807([1, 2, 3])) == int)); // OK
4461 static assert(is(typeof(f13807(["a", "b"])) == string)); // OK <- Error
4462 static assert(is(typeof(f13807!string(["a", "b"])) == string)); // OK
4465 /******************************************/
4468 struct Config14174(a, b) {}
4472 alias defConfig14174 = Config14174!(N14174, N14174);
4474 void accepter14174a(Config : Config14174!(T) = defConfig14174, T...)()
4476 static assert(accepter14174a.mangleof
4477 == "_D7breaker131__T14"~
4479 "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~
4484 void accepter14174b(Config : Config14174!(T) = defConfig14174, T...)()
4486 static assert(accepter14174b.mangleof
4487 == "_D7breaker131__T14"~
4489 "HTS7breaker51__T11Config14174TS7breaker6N14174TS7breaker6N14174Z11Config14174TS7breaker6N14174TS7breaker6N14174Z14"~
4496 accepter14174a!()(); // ok
4497 accepter14174b(); // error
4500 /******************************************/
4503 template a14836x(alias B, C...)
4505 int a14836x(D...)() if (D.length == 0) { return 1; }
4506 int a14836x(D...)(D d) if (D.length > 0) { return 2; }
4508 template a14836y(alias B, C...)
4510 int a14836y(T, D...)(T t) if (D.length == 0) { return 1; }
4511 int a14836y(T, D...)(T t, D d) if (D.length > 0) { return 2; }
4517 assert(a14836x!(v)() == 1);
4518 assert(a14836x!(v)(1) == 2);
4519 assert(a14836y!(v)(1) == 1);
4520 assert(a14836y!(v)(1, 2) == 2);
4523 /******************************************/
4526 template Qux14357(T : U*, U : V*, V)
4528 pragma(msg, T); // no match <- float**
4529 pragma(msg, U); // no match <- float*
4530 pragma(msg, V); // no match <- int
4531 enum Qux14357 = T.sizeof + V.sizeof;
4533 static assert(!__traits(compiles, Qux14357!(float**, int*)));
4535 /******************************************/
4538 template someT14481(alias e)
4540 alias someT14481 = e;
4543 mixin template Mix14481(alias e)
4545 alias SomeAlias = someT14481!e;
4554 /******************************************/
4557 template M14520(alias a) { enum M14520 = 1; }
4558 template M14520(string s) { enum M14520 = 2; }
4561 string f14520b() { assert(0); }
4562 string f14520c() { return "a"; }
4564 static assert(M14520!f14520a == 1);
4565 static assert(M14520!f14520b == 1);
4566 static assert(M14520!f14520c == 1);
4568 /******************************************/
4571 struct Interval14568()
4573 auto left = INVALID;
4575 auto opAssign()(Interval14568) { left; }
4578 auto interval14568(T)(T point)
4583 alias Instantiate14568(alias symbol, Args...) = symbol!Args;
4585 template Match14568(patterns...)
4587 static if (__traits(compiles, Instantiate14568!(patterns[0])))
4589 alias Match14568 = patterns[0];
4591 else static if (patterns.length == 1)
4595 template SubOps14568(Args...)
4599 template IntervalType(T...)
4601 alias Point() = typeof(T.interval14568);
4603 alias IntervalType = Match14568!(Point);
4605 alias Subspace = IntervalType!(Args);
4609 struct Nat14568 { mixin SubOps14568!(null); }
4611 /******************************************/
4616 template opDispatch(string name)
4618 void opDispatch()() {}
4621 alias a14603 = S14603.opDispatch!"go"; // OK
4622 alias b14603 = S14603.go; // OK <- NG
4626 template opDispatch(string name)
4628 void opDispatch()() {}
4631 alias Id14604(alias thing) = thing;
4632 alias c14604 = Id14604!(S14604.opDispatch!"go"); // ok
4633 alias d14604 = Id14604!(S14604.go); // issue 14604, 'Error: template instance opDispatch!"go" cannot resolve forward reference'
4635 /******************************************/
4638 enum CS14735 { yes, no }
4640 int indexOf14735a(Range )(Range s, in dchar c) { return 1; }
4641 int indexOf14735a(T, size_t n)(ref T[n] s, in dchar c) { return 2; }
4643 int indexOf14735b(Range )(Range s, in dchar c, in CS14735 cs = CS14735.yes) { return 1; }
4644 int indexOf14735b(T, size_t n)(ref T[n] s, in dchar c, in CS14735 cs = CS14735.yes) { return 2; }
4650 // Supported from 2.063: (http://dlang.org/changelog#implicitarraycast)
4651 assert(indexOf14735a(buf[0..32], '\0') == 2);
4652 assert(indexOf14735b(buf[0..32], '\0') == 2);
4654 // Have to work as same as above.
4655 assert(indexOf14735a(buf[], '\0') == 2);
4656 assert(indexOf14735b(buf[], '\0') == 2);
4659 /******************************************/
4664 auto func1 = (A14743 a) { a.func2!int(); };
4668 /******************************************/
4673 auto func(T)(T x, T y) { return x; }
4675 struct S1 { double x; alias x this; }
4676 struct S2 { double x; alias x this; }
4680 enum E1 : double { a = 1.0 }
4681 enum E2 : double { a = 1.0 }
4683 static assert(is(typeof( func(1 , 1 ) ) == int));
4684 static assert(is(typeof( func(1u, 1u) ) == uint));
4685 static assert(is(typeof( func(1u, 1 ) ) == uint));
4686 static assert(is(typeof( func(1 , 1u) ) == uint));
4688 static assert(is(typeof( func(1.0f, 1.0f) ) == float));
4689 static assert(is(typeof( func(1.0 , 1.0 ) ) == double));
4690 static assert(is(typeof( func(1.0 , 1.0f) ) == double));
4691 static assert(is(typeof( func(1.0f, 1.0 ) ) == double));
4693 static assert(is(typeof( func(s1, s1) ) == S1));
4694 static assert(is(typeof( func(s2, s2) ) == S2));
4695 static assert(is(typeof( func(s1, s2) ) == double));
4696 static assert(is(typeof( func(s2, s1) ) == double));
4698 static assert(is(typeof( func(E1.a, E1.a) ) == E1));
4699 static assert(is(typeof( func(E2.a, E2.a) ) == E2));
4700 static assert(is(typeof( func(E1.a, 1.0) ) == double));
4701 static assert(is(typeof( func(E2.a, 1.0) ) == double));
4702 static assert(is(typeof( func(1.0, E1.a) ) == double));
4703 static assert(is(typeof( func(1.0, E2.a) ) == double));
4704 static assert(is(typeof( func(E1.a, E2.a) ) == double));
4705 static assert(is(typeof( func(E2.a, E1.a) ) == double));
4708 /******************************************/
4713 alias R = int[100_000];
4715 auto front(T)(T[] a) {}
4718 auto bar1(T)(T, T[] a) { return T.init; }
4719 auto bar2(T)(T[] a, T) { return T.init; }
4721 static assert(is(typeof(bar1(1L, R.init)) == long));
4722 static assert(is(typeof(bar2(R.init, 1L)) == long));
4723 // <-- T should be deduced to int because R.init is rvalue...?
4726 static assert(is(typeof(bar1(x, R.init)) == int));
4727 static assert(is(typeof(bar2(R.init, x)) == int));
4730 /******************************************/
4734 auto f15116a(T)(string s, string arg2) { return 1; }
4735 auto f15116b(T)(int i, string arg2) { return 2; }
4737 template bish15116(T)
4739 alias bish15116 = f15116a!T;
4740 alias bish15116 = f15116b!T;
4745 alias func = bish15116!string;
4746 assert(func("", "") == 1);
4747 assert(func(12, "") == 2);
4750 /******************************************/
4755 void func(string M)() { }
4766 /******************************************/
4769 struct S15352(T, T delegate(uint idx) supplier)
4773 auto make15352a(T, T delegate(uint idx) supplier)()
4775 enum local = supplier; // OK
4776 S15352!(T, local) ret;
4780 auto make15352b(T, T delegate(uint idx) supplier)()
4782 S15352!(T, supplier) ret; // OK <- Error
4788 enum dg = delegate(uint idx) => idx;
4789 auto s1 = S15352!(uint, dg)();
4790 auto s2 = make15352a!(uint, dg)();
4791 auto s3 = make15352b!(uint, dg)();
4792 assert(is(typeof(s1) == typeof(s2)));
4793 assert(is(typeof(s1) == typeof(s3)));
4796 /******************************************/
4799 struct WithFoo15623a { void foo() {} }
4800 struct WithFoo15623b { void foo() {} }
4801 struct WithFoo15623c { void foo() {} }
4802 struct WithFoo15623d { void foo() {} }
4804 struct WithoutFoo15623a {}
4805 struct WithoutFoo15623b {}
4806 struct WithoutFoo15623c {}
4807 struct WithoutFoo15623d {}
4809 struct CallsFoo15623(T)
4812 void bar() { t.foo(); } // error occurs during TemplateInstance.semantic3
4815 // Instantiations outside of function bodies
4816 static assert( is(CallsFoo15623!WithFoo15623a));
4817 static assert(!is(CallsFoo15623!WithoutFoo15623a)); // OK <- NG
4818 static assert( __traits(compiles, CallsFoo15623!WithFoo15623b));
4819 static assert(!__traits(compiles, CallsFoo15623!WithoutFoo15623b)); // OK <- NG
4821 // Instantiations inside function bodies (OK)
4822 static assert( is(typeof({ alias Baz = CallsFoo15623!WithFoo15623c; return Baz.init; }())));
4823 static assert(!is(typeof({ alias Baz = CallsFoo15623!WithoutFoo15623c; return Baz.init; }())));
4824 static assert( __traits(compiles, { alias Baz = CallsFoo15623!WithFoo15623d; return Baz.init; }()));
4825 static assert(!__traits(compiles, { alias Baz = CallsFoo15623!WithoutFoo15623d; return Baz.init; }()));
4827 /******************************************/
4844 static assert(is(typeof(foo(ms, ms)) == S));
4845 static assert(is(typeof(foo(ms, cs)) == const S));
4846 static assert(is(typeof(foo(cs, ms)) == const S));
4847 static assert(is(typeof(foo(cs, cs)) == const S));
4850 /******************************************/
4965 printf("Success\n");