On Saturday, 21 April 2012 at 14:40:00 UTC, H. S. Teoh wrote:
I'm getting confused about the use of 'static' in this context.
What I
wanted was to make the regex module-global, but apparently
'static' has
an overloaded meaning here, and also makes it compile-time
evaluated?
How do I make it module-global without being compile-time
evaluated??
T
it just so happens to be that 'static' function variables in D
require compile-time available initializers. To initialize with a
runtime value on first execution, you have to implement that
manually:
void foo(int a)
{
static int first;
static first_initialized = false;
if(!first_initialized)
{
first = a;
first_initialized = true;
}
// ...
}