On Fri, 06 Jun 2014 06:14:30 -0400, Rene Zwanenburg <renezwanenb...@gmail.com> 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 that I want to use the values at compile time to create other values. Using static puts construction between compile time and run time.

Not exactly (at least I don't think). The static initializer itself is generated at compile time. But the assignment to the static variable is done at run time.

Initialising in static this means that the symbols need to be declared without initializers and that means not disabling default construction
><

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. If you want strictly compile-time generation of data, then immutable is the way to go.

But if you want to use it at runtime as well, immutable can hamper some things. I'm sure your example is a very small or reduced snippet of what you are actually doing.

-Steve

Reply via email to