In the codebase on our project, I found something like this:
struct MeshData {
MeshData() {}
MeshData(MeshData&& obj) { *this = std::move(obj); }
MeshData& operator=(MeshData&& obj) {
if (this != &obj) {
indexes = std::move(obj.indexes);
}
return *this;
}
std::vector<int> indexes;
};
Implementing move construction in terms of the move assignment seems like a clever idea to me that reduces code duplication, but after looking for information I didn't find any especific advice regarding this.
My question is: Is this an antipattern or are there any situations where this shouldn't be done?
Aucun commentaire:
Enregistrer un commentaire