Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@JMazurkiewicz
Copy link
Contributor

@JMazurkiewicz JMazurkiewicz commented May 25, 2023

Per [range.cartesian.view]/9-10:

Let p be the product of the sizes of all the ranges in bases_.
Preconditions: p can be represented by the return type.

Currently cartesian_product_view::size may fail when p can be represented by return type:

#include <ranges>

using namespace std;

int main() {
  const auto r1 = views::repeat(0, (numeric_limits<ptrdiff_t>::max)());
  const auto r2 = views::repeat(1, 0);
  (void)views::cartesian_product(r1, r1, r1, r2).size(); // FAIL!
}

Obviously 0 can be represented by any unsigned integral type. This PR fixes this bug.

@JMazurkiewicz JMazurkiewicz marked this pull request as ready for review May 25, 2023 22:40
@JMazurkiewicz JMazurkiewicz requested a review from a team as a code owner May 25, 2023 22:40
@JMazurkiewicz

This comment was marked as resolved.

@CaseyCarter CaseyCarter added ranges C++20/23 ranges bug Something isn't working labels May 25, 2023
@StephanTLavavej StephanTLavavej self-assigned this May 26, 2023
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 0d47d98 into microsoft:main May 31, 2023
@StephanTLavavej
Copy link
Member

Thanks for fixing this corner case! 0️⃣ ✖️ ♾️

@JMazurkiewicz JMazurkiewicz deleted the cartprod-fix-size-debug branch May 31, 2023 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ranges C++20/23 ranges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants