mirror of
https://github.com/esphome/esphome.git
synced 2025-10-19 18:23:46 +01:00
we need copy now
This commit is contained in:
@@ -208,9 +208,30 @@ template<typename T> class FixedVector {
|
|||||||
|
|
||||||
~FixedVector() { cleanup_(); }
|
~FixedVector() { cleanup_(); }
|
||||||
|
|
||||||
// Disable copy operations (avoid accidental expensive copies)
|
// Copy constructor - performs deep copy
|
||||||
FixedVector(const FixedVector &) = delete;
|
FixedVector(const FixedVector &other) {
|
||||||
FixedVector &operator=(const FixedVector &) = delete;
|
if (other.size_ > 0) {
|
||||||
|
init(other.size_);
|
||||||
|
for (size_t i = 0; i < other.size_; i++) {
|
||||||
|
push_back(other.data_[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy assignment operator - performs deep copy
|
||||||
|
FixedVector &operator=(const FixedVector &other) {
|
||||||
|
if (this != &other) {
|
||||||
|
cleanup_();
|
||||||
|
reset_();
|
||||||
|
if (other.size_ > 0) {
|
||||||
|
init(other.size_);
|
||||||
|
for (size_t i = 0; i < other.size_; i++) {
|
||||||
|
push_back(other.data_[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// Enable move semantics (allows use in move-only containers like std::vector)
|
// Enable move semantics (allows use in move-only containers like std::vector)
|
||||||
FixedVector(FixedVector &&other) noexcept : data_(other.data_), size_(other.size_), capacity_(other.capacity_) {
|
FixedVector(FixedVector &&other) noexcept : data_(other.data_), size_(other.size_), capacity_(other.capacity_) {
|
||||||
|
Reference in New Issue
Block a user