Skip to content

Instantly share code, notes, and snippets.

@fabiogaluppo
Last active October 13, 2015 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiogaluppo/fa63b9b24f201f7c802c to your computer and use it in GitHub Desktop.
Save fabiogaluppo/fa63b9b24f201f7c802c to your computer and use it in GitHub Desktop.
std::transform and iterator with predicate
std::vector<int> xs = { 1, 2, 3, 4, 5, 6, 7, 8 };
auto is_even = [](int i) {
return (i & 0x1) == 0x0;
};
auto iwp = make_iterator_with_predicate(xs, is_even);
std::transform(begin(iwp), end(iwp), begin(iwp), [](int i) { return i + 10; }); //xs = 1, 12, 3, 14, 5, 16, 7, 18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment