Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Ignoring the Voices: C++11 Example - Lambda Sorting
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
void PrintList(const vector<int>& list)
{
for (auto i : list)
{
cout << i << " ";
}
cout << endl;
}
int main(int argc, char** argv)
{
vector<int> myList = { 4, 1, 6, 2, 13 };
PrintList(myList);
sort(myList.begin(), myList.end(), [](int x, int y) -> bool { return x < y; });
PrintList(myList);
sort(myList.begin(), myList.end(), [](int x, int y) -> bool { return x > y; });
PrintList(myList);
}
Owner

Compiled as follows with GCC 4.6.1 ib Ubuntu 11.10

g++ -Wall -Werror -std=c++0x -o lambda_sort lambda_sort.cpp

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