Last active
August 29, 2015 14:16
-
-
Save yhirose/e6208ef2a571c89c1956 to your computer and use it in GitHub Desktop.
filter_and_map
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
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