boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
101 stars 113 forks source link

Cannot advance an iterator to an empty deque by zero, or take an empty slice. #143

Closed cs96and closed 4 years ago

cs96and commented 4 years ago

With Boost 1.72.0, the following code causes an assert under debug, or a divide by zero for release builds...

boost::container::deque<int> myDeque;
auto iter = myDeque.begin();
std::advance(iter, 0);

This happens when trying to take a zero sized slice of an empty deque...

boost::container::deque<int> myDeque;
nItems = 0;
for(const auto &item : myDeque | boost::adaptors::sliced(0, nItems))
{
    // do something
}

This looks similar to #83 which was a similar issue but for vectors instead of deques.

igaztanaga commented 4 years ago

Thanks for the report. This was fixed in https://github.com/boostorg/container/pull/137 and will be released for Boost 1.74.