| Issue |
86833
|
| Summary |
<algorithm>: `contains_subrange` should not use `std::cbegin` and `std::distance`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
hewillk
|
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
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs