Created
March 2, 2014 15:51
-
-
Save trikitrok/39b9a4c0b89160ca1d31 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
namespace VectorUtils { | |
template<typename T, typename Function> | |
std::vector<T> filter(const std::vector<T> & original, Function pred) { | |
std::vector<T> filtered; | |
std::copy_if(original.begin(), original.end(), | |
std::back_inserter(filtered), | |
pred); | |
return filtered; | |
} | |
template<typename T2, typename T1, typename Function> | |
std::vector<T2> map(const std::vector<T1> & original, Function f) { | |
std::vector<T2> mapped; | |
std::transform(original.begin(), original.end(), | |
std::back_inserter(mapped), | |
f); | |
return mapped; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment