Opened 9 years ago

Closed 9 years ago

#9519 closed Bugs (fixed)

wrong results for strided, reversed range

Reported by: Eric Niebler Owned by: Neil Groves
Milestone: To Be Determined Component: range
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

The following code:

#include <vector>
#include <numeric>
#include <iostream>
#include <boost/range/adaptor/strided.hpp>
#include <boost/range/adaptor/reversed.hpp>

int main()
{
    std::vector<int> vi(50);
    std::iota(vi.begin(), vi.end(), 0);
    using namespace boost::adaptors;
    for(int i : vi | strided(3) | reversed)
        std::cout << i << ' ';
    std::cout << '\n';
}

Yields the following output for me:

13 10 7 4 1 0

That's whack. I don't understand it at all. I would expect it to count down from 50 by steps of 3.

Attachments (1)

reversed_range.cpp (350 bytes ) - added by rednaks 9 years ago.
Correct bevhavior

Download all attachments as: .zip

Change History (5)

by rednaks, 9 years ago

Attachment: reversed_range.cpp added

Correct bevhavior

comment:1 by rednaks, 9 years ago

Did you tried to reverse then stride ? see attachement

comment:2 by Eric Niebler, 9 years ago

I don't see the point you're trying to make. Are you saying there isn't a bug?

comment:3 by Neil Groves, 9 years ago

Status: newassigned

comment:4 by Neil Groves, 9 years ago

Resolution: fixed
Status: assignedclosed

There clearly is a bug, and this particular adaptor has been problematic and suffering an unacceptable defect density. I have rewritten the adaptor and used Eric's example as a basis for a unit test. The changes are committed to the develop branch.

Note: See TracTickets for help on using tickets.