Skip to content

Make the comparator CmpExpIdx respect C++ requirements #932

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

Open
wants to merge 1 commit into
base: develop
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
17 changes: 11 additions & 6 deletions include/minizinc/flatten_internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,17 @@ public:
std::vector<KeepAlive>& x;
CmpExpIdx(std::vector<KeepAlive>& x0) : x(x0) {}
bool operator()(int i, int j) const {
if (Expression::equal(x[i](), x[j]())) {
return false;
}
if (Expression::isa<Id>(x[i]()) && Expression::isa<Id>(x[j]()) &&
Expression::cast<Id>(x[i]())->idn() != -1 && Expression::cast<Id>(x[j]())->idn() != -1) {
return Expression::cast<Id>(x[i]())->idn() < Expression::cast<Id>(x[j]())->idn();
const long long int i_idn =
Expression::isa<Id>(x[i]()) ? Expression::cast<Id>(x[i]())->idn() : -1;
const long long int j_idn =
Expression::isa<Id>(x[j]()) ? Expression::cast<Id>(x[j]())->idn() : -1;
const bool i_is_valid_id = i_idn != -1;
const bool j_is_valid_id = j_idn != -1;
if (i_is_valid_id != j_is_valid_id) {
return i_is_valid_id > j_is_valid_id;
}
if (i_is_valid_id && j_is_valid_id) {
return i_idn < j_idn;
}
return x[i]() < x[j]();
}
Expand Down