Title
Wording issue in nth_element
Status
c++14
Section
[alg.nth.element]
Submitter
Christopher Jefferson

Created on 2013-10-19.00:00:00 last changed 131 months ago

Messages

Date: 2014-02-13.06:35:03

Proposed resolution:

This wording is relative to N3797.

  1. Modify [alg.nth.element]/1 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, unless nth == last. Also for every iterator i in the range [first,nth) and every iterator j in the range [nth,last) it holds that: !(*j < *i) or comp(*j, *i) == false.

Date: 2014-02-13.06:35:03

[ Issaquah 2014-02-11: Move to Immediate ]

Date: 2014-02-13.06:35:03

The wording of nth_element says:

template<class RandomAccessIterator>
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
                   RandomAccessIterator last);

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 every iterator i in the range [first,nth) and every iterator j in the range [nth,last) it holds that: !(*j < *i) or comp(*j, *i) == false.

That wording, to me, implies that there must be an element at 'nth'. However, gcc at least accepts nth == last, and returns without effect (which seems like the sensible option).

Is it intended to accept nth == last? If so, then I would suggest adding this to the wording explicitly, say:

After nth_element the element in the position pointed to by nth, if any, is the element that would be in that position if the whole range were sorted. Also for every iterator i in the range [first,nth) and every iterator j in the range [nth,last) it holds that: !(*j < *i) or comp(*j, *i) == false.

History
Date User Action Args
2014-02-27 17:03:20adminsetstatus: wp -> c++14
2014-02-20 13:52:38adminsetstatus: immediate -> wp
2014-02-13 06:35:03adminsetmessages: + msg6836
2014-02-13 06:35:03adminsetstatus: new -> immediate
2013-10-19 13:07:48adminsetmessages: + msg6756
2013-10-19 00:00:00admincreate