What is the shortest way to define an immutable token of unique type?

Bastiaan Veelo Bastiaan at Veelo.net
Sun Mar 14 16:55:04 UTC 2021


On Sunday, 14 March 2021 at 16:37:58 UTC, Andrei Alexandrescu 
wrote:
> Is there a simpler way that this?
>
> struct Hex {}
> immutable Hex hex;
>
> I don't want to introduce two names in the scope, just `hex`. 
> Another attempt:
>
> immutable hex = function {};
>
> That's a bit... arcane. Is there another simple way? Thanks!

Hardly simpler, but Hex can be kept out of scope by making it 
Voldemort:

     immutable hex = (){struct Hex{} return Hex();}();

-- Bastiaan.


More information about the Digitalmars-d mailing list