<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/86833>86833</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
<algorithm>: `contains_subrange` should not use `std::cbegin` and `std::distance`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hewillk
</td>
</tr>
</table>
<pre>
https://github.com/llvm/llvm-project/blob/c335accb07c0cfa4bd7f47edc94c9005692edfcc/libcxx/include/__algorithm/ranges_contains_subrange.h#L72-L80
...because they are based on the C++17 iterator model rather than the C++20 Ranges iterator model.
In addition, `__n2` is an integer type and may not accommodate `difference_type`.
I believe the above can be just simplified to:
```cpp
if (ranges::distance(__range2) == 0)
return true;
```
testcase:
```cpp
#include <ranges>
#include <algorithm>
static_assert(
std::ranges::contains_subrange(
std::views::iota(0, 5),
std::views::iota(0, 5) | std::views::filter([](int i) { return true; }) )
);
```
https://godbolt.org/z/G6oMoM5Wz
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVEuP2zgM_jXMhWigUPHr4MNMsl4s0F72skdDDzpW15ECS57p9Ncv5MyrmW6BAoFiiB_1kfxIqhjdyTO3UNxDcdyoJY1hbkd-dNP070YH-9SOKV0iyDugDqg7uTQuemvCGaibpoeXv0-XOXxlk4A6PQUN1BkpC2WMFpURZlB7bathX7E1zd40QhRlQ2wHY_IDTptv34A65820WAbq-l5NpzC7NGaGWfkTx94En5TzsY-LXq-2I5D8XNGnz7UAcQRx9_7cbreajVoiYxr5CdXMqFVki8HnGzwA3QPd7yp0iWeVwoznYHnCWaWRZ0yj-gFIAv9eI7nBb698f3lU1rrkggc6IJSi7z1BKdBFVB6dT3zKzz5dGJW3eFZP6ENCZUw4n4NVibOXdcPAM3vDfYZCKV4IUPPk-GHNB5UOD4xGedSMX5eYMLrzZXKDY4spgLzDH2pSiuvPXC7XGzcgUH2tbRZY3lkXk_KGgeq-Xw0E1CDII8gjCqDm6ok4c1pmj2leGOT9DcNHKRLHZFTkTPPLmIDkcxMgyMNLbH_8zPjWIK_29YxJJWd6FSPPCah-Djkme03yfcIfOuoNj_jm8uD48dnDhaSAapEVLnJB6HBL8As0QnX4KXBwU-I5s6-TCFQ7n9BdXe5vyo1QHVfLix75439UuBnfYHWY0jbMJ6DuO1D3Zxm-hC_FP983tpW2kY3acLurdruiaGRRb8a20EqbnSxZqJ0ymopqEI1oiCQ1xii7cS0J2gtJ1a4Sza7eykqYWivWUuidHDTsBZ-Vm7Z5U2TujYtx4bYuayk3k9I8xXUFEXl-xNUIRHkjze26XfRyirAXk4spvr2SXJq4vW2F3Pel-KhsKTCOYZnsOnN5K0ApXrUwmk_OZ1CezPeW16EoxWaZp99fiGs-Eahb8_0vAAD__z-OpHc">