Code doesn't work - why?
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Sep 17 10:34:46 PDT 2014
    
    
  
On 09/17/2014 03:42 AM, Robin wrote:> Hiho,
 > However, I still do not understand why it didn't work for struct value
 > types since I do not perform any mutations on the state objects during
 > execution of the code.
I was a little sloppy with my response. :) What I suspected is still 
correct though. The following are the mutations:
     s0.addTransits(['0' : s1, '1' : s2]);
     s1.addTransits(['0' : s0, '1' : s2]);
     s2.addTransits(['0' : s2, '1' : s2]);
Note that s0 gets a copy of s1 before s1 knows about its transits.
 > When value types are copied bitwise then the associative array should
 > also be copied that way or at least point to the same mapping as the
 > source and thus shouldn't be empty after copying.
There is an issue with uninitialized associative arrays: Although one 
would think that both s1 copies would use the same AA, since the AA is 
uninitialized, they would both initialize it first, having separate AAs.
This is a pretty nasty problem as it matters whether the AA had a single 
record before the copy or not. :(
 > What changes are required in order to make it work with struct value
 > types as well?
I am ashamed to admit that I am not sure how to initialize an AA to the 
empty state. I can do the following though: :)
         this.transits['z'] = this;
         this.transits.remove('z');
Ali
    
    
More information about the Digitalmars-d-learn
mailing list