Static constructors in structs.
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Oct 30 13:58:36 PDT 2015
On 30.10.2015 21:23, TheFlyingFiddle wrote:
> Is this intended to work?
>
> struct A
> {
> __gshared static this()
> {
> //Add some reflection info to some global stuff.
> addReflectionInfo!(typeof(this));
> }
> }
>
> I just noticed this works in 2.069, is this intended?
static constructors are supposed to work, yes.
The description is on the class page:
http://dlang.org/class.html#static-constructor
__gshared doesn't do anything there, though. Use `shared static this`
instead, if you want the constructor to run only once per process, and
not once per thread.
More information about the Digitalmars-d-learn
mailing list