boostorg / boostorg/icl

boost::icl::interval_map::operator+= : entry doesn't get added if value is zero.

Open
#22 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16
Forks
50
PR merge metrics
No merged PRs in 30d

Description

When inserting an entry into a `boost::icl::interval_map`, the entry is not inserted if the value is 0. I am guessing this is a bug that happens when the value evaluates to a boolean false. note: using VS2017, C++14. Issue is present in 1.59 - 1.69 (including C++17 for 1.69)

```

#include
#include
#include

using namespace std;
typedef pair float_pair;

boost::icl::interval_map makeIntervalMap(const vector& intervals)
{
boost::icl::interval_map result;
int intervalCount = 0;

for (float_pair entry : intervals) {
result += make_pair(
boost::icl::interval::right_open(entry.first, entry.second),
intervalCount++
);
}

return result;
}

const vector intervals = {
make_pair(200.0f,250.0f),
make_pair(100.0f,199.0f),
make_pair(0.0f,50.0f),
};

int main()
{
boost::icl::interval_map m = makeIntervalMap(intervals);

for (auto it = m.begin(); it != m.end(); ++it) {
cout << it->first.lower() << ", " << it->first.upper() << endl;
}
}
```

In the same code, the interval_map has one fewer element than it should, with the interval corresponding to value 0 missing, Changing it to use a ones-based index works as a workaround. And if I remove the post-increment and try to assign every interval the value zero, none of them get added.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.