Created
May 13, 2018 12:31
-
-
Save saschagrunert/15e4d14198d90564fc88ceeeeafc4337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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