Remove unneeded self check in Box<T>::operator=
As long as T's operator= correctly handles self assignment, this logic
is correct without the additional check.
diff --git a/include/cxx.h b/include/cxx.h
index 0a9df91..ab03f32 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -597,15 +597,13 @@
template <typename T>
Box<T> &Box<T>::operator=(const Box &other) {
- if (this != &other) {
- if (this->ptr) {
- **this = *other;
- } else {
- allocation alloc;
- ::new (alloc.ptr) T(*other);
- this->ptr = alloc.ptr;
- alloc.ptr = nullptr;
- }
+ if (this->ptr) {
+ **this = *other;
+ } else {
+ allocation alloc;
+ ::new (alloc.ptr) T(*other);
+ this->ptr = alloc.ptr;
+ alloc.ptr = nullptr;
}
return *this;
}