Instantiation of nested structs should be allowed outside their parent scope

Timon Gehr timon.gehr at gmx.ch
Tue Nov 9 15:36:46 UTC 2021


On 09.11.21 16:30, Stanislav Blinov wrote:
> 
> ```d
> template isNothrowCopyable(To, From)
> if (is(immutable To == immutable From))
> {
>      enum bool isNothrowCopyable = is(typeof((ref scope From from) 
> nothrow { union U { To to; } U u = U(from); }));
> }
> ```
> 
> ...but it indeed doesn't work for nested structs. And a thing that does 
> "work" has to reimplement compiler's copy semantics, including 
> field-by-field blitting, calling constructors and postblits, etc.

template isNothrowCopyable(To, From)
if (is(immutable To == immutable From))
{
     enum bool isNothrowCopyable = is(typeof((ref scope From from) 
nothrow { union U { auto to=To.init; } U u = U(from); }));
}


More information about the Digitalmars-d mailing list