struct constructor with rvalue param of same struct type
vitamin
vit at vit.vit
Mon Jan 18 18:30:09 UTC 2021
Hello, is it possible to create constructor which initialize
'ptr3' with const rvalue of same type?
struct Foo{}
static struct Ptr{
void* impl;
//ctor 1
this(ref const typeof(this) x)pure nothrow @trusted
@nogc{/*...*/}
//ctor 2
this(const Foo foo)pure nothrow @trusted @nogc{/*...*/}
//ctor 3
//Error: `struct Ptr` may not define both a rvalue
constructor and a copy constructor
//this(const typeof(this) ptr)pure nothrow @trusted
@nogc{/*...*/} //
}
void main(){
const Ptr cptr;
Ptr ptr1 = cptr; //call ctor 1
Ptr ptr2 = delegate const(Foo)(){ //call ctor 2
return typeof(return).init;
}();
Ptr ptr3 = delegate const(Ptr)(){ //error
return typeof(return).init;
}();
}
More information about the Digitalmars-d-learn
mailing list