Potential strategy for avoiding problems with copy of a struct (maybe??)
Mathias LANG
geod24 at gmail.com
Sun Aug 22 10:32:21 UTC 2021
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/miuevyfxbujwrhghmiuw@forum.dlang.org
DMD on the other hand is much more likely to not perform NRVO /
move things, so be wary of compiler differences.
More information about the Digitalmars-d-learn
mailing list