__traits isCopyable vs isPOD
Paul Backus
snarwin at gmail.com
Tue Nov 29 00:50:54 UTC 2022
On Monday, 28 November 2022 at 23:11:37 UTC, Per Nordlöw wrote:
> the real question I had is whether one should use `isPOD`
> instead of `isCopyable` in cases
>
> ```d
> static if (__traits(isCopyable, Element))
> insertAt(element, index);
> else
> insertAt(move(element), index);
> ```
>
> because that avoids any potential call to the copy-constructor
> and destructor of `Element`. Afaict, one should.
If your goal is to avoid calling the copy constructor (and, I
assume, to avoid unnecessary instantiations of `move`), then
yeah, `isPOD` is the one you want.
More information about the Digitalmars-d-learn
mailing list