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

struct Appointment
{
    Appointment(const std::string& a_name,
                const std::string& a_location) : name(a_name),
                                                 location(a_location) {}
    std::string name;
    std::string location;
};

int main()
{
    std::vector<Appointment> appointments;
    appointments.push_back(Appointment("fred", "belfast"));
    appointments.push_back(Appointment("ivor", "london"));

    // Search by name.
    //
    const std::string name_to_find = "ivor";
    auto i = std::find_if(appointments.begin(),
                          appointments.end(),
                          [&](const Appointment& a_app)
                          {
                              return name_to_find == a_app.name;
                          });
    if (i != appointments.end())
    {
        std::cout << i->name << ", " << i->location << "\n";
    }

    // Search by location.
    //
    const std::string location_to_find = "belfast";
    i = std::find_if(appointments.begin(),
                     appointments.end(),
                     [&](const Appointment& a_app)
                     {
                         return location_to_find == a_app.location;
                     });
    if (i != appointments.end())
    {
        std::cout << i->name << ", " << i->location << "\n";
    }
    return 0;
}
