<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/100580>100580</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `<algorithm>`: `ranges::inplace_merge` doesn't seem to be able to utilize `ranges::upper_bound`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          hewillk
      </td>
    </tr>
</table>

<pre>
    ```cpp
#include <algorithm>
#include <vector>

int main() {
  std::vector<int> v;
  auto cmp = [](int&, int&) { return true; };
  std::ranges::sort(v, cmp);
  std::ranges::inplace_merge(v, v.begin(), cmp); // hard error
}
```
https://godbolt.org/z/soe8sa75q

The above code is rejected by libstdc++, libc++, and MSVC-STL, which shouldn't be because `ranges::inplace_merge` has the _same_ constraint signature as `ranges::sort`.
The root cause is that `inplace_merge` uses `upper_bound`, which then requires `Compare` to satisfy `indirect_strict_weak_order<const T*, I>` (note the `const` here), which is not guaranteed by the constraints of `inplace_merge`.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVE1v2zgQ_TXjyyCGRFmWddDBsWtggd1Tg70apDiWuKVElRw6SH_9gpKdpGmLAILNj3mPfI-PlCGYbiRqoHyE8riSkXvnm56ejbXfVsrplwa22fK10wTZEbI9iMKMrY2aEIqDtJ3zhvsBii-_m79Sy86_Tc6_ZmQcpBlB7EDUCNXjMo4YWEOxh2J_xx3MyFB8wSsUr0UyssN2mBCKIy57B7FLhWIL4oD31syMnjj6EdlHguIRoTq-o3pdz8uxo7C0g_MMYndNXO0wgag_Q5hxsrKl80C-ozv0ulbU3UX-xIUgTiBO2Euvkbx3_uZOdbw17q4v3Z55mleaYZ3TylleO9-BOP0AcQqOdkFW5ff3Jj_1hFK5K2HrNKEJ6Ok_apk0qhe0RgXWLYjH-TukgXc9OWr85-u_h4evT3-n_nNv2h5D76LVI4iKUREqamUMhLDN_mzGNsNeBuSe8BzkQGds3RjYyxSClD_J0RPK8JFmPoVttn5T451jXJY0iVFywvyyXAw0k8VpIn9WLo46Ofmqgnsa0dP3aPxSeHDDJP2MZYdBsgmXl4VaG08tnwN70_L5meS3s_OaUjBnGfgEYp-o_0oR32YIYjc6pllvujWpaPaAPN1isOzCBBwdYxellyPTcioJ9WZPQHf5ncKbJSvdFLouarmiJq9EXue7KitXfZPJnKjKa5nXSguqcqm2xa69lBexuWzqfGUakYlNVoky32zKrFxLJagqVH6hOtdyK2CT0SCNXVt7HVLQViaESE2eZeUuW1mpyIb7s-GbVPWgYhdgk1kTOLzh2LCl-RX58Fakkf2n0dGOwpK3QDSk41Ep1ZZSM7Kx5scv-fv53FfR2-bDBTLcR7Vu3QDilHZ6-3uYvEs3BMRplhtAnG6Kr434PwAA__9B7Zak">