Initializing values in associative arrays
    bearophile 
    bearophileHUGS at lycos.com
       
    Thu Nov 29 11:23:59 PST 2012
    
    
  
Joseph Rushton Wakeling:
> How safe is it to rely on doing something like this:
>
>     uint[size_t] x;
>
>     foreach(i; iota(0, 10))
>         x[i]++;
>
>     foreach(i; iota(5, 15))
>         x[i]++;
This is part of the D associative array specs, so in theory it's 
safe, but you have to keep this implementation bug in account:
http://d.puremagic.com/issues/show_bug.cgi?id=3825
> I note that the above works even if uint[size_t] is changed to 
> real[size_t], which is a surprise, because I'd have assumed 
> that everything would come out as nan's.
This is a known AA bug :-( I think that there is not yet a patch 
to fix it.
Bye,
bearophile
    
    
More information about the Digitalmars-d-learn
mailing list