Make example code adhere to C.65 (#2151)

C.65 requires move assignment to be safe for self-assignment. The given example is not safe for self-assignment as given right now. This commit fixes this.

Co-authored-by: Werner Henze <w.henze@avm.de>
This commit is contained in:
Werner Henze 2023-10-12 21:23:59 +02:00 committed by GitHub
parent 27e662bebb
commit a43285d95a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6438,9 +6438,11 @@ A non-throwing move will be used more efficiently by standard-library and langua
public:
Vector(Vector&& a) noexcept :elem{a.elem}, sz{a.sz} { a.elem = nullptr; a.sz = 0; }
Vector& operator=(Vector&& a) noexcept {
delete elem;
elem = a.elem; a.elem = nullptr;
sz = a.sz; a.sz = 0;
if (&a != this) {
delete elem;
elem = a.elem; a.elem = nullptr;
sz = a.sz; a.sz = 0;
}
return *this;
}
// ...