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 <digitalmars-d-learn@puremagic.com> 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 arrays and associative arrays, it means recreating a new
value
each and every time.
In your case, your code is equivalent to:
assert (!sameTail(DataAndView(1).data,DataAndView(1).view));
And the two DataAndView(1), being completely separated, do
not have
the same tail.
Yes, this should work (and execute the initializer at compile
time):
static b = ...
-Steve
Ah, the problem with static is that I want to use the values at
compile time to create other values. Using static puts
construction between compile time and run time. Initialising in
static this means that the symbols need to be declared without
initializers and that means not disabling default construction
><
A...
Immutables should be usable at compile time and not allocate a
new instance on every use when in module scope.