Skip to content

[views::cycle] wrong cycle count when advancing by negative offset #1856

@ell-gh

Description

@ell-gh

The assert in this code fires incorrectly:

int a[] = {1, 2};
auto c = a | ranges::views::cycle;
assert (c.begin () + 1 == c.begin () + 2 - 1);

The problem is that the cycle count calculation in cursor::advance() uses truncating division, instead of flooring division.

@hewillk This bug is also present in P3806R0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions