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 filterNot(Collection col,Predicate predicate ) {
- auto returnIterator = std::remove_if(col.begin(),col.end(),predicate);
- col.erase(returnIterator,std::end(col));
- return col;
- }
- int main()
- {
- auto println = [](const char *message) { std::cout << "\n" << message << '\n'; };
- auto lambda_echo = [](int i) { std::cout << std::setw(3) << i; };
- std::vector<int> col{ 23, 23, 37, 42, 23, 23, 37 };
- println("running filterNot");
- auto filterCol = filterNot(col,[](int val){ return val == 37;});
- std::copy(filterCol.begin(), filterCol.end(), std::ostream_iterator<int>(std::cout, " "));
- return 0;
- }
Add Comment
Please, Sign In to add comment