Re: inferred size for static array initialization

2016-10-18 Thread Namespace via Digitalmars-d-learn
On Tuesday, 18 October 2016 at 10:35:44 UTC, Nordlöw wrote: On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: immutable auto a = [1,2,3].s; Will that have zero run-time overhead compared to: immutable int[3] a = [1,2,3]; ? I'm not quite sure if pragma(inline, true) would result

Re: inferred size for static array initialization

2016-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/18/16 6:35 AM, Nordlöw wrote: On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: immutable auto a = [1,2,3].s; Will that have zero run-time overhead compared to: immutable int[3] a = [1,2,3]; Neither will have zero runtime overhead, but use the disassembler to see if there

Re: inferred size for static array initialization

2016-10-18 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: immutable auto a = [1,2,3].s; Will that have zero run-time overhead compared to: immutable int[3] a = [1,2,3]; ?

Re: inferred size for static array initialization

2016-05-03 Thread Basile B. via Digitalmars-d-learn
On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: I still like auto s(T, size_t n)(T[n] arr) { return arr; } Wooah, this trick is awesome. But actually it does the same thing that what I've proposed before. Exactly the same code is generated. So I'd say that it's rather a

Re: inferred size for static array initialization

2016-05-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/2/16 4:14 PM, Namespace wrote: I used it very often, but always assigned the result to an auto-type variable, never to a slice. Using auto is fine, but the slice should not happen if you are assigning slice to a local var. There is a bug report on this: https://issues.dlang.org/show_bug

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 20:05:15 UTC, Steven Schveighoffer wrote: On 5/2/16 3:38 PM, Namespace wrote: The assembler might be safe in some instances, but that doesn't reflect the original internal representation in the compiler. Some other configuration of calls may allow the compiler to reuse

Re: inferred size for static array initialization

2016-05-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/2/16 3:38 PM, Namespace wrote: The assembler might be safe in some instances, but that doesn't reflect the original internal representation in the compiler. Some other configuration of calls may allow the compiler to reuse that memory, and then you run into problems. I'm wondering if you us

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
The assembler might be safe in some instances, but that doesn't reflect the original internal representation in the compiler. Some other configuration of calls may allow the compiler to reuse that memory, and then you run into problems. I'm wondering if you used my rewrite if it would actually

Re: inferred size for static array initialization

2016-05-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/2/16 3:12 PM, Namespace wrote: On Monday, 2 May 2016 at 19:08:52 UTC, Steven Schveighoffer wrote: On 5/2/16 3:02 PM, Namespace wrote: On Monday, 2 May 2016 at 18:57:49 UTC, Namespace wrote: A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a d

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 19:08:52 UTC, Steven Schveighoffer wrote: On 5/2/16 3:02 PM, Namespace wrote: On Monday, 2 May 2016 at 18:57:49 UTC, Namespace wrote: A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a deeper issue of allowing slicing of r

Re: inferred size for static array initialization

2016-05-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/2/16 3:02 PM, Namespace wrote: On Monday, 2 May 2016 at 18:57:49 UTC, Namespace wrote: A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a deeper issue of allowing slicing of rvalues. This works: int[] as = [1, 2, 3].s; writeln(as[2]); O

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a deeper issue of allowing slicing of rvalues. This works: int[] as = [1, 2, 3].s; writeln(as[2]); Bug or feature? Or did I may misunderstood you? You can drop auto. It's just a placeholder

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 18:57:49 UTC, Namespace wrote: A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a deeper issue of allowing slicing of rvalues. This works: int[] as = [1, 2, 3].s; writeln(as[2]); Of course this slice is only valid as

Re: inferred size for static array initialization

2016-05-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/2/16 1:43 PM, Namespace wrote: On Monday, 2 May 2016 at 13:00:27 UTC, Erik Smith wrote: Is there a way to initialize a static array and have it's size inferred (and that works for arrays of structs using braced literals)? This would make it easier to maintain longer static array definition

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 13:00:27 UTC, Erik Smith wrote: Is there a way to initialize a static array and have it's size inferred (and that works for arrays of structs using braced literals)? This would make it easier to maintain longer static array definitions. The code below doesn't work whe

Re: inferred size for static array initialization

2016-05-02 Thread Erik Smith via Digitalmars-d-learn
I tried to combine the two solutions (Basile with the wrapper, Marco with the struct initializer support) but it didn't work. The struct initializer is not a array literal (seems obvious now). I might go with the 2nd but it's pretty heavy just to get the size. Thanks. struct S { int a

Re: inferred size for static array initialization

2016-05-02 Thread Marco Leise via Digitalmars-d-learn
Am Mon, 2 May 2016 18:52:11 +0200 schrieb ag0aep6g : > On 02.05.2016 15:53, Marco Leise wrote: > >immutable tab = { static enum S[] s = [ > > `static enum`? What kind of black magic is this? I don't know, but it works, haha. -- Marco

Re: inferred size for static array initialization

2016-05-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.05.2016 15:53, Marco Leise wrote: immutable tab = { static enum S[] s = [ `static enum`? What kind of black magic is this?

Re: inferred size for static array initialization

2016-05-02 Thread Marco Leise via Digitalmars-d-learn
Am Mon, 02 May 2016 13:00:27 + schrieb Erik Smith : > Is there a way to initialize a static array and have it's size > inferred (and that works for arrays of structs using braced > literals)? This would make it easier to maintain longer static > array definitions. The code below doesn't w

Re: inferred size for static array initialization

2016-05-02 Thread Basile B via Digitalmars-d-learn
On Monday, 2 May 2016 at 13:22:01 UTC, Basile B wrote: On Monday, 2 May 2016 at 13:00:27 UTC, Erik Smith wrote: Is there a way to initialize a static array and have it's size inferred (and that works for arrays of structs using braced literals)? This would make it easier to maintain longer st

Re: inferred size for static array initialization

2016-05-02 Thread Basile B via Digitalmars-d-learn
On Monday, 2 May 2016 at 13:00:27 UTC, Erik Smith wrote: Is there a way to initialize a static array and have it's size inferred (and that works for arrays of structs using braced literals)? This would make it easier to maintain longer static array definitions. The code below doesn't work whe