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

Timon Gehr timon.gehr at gmx.ch
Mon Mar 15 20:07:53 UTC 2021


On 14.03.21 17:37, 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!
> 

Not sure about simple or non-arcane, but this works:

immutable typeof(new class{}) hex;


More information about the Digitalmars-d mailing list