Instantiation of nested structs should be allowed outside their parent scope
Timon Gehr
timon.gehr at gmx.ch
Tue Nov 9 15:39:48 UTC 2021
On 09.11.21 16:36, Timon Gehr wrote:
> 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); }));
> }
(I don't know if that solves your problem, as I don't actually have an
example where your implementation does not work.)
More information about the Digitalmars-d
mailing list