Opened 12 years ago

Closed 11 years ago

#5352 closed Bugs (duplicate)

BOOST_REVERSE_FOREACH does not work with boost::counting_iterator (gcc 4.5.0 and 4.5.2 using -O3)

Reported by: Marc-Peter Schambach <Marc-Peter.Schambach@…> Owned by: Dave Abrahams
Milestone: To Be Determined Component: iterator
Version: Boost 1.46.0 Severity: Problem
Keywords: BOOST_REVERSE_FOREACH, counting_iterator Cc:

Description

The following code:

#include <iostream>
#include "boost/foreach.hpp"
#include <boost/iterator/counting_iterator.hpp>
int main(int, char**) {
  boost::counting_iterator<int> start(0), end(10);
  std::pair<boost::counting_iterator<int>, boost::counting_iterator<int> > iterators(start, end);
  std::cout << "Counting: ";
  BOOST_REVERSE_FOREACH(int t, iterators) {
    std::cout <<t<<" ";
  }
  std::cout << std::endl;
}

works fine with gcc-4.4.5 using -O3:

Counting: 9 8 7 6 5 4 3 2 1 0

but fails for gcc-4.5.0 and gcc-4.5.2 using -O3:

Counting: 70263556 70263556 70263556 70263556 70263556 70263556 70263556 70263556 70263556 70263556 

System: i686-pc-linux-gnu

Change History (3)

comment:1 by mimomorin@…, 12 years ago

This is a limitation of counting_iterator and not a bug of Boost.Foreach. See #2640.

comment:2 by Marc-Peter Schambach <Marc-Peter.Schambach@…>, 12 years ago

Component: foreachiterator
Owner: changed from Eric Niebler to Dave Abrahams

comment:3 by Michel Morin <mimomorin@…>, 11 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #2640.

Note: See TracTickets for help on using tickets.