Documentation: example no longer compiles

Denton Cockburn diboss at hotmail.com
Thu Feb 28 17:55:32 PST 2008


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()


More information about the Digitalmars-d-bugs mailing list