#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHN0cmluZz4KCnN0cnVjdCBBcHBvaW50bWVudAp7CiAgICBBcHBvaW50bWVudChjb25zdCBzdGQ6OnN0cmluZyYgYV9uYW1lLAogICAgICAgICAgICAgICAgY29uc3Qgc3RkOjpzdHJpbmcmIGFfbG9jYXRpb24pIDogbmFtZShhX25hbWUpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbG9jYXRpb24oYV9sb2NhdGlvbikge30KICAgIHN0ZDo6c3RyaW5nIG5hbWU7CiAgICBzdGQ6OnN0cmluZyBsb2NhdGlvbjsKfTsKCmludCBtYWluKCkKewogICAgc3RkOjp2ZWN0b3I8QXBwb2ludG1lbnQ+IGFwcG9pbnRtZW50czsKICAgIGFwcG9pbnRtZW50cy5wdXNoX2JhY2soQXBwb2ludG1lbnQoImZyZWQiLCAiYmVsZmFzdCIpKTsKICAgIGFwcG9pbnRtZW50cy5wdXNoX2JhY2soQXBwb2ludG1lbnQoIml2b3IiLCAibG9uZG9uIikpOwoKICAgIC8vIFNlYXJjaCBieSBuYW1lLgogICAgLy8KICAgIGNvbnN0IHN0ZDo6c3RyaW5nIG5hbWVfdG9fZmluZCA9ICJpdm9yIjsKICAgIGF1dG8gaSA9IHN0ZDo6ZmluZF9pZihhcHBvaW50bWVudHMuYmVnaW4oKSwKICAgICAgICAgICAgICAgICAgICAgICAgICBhcHBvaW50bWVudHMuZW5kKCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgWyZdKGNvbnN0IEFwcG9pbnRtZW50JiBhX2FwcCkKICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBuYW1lX3RvX2ZpbmQgPT0gYV9hcHAubmFtZTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgIGlmIChpICE9IGFwcG9pbnRtZW50cy5lbmQoKSkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgaS0+bmFtZSA8PCAiLCAiIDw8IGktPmxvY2F0aW9uIDw8ICJcbiI7CiAgICB9CgogICAgLy8gU2VhcmNoIGJ5IGxvY2F0aW9uLgogICAgLy8KICAgIGNvbnN0IHN0ZDo6c3RyaW5nIGxvY2F0aW9uX3RvX2ZpbmQgPSAiYmVsZmFzdCI7CiAgICBpID0gc3RkOjpmaW5kX2lmKGFwcG9pbnRtZW50cy5iZWdpbigpLAogICAgICAgICAgICAgICAgICAgICBhcHBvaW50bWVudHMuZW5kKCksCiAgICAgICAgICAgICAgICAgICAgIFsmXShjb25zdCBBcHBvaW50bWVudCYgYV9hcHApCiAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBsb2NhdGlvbl90b19maW5kID09IGFfYXBwLmxvY2F0aW9uOwogICAgICAgICAgICAgICAgICAgICB9KTsKICAgIGlmIChpICE9IGFwcG9pbnRtZW50cy5lbmQoKSkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgaS0+bmFtZSA8PCAiLCAiIDw8IGktPmxvY2F0aW9uIDw8ICJcbiI7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=