digitalmars.D.bugs - Documentation: example no longer compiles
- Denton Cockburn (21/21) Feb 28 2008 This example found at
- =?ISO-8859-1?Q?S=F6nke_Ludwig?= (3/28) Mar 01 2008 Or even better, change all 'char[]' to 'string' with respect to D1/2
This example found at http://www.digitalmars.com/d/2.0/templates-revisited.html no longer compiles in 2.011: template decimalDigit(int n) // [3] { const char[] decimalDigit = "0123456789"[n..n+1]; } template itoa(long n) { static if (n < 0) const char[] itoa = "-" ~ itoa!(-n); else static if (n < 10) const char[] itoa = decimalDigit!(n); else const char[] itoa = itoa!(n/10L) ~ decimalDigit!(n%10L); } char[] foo() { return itoa!(264); // returns "264" } the fix is to change the signature of 'char[] foo()' to const(char[]) foo()
Feb 28 2008
Denton Cockburn wrote:This example found at http://www.digitalmars.com/d/2.0/templates-revisited.html no longer compiles in 2.011: template decimalDigit(int n) // [3] { const char[] decimalDigit = "0123456789"[n..n+1]; } template itoa(long n) { static if (n < 0) const char[] itoa = "-" ~ itoa!(-n); else static if (n < 10) const char[] itoa = decimalDigit!(n); else const char[] itoa = itoa!(n/10L) ~ decimalDigit!(n%10L); } char[] foo() { return itoa!(264); // returns "264" } the fix is to change the signature of 'char[] foo()' to const(char[]) foo()Or even better, change all 'char[]' to 'string' with respect to D1/2 compatibility.
Mar 01 2008