Char literals
    Michal Minich 
    michal.minich at gmail.com
       
    Fri Nov  6 04:37:22 PST 2009
    
    
  
Hello Eldar,
> I've just written a simple replicate function (the one from std.range
> does not work in CTFE):
> T[] replicate(T)(int n, T value)
> {
> T[] ret;
> if (n > 0)
> {
> for(int i = 0; i < n; i++)
> ret ~= value;
> }
> return ret;
> }
> it's not the best implementation, but that's not the thing I want to
> say today. When I call it
> 
> string str = replicate(5, 'a');
> 
> I get
> 
> moc.d(370): Error: cannot implicitly convert expression
> (replicate(5,',')) of type char[] to string
> 
> That means that char literals are "char", but not "immutable(char)". I
> remember the whole conversation about array literals, but char
> literals are closer to those of the string. What's the reasoning
> behind leaving them as mutable char?
> 
no builtin type is immutable by default. 
string is not builtin type, it is defined as "alias immutable(char)[]  string;" 
in object.d file.
    
    
More information about the Digitalmars-d
mailing list