Problem with const correctness

Thiez thiezz at gmail.com
Mon Dec 10 05:37:45 PST 2012


On Monday, 10 December 2012 at 12:45:16 UTC, Dan wrote:
> That would be an infinite loop. If you have a compile time 
> cycle you would likely need your own custom dups anyway, as you 
> are doing low level and heap allocating already. But for the 
> simpler cases without cycles, if dup encounters a pointer it 
> creates a new instance on the heap (if compilation is possible) 
> and dup's into it.

Wouldn't it be better to do a cycle detection here? I imagine 
such a thing could be done quite easily by adding every pointer 
in the original struct to an associative array along with its 
(new) copy. Then, whenever you encounter a new pointer, you can 
check if it is already in the AA, and if so use the copy you made 
before. Of course this has some overhead compared to your 
suggestion, but it seems to me it would be safe in all cases, 
which makes more sense with a 'general dup'.


More information about the Digitalmars-d mailing list