Skip to content

Add a second cpp2::range constructor which takes 2 types, and deduce the common type for them (if available) #1270

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

Merged
merged 5 commits into from
Oct 5, 2024

Conversation

bluetarpmedia
Copy link
Contributor

Use a CTAD deduction guide to deduce the std::common_type for both types (if a common one exists).

This allows code like the following to compile without integer precision conversion warnings:

for 0 ..< vector.size() do (e) { ... }

since the integer literal 0 and the size expression evaluate as different signed/unsigned types.

Also update the regression tests after recent changes.

Fixes #1269

Use a CTAD deduction guide to deduce the `std::common_type` for both types (if a common one exists).

This allows code like the following to compile without integer precision conversion warnings:
```
for 0 ..< vector.size() do (e) { ... }
```
since the integer literal 0 and the size expression evaluate as different signed/unsigned types.
@feature-engineer
Copy link

feature-engineer commented Sep 19, 2024

Does putting e - 1 < 0 inside the loop still fails to compile (as it should)?
What about vector[e - 1] when e is zero?
Or when we iterate backwards?

@hsutter
Copy link
Owner

hsutter commented Sep 23, 2024

Thanks!

@feature-engineer AFAICS this only affects ..< and ..= expressions so those would be unchanged.

@hsutter hsutter merged commit ce033fe into hsutter:main Oct 5, 2024
17 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Wshorten-64-to-32 clang warning when using range 0 ..< vector.size()
3 participants