Re: Creating an array of default-constructed class instances

2013-02-10 Thread Ali Çehreli
On 02/10/2013 03:18 AM, monarch_dodra wrote: > On Sunday, 10 February 2013 at 09:48:04 UTC, Jos van Uden wrote: >> auto things = new Thing[10]; >> fill(things, new Thing(5)); > What you did just right there is allocate a *single* thing _instance_ > and then place 10 _references_ to that same thi

Re: Creating an array of default-constructed class instances

2013-02-10 Thread monarch_dodra
On Sunday, 10 February 2013 at 06:14:37 UTC, Simon wrote: Hi, I'm new to the D programming language. Overall I'm liking things very much, but I'm still getting the hang of a few things. Here's a basic programming pattern: I have a class called Thing, and while I'm coding I decide I need N Thi

Re: Creating an array of default-constructed class instances

2013-02-10 Thread monarch_dodra
On Sunday, 10 February 2013 at 09:48:04 UTC, Jos van Uden wrote: On 10-2-2013 7:14, Simon wrote: Hi, I'm new to the D programming language. Overall I'm liking things very much, but I'm still getting the hang of a few things. Here's a basic programming pattern: I have a class called Thing,

Re: Creating an array of default-constructed class instances

2013-02-10 Thread Jos van Uden
On 10-2-2013 7:14, Simon wrote: Hi, I'm new to the D programming language. Overall I'm liking things very much, but I'm still getting the hang of a few things. Here's a basic programming pattern: I have a class called Thing, and while I'm coding I decide I need N Thing instances. In C++ that's

Re: Creating an array of default-constructed class instances

2013-02-10 Thread Philippe Sigaud
On Sun, Feb 10, 2013 at 8:40 AM, Simon wrote: >> auto things = iota(10).map!(i => new Thing(i)).array; >> >> Ali > > > It's a shame there isn't any simple syntax for it, but that's some neat and > flexible code. Oh, you can easily use a template: import std.array; import std.algorithm; impo

Re: Creating an array of default-constructed class instances

2013-02-09 Thread Simon
On Sunday, 10 February 2013 at 06:57:42 UTC, Ali Çehreli wrote: On 02/09/2013 10:52 PM, Ali Çehreli wrote: > auto things = iota(10).map!(i => new Thing(i))().array; Actually, without the extra parentheses: auto things = iota(10).map!(i => new Thing(i)).array; Ali It's a shame there is

Re: Creating an array of default-constructed class instances

2013-02-09 Thread Ali Çehreli
On 02/09/2013 10:52 PM, Ali Çehreli wrote: > auto things = iota(10).map!(i => new Thing(i))().array; Actually, without the extra parentheses: auto things = iota(10).map!(i => new Thing(i)).array; Ali

Re: Creating an array of default-constructed class instances

2013-02-09 Thread Ali Çehreli
On 02/09/2013 10:14 PM, Simon wrote: > Hi, I'm new to the D programming language. Overall I'm liking > things very much, but I'm still getting the hang of a few things. > > Here's a basic programming pattern: I have a class called Thing, > and while I'm coding I decide I need N Thing instances. >

Re: Creating an array of default-constructed class instances

2013-02-09 Thread Maxim Fomin
On Sunday, 10 February 2013 at 06:14:37 UTC, Simon wrote: Hi, I'm new to the D programming language. Overall I'm liking things very much, but I'm still getting the hang of a few things. Here's a basic programming pattern: I have a class called Thing, and while I'm coding I decide I need N Thi

Creating an array of default-constructed class instances

2013-02-09 Thread Simon
Hi, I'm new to the D programming language. Overall I'm liking things very much, but I'm still getting the hang of a few things. Here's a basic programming pattern: I have a class called Thing, and while I'm coding I decide I need N Thing instances. In C++ that's a matter of std::vector things(