Can passing an address of this to a non-copyable object be made trusted? - i.e. can I disable moving?
aliak
something at something.com
Sun Aug 26 20:17:30 UTC 2018
So if we had this:
struct A(T) {
auto proxy() @trusted {
return B!T(&this);
}
}
struct B(T) {
private A!T* source;
private this(A!T* s) { source = s; }
@disable this();
@disable this(this) {}
@disable void opAssign(B!T);
}
In order for f to be "safe" I need to ensure that B!T(&this) does
not escape the scope of A!T. I figured disable construction and
copying may work, but it seems you can still get it moved:
void main() @safe {
auto f() {
auto a = A!int();
return a.proxy;
}
auto escaped = f; // escaped.source is gone...
}
Anyway around this?
Cheers,
- Ali
More information about the Digitalmars-d-learn
mailing list