Re: Creating an array of immutable objects

2017-02-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-02-15 01:08, David Zhang wrote: Thanks for your answers. Out of curiosity though, how could something like this be done with classes instead? You mean if FileDesc was a class? It's basically the same. You would need: Mutable array: 1. Add a constructor which sets all immutable instanc

Re: Creating an array of immutable objects

2017-02-14 Thread David Zhang via Digitalmars-d-learn
Thanks for your answers. Out of curiosity though, how could something like this be done with classes instead?

Re: Creating an array of immutable objects

2017-02-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-02-14 01:59, David Zhang wrote: 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*/; Yo

Re: Creating an array of immutable objects

2017-02-13 Thread Ali Çehreli via Digitalmars-d-learn
On 02/13/2017 04:59 PM, David Zhang wrote: 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. I realize that I misunderstood you; see below for a mutable array. The following code produces an immutable array throug

Creating an array of immutable objects

2017-02-13 Thread David Zhang via Digitalmars-d-learn
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