Allow sequences to be compared to 0

It is true if every member of the sequence passes the test.
This commit is contained in:
John Wiegley 2009-02-23 14:49:03 -04:00
parent f96daf5fde
commit 9a44b8a547

View file

@ -811,6 +811,26 @@ bool value_t::is_less_than(const value_t& val) const
return as_string() < val.as_string();
break;
case SEQUENCE:
switch (val.type()) {
case INTEGER:
case AMOUNT: {
if (val.is_nonzero())
break;
bool no_amounts = true;
foreach (const value_t& value, as_sequence()) {
if (value >= 0L)
return false;
no_amounts = false;
}
return ! no_amounts;
}
default:
break;
}
break;
default:
break;
}
@ -881,6 +901,26 @@ bool value_t::is_greater_than(const value_t& val) const
return as_string() > val.as_string();
break;
case SEQUENCE:
switch (val.type()) {
case INTEGER:
case AMOUNT: {
if (val.is_nonzero())
break;
bool no_amounts = true;
foreach (const value_t& value, as_sequence()) {
if (value <= 0L)
return false;
no_amounts = false;
}
return ! no_amounts;
}
default:
break;
}
break;
default:
break;
}