[LLVMbugs] [Bug 22541] New: minmax should return the rightmost element when several elements are equivalent to the largest

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Feb 10 23:29:52 PST 2015


http://llvm.org/bugs/show_bug.cgi?id=22541

            Bug ID: 22541
           Summary: minmax should return the rightmost element when
                    several elements are equivalent to the largest
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kariya_mitsuru at hotmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

Created attachment 13839
  --> http://llvm.org/bugs/attachment.cgi?id=13839&action=edit
clang++ -v

Please see the sample code below

=========================== sample code ===========================
#include <iostream>
#include <algorithm>

int main()
{
    auto p = std::minmax({ 1, 2, 3 }, [](int, int) { return false; });
    std::cout << "min = " << p.first << ", max = " << p.second << std::endl;
}
=========================== sample code ===========================

=========================== output ===========================
min = 1, max = 1
=========================== output ===========================

cf. http://melpon.org/wandbox/permlink/BSk4xURxuhIIOvlt


The C++11 standard 25.4.7[alg.min.max]/p.19 says, "y is a copy of the rightmost
argument when several arguments are equivalent to the largest."

Since minmax_element returns the rightmost iterator intentionally, I think it
is intentional rather than typo.

All integers are equivalent in the sample code above, so all element is the
smallest and the largest.

So the output should be
=========================== output ===========================
min = 1, max = 3
=========================== output ===========================

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150211/a8dfa2f4/attachment.html>


More information about the llvm-bugs mailing list