join_view — flatten nested ranges. split_view — split range by delimiter.
1#include <ranges>23// join_view — flatten4std::vector<std::vector<int>> nested = {{1,2}, {3,4}, {5,6}};5auto flat = nested | std::views::join;6for (int x : flat) {7 std::cout << x << " "; // 1 2 3 4 5 68}910// String splitting11std::string csv = "a,b,c,d";12auto tokens = csv | std::views::split(',');13for (auto token : tokens) {14 std::cout << std::string_view(token) << " ";15}16// a b c d1718// Split by substring19std::string text = "one::two::three";20auto parts = text | std::views::split("::");21for (auto part : parts) {22 std::cout << std::string_view(part) << " ";23}24// one two three2526// Split by predicate27std::string ws = "hello world test";28auto words = ws | std::views::split(std::isspace);29for (auto word : words) {30 std::cout << std::string_view(word) << " ";31}32// hello world test3334// Composable35auto result = csv36 | std::views::split(',')37 | std::views::transform([](auto token) {38 return std::string_view(token);39 });
Benefits: