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

cannot cartesian_product(enumerate, enumerate) | transform #1422

Closed
david8dixon opened this issue Jan 31, 2020 · 3 comments · Fixed by #1440
Closed

cannot cartesian_product(enumerate, enumerate) | transform #1422

david8dixon opened this issue Jan 31, 2020 · 3 comments · Fixed by #1440
Labels

Comments

@david8dixon
Copy link
Contributor

I am enumerating a vector of vectors and then I take the cartesian product of the enumeration with itself (which works fine), but when I try to transform the result it fails. The following link contains the reproducer:

https://wandbox.org/permlink/AL9HJ8pWbBBntXuN

@pkubik
Copy link

pkubik commented Feb 19, 2020

Doesn't work for simpler views too:

  auto ints = ranges::views::ints(0, 5);
  auto cp = ranges::views::cartesian_product(ints, ints);
  auto to_one = [](auto&& tup){return 1;};
  auto adjacent_cells_2 = cp | ranges::views::transform(to_one);

@ericniebler
Copy link
Owner

Doesn't work for simpler views too: ...

Nope, that code works fine.

  auto enumerated = v1 | ranges::views::enumerate;
  auto cp = ranges::views::cartesian_product(enumerated, enumerated);

This is a legit problem. After the above, the range library doesn't think cp is an input range. That's because it has the following associated types:

value type: std::tuple<V, V>, where V is std::pair<std::size_t, std::vector<int>>
reference: ranges::common_tuple<R, R>, where R is ranges::common_pair<std::size_t, std::vector<int>&>

The computed common reference of these types is:
common reference: std::tuple<R, R>, where R is ranges::common_pair<const std::size_t&, std::vector<int>&>

The trouble is, an lvalue reference to the value type is not convertible to the common reference. std::tuple doesn't provide that conversion. The upshot is that the iterators of the cartesian_product view do not satisfy readable.

I think the problem here is that the computed common reference of ranges::common_tuple yields a std::tuple instead of another ranges::common_tuple. I suspect making this change will cause other things to break though. I need to think about this.

@pkubik
Copy link

pkubik commented Feb 26, 2020

Sorry, it failed for me when I used a regular reference to for the tuple:

 auto to_one = [](auto& tup){return 1;};

I didn't compare the error messages carefully enough. Nevermind.

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.

3 participants