Skip to content

Instantly share code, notes, and snippets.

@ghamarian
Created March 5, 2022 19:50
Show Gist options
  • Save ghamarian/dcf383209256117f8495bd4d1f6dc3f8 to your computer and use it in GitHub Desktop.
Save ghamarian/dcf383209256117f8495bd4d1f6dc3f8 to your computer and use it in GitHub Desktop.
// rangesFilterTransform.cpp
#include <iostream>
//#include <ranges>
#include <range/v3/all.hpp>
#include <vector>
int main() {
std::vector<int> numbers = {1, 2, 3, 4, 5, 6};
auto results = numbers | ranges::views::filter([](int n){ return n % 2 == 0; })
| ranges::views::transform([](int n){ return n * 2; });
auto results = numbers | ranges::views::filter([](int n) { return n % 2 == 0; })
for (auto v: results) std::cout << v << " "; // 4 8 12
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment