stl - What is multi-pass guarantee per C++ ISO standard? -
reading working draft n3337-1, standard programming language c++, 24.2.5 forward iterators, page 806.
from draft:
two dereferenceable iterators a
, b
of type x
offer multi-pass guarantee if:
— a == b
implies ++a == ++b
and
— x
pointer type or expression (void)++x(a), *a
equivalent expression *a
.
[ note: requirement a == b
implies ++a == ++b
(which not true input , output iterators) , removal of restrictions on number of assignments through mutable iterator (which applies output iterators) allows use of multi-pass one-directional algorithms forward iterators. —end note ]
could re-interpret in easier terms ? understand forward iterators multi-pass, don't understand how accomplished per c++ standard requirements.
the terms states all, i'd think: can pass through sequence multiple times , remember positions within sequence. long sequence doesn't change, starting @ specific position (iterator) you'll traverse on same objects want in same order. however, can go forward, there no way move backwards. canonical example of sequence singly-linked list.
the quoted clause says, if have 2 iterators comparing equal , increment each 1 of them, same position , compare equal again:
if (it1 == it2) { ++it1; ++it2; assert(it1 == it2); // has hold multi-pass sequences }
the weird expression ++x(a), *a
intended advance iterator independent a
, requirement ++x(a), *a
being equivalent *a
means iterator on sequence using independent iterator doesn't change a
refers to. unlike input iterator ++init(a), *a
not equivalent *a
first expression can have change position, possibly invalidating a
and/or change value referring to.
by contrast, single-pass sequence (input , output iterations in standard terms) can traversed once: trying traverse sequence multiple times not work work. canonical example of sequences input keyboard , output console: once read, can't same characters again , once sent can't undo characters.
Comments
Post a Comment