-
Notifications
You must be signed in to change notification settings - Fork 251
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Mutable that
in move constructor?
#715
Comments
In cpp1, move constructor (
in above case, move constructor( In cpp2, the syntax for move constructor is : And if you still want to do same thing as |
https://github.com/hsutter/cppfront/discussions/categories/q-a is a place for questions. |
in that makes sense because it is a copy and you aren't modifying that.
move that makes sense because that is an R value reference, and you can steal it's resources with impunity, knowing that nothing else can mistakenly use those resources as it will go out of scope and destruct after use.
inout that would be dangerous, like you say, you become in charge of setting moved resources to sensible null values e.t.c otherwise something else might later also assume ownership and modify them without the first owners knowledge or consent. This option is error prone and probably not what you wanted to do anyway?
On 1 October 2023 20:29:27 Samuel Kyletoft ***@***.***> wrote:
How on earth do I write a move constructor that resets the moved from object? (Like setting pointers to null or the like).
Going from this:
struct Bar {
int b = 5;
Bar(int b_): b(b_) {}
Bar(Bar& that) {
this->b = that.b;
that.b = 0;
}
};
I tried to write this:
Foo: @struct type = {
public a: i32 = 5;
operator=: (out this, a_: i32) = {
a = a_;
}
operator=: (out this, inout that) = {
this.a = that.a + 1;
that.a = 0;
}
}
But I'm only allowed to use in or move for that? Surely this is not just unsupported?
Sorry to take up space in the issue tracker, but I'm not aware of any better forum.
—
Reply to this email directly, view it on GitHub<#715>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQPAIXR3RKATTCJ7C6DX5HABJANCNFSM6AAAAAA5ORA2O4>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
How on earth do I write a move constructor that resets the moved from object? (Like setting pointers to null or the like).
Going from this:
I tried to write this:
But I'm only allowed to use
in
ormove
forthat
? Surely this is not just unsupported?Sorry to take up space in the issue tracker, but I'm not aware of any better forum.
The text was updated successfully, but these errors were encountered: