On Sunday, 22 August 2021 at 07:58:12 UTC, james.p.leblanc wrote:

Is there a better way?

Best Regards,
James

```
public mixin template NonMovableOrCopyable ()
{
    @disable this ();
    @disable this (this);
@disable ref typeof (this) opAssign () (auto ref typeof(this) rhs);
}
```

This will catch most mistakes at CT. However the language is technically free to copy / move structs at will (and interior pointers are forbidden). A recent enough version of LDC (>= v1.20.0 IIRC, might be v1.22.0) will do a very good job at not needlessly moving things around. See for example the discussion here: https://forum.dlang.org/thread/miuevyfxbujwrhghm...@forum.dlang.org

DMD on the other hand is much more likely to not perform NRVO / move things, so be wary of compiler differences.

Reply via email to