AAnonymous
#include <bits/stdc++.h>
class Person {
public:
explicit Person(int n) : number(n) {};
int getNumber() const { return number; };
private:
int number;
};
int main() {
std::list<Person *> personList;
auto printList = [&]() {
for (auto& person : personList)
std::cout << person->getNumber() << ", ";
std::cout << std::endl;
};
personList.emplace_back(new Person(1));
personList.emplace_back(new Person(5));
personList.emplace_back(new Person(9));
personList.emplace_back(new Person(3));
personList.emplace_back(new Person(7));
// order -> 1, 5, 9, 3, 7
printList();
// sorting
personList.sort([](const Person* a, const Person* b){
return a->getNumber() < b->getNumber();
});
// order -> 1, 3, 5, 7, 9
printList();
// release after exit
}