hasElaborateCopyConstructor bug?

Paul Backus snarwin at gmail.com
Sun Jun 2 04:02:08 UTC 2019


On Saturday, 1 June 2019 at 23:29:08 UTC, SrMordred wrote:
> On Saturday, 1 June 2019 at 21:39:33 UTC, SImen Kjærås wrote:
>> On Saturday, 1 June 2019 at 21:05:32 UTC, SrMordred wrote:
>
>> hasElaborateCopyConstructor checks if the type defines a 
>> postblit[0].
>  Yes, I know this.
>
> But since dmd 2.086 we have copy ctors:
> https://dlang.org/changelog/2.086.0.html#copy_constructor
>
> And its seem logical that if I want a trait that check if copy 
> ctors exists I will use this name 'hasElaborateCopyConstructor'
>
> So it looks like a naming issue for me.
> Unless postblits will be eventually replaced by copy ctors.

Here's something I came up with to check for new-style copy 
constructors:

import std.traits;
import std.meta;

template hasNewCopyConstructor(T)
{
     static if (hasMember!(T, "__ctor")) {
         enum hasCopyConstructor = anySatisfy!(
             isNewCopyConstructor,
             __traits(getOverloads, T, "__ctor")
         );
     } else {
         enum hasNewCopyConstructor = false;
     }
}

enum isNewCopyConstructor(alias ctor) =
     is(Unqual!(Parameters!ctor[0]) == __traits(parent, ctor))
     && (ParameterStorageClassTuple!ctor[0] & 
ParameterStorageClass.ref_);

Haven't tested it extensively, so use at your own risk, but it 
should work.



More information about the Digitalmars-d-learn mailing list