Created on 2011-08-17.00:00:00 last changed 131 months ago
Proposed resolution:
This wording is relative to the FDIS.
Change [alg.reverse] p4 as follows:
template<class BidirectionalIterator, class OutputIterator> OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);-4- Effects: Copies the range [first,last) to the range [result,result+(last-first)) such that for any non-negative integer i < (last - first) the following assignment takes place: *(result + (last - first) - 1 - i) = *(first + i).
-5- Requires: The ranges [first,last) and [result,result+(last-first)) shall not overlap. -6- Returns: result + (last - first). -7- Complexity: Exactly last - first assignments.
[ 2012, Portland: applied to WP ]
[ 2012, Kona ]
Move to Ready.
The output of the program below should be:
"three two one null \n"
But when std::reverse_copy is implemented as described in N3291 [alg.reverse] it's:
"null three two one \n"
because there's an off by one error in [alg.reverse]/4; the definition should read:
*(result + (last - first) - 1 - i) = *(first + i)
Test program:
#include <algorithm> #include <iostream> template <typename BiIterator, typename OutIterator> auto reverse_copy_as_described_in_N3291( BiIterator first, BiIterator last, OutIterator result ) -> OutIterator { // 25.3.10/4 [alg.reverse]: // "...such that for any non-negative integer i < (last - first)..." for ( unsigned i = 0; i < ( last - first ); ++i ) // "...the following assignment takes place:" *(result + (last - first) - i) = *(first + i); // 25.3.10/6 return result + (last - first); } int main() { using std::begin; using std::end; using std::cout; static const char*const in[3] { "one", "two", "three" }; const char* out[4] { "null", "null", "null", "null" }; reverse_copy_as_described_in_N3291( begin( in ), end( in ), out ); for ( auto s : out ) cout << s << ' '; cout << std::endl; return 0; }
History | |||
---|---|---|---|
Date | User | Action | Args |
2014-02-20 13:20:35 | admin | set | status: wp -> c++14 |
2012-11-03 04:16:46 | admin | set | messages: + msg6265 |
2012-10-25 12:46:45 | admin | set | status: voting -> wp |
2012-10-16 15:35:12 | admin | set | status: ready -> voting |
2012-02-12 18:36:43 | admin | set | messages: + msg5999 |
2012-02-12 18:36:43 | admin | set | status: new -> ready |
2011-11-22 22:51:03 | admin | set | messages: + msg5887 |
2011-08-17 00:00:00 | admin | create |