<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Can't std::sort a collection of std::pair if one pair element is const"
   href="http://llvm.org/bugs/show_bug.cgi?id=19085">19085</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Can't std::sort a collection of std::pair if one pair element is const
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.3
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>james@weatherley.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <iostream>
#include <vector>

int main(int argc, const char * argv[])
{
    // Replace the std::vector declaration with the commented out one and it
builds.
    //
    //std::vector<std::pair<int, int>> vec = {
    std::vector<std::pair<const int, int>> vec = {
        std::make_pair(9, 8),
        std::make_pair(7, 6),
        std::make_pair(5, 4),
        std::make_pair(3, 2)
    };

    std::sort(vec.begin(), vec.end(), [](const std::pair<const int, int>& p1,
const std::pair<const int, int>&p2) {
        return true;
    });

    for(auto pair:vec)
    {
        std::cout << pair.first    << " : " << pair.second    << "\n";
    }
}

Build the above and you get errors:

/Applications/Xcode5.0/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/utility:292:15:
Read-only variable is not assignable

/Applications/Xcode5.0/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/utility:255:15:
Read-only variable is not assignable

I'm sorting - why does it want to assign to the const int pair element? Change
the pair declaration to a pair of non-const ints and it builds just fine.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>