1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-26 23:22:21 +01:00
This commit is contained in:
J. Nick Koston
2025-08-01 15:26:04 -10:00
parent 8bf3d52fb0
commit 13c749ceda
2 changed files with 8 additions and 10 deletions

View File

@@ -20,19 +20,15 @@ void ComponentIterator::begin(bool include_internal) {
template<typename Container> template<typename Container>
void ComponentIterator::process_platform_item_(const Container &items, void ComponentIterator::process_platform_item_(const Container &items,
bool (ComponentIterator::*on_item)(typename Container::value_type)) { bool (ComponentIterator::*on_item)(typename Container::value_type)) {
// Since static_vector doesn't have size(), we need to iterate differently if (this->at_ >= items.size()) {
size_t index = 0; this->advance_platform_();
for (auto *item : items) { } else {
if (index++ == this->at_) { auto *item = items[this->at_];
if ((item->is_internal() && !this->include_internal_) || (this->*on_item)(item)) { if ((item->is_internal() && !this->include_internal_) || (this->*on_item)(item)) {
this->at_++; this->at_++;
} }
return;
} }
} }
// If we get here, we've reached the end
this->advance_platform_();
}
void ComponentIterator::advance_platform_() { void ComponentIterator::advance_platform_() {
this->state_ = static_cast<IteratorState>(static_cast<uint32_t>(this->state_) + 1); this->state_ = static_cast<IteratorState>(static_cast<uint32_t>(this->state_) + 1);

View File

@@ -113,6 +113,8 @@ template<typename T, size_t N> class StaticVector {
} }
} }
size_t size() const { return count_; }
// For range-based for loops // For range-based for loops
iterator begin() { return data_.begin(); } iterator begin() { return data_.begin(); }
iterator end() { return data_.begin() + count_; } iterator end() { return data_.begin() + count_; }