why @property cannot be pass as ref ?
ChangLong
changlon at gmail.com
Sat Dec 30 03:49:37 UTC 2017
On Wednesday, 20 December 2017 at 18:43:21 UTC, Ali Çehreli wrote:
> Thanks to Mengü for linking to that section. I have to make
> corrections below.
>
> Ali
Thanks for explain, Ali And Mengu.
What I am try to do is implement a unique data type. (the
ownership auto moved into new handle)
consider this code:
import std.stdio;
struct S {
@disable this(this);
void* socket;
this (void* i) {
socket = i;
}
void opAssign()(auto ref S s ){
socket = s.socket ;
s.socket = null ;
}
@nogc @safe
ref auto byRef() const pure nothrow return
{
return this;
}
}
void main() {
static __gshared size_t socket;
auto lvalue = S(&socket); // pass rvalue into lvalue,
working
S l2 = void;
l2 = lvalue; // pass lvalue into lvalue, working
auto l3 = l2.byRef; // pass lvalue into lvalue, not working
}
I can not assign l2 to l3 because "Error: struct app.S is not
copyable because it is annotated with @disable", but it working
if I init l3 with void.
More information about the Digitalmars-d-learn
mailing list