-
Notifications
You must be signed in to change notification settings - Fork 0
/
opover.d
124 lines (106 loc) · 2.2 KB
/
opover.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
struct BinOpUFCS{
}
auto opBinary(string op)(BinOpUFCS lhs,BinOpUFCS rhs){
//1=2;
return 2;
}
auto opBinaryRight(string op)(BinOpUFCS rhs, BinOpUFCS lhs){
//1=2;
return 3;
}
auto opUnary(dstring op)(){
return ""+1; // error
}
pragma(msg, BinOpUFCS()+BinOpUFCS()); // error
pragma(msg, ""+1); // error
pragma(msg, +BinOpUFCS());
struct UFCS{this(){}}
int opIndex(UFCS i, int x){
return x;
}
string opBinary(string s)(UFCS a, UFCS b){
return s;
}
pragma(msg, "UFCS.opIndex: ",UFCS()[3]);
pragma(msg, "UFCS.opBinary: ",UFCS()>>>UFCS());
struct S{
int opIndex(int x)const{
return x;
}
auto opIndex(T...)(T indices)const{
return indices.length;
}
int[] opSlice(int a,int b)const{
return [a,b];
}
string opUnary(string op)()const{
return "opUnary: "~op;
}
string opBinary(string op)(const S rhs)const{
return "opBinary: "~op;
}
string opOpAssign(string op)(const S rhs)const{
return "opOpAssign: "~op;
}
}
immutable S s;
struct T{}
immutable T t;
pragma(msg, "opIndex: ",s.opIndex(1,2,3));
int testIndex(int x){
S s;
return s[x];
}
pragma(msg, "opIndex: ",s[53]);
pragma(msg, t[2]); // error
pragma(msg, "opSlice: ",s[3..4]);
pragma(msg, t[3..4]); // error
pragma(msg, "opIndex: ",s[1,2,3]);
pragma(msg, t[1,2,3]); // error
//["-","+","~","*","++","--"]
pragma(msg, -s);
pragma(msg, +s);
pragma(msg, ~s);
pragma(msg, *s);
pragma(msg, ++s);
pragma(msg, --s);
pragma(msg, s+s);
pragma(msg, s-s);
pragma(msg, s*s);
pragma(msg, s/s);
pragma(msg, s%s);
pragma(msg, s^^s);
pragma(msg, s&s);
pragma(msg, s|s);
pragma(msg, s^s);
pragma(msg, s<<s);
pragma(msg, s>>s);
pragma(msg, s>>>s);
pragma(msg, s~s);
pragma(msg, s in s);
pragma(msg, s !in s); // error
struct SupportNotIn{
bool opBinaryRight(string op)(int l) if(op=="in"){
return !l;
}
}
pragma(msg, "opBinaryRight!\"!in\"(1):", 1 !in SupportNotIn());
pragma(msg, "opBinaryRight!\"!in\"(0):", 0 !in SupportNotIn());
pragma(msg, s+=s);
pragma(msg, s-=s);
pragma(msg, s*=s);
pragma(msg, s/=s);
pragma(msg, s%=s);
pragma(msg, s^^=s);
pragma(msg, s&=s);
pragma(msg, s|=s);
pragma(msg, s^=s);
pragma(msg, s<<=s);
pragma(msg, s>>=s);
pragma(msg, s>>>s);
pragma(msg, s~s);
// +/
// +/
// +/
alias immutable(char)[] string;
alias immutable(dchar)[] dstring;