Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <iomanip>
- #include <functional>
- #include <iterator>
- template <typename Collection,typename Predicate>
- Collection filter(Collection col, Predicate predicate) {
- auto fnCol = filterNot(col,[predicate](typename Collection::value_type i) { return !predicate(i);});
- return fnCol;
- }
- int main()
- {
- auto println = [](const char *message) { std::cout << "\n" << message << '\n'; };
- std::vector<int> col{ 23, 23, 37, 42, 23, 23, 37 };
- println("running filter");
- auto condition = [](int value) {
- return value > 30;
- };
- auto filterCol = filter(col,condition);
- std::copy(filterCol.begin(), filterCol.end(), std::ostream_iterator<int>(std::cout, " "));
- return 0;
- }
Add Comment
Please, Sign In to add comment