Skip to content

Instantly share code, notes, and snippets.

@jb55
Created August 19, 2010 04:13
Show Gist options
  • Select an option

  • Save jb55/537010 to your computer and use it in GitHub Desktop.

Select an option

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

jb55 commented Aug 19, 2010

Copy link
Copy Markdown
Author

compiled on gcc 4.5.1

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