hasElaborateCopyConstructor bug?
Paul Backus
snarwin at gmail.com
Sun Jun 2 14:32:16 UTC 2019
On Sunday, 2 June 2019 at 06:59:02 UTC, Jonathan M Davis wrote:
> Almost certainly, hasElaborateCopyConstructor should be updated
> to test for both postblit constructors and copy constructors,
> since its purpose is to test for whether the type has a
> user-defined copying function [...] Whether
> hasElaborateCopyConstructor was the best name is debatable, but
> it _does_ involve "elaborate" copying, and copy constructors
> weren't actually in the language at the time. The documentation
> is wonderfully confusing though in that it talks about copy
> constructors and then says that a copy constructor is
> introduced by defining this(this) for a struct. So, it
> basically calls a postblit constructor a copy constructor.
I've made the mistake in the past of trying to use
hasElaborateCopyConstructor to test for the presence of
__xpostblit, and I'm sure I'm not the only one. The name is quite
misleading--even more so now that D has real copy constructors.
If std.v2 ever materializes, we'll have an opportunity to fix
papercuts like this. Until then, my preferred workaround is to
use a renaming import:
import std.traits: hasNontrivialCopy =
hasElaborateCopyConstructor;
More information about the Digitalmars-d-learn
mailing list