mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
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:
parent
27e662bebb
commit
a43285d95a
|
@ -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;
|
||||
}
|
||||
// ...
|
||||
|
|
Loading…
Reference in New Issue
Block a user