Blog Post #0105: D-specific Stuff for GUI Programming

Jacob Carlborg doob at me.com
Mon Mar 23 10:41:43 UTC 2020


On Monday, 23 March 2020 at 10:26:33 UTC, Jacob Carlborg wrote:

> If it's enough with CTFE compatible code in the constructor, 
> the following is a much simpler version:
>
> class DSingleton
> {
>     private __gshared DSingleton instance = new DSingleton;
>
>     DSingleton get()
>     {
>         return instance;
>     }
> }

Or if an immutable instance work, the getter is not necessary and 
the instance can be exposed directly.

class DSingleton
{
     immutable DSingleton instance = new DSingleton;
}

--
/Jacob Carlborg


More information about the Digitalmars-d-announce mailing list