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

Fix zip/zip_with distance_to #1776

Merged
merged 3 commits into from May 23, 2023
Merged

Conversation

PkXwmpgN
Copy link
Contributor

@PkXwmpgN PkXwmpgN commented Apr 23, 2023

The distance between iterators is wrongly calculated when the first zipped range is empty:

    std::vector<int> a = {1, 2, 3, 4, 5};
    std::vector<int> b;

    auto z0 = zip(b, a);
    auto z1 = zip(a, b);

    auto d0 = ranges::distance(ranges::begin(z0), ranges::end(z0));
    auto d1 = ranges::distance(ranges::begin(z1), ranges::end(z1));
    
    assert(d0 == 0); // failed d0 == 5
    assert(d1 == 0); // pass

With MSVC

   std::vector<int> a = {1, 2, 3, 4, 5};
   std::vector<int> b; 
   auto v = zip(b, a) | ranges::to_vector; // access violation

include/range/v3/view/zip_with.hpp Outdated Show resolved Hide resolved
@brevzin brevzin merged commit 5ac35e4 into ericniebler:master May 23, 2023
3 checks passed
@brevzin
Copy link
Collaborator

brevzin commented May 23, 2023

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants