Skip to content

Inconsistent interval operators #2

@snedeljkovic

Description

@snedeljkovic

I wonder why is the less-than operator implemented such as to ignore the value, while the value is used in the equality operator? Strictly speaking types that implement the concept of equality need not necessarily implement less-than and vice-versa. It seems that the goal was to implement both operator via less-than over the fields.

The reason I'm asking this is practical: When adding Interval objects to sets or maps the behavior is different to adding them to an IntervalTree.

bool operator==(const Interval &other) const
{
return !(low < other.low || other.low < low
|| high < other.high || other.high < high
|| value < other.value || other.value < value);
}
bool operator<(const Interval &other) const
{
return (low < other.low || high < other.high);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions