Skip to content

Instantly share code, notes, and snippets.

@yhirose
Last active August 29, 2015 14:16
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 yhirose/e6208ef2a571c89c1956 to your computer and use it in GitHub Desktop.
Save yhirose/e6208ef2a571c89c1956 to your computer and use it in GitHub Desktop.
filter_and_map
template <typename T, typename Pred, typename Conv>
auto filter_and_map(const vector<T>& cont, Pred pred, Conv conv) -> vector<typename std::remove_const<decltype(conv(T()))>::type> {
vector<typename std::remove_const<decltype(conv(T()))>::type> r;
for (const auto& el: cont) {
if (pred(el)) r.push_back(conv(el));
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment