Dynamic array of strings and appending a zero length array
    Cecil Ward 
    cecil at cecilward.com
       
    Sat Jul  8 17:15:26 UTC 2023
    
    
  
I have a dynamic array of dstrings and I’m spending dstrings to 
it. At one point I need to append a zero-length string just to 
increase the length of the array by one but I can’t have a slot 
containing garbage. I thought about ++arr.length - would that 
work, while giving me valid contents to the final slot ?
What I first did was
    arr ~= [];
This gave no errors but it doesn’t increase the array length, so 
it seems. Is that a bug ? Or is it supposed to do that?
Then I tried
     arr ~= ""d;
and that did work. Is there anything more efficient that I could 
do instead?
I actually have an alias for the type of the strings so that they 
can be either dstrings or wstrings with just a recompilation. How 
should I then generate a zero-length string that has th correct 
type of dstring or wstring as I am stuck with the ‘d’-suffix on 
the end of the ""d at the moment. Can I just cast ? Not a 
reinterpret cast, but a proper value conversion?
    
    
More information about the Digitalmars-d-learn
mailing list