C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Question on forward iterator requirements (especially paragraph 2 of 23.3.5.5)
From: Jason McKesson (jmckesson_at_[hidden])
Date: 2021-01-29 19:43:56


On Fri, Jan 29, 2021 at 8:16 PM Will Hawkins via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
>
>
> On Fri, Jan 29, 2021 at 7:15 PM Will Hawkins <hawkinsw_at_[hidden]> wrote:
>>
>> Hello everyone!
>>
>> I hope that these are reasonable questions and not a waste of time.
>>
>> First, I have been reading the requirements for forward iterators in 23.3.5.5 and am focused on Paragraph 2 [1].
>>
>> Given,
>> - The vector v in std::vector<int> v{}; is an empty sequence, and
>> - The vector iterator v_it in std::vector<v>::iterator v_it{}; is a value-initialized iterator that meets the requirements of forward iterator,
>>
>> is it specified (per Note 1 of Paragraph 2) that
>>
>> v.end() == v_it
>>
>> ?
>
>
> After further discussion with another language expert, I have been convinced that the paragraph does not specify that v.end() must equal v_it. Rather, it only specifies that
>
> v_it == u_it
>
> where
>
> std::vector<v>::iterator v_it{};
> std::vector<v>::iterator u_it{};
>
> Is this the correct conclusion to draw from that paragraph?
>
> My confusion arose from the use of the phrase "same empty sequence" in Note 1. I was reading that to mean "all empty sequences of the same type".
>
> I would love to know why Note 1 was included. It seems to add ambiguity rather than clarify. Thoughts?

It seems pretty clear to me. There are three facts at play:

1: Forward-iterators specify locations within a half-open range.

2: Only iterators into the same range can be compared.

3: Value initialized iterators compare equal to other
value-initialized iterators.

The conclusion of these is that all value-initialized iterators are
logically an iterator into the same empty range. This is why it is a
non-normative annotation rather than a hard rule.


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups