Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypedVarHost::Has #296

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions omnn/math/VarHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,28 @@ namespace math {
return IsArithmeticId;
}

bool Has(const ::std::any& id) const override {
IMPLEMENT
return varIds.find(::std::any_cast<T>(id)) != varIds.end();
bool Has(const std::any& id) const override {
try {
return varIds.find(std::any_cast<T>(id)) != varIds.end();
} catch (const std::bad_any_cast&) {
// Handle the error, e.g., log it or return a default value
// For now, we'll return false to indicate the id was not found
return false;
}
}

size_t Hash(const ::std::any& id) const override {
return std::hash<T>()(::std::any_cast<T>(id));
size_t Hash(const std::any& id) const override {
return std::hash<T>()(std::any_cast<T>(id));
}

bool CompareIdsLess(const ::std::any& a, const ::std::any& b) const override {
return ::std::any_cast<T>(a) < ::std::any_cast<T>(b);

bool CompareIdsLess(const std::any& a, const std::any& b) const override {
try {
return std::any_cast<T>(a) < std::any_cast<T>(b);
} catch (const std::bad_any_cast&) {
// Handle the error, e.g., log it or return a default value
// For now, we'll return false to indicate the comparison failed
return false;
}
}

bool CompareIdsEqual(const ::std::any& a, const ::std::any& b) const override {
Expand Down
Loading