Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:46:13+00:00 2026-06-06T12:46:13+00:00

I read the description of std::nth_element at http://www.sgi.com/tech/stl/nth_element.html template <class RandomAccessIterator> void nth_element(RandomAccessIterator first,

  • 0

I read the description of std::nth_element at http://www.sgi.com/tech/stl/nth_element.html

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

Note that the preconditions are

  1. [first, nth) is a valid range.
  2. [nth, last) is a valid range.

My question is:

Is it valid to call std::nth_element(a.begin(), a.end(), a.end())? If so, what’s its effect? It doesn’t violate the preconditions above, anyway. Anywhere in the language standard (or other documents) stated that nth must be pointing to an element in a?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:46:15+00:00Added an answer on June 6, 2026 at 12:46 pm

    It’s valid and is probably, but not guaranteed by the standard, a null operation. With the given data, the two preconditions become:

    [a.begin(), a.end()) is a valid range.
    [a.end(), a.end()) is a valid range.
    

    Which are both true, the second interval is empty though. From the standard 25.3.2/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) or comp(*j, *i) ==
    false.

    If the whole range was sorted the original a.end() would be at a.end() and for the second part the range [nth, last) is empty so there are no elements for which to evaluate the !(*i > *j) and comp(*j, *i) == false conditions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just read this description of the Android Support Package / Compatibility Library... http://developer.android.com/sdk/compatibility-library.html
I have read the examples here: http://framework.zend.com/manual/en/zend.gdata.spreadsheets.html But those examples assume the spreadsheet to
I am doing the following: System.Net.WebRequest myRequest = System.Net.WebRequest.Create(http://www.atlantawithkid.com/feed/); System.Net.WebResponse myResponse = myRequest.GetResponse(); System.IO.Stream
Read the comments in the code for a description: <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
Problem description: Read an xml file, traverse to a particular node (element), if it
This is my homework, but please read my problem description first. I have to
I read the book Algorithm Design, chapter 1, it gave a very short description
Whats the best way to read/write file properties (like author, description, etc) in C#?
Code: soup=BeautifulSoup(f.read()) data=soup.findAll('node',{'id':'memory'}) print data Output [<node id=memory claimed=true class=memory handle=DMI:000E> <description> System Memory
I just read a comment by GMan that class A { public: A() :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.