Skip to content

Instantly share code, notes, and snippets.

@saschagrunert
Created May 13, 2018 12:31
Show Gist options
  • Save saschagrunert/15e4d14198d90564fc88ceeeeafc4337 to your computer and use it in GitHub Desktop.
Save saschagrunert/15e4d14198d90564fc88ceeeeafc4337 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <vector>
int main(void) {
// Create a vector
std::vector<uint32_t> v = {1, 2, 3, 4, 5};
// Filter by copying
std::vector<uint32_t> res;
std::copy_if(v.cbegin(),
v.cend(),
std::back_inserter(res),
[&](const uint32_t v) {
return v > 3;
});
// Outputs to:
// 4
// 5
for (const auto & r : res) {
std::cout << r << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment