Код: Выделить всё
#include
#include
#include
#include
struct Token
{
std::string value;
bool used = false;
};
int main()
{
auto tokens = std::vector{Token{"p1"}, Token{"p2"}, Token{"++"}, Token{"p3"}};
auto view = tokens
| std::views::drop_while([](auto const & token) { return token.used; })
| std::views::take_while([](auto const & token) { return !token.used; })
| std::views::filter([](auto const &) { return true; }); // without this filter it works fine
auto strs = std::vector();
for (auto& elem : view)
{
elem.used = true;
strs.push_back(elem.value);
}
for (auto const & str : strs)
{
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79502108/can-i-compose-take-while-and-filter-and-mutate-underlying-sequence[/url]