3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-07 09:42:14 +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

@ -19,6 +19,7 @@ Revision History:
--*/
#pragma once
#include <string>
#include <optional>
#include "math/lp/numeric_pair.h"
#include "math/lp/lp_types.h"
#include "util/debug.h"
@ -52,11 +53,11 @@ std::ostream& print_vector(const C * t, unsigned size, std::ostream & out) {
template <typename A, typename B>
bool try_get_value(const std::unordered_map<A,B> & map, const A& key, B & val) {
std::optional<B> try_get_value(const std::unordered_map<A,B> & map, const A& key) {
const auto it = map.find(key);
if (it == map.end()) return false;
val = it->second;
return true;
if (it == map.end())
return std::nullopt;
return it->second;
}
template <typename A, typename B>