Movatterモバイル変換


[0]ホーム

URL:



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

1206. Incorrect requires formove_backward andcopy_backward

Section: 26.7.2[alg.move]Status:C++11Submitter: Howard HinnantOpened: 2009-09-13Last modified: 2016-01-28

Priority:Not Prioritized

View all issues withC++11 status.

Discussion:

26.7.2[alg.move], p6 says:

template<class BidirectionalIterator1, class BidirectionalIterator2>  BidirectionalIterator2    move_backward(BidirectionalIterator1 first,                  BidirectionalIterator1 last,                  BidirectionalIterator2 result);

...

Requires:result shall not be in the range[first,last).

This is essentially an "off-by-one" error.

Whenresult == last, whichis allowed by this specification, then the range[first, last)is being move assigned into the range[first, last). Themove(forward) algorithm doesn't allow self move assignment, and neither shouldmove_backward. Solast should be included in the range whichresult can not be in.

Conversely, whenresult == first, whichis not allowed by thisspecification, then the range[first, last)is being move assigned into the range[first - (last-first), first).I.e. into anon-overlapping range. Thereforefirst shouldnot be included in the range whichresult can not be in.

The same argument applies tocopy_backward though copy assigning elementsto themselves (result == last) should be harmless (though is disallowedbycopy).

[2010 Pittsburgh: Moved to Ready.]

Proposed resolution:

Change 26.7.2[alg.move], p6:

template<class BidirectionalIterator1, class BidirectionalIterator2>  BidirectionalIterator2    move_backward(BidirectionalIterator1 first,                  BidirectionalIterator1 last,                  BidirectionalIterator2 result);

...

Requires:result shall not be in the range[(first,last]).

Change 26.7.1[alg.copy], p13:

template<class BidirectionalIterator1, class BidirectionalIterator2>  BidirectionalIterator2    copy_backward(BidirectionalIterator1 first,                  BidirectionalIterator1 last,                  BidirectionalIterator2 result);

...

Requires:result shall not be in the range[(first,last]).


[8]ページ先頭

©2009-2026 Movatter.jp