3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-23 00:37:36 +00:00

Refactor counter::get_max_positive to use std::optional (#8289)

* Initial plan

* Refactor counter::get_max_positive to use std::optional

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix C++17 compatibility by replacing transform() with has_value()/value()

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Address code review: avoid calling get_max_positive twice

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-22 17:39:53 -08:00 committed by Nikolaj Bjorner
parent 8b0f9d6ce7
commit c6e3045226
6 changed files with 22 additions and 24 deletions

View file

@ -49,21 +49,18 @@ void counter::collect_positive(uint_set & acc) const {
acc.insert(kv.m_key);
}
bool counter::get_max_positive(unsigned & res) const {
bool found = false;
std::optional<unsigned> counter::get_max_positive() const {
std::optional<unsigned> result;
for (auto const& kv : *this) {
if (kv.m_value > 0 && (!found || kv.m_key > res) ) {
found = true;
res = kv.m_key;
if (kv.m_value > 0 && (!result || kv.m_key > *result)) {
result = kv.m_key;
}
}
return found;
return result;
}
unsigned counter::get_max_positive() const {
unsigned max_pos;
VERIFY(get_max_positive(max_pos));
return max_pos;
unsigned counter::get_max_positive_or_zero() const {
return get_max_positive().value_or(0);
}
int counter::get_max_counter_value() const {