Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.

1311. multi-pass property of Forward Iterator underspecified

Section: 24.3.5.5[forward.iterators]Status:ResolvedSubmitter: Alisdair MeredithOpened: 2010-02-07Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [forward.iterators].

View all issues withResolved status.

Discussion:

The following example demonstrates code that would meet the guarantees of aForward Iterator, but only permits a single traversal of the underlyingsequence:

template< typename ForwardIterator>struct bad_iterator {  shared_ptr<ForwardIterator> impl;  bad_iterator( ForwardIterator iter ) {     : impl{new ForwardIterator{iter} }      {  }  auto operator*() const -> decltype(*ForwardIterator{}) {     return **impl;  }  auto operator->() const -> ForwardIterator {     return *impl;  }  auto operator==(bad_iterator const & rhs) const -> bool {     return impl == rhs.impl;  }  auto operator++() -> bad_iterator& {     ++(*impl);     return *this;  }  // other operations as necessary...};

Here, we useshared_ptr to wrap a forward iterator, so all iteratorsconstructed from the same original iterator share the same 'value', andincrementing any one copy increments all others.

There is a missing guarantee, expressed by the following code sequence

FwdIter x = seq.begin();  // obtain forward iterator from a sequenceFwdIter y = x;            // copy the iteratorassert(x == y);           // iterators must be the same++x;                      // increment *just one* iteratorassert(x != y);           // iterators *must now be different*++y;                      // increment the other iteratorassert(x == y);           // now the iterators must be the same again

That inequality in the middle is an essential guarantee. Note that this list issimplified, as each assertion should also note that they refer to exactly thesame element(&*x == &*y) but I am not complicating the issuewith tests to support proxy iterators, or value types overloading unaryoperator+.

I have not yet found a perverse example that can meet this additionalconstraint, and not meet the multi-pass expectations of a Forward Iteratorwithout also violating other Forward Iterator requirements.

Note that I do not yet have standard-ready wording to resolve the problem, assaying this neatly and succinctly in 'standardese' is more difficult.

[2010 Pittsburgh: Moved toNAD EditorialResolved. Rationale added below.]

Rationale:

Solved byN3066.

Proposed resolution:


[8]ページ先頭

©2009-2026 Movatter.jp