Created on 2012-07-06.00:00:00 last changed 131 months ago
Proposed resolution:
This wording is relative to N3376.
Change [alg.nth.element] p1 as indicated:
template<class RandomAccessIterator> void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last); template<class RandomAccessIterator, class Compare> void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);-1- After nth_element the element in the position pointed to by nth is the element that would be in that position if the whole range were sorted. Also for any iterator i in the range [first,nth) and any iterator j in the range [nth,last) it holds that:
!(*i > *j)!(*j < *i) or comp(*j, *i) == false.
[ 2013-04-20 Bristol ]
[ 2012-10 Portland: Move to Ready ]
This is clearly correct by inspection, moved to Ready by unanimous consent.
The specification of nth_element refers to operator< whereas all sorting without a compare function is based on operator<. While it is true that for all regular types both operators should be defined accordingly, all other sorting algorithms only rely on existence of operator<. So I guess the paragraph p1
After nth_element the element in the position pointed to by nth is the element that would be in that position if the whole range were sorted. Also for any iterator i in the range [first,nth) and any iterator j in the range [nth,last) it holds that: !(*i > *j) or comp(*j, *i) == false.
should read
After nth_element the element in the position pointed to by nth is the element that would be in that position if the whole range were sorted. Also for any iterator i in the range [first,nth) and any iterator j in the range [nth,last) it holds that: !(*j < *i) or comp(*j, *i) == false.
Note only "!(*i > *j)" was changed to "!(*j < *i)" and it would be more symmetric with comp(*j, *i) as well.
In theory this might be a semantic change to the spec, but I believe the mistake is unintended.History | |||
---|---|---|---|
Date | User | Action | Args |
2014-02-20 13:20:35 | admin | set | status: wp -> c++14 |
2013-04-25 19:07:07 | admin | set | status: voting -> wp |
2013-04-19 22:22:17 | admin | set | messages: + msg6475 |
2013-04-19 22:22:17 | admin | set | status: ready -> voting |
2012-10-16 15:35:12 | admin | set | messages: + msg6175 |
2012-10-16 15:35:12 | admin | set | status: new -> ready |
2012-08-05 17:14:08 | admin | set | messages: + msg6098 |
2012-07-06 00:00:00 | admin | create |