Genuine copy of an element from an associative array
    Holzofen 
    z5iph7ukvx at yopmail.com
       
    Thu Oct  3 12:23:27 UTC 2024
    
    
  
This is my (feeble) source code, for testing purposes only:
     uint64 sod_decompose(const uint64 n, const uint64 mod, const 
ref uint64[] primes, const ref uint64[uint64][uint64] factorials)
     {
         auto result = factorials[n];
         for (uint64 k = 2; k < n - 1; k++) {
             auto backup = factorials[n];
             tuple("1", backup).writeln;
             foreach (p, e; factorials[k]) {
                 backup[p] -= e;
             }
             tuple("2", backup).writeln;
             foreach (p, e; factorials[n-k]) {
                 backup[p] -= e;
             }
             tuple("3", backup).writeln;
         }
         return 0;
     }
uint64 is equivalent to ulong. Upon compilation I get this error:
Error: cannot modify `const` expression `backup[p]`
which concerns these two lines: backup[p] -= e;
Without the const statement in the function declaration the 
source array will be modified which is definitely not desirable. 
Could anybody point me to a way how to make a straight copy 
without meddling with the source array?
Thank you!
    
    
More information about the Digitalmars-d-learn
mailing list