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 unop>
- void for_each(Collection col, unop op) {
- std::for_each(col.begin(), col.end(), op);
- }
- 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 };
- // call for_each to print the vector
- println("running for_each<T>");
- for_each(col, lambda_echo);
- return 0;
- }
Add Comment
Please, Sign In to add comment