Created on 2019-04-03.00:00:00 last changed 5 months ago
Proposed resolution:
This wording is relative to N4810.
[Drafting Note: Three mutually exclusive options are prepared, depicted below by Option A, Option B, and Option C, respectively.]
Option A
NAD, the name BidirectionalIterator actually means that prev requires bidirectional iterators, in which case this change to libcxx is incorrect.
Option B
Modify [iterator.synopsis], header <iterator> synopsis, as indicated:
// [iterator.operations], iterator operations […] template<classBidirectionalInputIterator> constexprBidirectionalInputIterator prev(BidirectionalInputIterator x, typename iterator_traits<BidirectionalInputIterator>::difference_type n = 1);
Modify [iterator.operations] as indicated:
template<classBidirectionalInputIterator> constexprBidirectionalInputIterator prev(BidirectionalInputIterator x, typename iterator_traits<BidirectionalInputIterator>::difference_type n = 1);-7- Effects: Equivalent to: advance(x, -n); return x;
Option C
The intent of the wording is that the template parameters apply requirements, and the defect is that they do not. We should add a requirement in [iterator.operations]/1 to the effect that the template parameter names impose said requirements.
[ 2024-06-18; Jonathan adds a comment ]
Related to LWG 2353 which made a similar change to `std::next`. Also, if we require a Cpp17BidirectionalIterator here, then that means you can't use `std::prev` on a `std::bidirectional_iterator` unless it also meets the Cpp17BidirectionalIterator requirements. That seems like an unnecessary restriction, since `std::prev` doesn't do anything that wouldn't work fine with any type that models `std::bidirectional_iterator`.
[ 2022-04-22; Jonathan adds a comment ]
P2408 changes the requirements for types substituting BidirectionalIterator etc. in the Algorithms clause. We should consider whether that is appropriate here, especially as algorithms might make use of std::prev internally. An algorithm that was changed by P2408 to accept types that model bidirectional_iterator instead of requiring Cpp17BidirectionalIterator might have to stop using std::prev if we don't resolve this issue to allow it.
We should consider whether distance, advance and next need the same treatment.
[ 2019-06-12 Priority set to 3 after reflector discussion ]
MSVC++ (and apparently libc++) have asserts that std::prev only accepts BidirectionalIterators, because it's declared in the standard as accepting only BidirectionalIterator. libc++ changed their tests (in this commit), apparently from a bug report from Ville and Jonathan, saying that one could theoretically call std::prev with a negative number.
The standardese in [iterator.operations] strongly indicates that prev requires a BidirectionalIterator, but I don't see the usual wording that connects template type parameters of that name to the <algorithm> requirements or similar. So perhaps one could argue that the name Bidirectional there has no meaning. Even if that is the case, that's a defect in the other direction.History | |||
---|---|---|---|
Date | User | Action | Args |
2024-06-18 11:40:55 | admin | set | messages: + msg14166 |
2022-04-22 17:05:58 | admin | set | messages: + msg12420 |
2019-06-10 05:16:56 | admin | set | messages: + msg10431 |
2019-04-06 16:02:43 | admin | set | messages: + msg10385 |
2019-04-03 00:00:00 | admin | create |