On 03/02/2015 02:06 PM, Mark Isaacson wrote:

> I'm looking for the D equivalent of:
>
> //C++
> void foo() {
>    static string bar = painfulToInitialize(); //Always returns the same
> value
>    /* A bunch of code */
> }

immutable string bar;

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

void foo() {
}

When needed, 'bar' can be mutable as well but you have to take care of synchronization yourself in that case.

> 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

Reply via email to