Skip to content

Composing ranges::view::cycle with ranges::view::slice #778

@tremmelg

Description

@tremmelg

Composing ranges::view::cycle with ranges::view::slice results in a view that returns begin and endpoints that compare equal. On the other hand, ranges::distance returns the expected 512. Also, see the example below.

#include <iostream>
#include <iterator>
#include <vector>

#include <range/v3/all.hpp>

int main() {
  const auto length = 512;
  const auto k = 16;

  std::vector<int> input(length);

  auto output = ranges::view::cycle(input)
              | ranges::view::slice(length + k, 2 * length + k);

  if (ranges::begin(output) == ranges::end(output)) {
    std::cout << "End equals begin!\n";
    std::cout << "Size: " << std::size(output) << "\n";
    std::cout << "Distance: " << ranges::distance(output) << "\n";
    return 1;
  }
}

Compiling the above example against 2ff4cf2 and running it gives:

% ./cycle_slice
End equals begin!
Size: 512
Distance: 512

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions