Initializing an Immutable Field with Magic: The "Fake Placement New" Technique

FeepingCreature feepingcreature at gmail.com
Fri Jul 26 10:40:18 UTC 2019


On Friday, 26 July 2019 at 10:25:06 UTC, ag0aep6g wrote:
> That looks like a complicated way of casting away immutable.
> `cast(int) value.s.i = 5;` also "works", but has undefined 
> behavior, of course. Surely, calling `__ctor` on an existing 
> immutable instance also has undefined behavior.

Sure, in this example you can do that, but in a generic function 
you have no idea what's inside S.



More information about the Digitalmars-d mailing list