Это минимальный пример:
Код: Выделить всё
#include
#include
int main()
{
auto vec = std::vector{1, 2, 3, 4, 5, 6, 7, 8};
auto view = vec
| std::views::take_while([](auto i) { return i < 8; })
| std::views::filter([past_value = false](auto i) mutable
{
if (past_value)
{
return true;
}
else
{
return false;
}
});
auto end1 = std::ranges::end(view);
auto end2 = std::ranges::end(view);
return end1 == end2;
}
Код: Выделить всё
:26:17: error: invalid operands to binary expression ('_Sentinel' and '_Sentinel')
26 | return end1 == end2;
| ~~~~ ^ ~~~~
/opt/compiler-explorer/gcc-15.2.0/lib/gcc/x86_64-linux-gnu/15.2.0/../../../../include/c++/15.2.0/ranges:1801:2: note: candidate function (with reversed parameter order) not viable: no known conversion from '_Sentinel' to 'const _Iterator' for 2nd argument
1801 | operator==(const _Iterator& __x, const _Sentinel& __y)
| ^ ~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-15.2.0/lib/gcc/x86_64-linux-gnu/15.2.0/../../../../include/c++/15.2.0/ranges:1801:2: note: candidate function not viable: no known conversion from '_Sentinel' to 'const _Iterator' for 1st argument
1801 | operator==(const _Iterator& __x, const _Sentinel& __y)
| ^ ~~~~~~~~~~~~~~~~~~~~
1 error generated.
Compiler returned: 1
Код: Выделить всё
: In function 'int main()':
:26:17: error: no match for 'operator==' (operand types are 'std::ranges::filter_view::_Sentinel' and 'std::ranges::filter_view::_Sentinel')
26 | return end1 == end2;
| ~~~~ ^~ ~~~~
| | |
| | _Sentinel
| _Sentinel
:26:17: note: there is 1 candidate
26 | return end1 == end2;
| ~~~~~^~~~~~~
In file included from :1:
/cefs/22/22e6cdc013c8541ce3d1548e_consolidated/compilers_c++_x86_gcc_15.2.0/include/c++/15.2.0/ranges:1801:9: note: candidate 1: 'constexpr bool std::ranges::operator==(const filter_view::_Iterator&, const filter_view::_Sentinel&)' (reversed)
1801 | operator==(const _Iterator& __x, const _Sentinel& __y)
| ^~~~~~~~
/cefs/22/22e6cdc013c8541ce3d1548e_consolidated/compilers_c++_x86_gcc_15.2.0/include/c++/15.2.0/ranges:1801:37: note: no known conversion for argument 1 from 'std::ranges::filter_view::_Sentinel' to 'const std::ranges::filter_view::_Iterator&'
1801 | operator==(const _Iterator& __x, const _Sentinel& __y)
| ~~~~~~~~~~~~~~~~~^~~
Compiler returned: 1
Смотрите живую демонстрацию.
Не является ли сравнение двух дозорных неправильным? Разве std::ranges::end(view) == std::ranges::end(view) компилируется для любого представления?
Подробнее здесь: https://stackoverflow.com/questions/798 ... -sentinels
Мобильная версия