Демо(https://godbolt.org/z/aqdh7ohva) )
Код: Выделить всё
#include
#include
#include
int main()
{
std::vector v = { 0, 1, 2, 3, 4, 5, 6 };
const bool strategy_check_for_zero = true;
auto selected = v | std::views::filter([=](const auto& v) { return !strategy_check_for_zero || v != 0; });
// Impossible to do; why?
selected = v | std::views::filter([=](const auto& v) { return true; });
std::ranges::copy(selected, std::ostream_iterator{std::cout, ", "});
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79365549/why-view-cant-be-assigned-even-with-the-same-type[/url]