Subject: [Boost-bugs] [Boost C++ Libraries] #7680: Poor choice of difference_type for zip_iterator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-11-11 04:37:07
#7680: Poor choice of difference_type for zip_iterator
------------------------------------+---------------------------------------
Reporter: matthias_berndt@⦠| Owner: dave
Type: Bugs | Status: new
Milestone: To Be Determined | Component: iterator
Version: Boost 1.52.0 | Severity: Problem
Keywords: |
------------------------------------+---------------------------------------
Hi,
the following program results in an integer overflow on my system (Linux
g++ 4.7.2):
{{{#!c++
#include <boost/iterator/zip_iterator.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <iostream>
int main() {
boost::counting_iterator<unsigned short> i1(0);
boost::counting_iterator<unsigned long long> i2(0);
auto i3 = boost::make_zip_iterator(boost::make_tuple(i1, i2));
i3 += 3221225472u;
std::cout << boost::get<1>(*i3) << '\n';
}
}}}
It prints 18446744072635809792, but I'd expect it to print 3221225472.
boost::zip_iterator seems to use the first underlying iterator's
difference_type as its own difference_type, which isn't necessarily the
right choice.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7680> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC