Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 17:22 schrieb Marc Schütz: > auto concat(T : E[n], E, size_t n)(const E[][] args...) @nogc > { > size_t offset = 0; > T result = void; > foreach(arr; args) { > result[offset .. offset+arr.length] = arr; > offset += arr.length; > } >

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 17:12 schrieb Johannes Loher: > Am 05.07.2016 um 16:39 schrieb Rene Zwanenburg: >> On Tuesday, 5 July 2016 at 12:34:20 UTC, Johannes Loher wrote: >>> I tried this, but it does not work correctly with slices. >> >> The length of a slice is a runtime value, which is why it can't be

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Marc Schütz via Digitalmars-d-learn
auto concat(T : E[n], E, size_t n)(const E[][] args...) @nogc { size_t offset = 0; T result = void; foreach(arr; args) { result[offset .. offset+arr.length] = arr; offset += arr.length; } assert(offset == result.length); return result; } static immutable

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 16:39 schrieb Rene Zwanenburg: > On Tuesday, 5 July 2016 at 12:34:20 UTC, Johannes Loher wrote: >> I tried this, but it does not work correctly with slices. > > The length of a slice is a runtime value, which is why it can't be used > to set static array size. What were you

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 5 July 2016 at 12:34:20 UTC, Johannes Loher wrote: I tried this, but it does not work correctly with slices. The length of a slice is a runtime value, which is why it can't be used to set static array size. What were you trying to achieve? Avoid copying the input arrays, or

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 00:41 schrieb Rene Zwanenburg: > On Monday, 4 July 2016 at 19:22:52 UTC, Johannes Loher wrote: >> This looks really nice, but I have several occurences of this, with >> different arrays (and lengths), so i would need to create several of >> those structs. But it looks really clean

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-04 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 4 July 2016 at 19:22:52 UTC, Johannes Loher wrote: This looks really nice, but I have several occurences of this, with different arrays (and lengths), so i would need to create several of those structs. But it looks really clean :) You can use a template to remove the boilerplate.

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-04 Thread Johannes Loher via Digitalmars-d-learn
Am 04.07.2016 um 19:24 schrieb ZombineDev: > On Monday, 4 July 2016 at 14:31:41 UTC, Johannes Loher wrote: >> In a project I am currently working on, I have lot's of code of the >> following form: >> >> static immutable ubyte[4] sigma0 = [101, 120, 112, 97]; static >> immutable ubyte[4] sigma1 =

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-04 Thread Johannes Loher via Digitalmars-d-learn
Am 04.07.2016 um 20:33 schrieb Ali Çehreli: > On 07/04/2016 07:31 AM, Johannes Loher wrote: >> In a project I am currently working on, I have lot's of code of the >> following form: >> >> static immutable ubyte[4] sigma0 = [101, 120, 112, 97]; >> static immutable ubyte[4] sigma1 = [110, 100, 32,

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-04 Thread Ali Çehreli via Digitalmars-d-learn
On 07/04/2016 07:31 AM, Johannes Loher wrote: > In a project I am currently working on, I have lot's of code of the > following form: > > static immutable ubyte[4] sigma0 = [101, 120, 112, 97]; > static immutable ubyte[4] sigma1 = [110, 100, 32, 51]; > static immutable ubyte[4] sigma2 = [ 50,

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-04 Thread ZombineDev via Digitalmars-d-learn
On Monday, 4 July 2016 at 14:31:41 UTC, Johannes Loher wrote: In a project I am currently working on, I have lot's of code of the following form: static immutable ubyte[4] sigma0 = [101, 120, 112, 97]; static immutable ubyte[4] sigma1 = [110, 100, 32, 51]; static immutable ubyte[4] sigma2

Initializing static array with contents of (static and dynamic) arrays

2016-07-04 Thread Johannes Loher via Digitalmars-d-learn
In a project I am currently working on, I have lot's of code of the following form: static immutable ubyte[4] sigma0 = [101, 120, 112, 97]; static immutable ubyte[4] sigma1 = [110, 100, 32, 51]; static immutable ubyte[4] sigma2 = [ 50, 45, 98, 121]; static immutable ubyte[4] sigma3 = [116,