mirror of
https://github.com/Z3Prover/z3
synced 2026-02-17 06:11:44 +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:
parent
2e7b700769
commit
1bb471447e
14 changed files with 92 additions and 44 deletions
|
|
@ -96,16 +96,17 @@ void dl_query_test(ast_manager & m, smt_params & fparams, params_ref& params,
|
|||
f_b.reset();
|
||||
f_q.reset();
|
||||
for(unsigned col=0; col<sig_b.size(); ++col) {
|
||||
uint64_t sort_sz;
|
||||
if(!decl_util.try_get_size(sig_q[col], sort_sz)) {
|
||||
if (auto sort_sz = decl_util.try_get_size(sig_q[col])) {
|
||||
uint64_t num = ran()%(*sort_sz);
|
||||
app * el_b = decl_util.mk_numeral(num, sig_b[col]);
|
||||
f_b.push_back(el_b);
|
||||
app * el_q = decl_util.mk_numeral(num, sig_q[col]);
|
||||
f_q.push_back(el_q);
|
||||
}
|
||||
else {
|
||||
warning_msg("cannot get sort size");
|
||||
return;
|
||||
}
|
||||
uint64_t num = ran()%sort_sz;
|
||||
app * el_b = decl_util.mk_numeral(num, sig_b[col]);
|
||||
f_b.push_back(el_b);
|
||||
app * el_q = decl_util.mk_numeral(num, sig_q[col]);
|
||||
f_q.push_back(el_q);
|
||||
}
|
||||
|
||||
bool found_in_b = rel_b.contains_fact(f_b);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ Revision History:
|
|||
#include "util/trace.h"
|
||||
#include "util/debug.h"
|
||||
#include "util/memory_manager.h"
|
||||
#include "math/lp/lp_utils.h"
|
||||
#include "ast/dl_decl_plugin.h"
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
static void tst1() {
|
||||
std::optional<int> v;
|
||||
|
|
@ -66,9 +69,32 @@ static void tst3() {
|
|||
ENSURE(*(*v) == 10);
|
||||
}
|
||||
|
||||
static void tst_try_get_value() {
|
||||
std::unordered_map<int, std::string> map;
|
||||
map[1] = "one";
|
||||
map[2] = "two";
|
||||
map[3] = "three";
|
||||
|
||||
// Test successful retrieval
|
||||
auto result1 = try_get_value(map, 1);
|
||||
ENSURE(result1.has_value());
|
||||
ENSURE(*result1 == "one");
|
||||
|
||||
auto result2 = try_get_value(map, 2);
|
||||
ENSURE(result2.has_value());
|
||||
ENSURE(*result2 == "two");
|
||||
|
||||
// Test unsuccessful retrieval
|
||||
auto result_missing = try_get_value(map, 999);
|
||||
ENSURE(!result_missing.has_value());
|
||||
|
||||
TRACE(optional, tout << "try_get_value tests passed\n";);
|
||||
}
|
||||
|
||||
void tst_optional() {
|
||||
tst1();
|
||||
tst2();
|
||||
tst3();
|
||||
tst_try_get_value();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue