-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
[libc++] std::prev(it) should not compile for a non-bidi iterator #109456
Comments
I think it would be better to static_assert here, since this isn't a constraint. |
There's LWG3197 for this, which is still open now. |
Per the LWG issue mentioned by @frederick-vs-ja , it seems like it's not clear to everyone whether there is a constraint or not. IMO this should definitely be a constraint, |
CC @jwakely perhaps we want to bring back that LWG issue to the table? |
It's been on the table for five years 😄 apart from the note I added a few months ago nobody had made a case for why we should prefer any of the options. |
I would argue for option (A) or option (C) in LWG3197, otherwise the result is that calling (That's me trying to make a case BTW 🙂) |
std::prev(it, n)
could conceivably be well-formed for a non-bidirectionalit
ifn
is negative, howeverstd::prev(it)
is always UB, and we can easily diagnose it at compile-time. Right nowstd::prev(non_bidi)
is a no-op, which is absolutely vexing.https://godbolt.org/z/zaG3jTEqP
Potential patch:
The text was updated successfully, but these errors were encountered: