Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour of ranges::distance with ranges::view::zip using infinite views. #783

Closed
tremmelg opened this issue Feb 7, 2018 · 0 comments · Fixed by #913
Closed
Labels

Comments

@tremmelg
Copy link

tremmelg commented Feb 7, 2018

Calling ranges::distance with a ranges::zip_view that has an infinite view component gives different results depending on the specific infinite view.

#include <range/v3/all.hpp>
#include <vector>
#include <iostream>

int main() {
  std::vector<int> input(1024);

  auto cycle = ranges::view::cycle(input);
  auto zip_cycle = ranges::view::zip(input, cycle);

  std::cout << "Cycle: " << ranges::distance(zip_cycle) << "\n";

  auto repeat = ranges::view::repeat(42);
  auto zip_repeat = ranges::view::zip(input, repeat);

  std::cout << "Repeat: " << ranges::distance(zip_repeat) << "\n";

  auto iota = ranges::view::iota(0);
  auto zip_iota = ranges::view::zip(input, iota);

  std::cout << "Iota: " << ranges::distance(zip_iota) << "\n";

  auto generate = ranges::view::generate([]() { return 42; });
  auto zip_generate = ranges::view::zip(input, generate);

  std::cout << "Generate: " << ranges::distance(zip_generate) << "\n";
}

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

% ./zip_distance
Cycle: 0
Repeat: 0
Iota: 1024
Generate: 1024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants