Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename Type>
- void for_each(const Type& container, std::function<void(typename Type::value_type)> &funct) {
- for (auto&& elem : container) {
- funct(elem);
- }
- }
- int main() {
- vector<int> v = { 1, 2, 3 };
- for_each(v, [](int e){
- cout << e << endl;
- });
- for_each(vector<int>({ 1, 2, 3 }), [](int e){
- cout << e << endl;
- });
- function<void(int)> funct = [](int e) {
- cout << e << endl;
- };
- for_each(v, funct);
- for_each(vector<int>{1}, funct);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement