Creating an array of immutable objects

David Zhang via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 13 16:59:49 PST 2017


Hi,

I have a struct with two immutable members, and I want to make an 
array of them. How do I to this? I'm using allocators for this.

string[] paths;

struct FileDesc {
     immutable string path;
     immutable uint index;
}

_fileDesc = /*something*/;

You can't use alloc.makeArray because it requires a range with 
which to initialize the array, and while I can produce an array 
of paths, I don't know how to merge both a range of paths and 
indices. Lockstep doesn't work.

I also tried using emplace and an allocated byte array, but it 
gave me random values and was (I think) unnecessarily 
complicated. What am I missing?


More information about the Digitalmars-d-learn mailing list