3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-25 11:34:01 +00:00

Adopt std::optional for try_get_value and try_get_size functions (#8268)

* Initial plan

* Convert try_get_value and try_get_size to use std::optional

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

* Add unit tests for std::optional conversions and fix compilation error

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

* Address code review comments - improve readability and reduce code duplication

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-21 12:41:50 -08:00 committed by GitHub
parent 2e7b700769
commit 1bb471447e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 92 additions and 44 deletions

View file

@ -659,8 +659,7 @@ namespace datalog {
app* dl_decl_util::mk_numeral(uint64_t value, sort* s) {
if (is_finite_sort(s)) {
uint64_t sz = 0;
if (try_get_size(s, sz) && sz <= value) {
if (auto sz = try_get_size(s); sz.has_value() && *sz <= value) {
m.raise_exception("value is out of bounds");
}
parameter params[2] = { parameter(rational(value, rational::ui64())), parameter(s) };
@ -758,13 +757,12 @@ namespace datalog {
return m.mk_sort(get_family_id(), DL_FINITE_SORT, 2, params);
}
bool dl_decl_util::try_get_size(const sort * s, uint64_t& size) const {
std::optional<uint64_t> dl_decl_util::try_get_size(const sort * s) const {
sort_size sz = s->get_info()->get_num_elements();
if (sz.is_finite()) {
size = sz.size();
return true;
return sz.size();
}
return false;
return std::nullopt;
}
app* dl_decl_util::mk_lt(expr* a, expr* b) {