#include #include #include #include int main() { std::vector container{1, 3, 2, 4, 6, 7, 5, 7, 8, 9, 10}; // Methods for lazy evaluation. auto transformed = // We start with the container. // This is optional, we can add it later at line 19. container // Pipe is used to chain operations. | std::ranges::views::filter([](int value) { return value % 2 == 0; }) | std::ranges::views::transform([](int value) { return value * 2; }) | std::ranges::views::reverse; std::cout << "Value" << std::endl; for (auto&& item : transformed) { std::cout << "- " << item << std::endl; } // Use with strings is not optimal but possible. // The main issues is that we start with line as an container and split it into sub-ranges. // Next we need to concert each subrange into string_view. // std::string_view line = "Some line\twith tokens and white spaces."; // Slightly better with lates working draft but ... auto transformation = // Split using space. std::ranges::views::split(' ') // Magic ~ create strings (start character, size), for start character we need to get the address from an interator. | std::ranges::views::transform([](auto&& range) { return std::string_view(&*range.begin(), range.size()); }) // Remove empty. | std::ranges::views::filter([](auto item) { return !item.empty(); }); std::cout << "Tokens from '" << line << "'" << std::endl; for (auto&& token : line | transformation) { std::cout << "- '" << token << "'" << std::endl; } }