#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

struct Person
{
    std::string firstName;
    std::string lastName;
    int age;

    bool operator<(const Person &other) const
    {
        return std::tie(lastName, firstName, age)
            < std::tie(other.lastName, other.firstName, other.age);
    }
};

void print(const std::string& title, const std::vector<Person> &people)
{
    std::cout << title << "\n";
    for (const Person &person : people)
    {
        std::cout << person.lastName << ", " 
            << person.firstName << ", " 
            << person.age << "\n";
    }
}

int main()
{
    std::vector<Person> people {
        { "Bill", "Gates", 44 },
        { "Gates", "Bill", 44 },
        { "Back", "Gates", 43 },
        { "Front", "Gates", 44 },
        { "Bill", "Gates", 43 },
        { "Gates", "Bill", 43 },
        { "Back", "Gates", 44 },
        { "Front", "Gates", 43 },
    };

    print("Before Sort:", people);
    std::sort(people.begin(), people.end());
    print("After Sort:", people);

    return 0;
}