Skip to content

Instantly share code, notes, and snippets.

@c650
Created August 10, 2020 16:25
Show Gist options
  • Save c650/56583c7547d742f4fca9e0966f86bd87 to your computer and use it in GitHub Desktop.
Save c650/56583c7547d742f4fca9e0966f86bd87 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int main() {
std::vector<int> v{1,2,3,4};
std::vector<int> b;
std::transform(v.begin(), v.end(), std::back_inserter(b), [](int a){return 2 * a;});
auto it = std::remove_if(b.begin(), b.end(), [](int a){return a % 6 != 0;});
b.erase(it, b.end());
int res = std::accumulate(b.begin(), b.end(), 0); // by default, accumulate adds all the elements
std::cout << res << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment