/
template9.d
1318 lines (1053 loc) · 25.5 KB
/
template9.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// PERMUTE_ARGS:
// Note: compiling this overflows the stack if dmd is build with DEBUG
module breaker;
import std.c.stdio;
/**********************************/
U foo(T, U)(U i)
{
return i + 1;
}
int foo(T)(int i)
{
return i + 2;
}
void test1()
{
auto i = foo!(int)(2L);
// assert(i == 4); // now returns 3
}
/**********************************/
U foo2(T, U)(U i)
{
return i + 1;
}
void test2()
{
auto i = foo2!(int)(2L);
assert(i == 3);
}
/**********************************/
class Foo3
{
T bar(T,U)(U u)
{
return cast(T)u;
}
}
void test3()
{
Foo3 foo = new Foo3;
int i = foo.bar!(int)(1.0);
assert(i == 1);
}
/**********************************/
T* begin4(T)(T[] a) { return a.ptr; }
void copy4(string pred = "", Ranges...)(Ranges rs)
{
alias rs[$ - 1] target;
pragma(msg, typeof(target).stringof);
auto tb = begin4(target);//, te = end(target);
}
void test4()
{
int[] a, b, c;
copy4(a, b, c);
// comment the following line to prevent compiler from crashing
copy4!("a > 1")(a, b, c);
}
/**********************************/
import std.stdio:writefln;
template foo5(T,S)
{
void foo5(T t, S s) {
writefln("typeof(T)=",typeid(T)," typeof(S)=",typeid(S));
}
}
template bar5(T,S)
{
void bar5(S s) {
writefln("typeof(T)=",typeid(T),"typeof(S)=",typeid(S));
}
}
void test5()
{
foo5(1.0,33);
bar5!(double,int)(33);
bar5!(float)(33);
}
/**********************************/
int foo6(T...)(auto ref T x)
{ int result;
foreach (i, v; x)
{
if (v == 10)
assert(__traits(isRef, x[i]));
else
assert(!__traits(isRef, x[i]));
result += v;
}
return result;
}
void test6()
{ int y = 10;
int r;
r = foo6(8);
assert(r == 8);
r = foo6(y);
assert(r == 10);
r = foo6(3, 4, y);
assert(r == 17);
r = foo6(4, 5, y);
assert(r == 19);
r = foo6(y, 6, y);
assert(r == 26);
}
/**********************************/
auto ref min(T, U)(auto ref T lhs, auto ref U rhs)
{
return lhs > rhs ? rhs : lhs;
}
void test7()
{ int x = 7, y = 8;
int i;
i = min(4, 3);
assert(i == 3);
i = min(x, y);
assert(i == 7);
min(x, y) = 10;
assert(x == 10);
static assert(!__traits(compiles, min(3, y) = 10));
static assert(!__traits(compiles, min(y, 3) = 10));
}
/**********************************/
// 5946
template TTest8()
{
int call(){ return this.g(); }
}
class CTest8
{
int f() { mixin TTest8!(); return call(); }
int g() { return 10; }
}
void test8()
{
assert((new CTest8()).f() == 10);
}
/**********************************/
// 693
template TTest9(alias sym)
{
int call(){ return sym.g(); }
}
class CTest9
{
int f1() { mixin TTest9!(this); return call(); }
int f2() { mixin TTest9!this; return call(); }
int g() { return 10; }
}
void test9()
{
assert((new CTest9()).f1() == 10);
assert((new CTest9()).f2() == 10);
}
/**********************************/
// 5015
import breaker;
static if (is(ElemType!(int))){}
template ElemType(T) {
alias _ElemType!(T).type ElemType;
}
template _ElemType(T) {
alias r type;
}
/**********************************/
// 6404
// receive only rvalue
void rvalue(T)(auto ref T x) if (!__traits(isRef, x)) {}
void rvalueVargs(T...)(auto ref T x) if (!__traits(isRef, x[0])) {}
// receive only lvalue
void lvalue(T)(auto ref T x) if ( __traits(isRef, x)) {}
void lvalueVargs(T...)(auto ref T x) if ( __traits(isRef, x[0])) {}
void test6404()
{
int n;
static assert(!__traits(compiles, rvalue(n)));
static assert( __traits(compiles, rvalue(0)));
static assert( __traits(compiles, lvalue(n)));
static assert(!__traits(compiles, lvalue(0)));
static assert(!__traits(compiles, rvalueVargs(n)));
static assert( __traits(compiles, rvalueVargs(0)));
static assert( __traits(compiles, lvalueVargs(n)));
static assert(!__traits(compiles, lvalueVargs(0)));
}
/**********************************/
// 2246
class A2246(T,d){
T p;
}
class B2246(int rk){
int[rk] p;
}
class C2246(T,int rk){
T[rk] p;
}
template f2246(T:A2246!(U,d),U,d){
void f2246(){ }
}
template f2246(T:B2246!(rank),int rank){
void f2246(){ }
}
template f2246(T:C2246!(U,rank),U,int rank){
void f2246(){ }
}
void test2246(){
A2246!(int,long) a;
B2246!(2) b;
C2246!(int,2) c;
f2246!(A2246!(int,long))();
f2246!(B2246!(2))();
f2246!(C2246!(int,2))();
}
/**********************************/
// 1684
template Test1684( uint memberOffset ){}
class MyClass1684 {
int flags2;
mixin Test1684!(cast(uint)flags2.offsetof) t1; // compiles ok
mixin Test1684!(cast(int)flags2.offsetof) t2; // compiles ok
mixin Test1684!(flags2.offsetof) t3; // Error: no property 'offsetof' for type 'int'
}
/**********************************/
void bug4984a(int n)() if (n > 0 && is(typeof(bug4984a!(n-1) ()))) {
}
void bug4984a(int n : 0)() {
}
void bug4984b(U...)(U args) if ( is(typeof( bug4984b(args[1..$]) )) ) {
}
void bug4984b(U)(U u) {
}
void bug4984() {
bug4984a!400();
bug4984b(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
}
/***************************************/
// 2579
void foo2579(T)(T delegate(in Object) dlg)
{
}
void test2579()
{
foo2579( (in Object o) { return 15; } );
}
/**********************************/
// 4953
void bug4953(T = void)(short x) {}
static assert(is(typeof(bug4953(3))));
/**********************************/
// 5886 & 5393
struct K5886 {
void get1(this T)() const {
pragma(msg, T);
}
void get2(int N=4, this T)() const {
pragma(msg, N, " ; ", T);
}
}
void test5886() {
K5886 km;
const(K5886) kc;
immutable(K5886) ki;
km.get1; // OK
kc.get1; // OK
ki.get1; // OK
km.get2; // OK
kc.get2; // OK
ki.get2; // OK
km.get2!(1, K5886); // Ugly
kc.get2!(2, const(K5886)); // Ugly
ki.get2!(3, immutable(K5886)); // Ugly
km.get2!8; // Error
kc.get2!9; // Error
ki.get2!10; // Error
}
// --------
void test5393()
{
class A
{
void opDispatch (string name, this T) () { }
}
class B : A {}
auto b = new B;
b.foobar();
}
/**********************************/
// 5896
struct X5896
{
T opCast(T)(){ return 1; }
const T opCast(T)(){ return 2; }
immutable T opCast(T)(){ return 3; }
shared T opCast(T)(){ return 4; }
const shared T opCast(T)(){ return 5; }
}
void test5896()
{
auto xm = X5896 ();
auto xc = const(X5896) ();
auto xi = immutable(X5896) ();
auto xs = shared(X5896) ();
auto xcs= const(shared(X5896))();
assert(cast(int)xm == 1);
assert(cast(int)xc == 2);
assert(cast(int)xi == 3);
assert(cast(int)xs == 4);
assert(cast(int)xcs== 5);
}
/**********************************/
// 6825
void test6825()
{
struct File
{
void write(S...)(S args) {}
}
void dump(void delegate(string) d) {}
auto o = File();
dump(&o.write!string);
}
/**********************************/
// 6789
template isStaticArray6789(T)
{
static if (is(T U : U[N], size_t N)) // doesn't match
{
pragma(msg, "> U = ", U, ", N:", typeof(N), " = ", N);
enum isStaticArray6789 = true;
}
else
enum isStaticArray6789 = false;
}
void test6789()
{
alias int[3] T;
static assert(isStaticArray6789!T);
}
/**********************************/
// 2778
struct ArrayWrapper2778(T)
{
T[] data;
alias data this;
}
void doStuffFunc2778(int[] data) {}
void doStuffTempl2778(T)(T[] data) {}
int doStuffTemplOver2778(T)(void* data) { return 1; }
int doStuffTemplOver2778(T)(ArrayWrapper2778!T w) { return 2; }
void test2778()
{
ArrayWrapper2778!(int) foo;
doStuffFunc2778(foo); // Works.
doStuffTempl2778!(int)(foo); // Works.
doStuffTempl2778(foo); // Error
assert(doStuffTemplOver2778(foo) == 2);
}
// ----
void test2778aa()
{
void foo(K, V)(V[K] aa){ pragma(msg, "K=", K, ", V=", V); }
int[string] aa1;
foo(aa1); // OK
struct SubTypeOf(T)
{
T val;
alias val this;
}
SubTypeOf!(string[char]) aa2;
foo(aa2); // NG
}
// ----
void test2778get()
{
void foo(ubyte[]){}
static struct S
{
ubyte[] val = [1,2,3];
@property ref ubyte[] get(){ return val; }
alias get this;
}
S s;
foo(s);
}
/**********************************/
// 6208
int getRefNonref(T)(ref T s){ return 1; }
int getRefNonref(T)( T s){ return 2; }
int getAutoRef(T)(auto ref T s){ return __traits(isRef, s) ? 1 : 2; }
void getOut(T)(out T s){ ; }
void getLazy1(T=int)(lazy void s){ s(), s(); }
void getLazy2(T)(lazy T s){ s(), s(); }
void test6208a()
{
int lvalue;
int rvalue(){ int t; return t; }
assert(getRefNonref(lvalue ) == 1);
assert(getRefNonref(rvalue()) == 2);
assert(getAutoRef(lvalue ) == 1);
assert(getAutoRef(rvalue()) == 2);
static assert( __traits(compiles, getOut(lvalue )));
static assert(!__traits(compiles, getOut(rvalue())));
int n1; getLazy1(++n1); assert(n1 == 2);
int n2; getLazy2(++n2); assert(n2 == 2);
struct X
{
int f(T)(auto ref T t){ return 1; }
int f(T)(auto ref T t, ...){ return -1; }
}
auto xm = X ();
auto xc = const(X)();
int n;
assert(xm.f!int(n) == 1); // resolved 'auto ref'
assert(xm.f!int(0) == 1); // ditto
}
void test6208b()
{
void foo(T)(const T value) if (!is(T == int)) {}
int mn;
const int cn;
static assert(!__traits(compiles, foo(mn))); // OK -> OK
static assert(!__traits(compiles, foo(cn))); // NG -> OK
}
void test6208c()
{
struct S
{
// Original test case.
int foo(V)(in V v) { return 1; }
int foo(Args...)(auto ref const Args args) { return 2; }
// Reduced test cases
int hoo(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst
int hoo(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst
// If deduction matching level is same, tuple parameter is less specialized than others.
int bar(V)(V v) { return 1; } // typeof(10) : V -> MATCHexact
int bar(Args...)(const Args args) { return 2; } // typeof(10) : const Args[0] -> MATCHconst
int baz(V)(const V v) { return 1; } // typeof(10) : const V -> MATCHconst
int baz(Args...)(Args args) { return 2; } // typeof(10) : Args[0] -> MATCHexact
inout(int) war(V)(inout V v) { return 1; }
inout(int) war(Args...)(inout Args args){ return 2; }
inout(int) waz(Args...)(inout Args args){ return 0; } // wild deduction test
}
S s;
int nm = 10;
assert(s.foo(nm) == 1);
assert(s.hoo(nm) == 1);
assert(s.bar(nm) == 1);
assert(s.baz(nm) == 2);
assert(s.war(nm) == 1);
static assert(is(typeof(s.waz(nm)) == int));
const int nc = 10;
assert(s.foo(nc) == 1);
assert(s.hoo(nc) == 1);
assert(s.bar(nc) == 1);
assert(s.baz(nc) == 1);
assert(s.war(nc) == 1);
static assert(is(typeof(s.waz(nc)) == const(int)));
immutable int ni = 10;
assert(s.foo(ni) == 1);
assert(s.hoo(ni) == 1);
assert(s.bar(ni) == 1);
assert(s.baz(ni) == 2);
assert(s.war(ni) == 1);
static assert(is(typeof(s.waz(ni)) == immutable(int)));
static assert(is(typeof(s.waz(nm, nm)) == int));
static assert(is(typeof(s.waz(nm, nc)) == const(int)));
static assert(is(typeof(s.waz(nm, ni)) == const(int)));
static assert(is(typeof(s.waz(nc, nm)) == const(int)));
static assert(is(typeof(s.waz(nc, nc)) == const(int)));
static assert(is(typeof(s.waz(nc, ni)) == const(int)));
static assert(is(typeof(s.waz(ni, nm)) == const(int)));
static assert(is(typeof(s.waz(ni, nc)) == const(int)));
static assert(is(typeof(s.waz(ni, ni)) == immutable(int)));
}
/**********************************/
// 6805
struct T6805
{
template opDispatch(string name)
{
alias int Type;
}
}
static assert(is(T6805.xxx.Type == int));
/**********************************/
// 6738
struct Foo6738
{
int _val = 10;
@property int val()() { return _val; }
int get() { return val; } // fail
}
void test6738()
{
Foo6738 foo;
auto x = foo.val; // ok
assert(x == 10);
assert(foo.get() == 10);
}
/**********************************/
// 7498
template IndexMixin(){
void insert(T)(T value){ }
}
class MultiIndexContainer{
mixin IndexMixin!() index0;
class Index0{
void baburk(){
this.outer.index0.insert(1);
}
}
}
/**********************************/
// 6780
@property int foo6780()(){ return 10; }
int g6780;
@property void bar6780()(int n){ g6780 = n; }
void test6780()
{
auto n = foo6780;
assert(n == 10);
bar6780 = 10;
assert(g6780 == 10);
}
/**********************************/
// 6891
struct S6891(int N, T)
{
void f(U)(S6891!(N, U) u) { }
}
void test6891()
{
alias S6891!(1, void) A;
A().f(A());
}
/**********************************/
// 6994
struct Foo6994
{
T get(T)(){ return T.init; }
T func1(T)()
if (__traits(compiles, get!T()))
{ return get!T; }
T func2(T)()
if (__traits(compiles, this.get!T())) // add explicit 'this'
{ return get!T; }
}
void test6994()
{
Foo6994 foo;
foo.get!int(); // OK
foo.func1!int(); // OK
foo.func2!int(); // NG
}
/**********************************/
// 3467 & 6806
struct Foo3467( uint n )
{
Foo3467!( n ) bar( ) {
typeof( return ) result;
return result;
}
}
struct Vec3467(size_t N)
{
void opBinary(string op:"~", size_t M)(Vec3467!M) {}
}
void test3467()
{
Foo3467!( 4 ) baz;
baz = baz.bar;// FAIL
Vec3467!2 a1;
Vec3467!3 a2;
a1 ~ a2; // line 7, Error
}
struct TS6806(size_t n) { pragma(msg, typeof(n)); }
static assert(is(TS6806!(1u) == TS6806!(1)));
/**********************************/
// 4413
struct Foo4413
{
alias typeof(this) typeof_this;
void bar1(typeof_this other) {}
void bar2()(typeof_this other) {}
void bar3(typeof(this) other) {}
void bar4()(typeof(this) other) {}
}
void test4413()
{
Foo4413 f;
f.bar1(f); // OK
f.bar2(f); // OK
f.bar3(f); // OK
f.bar4(f); // ERR
}
/**********************************/
// 4675
template isNumeric(T)
{
enum bool test1 = is(T : long); // should be hidden
enum bool test2 = is(T : real); // should be hidden
enum bool isNumeric = test1 || test2;
}
void test4675()
{
static assert( isNumeric!int);
static assert(!isNumeric!string);
static assert(!__traits(compiles, isNumeric!int.test1)); // should be an error
static assert(!__traits(compiles, isNumeric!int.test2)); // should be an error
static assert(!__traits(compiles, isNumeric!int.isNumeric));
}
/**********************************/
// 5525
template foo5525(T)
{
T foo5525(T t) { return t; }
T foo5525(T t, T u) { return t + u; }
}
void test5525()
{
alias foo5525!int f;
assert(f(1) == 1);
assert(f(1, 2) == 3);
}
/**********************************/
// 5801
int a5801;
void bar5801(T = double)(typeof(a5801) i) {}
void baz5801(T)(typeof(a5801) i, T t) {}
void test5801()
{
bar5801(2); // Does not compile.
baz5801(3, "baz"); // Does not compile.
}
/**********************************/
// 2550
template pow10_2550(long n)
{
const long pow10_2550 = 0;
static if (n < 0)
const long pow10_2550 = 0;
else
const long pow10_2550 = 10 * pow10_2550!(n - 1);
}
template pow10_2550(long n:0)
{
const long pow10_2550 = 1;
}
static assert(pow10_2550!(0) == 1);
/**********************************/
void foo10(T)(T prm)
{
pragma(msg, T);
static assert(is(T == const(int)[]));
}
void boo10(T)(ref T val) // ref paramter doesn't remove top const
{
pragma(msg, T);
static assert(is(T == const(int[])));
}
void goo10(T)(auto ref T val) // auto ref with lvalue doesn't
{
pragma(msg, T);
static assert(is(T == const(int[])));
}
void hoo10(T)(auto ref T val) // auto ref with rvalue does
{
pragma(msg, T);
static assert(is(T == const(int)[]));
}
void bar10(T)(T prm)
{
pragma(msg, T);
static assert(is(T == const(int)*));
}
void test10()
{
const a = [1,2,3];
static assert(is(typeof(a) == const(int[])));
foo10(a);
boo10(a);
goo10(a);
hoo10(cast(const(int[]))[1,2,3]);
int n;
const p = &n;
static assert(is(typeof(p) == const(int*)));
bar10(p);
}
/**********************************/
// 3092
template Foo3092(A...)
{
alias A[0] Foo3092;
}
static assert(is(Foo3092!(int, "foo") == int));
/**********************************/
// 7037
struct Foo7037 {}
struct Bar7037 { Foo7037 f; alias f this; }
void works7037( T )( T value ) if ( is( T : Foo7037 ) ) {}
void doesnotwork7037( T : Foo7037 )( T value ) {}
void test7037()
{
Bar7037 b;
works7037( b );
doesnotwork7037( b );
}
/**********************************/
// 7110
struct S7110
{
int opSlice(int, int) const { return 0; }
int opSlice() const { return 0; }
int opIndex(int, int) const { return 0; }
int opIndex(int) const { return 0; }
}
enum e7110 = S7110();
template T7110(alias a) { } // or T7110(a...)
alias T7110!( S7110 ) T71100; // passes
alias T7110!((S7110)) T71101; // passes
alias T7110!( S7110()[0..0] ) A0; // passes
alias T7110!( (e7110[0..0]) ) A1; // passes
alias T7110!( e7110[0..0] ) A2; // passes
alias T7110!( S7110()[0, 0] ) B0; // passes
alias T7110!( (e7110[0, 0]) ) B1; // passes
alias T7110!( e7110[0, 0] ) B2; // passes
alias T7110!( S7110()[] ) C0; // passes
alias T7110!( (e7110[]) ) C1; // passes
alias T7110!( e7110[] ) C2; // fails: e7110 is used as a type
alias T7110!( S7110()[0] ) D0; // passes
alias T7110!( (e7110[0]) ) D1; // passes
alias T7110!( e7110[0] ) D2; // fails: e7110 must be an array or pointer type, not S7110
/**********************************/
// 7124
template StaticArrayOf(T : E[dim], E, size_t dim)
{
pragma(msg, "T = ", T, ", E = ", E, ", dim = ", dim);
alias E[dim] StaticArrayOf;
}
template DynamicArrayOf(T : E[], E)
{
pragma(msg, "T = ", T, ", E = ", E);
alias E[] DynamicArrayOf;
}
template AssocArrayOf(T : V[K], K, V)
{
pragma(msg, "T = ", T, ", K = ", K, ", V = ", V);
alias V[K] AssocArrayOf;
}
void test7124()
{
struct SA { int[5] sa; alias sa this; }
static assert(is(StaticArrayOf!SA == int[5]));
struct DA { int[] da; alias da this; }
static assert(is(DynamicArrayOf!DA == int[]));
struct AA { int[string] aa; alias aa this; }
static assert(is(AssocArrayOf!AA == int[string]));
}
/**********************************/
// 7359
bool foo7359(T)(T[] a ...)
{
return true;
}
void test7359()
{
assert(foo7359(1,1,1,1,1,1)); // OK
assert(foo7359("abc","abc","abc","abc")); // NG
}
/**********************************/
// 7363
template t7363()
{
enum e = 0;
static if (true)
enum t7363 = 0;
}
static assert(!__traits(compiles, t7363!().t7363 == 0)); // Assertion fails
static assert(t7363!() == 0); // Error: void has no value
template u7363()
{
static if (true)
{
enum e = 0;
enum u73631 = 0;
}
alias u73631 u7363;
}
static assert(!__traits(compiles, u7363!().u7363 == 0)); // Assertion fails
static assert(u7363!() == 0); // Error: void has no value
/**********************************/
struct S4371(T ...) { }
alias S4371!("hi!") t;
static if (is(t U == S4371!(U))) { }
/**********************************/
// 7416
void t7416(alias a)() if(is(typeof(a())))
{}
void test7416() {