Documentation of std::nth_element

Jan 29, 2021 at 1:01pm
Hi,

I'm using std::nth_element on vectors, some of them are pre-sorted and some are not. I found that my code implicitly assumes that vectors which are already sorted are not modified, but that is false.

I think the description would benefit from a small warning, e.g. "...elements following it are less. Note that pre-sorted ranges don't necessarily stay sorted".

Is there a way to submit such suggestions?

Best Regards,
Alexander
Jan 29, 2021 at 2:10pm
It's an unwarranted assumption to expect the employed algorithm to be limited in that way. If you need to keep an ordered container in order, you can do the initial test yourself with std::is_sorted (or possibly std::is_sorted_until).

At any rate, AFAIK this site is no longer being updated.
Last edited on Jan 29, 2021 at 3:15pm
Jan 29, 2021 at 2:10pm
Which description from where?

If for the cplusplus.com site, then probably not as the site Reference section hasn't been updated for some years.
Last edited on Jan 29, 2021 at 2:13pm
Topic archived. No new replies allowed.