On Fri, 30 Jul 2010 12:46:20 -0400, bearophile <bearophileh...@lycos.com>
wrote:
Steven Schveighoffer:
> char[] divider = new char[5];
> divider[] = '-';
That assigns 0xff to all divider chars, and then assigns '-'. I think
there's a way to do it without the initial assignment.
I was wrong, I looked through the runtime and did not find such a function.
I think I may have read it in my copy of TDPL that I reviewed.
In any case, I think D deserves a way to do that.
In past there was some way to do that:
typedef char mchar = '-';
mchar[] divider = new mchar[5];
As a way to initialize an array, this is horrible :)
Now you have to initialize the dynamic array two times (using a char
struct with alias this is probably not a good idea).
I have shown this problem, but I think Walter was not interested. Maybe
LDC will able to optimize away the first initialization, I have an
enhancement request for LLVM.
I think a function to do it is fine, like makeArray('-', 5);
-Steve