When D feels unfinished: union initialization and NRVO

Mathias Lang pro.mathias.lang at gmail.com
Fri Mar 20 12:27:37 UTC 2020


On Thursday, 19 March 2020 at 18:41:07 UTC, Jacob Carlborg wrote:
> On 2020-03-19 11:17, Mathias Lang wrote:
>
>> but as often, the solution is to turn a runtime parameter into 
>> a compile time one and to add another level of indirection.
>
> If you don't use static initialization and instead assign the 
> fields one by one it should work without the indirection.

But you can't deal with user-provided types. You'll have to 
blindly cast away to mutable to make it work. And from my 
experience, ignoring the type system always comes back to bite 
you at one point or another.


More information about the Digitalmars-d mailing list