Re: When is a slice not a slice?

2014-06-17 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 5 June 2014 at 19:45:59 UTC, Alix Pexton wrote: unittest { auto a = DataAndView(1); assert (sameTail(a.data, a.view)); enum b = DataAndView(1); assert (!sameTail(b.data, b.view)); } Just a request of presentation. Please make expected assertions:

Re: When is a slice not a slice?

2014-06-16 Thread Alix Pexton via Digitalmars-d-learn
On 06/06/2014 7:39 PM, Steven Schveighoffer wrote: On Fri, 06 Jun 2014 06:14:30 -0400, Rene Zwanenburg wrote: Immutables should be usable at compile time and not allocate a new instance on every use when in module scope. I was about to say this. But immutable can have its own set of issues. I

Re: When is a slice not a slice?

2014-06-07 Thread Alix Pexton via Digitalmars-d-learn
On 06/06/2014 7:39 PM, Steven Schveighoffer wrote: On Fri, 06 Jun 2014 06:14:30 -0400, Rene Zwanenburg wrote: Immutables should be usable at compile time and not allocate a new instance on every use when in module scope. I was about to say this. But immutable can have its own set of issues.

Re: When is a slice not a slice?

2014-06-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On Fri, 06 Jun 2014 06:14:30 -0400, Rene Zwanenburg wrote: On Friday, 6 June 2014 at 08:17:43 UTC, Alix Pexton wrote: On 05/06/2014 8:58 PM, Steven Schveighoffer wrote: Yes, this should work (and execute the initializer at compile time): static b = ... Ah, the problem with static is t

Re: When is a slice not a slice?

2014-06-06 Thread Rene Zwanenburg via Digitalmars-d-learn
On Friday, 6 June 2014 at 08:17:43 UTC, Alix Pexton wrote: On 05/06/2014 8:58 PM, Steven Schveighoffer wrote: On Thu, 05 Jun 2014 15:56:00 -0400, Philippe Sigaud via Digitalmars-d-learn wrote: enum b = DataAndView(1); assert (!sameTail(b.data, b.view)); I suppose it's because

Re: When is a slice not a slice?

2014-06-06 Thread Alix Pexton via Digitalmars-d-learn
On 05/06/2014 8:58 PM, Steven Schveighoffer wrote: On Thu, 05 Jun 2014 15:56:00 -0400, Philippe Sigaud via Digitalmars-d-learn wrote: enum b = DataAndView(1); assert (!sameTail(b.data, b.view)); I suppose it's because enums are manifest constants: the value they represent is

Re: When is a slice not a slice?

2014-06-06 Thread Alix Pexton via Digitalmars-d-learn
On 06/06/2014 8:52 AM, Alix Pexton wrote: And the two DataAndView(1), being completely separated, do not have the same tail. Ah, Isee, that does kinda make sense ^^ A re-factoring we go... However, the code that originally tripped over this issue had the call to sameTail in the struct's

Re: When is a slice not a slice?

2014-06-06 Thread Alix Pexton via Digitalmars-d-learn
On 05/06/2014 8:56 PM, Philippe Sigaud via Digitalmars-d-learn wrote: enum b = DataAndView(1); assert (!sameTail(b.data, b.view)); I suppose it's because enums are manifest constants: the value they represent is 'copy-pasted' anew everywhere it appears in the code. So for arra

Re: When is a slice not a slice?

2014-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thu, 05 Jun 2014 15:56:00 -0400, Philippe Sigaud via Digitalmars-d-learn wrote: enum b = DataAndView(1); assert (!sameTail(b.data, b.view)); I suppose it's because enums are manifest constants: the value they represent is 'copy-pasted' anew everywhere it appears in the co

Re: When is a slice not a slice?

2014-06-05 Thread Philippe Sigaud via Digitalmars-d-learn
> enum b = DataAndView(1); > assert (!sameTail(b.data, b.view)); I suppose it's because enums are manifest constants: the value they represent is 'copy-pasted' anew everywhere it appears in the code. So for arrays and associative arrays, it means recreating a new value each and eve

When is a slice not a slice?

2014-06-05 Thread Alix Pexton via Digitalmars-d-learn
In CTFE it seems. Only tested with DMD on Windows though. Is this a known limitation, or a bug, I couldn't find anything that seemed to match it in the bugzilla. import std.array; struct DataAndView { int[] data, view; this(int x) { data = [1, 2, 3, 4,