Skip to content

[QUESTION] Mutable that in move constructor? #715

Description

@SKyletoft

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions