-
Notifications
You must be signed in to change notification settings - Fork 0
/
overload.d
119 lines (79 loc) · 2.71 KB
/
overload.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
bool testFwdDecl(int x);
static assert(testFwdDecl(2) && !testFwdDecl(3));
bool testFwdDecl(int x)=>x==2;
template iftioverload(T){
T iftioverload(T a, float b){return a;}
int iftioverload(int a, double b){return a;}
}
void testiftioverload(){
iftioverload!()(2,2); // TODO: how should this behave?
}
alias immutable(char)[] string;
int fun(int delegate(int,int) a){return a(1,2);}
auto fun(string delegate(int,string) b){return b(1,"2");}
pragma(msg, fun((a,b){static if(is(typeof(b)==string)) return ""; else return 2;})); // error: ambiguous
int fun(int delegate(int,int) a, string delegate(int,string) b){return a(1,2);}
int fun(string delegate(int,string) b, int delegate(int,int) a){return a(1,2);}
pragma(msg, fun((a,b){static if(is(typeof(b)==string)) return 1; else return "";}, (a,b)=>b));// error: no match
bool isLvalue(ref int x){return true;}
bool isLvalue(int x){return false;}
static assert(!isLvalue(1));
static assert({int x;return isLvalue(x);}());
bool testRefOv(ref int x, double y){return true;}
bool testRefOv(int x, int y){return false;}
static assert(!testRefOv(1,1));
static assert(!{int x;return testRefOv(x,1);}());
static assert({int x;return testRefOv(x,1.0);}());
static assert(!is(typeof({return testRefOv(1,1.0);})));
bool testRefOv2(const ref int){ return true; }
bool testRefOv2(ref immutable(int)){ return false; }
static assert(is(typeof({immutable int x; return testRefOv2(x);})));
static assert(!{immutable int x; return testRefOv2(x);}());
int foo(typeof(foo(2,3)) x){return x;} // TODO
int foo(int,int){return 2;}
bool foo(undef){return 1;} // error
bool foo(undef a,undef b){return e;} // error
pragma(msg, foo("asdf","asdf"));
void foo(int, int){}
void foo(double, int){}
void bar(const int){}
void bar(shared int){}
void qux(double){}
void qux(int,double=2){} // this one should be called
void qux2(int){} // this one should be called
void qux2(int,double=2.0){}
void baz(int x, double y){}
void baz(immutable(int) x, double y){}
//auto lol(){return lol(1);}
//int lol(typeof(lol()) x){return lol();}
//int lol(int){return 1;}
//int bar(typeof(lol)*x){pragma(msg,typeof(x));return 2;}
//auto a(){return a(1);}
//auto a(int){return a();}
int foo(immutable(char)[] s){return 0;}
double foo(immutable(wchar)[] d){return 0;}
double foo(immutable(dchar)[] s){return 0;}
void testref(int y){}
void testref(out int x){const(int) d=x;testref(d);}
void testref(ref immutable int y){}
immutable str = "hello";
void main(){
enum str=str;
pragma(msg, typeof("hello"));
pragma(msg, typeof(foo("hello"d)));
pragma(msg, typeof(foo(str)));
/+qux(1);
qux2(2);
//duh(guh);
//duh(1);
//duh(duh);+/
//pragma(msg,typeof(lol()));
/+
foo(1,1);
foo(1.0,1);
foo(1,1L);
bar(1);
+/
//baz(1,1);
}
// +/