Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/11/15 7:51 AM, Daniel Kozák via Digitalmars-d-learn wrote: On Thu, 11 Jun 2015 11:43:25 + via Digitalmars-d-learn wrote: On Thursday, 11 June 2015 at 08:33:46 UTC, Daniel Kozák wrote: On Wed, 10 Jun 2015 20:22:17 + Adel Mamin via Digitalmars-d-learn wrote: ubyte[5] a = 0xAA;

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread weaselcat via Digitalmars-d-learn
On Thursday, 11 June 2015 at 07:57:47 UTC, Per Nordlöw wrote: On Wednesday, 10 June 2015 at 22:03:52 UTC, Ali Çehreli wrote: Another option: void main() { auto a2 = new ubyte[5]; But this causes an extra zero-initialization of a2. just an fyi, gdc optimizes this away(looks like it overwr

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 11 Jun 2015 11:43:25 + via Digitalmars-d-learn wrote: > On Thursday, 11 June 2015 at 08:33:46 UTC, Daniel Kozák wrote: > > On Wed, 10 Jun 2015 20:22:17 + > > Adel Mamin via Digitalmars-d-learn > > > > wrote: > > > >> ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes. > >> auto a2 = n

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread via Digitalmars-d-learn
On Thursday, 11 June 2015 at 08:33:46 UTC, Daniel Kozák wrote: On Wed, 10 Jun 2015 20:22:17 + Adel Mamin via Digitalmars-d-learn wrote: ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes. auto a2 = new ubyte[5]; // Fine. Five 0 bytes. Now, let's say, I want to allocate an array of a size, deriv

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread via Digitalmars-d-learn
On Thursday, 11 June 2015 at 07:57:47 UTC, Per Nordlöw wrote: On Wednesday, 10 June 2015 at 22:03:52 UTC, Ali Çehreli wrote: Another option: void main() { auto a2 = new ubyte[5]; But this causes an extra zero-initialization of a2. a2[] = 0xAA;// <-- Assign to "all elements" Is

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread Daniel Kozák via Digitalmars-d-learn
On Wed, 10 Jun 2015 20:22:17 + Adel Mamin via Digitalmars-d-learn wrote: > ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes. > auto a2 = new ubyte[5]; // Fine. Five 0 bytes. > Now, let's say, I want to allocate an array of a size, derived at > run time, and initialize it to some non-zero value at

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-11 Thread via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 22:03:52 UTC, Ali Çehreli wrote: Another option: void main() { auto a2 = new ubyte[5]; But this causes an extra zero-initialization of a2. a2[] = 0xAA;// <-- Assign to "all elements" Is auto a2 = value.repeat(size).array; better in this regar

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 06/10/2015 01:22 PM, Adel Mamin wrote: ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes. auto a2 = new ubyte[5]; // Fine. Five 0 bytes. Now, let's say, I want to allocate an array of a size, derived at run time, and initialize it to some non-zero value at the same time. What would be the shortest w

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-10 Thread Michael Coulombe via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 20:22:18 UTC, Adel Mamin wrote: ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes. auto a2 = new ubyte[5]; // Fine. Five 0 bytes. Now, let's say, I want to allocate an array of a size, derived at run time, and initialize it to some non-zero value at the same time. What w

Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-10 Thread Low Functioning via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 20:22:18 UTC, Adel Mamin wrote: ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes. auto a2 = new ubyte[5]; // Fine. Five 0 bytes. Now, let's say, I want to allocate an array of a size, derived at run time, and initialize it to some non-zero value at the same time. What w