Topic: Off by one error in std::reverse_copy for N3291=11-0061 25.3.10
Author: SG<s.gesemann@gmail.com>
Date: Wed, 24 Aug 2011 14:06:51 -0700 (PDT) Raw View
On 17 Aug., 05:29, peter miller wrote:
> [...]
> because there's an off by one error in 25.3.10/4; the definition should
> read:
>
> *(result + (last - first) - 1 - i) = *(first + i)
> ^^^
I agree. Good catch. Hopefully, the committee will notice this as I
don't really know what the exact protocol is for reporting these
errors. Posting here is a good start, I guess.
Cheers!
SG
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?=<daniel.kruegler@googlemail.com>
Date: Thu, 25 Aug 2011 20:50:15 CST Raw View
On 2011-08-24 23:06, SG wrote:
> On 17 Aug., 05:29, peter miller wrote:
>> [...]
>> because there's an off by one error in 25.3.10/4; the definition should
>> read:
>>
>> *(result + (last - first) - 1 - i) = *(first + i)
>> ^^^
>
> I agree. Good catch. Hopefully, the committee will notice this
I have forwarded Peter's description to the LWG group, so they must have
noticed it ;-)
> as I
> don't really know what the exact protocol is for reporting these
> errors. Posting here is a good start, I guess.
The description in
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html
says (search for "How to submit an issue") that you can send an e-mail
to the author of the list and this e-email address is provided on the
top of the document (search for "Reply to").
But as you say, I generally recommend to post to this group (or
c.l.c.mod) first, because sometimes people believe that there is an
issue, but in fact there isn't.
Greetings from Bremen,
- Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "peter miller" <fuchsia.groan@virgin.net>
Date: Thu, 1 Sep 2011 11:11:10 -0700 (PDT) Raw View
Daniel (and SG)
> I have forwarded Peter's description to the LWG group, so they must
> have noticed it ;-)
Yeah, and I ought to have said "thanks" for that, by now. So thanks,
Daniel; you do great work.
(And I might get back to replying about iterators - eventually.
Some of it was me forgetting about uniform initializers...)
> But as you say, I generally recommend to post to this group (or
> c.l.c.mod) first, because sometimes people believe that there is an
> issue, but in fact there isn't.
And even standards' writers can make schoolboy errors... ;)
It also gives the C++ community a "heads up". So it's a bit
more public spirited, too.
Cheers
Peter
(PS This is a resend, because of my ISP's flaky news server.)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "peter miller" <fuchsia.groan@virgin.net>
Date: Tue, 16 Aug 2011 21:29:03 CST Raw View
/*
Hi,
the output of the program below should be:
"three two one null \n"
But when std::reverse_copy is implemented as described in
N3291=11-0061 25.3.10 [alg.reverse] it's:
"null three two one \n"
because there's an off by one error in 25.3.10/4; the definition should
read:
*(result + (last - first) - 1 - i) = *(first + i)
^^^
Hopefully, I've not made an embarrassing mistake of my own.
Peter
*/
#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;
}
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?ISO-8859-15?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Thu, 18 Aug 2011 07:53:25 CST Raw View
On 2011-08-17 05:29, peter miller wrote:
>
> /*
> Hi,
>
> the output of the program below should be:
>
> "three two one null \n"
>
> But when std::reverse_copy is implemented as described in
> N3291=11-0061 25.3.10 [alg.reverse] it's:
>
> "null three two one \n"
>
> because there's an off by one error in 25.3.10/4; the definition should
> read:
>
> *(result + (last - first) - 1 - i) = *(first + i)
I agree with your problem analysis. Forwarded to the library working group.
Greetings from Bremen,
- Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]