Is there any guarantees that a
stays a valid object when I do a = std::move(a)
? Should I correctly handle this case when implement move operator=? If so, are there any best practices to do it?
Asked
Active
Viewed 72 times
1

Livace
- 126
- 7
-
You should handle that case. It is sometimes not possible to predict if what you are moving is the object itself – Aykhan Hagverdili Apr 18 '19 at 21:13
-
You can do an explicit `if (this != &other)`, but this may not be the best implementation considering `a = std::move(a)` does not happen too often – Aykhan Hagverdili Apr 18 '19 at 21:14
-
@Ayxan That should probably be in an answer – Justin Apr 18 '19 at 21:16