Range

To perform sequential operation on series.

Example: Imagine you have a list of names and you want to find all names starting with the letter "A", convert them to uppercase, and collect them into a new list.

#include <iostream>
#include <vector>
#include <string>
#include <ranges>

int main() {
  std::vector<std::string> names = {"Alice", "Bob", "Charlie", "Amanda", "Brian"};

  // Using C++20 Ranges and Views
  auto result = names 
        | std::views::filter([](const std::string& name) { 
            return name.starts_with("A"); 
          })
        | std::views::transform([](std::string name) {
            for (auto& c : name) c = toupper(c);
            return name;
          });

  for (const auto& name : result) {
    std::cout << name << " "; // Output: ALICE AMANDA 
  }

  return 0;
}