I have a container of objects. I need to implement search by multiple parameters (i.e. users can choose different parameters, and i need to find all objects with those parameters).
Suppose we have a container std::vector<Person> v
in which objects with fields are stored: [name, age, profession].
["Lucy", 18, "None"],
["Alex", 25, "Teacher"],
["Lucy", 18, "Student"],
["Lucy", 25, "None"],
["Sofia", 25, "None"].
For example, User needs all the people named Lucy. He gets the result:
["Lucy", 18, "None"],
["Lucy", 18, "Student"],
["Lucy", 25, "None"].
Now users wants to find people with the name Lucy at the age of 18. He will get the result:
["Lucy", 18, "None"],
["Lucy", 18, "Student"].
Now he needs people without a profession at the age of 25.
["Lucy", 25, "None"],
["Sofia", 25, "None"].
The choice of fields by which the search will take place depends on the user's choice! He can choose parameters of search in GUI.
I suppose I need some comparator, but have no idea how it should look like.
template<typename _Comp>
struct Person
{
std::string name;
int age;
std::string profession;
};