1 diff -Nurp a/src/phobos/std/conv.d b/src/phobos/std/conv.d
2 --- a/src/phobos/std/conv.d 2012-04-17 12:02:10.824875716 +0200
3 +++ b/src/phobos/std/conv.d 2012-04-17 12:15:10.654126508 +0200
4 @@ -101,6 +101,12 @@ private
5 formatValue(w, src, f);
9 + template isEnumStrToStr(S, T) // @@@Workaround@@@
11 + enum isEnumStrToStr = isImplicitlyConvertible!(S, T) &&
12 + is(S == enum) && isSomeString!T;
17 @@ -250,7 +256,7 @@ If the source type is implicitly convert
18 to) simply performs the implicit conversion.
20 T toImpl(T, S)(S value)
21 - if (isImplicitlyConvertible!(S, T))
22 + if (isImplicitlyConvertible!(S, T) && !isEnumStrToStr!(S, T))
24 alias isUnsigned isUnsignedInt;
26 @@ -1032,8 +1038,7 @@ unittest
30 - if (!isImplicitlyConvertible!(S, T) &&
32 + if (is(S == enum) &&
36 @@ -1042,21 +1047,26 @@ T toImpl(T, S)(S s)
39 debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
41 - assert(to! string(E.a) == "a"c);
42 - assert(to!wstring(E.b) == "b"w);
43 - assert(to!dstring(E.c) == "c"d);
45 - enum F : real { x = 1.414, y = 1.732, z = 2.236 }
46 - assert(to! string(F.x) == "x"c);
47 - assert(to!wstring(F.y) == "y"w);
48 - assert(to!dstring(F.z) == "z"d);
50 + enum EB { a = true }
51 + enum EU { a = 0, b = 1, c = 2 } // base type is unsigned
52 + enum EI { a = -1, b = 0, c = 1 } // base type is signed (bug 7909)
53 + enum EF : real { a = 1.414, b = 1.732, c = 2.236 }
54 + enum EC { a = 'a', b = 'b' }
55 + enum ES : string { a = "aaa", b = "bbb" }
57 + foreach (E; TypeTuple!(EB, EU, EI, EF, EC, ES))
59 + assert(to! string(E.a) == "a"c);
60 + assert(to!wstring(E.a) == "a"w);
61 + assert(to!dstring(E.a) == "a"d);
64 // Test an value not corresponding to an enum member.
66 - assert(to! string(o) == "cast(E)5"c);
67 - assert(to!wstring(o) == "cast(E)5"w);
68 - assert(to!dstring(o) == "cast(E)5"d);
70 + assert(to! string(o) == "cast(EU)5"c);
71 + assert(to!wstring(o) == "cast(EU)5"w);
72 + assert(to!dstring(o) == "cast(EU)5"d);
76 @@ -1073,7 +1083,7 @@ deprecated T toImpl(T, S)(S s, in T left
80 - if (is(Unqual!S == bool) &&
85 @@ -1090,7 +1100,7 @@ unittest
89 - if (isSomeChar!(Unqual!S) &&
94 @@ -1132,7 +1142,7 @@ unittest
97 T toImpl(T, S)(S input)
98 - if (isIntegral!S && isUnsigned!S &&
102 return toStr!T(input);
103 @@ -1149,26 +1159,7 @@ unittest
104 assert(to!string(to!Int(9)) == "9");
105 assert(to!string(to!Int(123)) == "123");
110 -T toImpl(T, S)(S value)
111 - if (isIntegral!S && isSigned!S &&
114 - return toStr!T(value);
119 - debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
120 - assert(wtext(int.max) == "2147483647"w);
121 - assert(wtext(int.min) == "-2147483648"w);
122 - assert(to!string(0L) == "0");
127 foreach (Int; TypeTuple!(byte, short, int, long))
129 debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
130 @@ -1184,9 +1175,17 @@ unittest
136 + debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
137 + assert(wtext(int.max) == "2147483647"w);
138 + assert(wtext(int.min) == "-2147483648"w);
139 + assert(to!string(0L) == "0");
143 T toImpl(T, S)(S value, uint radix)
144 - if (isIntegral!(Unqual!S) &&
145 + if (isIntegral!S &&
149 @@ -1194,7 +1193,7 @@ in
153 - static if (!is(Unqual!S == ulong))
154 + static if (!is(IntegralTypeOf!S == ulong))
156 enforce(radix >= 2 && radix <= 36, new ConvException("Radix error"));
158 @@ -2076,24 +2075,25 @@ Target parse(Target, Source)(ref Source
159 ~ to!string(s) ~ "'");
162 -//@@@BUG4737@@@: typeid doesn't work for scoped enum with initializer
165 - private enum F : real { x = 1.414, y = 1.732, z = 2.236 }
169 debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
171 - assert(to!E("a"c) == E.a);
172 - assert(to!E("b"w) == E.b);
173 - assert(to!E("c"d) == E.c);
175 - assert(to!F("x"c) == F.x);
176 - assert(to!F("y"w) == F.y);
177 - assert(to!F("z"d) == F.z);
178 + enum EB : bool { a = true, b = false, c = a }
179 + enum EU { a, b, c }
180 + enum EI { a = -1, b = 0, c = 1 }
181 + enum EF : real { a = 1.414, b = 1.732, c = 2.236 }
182 + enum EC : char { a = 'a', b = 'b', c = 'c' }
183 + enum ES : string { a = "aaa", b = "bbb", c = "ccc" }
185 + foreach (E; TypeTuple!(EB, EU, EI, EF, EC, ES))
187 + assert(to!E("a"c) == E.a);
188 + assert(to!E("b"w) == E.b);
189 + assert(to!E("c"d) == E.c);
191 - assertThrown!ConvException(to!E("d"));
192 + assertThrown!ConvException(to!E("d"));
196 version (none) // TODO: BUG4744
197 diff -Nurp a/src/phobos/std/stdio.d b/src/phobos/std/stdio.d
198 --- a/src/phobos/std/stdio.d 2012-04-17 12:02:10.957874054 +0200
199 +++ b/src/phobos/std/stdio.d 2012-04-17 12:15:10.648126586 +0200
200 @@ -665,19 +665,19 @@ arguments in text format to the file. */
204 - static if (isSomeString!A && !is(A == enum))
205 + static if (isSomeString!A)
209 - else static if (isIntegral!A && !is(A == enum))
210 + else static if (isIntegral!A)
214 - else static if (isBoolean!A && !is(A == enum))
215 + else static if (isBoolean!A)
217 put(w, arg ? "true" : "false");
219 - else static if (isSomeChar!A && !is(A == enum))
220 + else static if (isSomeChar!A)
224 diff -Nurp a/src/phobos/std/traits.d b/src/phobos/std/traits.d
225 --- a/src/phobos/std/traits.d 2012-04-17 12:02:10.897874804 +0200
226 +++ b/src/phobos/std/traits.d 2012-04-17 12:15:10.647126599 +0200
227 @@ -2693,7 +2693,7 @@ unittest
231 -template BooleanTypeOf(T)
232 +template BooleanTypeOf(T) if (!is(T == enum))
234 inout(bool) idx( inout(bool) );
235 shared(inout bool) idx( shared(inout bool) );
236 @@ -2727,7 +2727,7 @@ unittest
240 -template IntegralTypeOf(T)
241 +template IntegralTypeOf(T) if (!is(T == enum))
243 inout( byte) idx( inout( byte) );
244 inout( ubyte) idx( inout( ubyte) );
245 @@ -2786,7 +2786,7 @@ unittest
249 -template FloatingPointTypeOf(T)
250 +template FloatingPointTypeOf(T) if (!is(T == enum))
252 inout( float) idx( inout( float) );
253 inout(double) idx( inout(double) );
254 @@ -2825,7 +2825,7 @@ unittest
258 -template NumericTypeOf(T)
259 +template NumericTypeOf(T) if (!is(T == enum))
261 static if (is(IntegralTypeOf!T X))
262 alias X NumericTypeOf;
263 @@ -2853,7 +2853,7 @@ unittest
267 -template UnsignedTypeOf(T)
268 +template UnsignedTypeOf(T) if (!is(T == enum))
270 static if (is(IntegralTypeOf!T X) &&
271 staticIndexOf!(Unqual!X, UnsignedIntTypeList) >= 0)
272 @@ -2862,7 +2862,7 @@ template UnsignedTypeOf(T)
273 static assert(0, T.stringof~" is not an unsigned type.");
276 -template SignedTypeOf(T)
277 +template SignedTypeOf(T) if (!is(T == enum))
279 static if (is(IntegralTypeOf!T X) &&
280 staticIndexOf!(Unqual!X, SignedIntTypeList) >= 0)
281 @@ -2875,7 +2875,7 @@ template SignedTypeOf(T)
285 -template CharTypeOf(T)
286 +template CharTypeOf(T) if (!is(T == enum))
288 inout( char) idx( inout( char) );
289 inout(wchar) idx( inout(wchar) );
290 @@ -2930,7 +2930,7 @@ unittest
294 -template StaticArrayTypeOf(T)
295 +template StaticArrayTypeOf(T) if (!is(T == enum))
297 inout(U[n]) idx(U, size_t n)( inout(U[n]) );
299 @@ -2961,7 +2961,7 @@ unittest
303 -template DynamicArrayTypeOf(T)
304 +template DynamicArrayTypeOf(T) if (!is(T == enum))
306 inout(U[]) idx(U)( inout(U[]) );
308 @@ -3001,7 +3001,7 @@ unittest
312 -template ArrayTypeOf(T)
313 +template ArrayTypeOf(T) if (!is(T == enum))
315 static if (is(StaticArrayTypeOf!T X))
317 @@ -3017,7 +3017,7 @@ unittest
321 -template StringTypeOf(T) if (isSomeString!T)
322 +template StringTypeOf(T) if (!is(T == enum) && isSomeString!T)
324 alias ArrayTypeOf!T StringTypeOf;
326 @@ -3047,7 +3047,7 @@ unittest
330 -template AssocArrayTypeOf(T)
331 +template AssocArrayTypeOf(T) if (!is(T == enum))
333 immutable(V [K]) idx(K, V)( immutable(V [K]) );
335 @@ -3279,7 +3279,10 @@ Detect whether we can treat T as one of
337 template isSomeString(T)
339 - enum isSomeString = isNarrowString!T || is(T : const(dchar[]));
340 + static if (is(T == enum))
341 + enum isSomeString = false;
343 + enum isSomeString = isNarrowString!T || is(T : const(dchar[]));