Merge remote-tracking branch 'origin/parition_callbacks' into parition_callbacks

This commit is contained in:
J. Nick Koston
2025-11-09 23:20:01 -06:00

View File

@@ -893,11 +893,12 @@ template<typename... Ts> class PartitionedCallbackManager<void(Ts...)> {
this->callbacks_ = make_unique<std::vector<std::function<void(Ts...)>>>();
}
// Add to first partition: append then swap into position
// Add to first partition: append then rotate into position
this->callbacks_->push_back(std::move(callback));
// Avoid potential underflow: rewrite comparison to not subtract from size()
if (*first_count + 1 < this->callbacks_->size()) {
std::swap((*this->callbacks_)[*first_count], (*this->callbacks_)[this->callbacks_->size() - 1]);
// Use std::rotate to maintain registration order in second partition
std::rotate(this->callbacks_->begin() + *first_count, this->callbacks_->end() - 1, this->callbacks_->end());
}
(*first_count)++;
}