Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

copy_backward

37 views
Skip to first unread message

Fraser Ross

unread,
Aug 30, 2018, 8:12:56 AM8/30/18
to
In the standard it says "Copies elements in the range [first, last) into
the range [result - (last-first), result) starting from last - 1 and
proceeding to first."

I think it should say proceeding to first - 1. first - 1 would refer to
the iterator one past the end. The same mistake is made with
move_backward. There is also inconsistency with fonts and boldness for
these expressions.

Fraser.

Alf P. Steinbach

unread,
Aug 30, 2018, 9:30:30 AM8/30/18
to
The author (Richard?) must have meant the inclusive "to". We could avoid
most of these implicit appeals to common sense by making that appeal
explicit: "to first, or thereabouts, whatever". One reason I like that
idea very much is that while it would work nicely for programmers it
could and hopefully would give the Language Lawyers™ the fits.

Cheers!,

- Alf

Jorgen Grahn

unread,
Aug 30, 2018, 9:35:50 AM8/30/18
to
On Thu, 2018-08-30, Fraser Ross wrote:
> In the standard it says "Copies elements in the range [first, last) into
> the range [result - (last-first), result) starting from last - 1 and
> proceeding to first."
>
> I think it should say proceeding to first - 1. first - 1 would refer to
> the iterator one past the end. The same mistake is made with
> move_backward.

Let's assume the range is [2, 6), i.e. [2, 3, 4, 5].
Then it should copy 5, 4, 3, 2, i.e.

starting from 5 = 6-1 = last-1
proceeding to 2 = first

Looks correct to me.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Fraser Ross

unread,
Aug 30, 2018, 10:01:20 AM8/30/18
to
On 30/08/2018 14:35, Jorgen Grahn wrote:
> On Thu, 2018-08-30, Fraser Ross wrote:
>> In the standard it says "Copies elements in the range [first, last) into
>> the range [result - (last-first), result) starting from last - 1 and
>> proceeding to first."
>>
>> I think it should say proceeding to first - 1. first - 1 would refer to
>> the iterator one past the end. The same mistake is made with
>> move_backward.
>
> Let's assume the range is [2, 6), i.e. [2, 3, 4, 5].
> Then it should copy 5, 4, 3, 2, i.e.
>
> starting from 5 = 6-1 = last-1
> proceeding to 2 = first
>
> Looks correct to me.
>
> /Jorgen
>

In C++ an end iterator points one past the last element. The algorithm
descriptions would be better understood if the convention was stuck to.

Fraser.

Fraser Ross

unread,
Aug 30, 2018, 10:02:21 AM8/30/18
to
On 30/08/2018 14:35, Jorgen Grahn wrote:
> On Thu, 2018-08-30, Fraser Ross wrote:
>> In the standard it says "Copies elements in the range [first, last) into
>> the range [result - (last-first), result) starting from last - 1 and
>> proceeding to first."
>>
>> I think it should say proceeding to first - 1. first - 1 would refer to
>> the iterator one past the end. The same mistake is made with
>> move_backward.
>
> Let's assume the range is [2, 6), i.e. [2, 3, 4, 5].
> Then it should copy 5, 4, 3, 2, i.e.
>
> starting from 5 = 6-1 = last-1
> proceeding to 2 = first
>
> Looks correct to me.
>
> /Jorgen
>

james...@alumni.caltech.edu

unread,
Aug 30, 2018, 10:22:37 AM8/30/18
to
True - but that description describes which objects get copied. No
attempt is supposed to be made to copy the object that the end iterator
refers to, since such an attempt would have undefined behavior.

Fraser Ross

unread,
Aug 30, 2018, 10:45:18 AM8/30/18
to
It refers to the range of iterators and specific iterators of that range
so I disagree. The wording is done identically to that for copy where
they correctly use the C++ end iterator convention.

Fraser.

Jorgen Grahn

unread,
Aug 30, 2018, 10:46:09 AM8/30/18
to
I think the difference is this: when I read "... proceeding to first"
I don't interpret that in in a "normal" context, as if we've left the
iterator terminology at that point. It didn't occur to me until now that
it could be interpreted differently.

Fraser Ross

unread,
Aug 31, 2018, 10:31:57 AM8/31/18
to
I think you are correct. I was confused by comparing the incorrect
descriptions of copy and move. If you look at for_each the description
there is correct saying: "... starting from first and proceeding to last
- 1."

Fraser.
0 new messages