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 Condition>
- bool if_exist(Collection col, Condition con) {
- auto exist = std::find_if(col.begin(), col.end(), con);
- return exist != col.end();
- }
- 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 exist() function");
- auto check_func = [] (int val) {
- return val == 20;
- };
- std::cout << if_exist(col, check_func) << '\n';
- return 0;
- }
Add Comment
Please, Sign In to add comment