#2649 closed Bugs (fixed)
iterator_range's assignment fires an assert when rhs is singular
| Reported by: | Owned by: | Neil Groves | |
|---|---|---|---|
| Milestone: | Boost 1.43.0 | Component: | range |
| Version: | Boost 1.36.0 | Severity: | Regression |
| Keywords: | iterator_range | Cc: | eyal.farago@… |
Description
the following code will raise an assertion in debug builds:
typedef boost::iterator_range<std::string> str_range_t;
std::string eyal("eyal");
str_range_t eyal_range( eyal ), empty_range;
//here it is...
eyal_range = empty_range;
the reason for the assert is an assert in iterator_range's begin/end methods, the assignment operator is doing something like
this->m_begin = rhs.begin()
which fails for debug builds when rhs is singular.
a lot has been said about the decision to remove the singular member/concept from the library code, but I believe that assigning a singular range should not raise an assert.
ps. I stumbled upon this bug after upgrading from 1.34 to 1.36, "I think this is a really nasty one because:
- it denies me from using a very standard use case.
- it simply crashes in release builds.
- a massive behavior change for singular ranges which used to behave like empty ranges. while I agree that using iterators of a singular range is a bad idea, querying for its length is not.
eyal.
Change History (3)
comment:1 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:3 by , 13 years ago
| Milestone: | Boost 1.38.0 → Boost 1.43.0 |
|---|
Note:
See TracTickets
for help on using tickets.

The submitted code should never have compiled since iterator_range<std::string> is illegal.
The newly merged RangeEx into Range runs the following code without assertion in debug, or crash in release.
I made the decision to remove the singularity concept from Boost.Range entirely. It is my opinion that singularity is a property of iterators and that it is not possible to usefully augment range to provide additional safety without removing the capability to support valid use-cases.
#include <string> #include <boost/range/iterator.hpp> #include <boost/range/sub_range.hpp>
typedef boost::sub_range<std::string> str_range_t;
int main(int argc, const char* argv[]) {
}