[ 
https://issues.apache.org/jira/browse/STDCXX-1033?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Martin Sebor closed STDCXX-1033.
--------------------------------

    Resolution: Fixed

> incorrect documentation of nth_element in User's Guide
> ------------------------------------------------------
>
>                 Key: STDCXX-1033
>                 URL: https://issues.apache.org/jira/browse/STDCXX-1033
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: Documentation
>    Affects Versions: 4.2.1
>            Reporter: Martin Sebor
>            Assignee: Martin Sebor
>            Priority: Minor
>             Fix For: 4.2.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> From an external source:
> {quote}
> There appears to be an error in your documentation here:
> http://stdcxx.apache.org/doc/stdlibug/14-3.html#idx353
> This is your example:
> The example program illustrates finding the fifth largest value in a 
> {{vector}} of random numbers.
> {code}
> void nth_element_example()
> // illustrates the use of the nth_element algorithm
> // see alg7.cpp for complete source code
> {
>   // make a vector of random integers
>   std::vector<int> aVec(10);
>   std::generate(aVec.begin(), aVec.end(), randomValue);
>  
>   // now find the 5th largest
>   std::vector<int>::iterator nth = aVec.begin() + 4;
>   std::nth_element(aVec.begin(), nth, aVec.end());
>  
>   std::cout << "fifth largest is " << *nth << std::endl;
> }
> {code}
> However {{nth_element}} uses {{<}} as the default predicate so your example 
> will produce the 5th smallest element, not the 5th largest.
> To get the fifth largest you should use {{std::greater<int>()}} as a 
> predicate or use the fifth from the other end, i.e. {{aVec.end() - 5}}.
> {quote}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to