C++ Logo

std-discussion

Advanced search

Re: Question on forward iterator requirements (especially paragraph 2 of 23.3.5.5)

From: Will Hawkins <hawkinsw_at_[hidden]>
Date: Fri, 29 Jan 2021 20:51:07 -0500
On Fri, Jan 29, 2021 at 8:44 PM Jason McKesson via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> 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.
>

Thank you for the response. I agree that (2) and (3) are very clear. I am
glad that we are on the same page about what those mean. I wish that you
had been the one to write the non-normative annotation. I feel like "All
value-initialized iterators are iterators into the same, notional empty
range." would be perfect.

Thanks again for taking the time to reply.

Will


> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2021-01-29 19:51:21