The following code example is taken from the book
 
  C++20 - The Complete Guide
 by Nicolai M. Josuttis,
 Leanpub, 2021 
 
 The code is licensed under a
 
     Creative Commons Attribution 4.0 International License.
      
 
 
// raw code
 
#include <iostream> 
#include <string> 
#include <vector> 
#include <ranges> 
 
void print(std::ranges::input_range auto&& coll) 
{ 
  for (const auto& elem : coll) {  
    std::cout << elem << ' '; 
  } 
  std::cout << '\n'; 
} 
 
int main() 
{ 
  std::vector coll{1, 2, 3, 4, 1, 2, 3, 4, 1}; 
 
  print(coll);                                   // 1 2 3 4 1 2 3 4 1  
  auto less4 = [] (auto v) { return v < 4; }; 
  print(std::ranges::filter_view{coll, less4});  // 1 2 3 1 2 3 1  
  print(coll | std::views::filter(less4));       // 1 2 3 1 2 3 1  
}