I've got a vector with objects of a custom data type. One of the fields of this data type is an enum. I want to make sure that for all enum values at least one entry is added to the vector.
I want to use std::find_if to check if the vector has an entry for a certain enum value. But I'm not sure how to write & use the lambda correctly. Here's what I got:
struct CustomType
{
EnumType type {EnumType::DEFAULT};
int x;
};
std::vector<CustomType> tmp;
// fetch values from database and add them to the vector
// for some EnumType values there might not be a record added to the vector
auto hasEnumType = [](const CustomType& customType, const EnumType& enumType) -> bool
{
return (customType.type == enumType);
};
// What do I replace '?' with to get the current position
if (std::find_if(tmp.begin(), tmp.end(), hasEnumType(?, EnumType::VALUE1)) != tmp.end())
{
//add CustomType with VALUE1 to vector
}
Aucun commentaire:
Enregistrer un commentaire