On 05/26/2013 05:59 PM, Ali Çehreli wrote: > On 05/26/2013 05:38 AM, Simen Kjaeraas wrote: > > >> Tuple!(size_t, size_t)[][] data = createData(); >> immutable dataImm = assumeUnique(data); >> data = null; // Simply to ensure no mutable references exist. > > The last line is not needed. assumeUnique already does that. :)
That's fantastic, thank you both very much. Does that also work for arbitrary data structures (e.g. also associative arrays, complex structs/classes etc.)? Related question -- assume that I now want to store that immutable data inside a broader storage class, but I want that storage class to be agnostic as to whether the data is immutable, const or mutable. Something like this: class MyDataStore { float[] someData; uint[] someMoreData; Tuple!(size_t, size_t)[][] importedData; this(float[] sd, uint[] smd, Tuple!(size_t, size_t)[][] id) { someData = sd; someMoreData = smd; importedData = id; } } ... which of course fails if you try passing it immutable data for any of the parameters. So, is there a way to make this broader storage class type-qualifier-agnostic? I guess applying "inout" to the input parameters is necessary, but it's clearly not sufficient as the code then fails when trying to assign to the class' internal variables.