-
Notifications
You must be signed in to change notification settings - Fork 403
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
Consolidate mutual calls of move/copy assign and move/copy c'tor #1686
Comments
What about the copy c'tor/assignment operator? The argumentation from above is also true for copy. |
First of all, we use the same approach also in the copy constructor and I would assume that Matthias argument applies to this as well. The argument why we pursued this approach was:
Sometimes we cannot pursue this approach since the members are not trivially constructible or in very rare cases, it would be too time consuming. For now I would propose that we do not change anything in our codebase. In the near future we have to make all our constructs at least weak exception safe which would mean that we have to pursue a different approach and this is the time where we should tackle this challenge safely and efficiently . |
In my opinion this should not be part of the 3.0 release. It is part of the release where we remove |
I also think this is not required to be in v3.0. This is a non-breaking change and can be done anytime. @elfenpiff the issue is two fold. I think we all agree on removing the check for The more controversial part is to do copy/move via the initializer list. I can see the point in trying to prevent the useless default initialization, especially for cases where this is not negligible. Another freaky solution would be this // disclaimer: don't do this at home kids
class Foo
{
public:
Foo() = default;
Foo(const Foo& other)
: data(other.data)
{
}
Foo(Foo&& other)
: data(std::move(other.data))
{
other.data = 0;
}
Foo& operator=(const Foo& rhs)
{
if (this != &rhs)
{
this->~Foo();
new (this) Foo(rhs);
}
return *this;
}
Foo& operator=(Foo&& rhs)
{
if (this != &rhs)
{
this->~Foo();
new (this) Foo(std::move(rhs));
}
return *this;
}
uint32_t data{0};
}; A cold shiver ran down my spine while writing that code. I never used it myself and never saw something like that but it seems to work 😬 There are issues with exception though and maybe other stuff like unintentional double deletes ... better you forget about this 😅 |
Brief refactoring description
Throughout the code base, there different strategies are used to avoid code duplication when it comes to move/copy assignment operator and move/copy c'tor. This should be consolidated according to comment below.
Detailed information
From @MatthiasKillat this comment:
The text was updated successfully, but these errors were encountered: