#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
struct my_struct
{
std::string first_name;
std::string last_name;
};
struct CompareFirstName
{
explicit CompareFirstName(const std::string& s) : first_name(s) {}
bool operator () (const my_struct& person) const
{
return person.first_name == first_name;
}
std::string first_name;
};
int main()
{
std::vector<my_struct> my_vector(5);
my_vector[0].first_name = "David";
my_vector[0].last_name = "Andriw";
my_vector[1].first_name = "Jhon";
my_vector[1].last_name = "Monta";
my_vector[2].first_name = "Jams";
my_vector[2].last_name = "Ruth";
my_vector[3].first_name = "David";
my_vector[3].last_name = "AAA";
my_vector[4].first_name = "Jhon";
my_vector[4].last_name = "BBB";
for(int i = 0; i < my_vector.size(); i++)
{
int my_count = std::count_if(my_vector.begin(), my_vector.end(),
CompareFirstName(my_vector[i].first_name));
std::cout << "First_Name: " << my_vector[i].first_name << "\tCOUNT: " << my_count << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgoKc3RydWN0IG15X3N0cnVjdAp7CiAgICBzdGQ6OnN0cmluZyBmaXJzdF9uYW1lOwogICAgc3RkOjpzdHJpbmcgbGFzdF9uYW1lOwp9OwoKc3RydWN0IENvbXBhcmVGaXJzdE5hbWUKewogICAgZXhwbGljaXQgQ29tcGFyZUZpcnN0TmFtZShjb25zdCBzdGQ6OnN0cmluZyYgcykgOiBmaXJzdF9uYW1lKHMpIHt9CgogICAgYm9vbCBvcGVyYXRvciAoKSAoY29uc3QgbXlfc3RydWN0JiBwZXJzb24pIGNvbnN0CiAgICB7CiAgICAgICAgcmV0dXJuIHBlcnNvbi5maXJzdF9uYW1lID09IGZpcnN0X25hbWU7CiAgICB9CgogICAgc3RkOjpzdHJpbmcgZmlyc3RfbmFtZTsKfTsKCmludCBtYWluKCkKewogIHN0ZDo6dmVjdG9yPG15X3N0cnVjdD4gbXlfdmVjdG9yKDUpOw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