-
-
Save fabiogaluppo/210b843dcfd01b9aed3f to your computer and use it in GitHub Desktop.
std::copy and iterator_with_predicate
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
std::vector<int> xs = { 1, 2, 3, 4, 5, 6, 7, 8 }, ys; | |
ys.resize(xs.size() / 2); | |
auto is_odd = [](int i) { | |
return (i & 0x1) == 0x1; | |
}; | |
auto iwp = make_iterator_with_predicate(xs, is_odd); | |
std::copy(iwp.begin(), iwp.end(), ys.begin()); //ys = 1, 3, 5, 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment