Replies: 3 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 |
Beta Was this translation helpful? Give feedback.
-
https://github.com/hsutter/cppfront/discussions/categories/q-a is a place for questions. |
Beta Was this translation helpful? Give feedback.
-
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: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions