Skip to content

Instantly share code, notes, and snippets.

@Javran
Created September 22, 2012 04:34
Show Gist options
  • Save Javran/3765122 to your computer and use it in GitHub Desktop.
Save Javran/3765122 to your computer and use it in GitHub Desktop.
anonymous function in c++ !
// compile with args: -lstdc++ -std=c++0x
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <numeric>
int a[16];
int main()
{
srand(time(0));
int i;
for (i=0; i<16; ++i)
a[i] = rand();
printf("Gen:\n");
std::for_each(a, a+16, [](int x){ printf("%d\n", x); });
std::sort(a, a+16, [](int x, int y) {return x<y;});
printf("Sort:\n");
std::for_each(a, a+16, [](int x){ printf("%d\n", x); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment