Skip to content

Instantly share code, notes, and snippets.

@jb55
Created August 19, 2010 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jb55/537010 to your computer and use it in GitHub Desktop.
Save jb55/537010 to your computer and use it in GitHub Desktop.
#include <iostream>
template <typename TList, typename TFunc>
void forEach(const TList& list, const TFunc& fn) {
for (auto it = list.begin(); it != list.end(); ++it)
fn(*it);
}
int main()
{
forEach({1,2,3,4}, [](int i) {
std::cout << i << "\n";
});
}
/* out
1
2
3
4
*/
@jb55
Copy link
Author

jb55 commented Aug 19, 2010

compiled on gcc 4.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment