On Monday, 2 March 2015 at 23:07:30 UTC, Ali Çehreli wrote:
immutable string bar;

shared static this()
{
    bar = painfulToInitialize();
}

void foo() {
}

Clever :).


> I don't need the thread-safety that C++ provides in that case,

I am not aware of such safety. (?) Is that a newer C++ feature?

Ali

New as of C++11. All function-scope statics are guaranteed to be initialized in a thread-safe manner. Exactly one thread will initialize the variable the first time the function is called.

Reply via email to