I'm exploring the ranges functions.
struct User
{
std::string name;
int age;
std::string gender;
template<class Os> friend
Os& operator<<(Os& os, User const& u)
{
return os << "\n" << std::right << std::setw(10)
<< u.name << " - " << u.age << ", " << u.gender;
}
};
std::vector<User> users = {
{"Dorothy", 59, "F"},
{"Allan", 60, "M"},
{"Kenny", 33, "M"},
{"Jaye", 30, "F"}
};
int main()
{
std::cout << "Count of M users: " <<
std::ranges::count_if(users, [](const User& u) {return u.gender == "M"; }) <<
std::endl;
const User match { "Ed", 44, "M" };
std::cout << "Count of Ed users: " <<
std::ranges::count(users, match) <<
std::endl;
}
The count_if functions as expected. The count expression generates an error in MSVS 2019.
Error C7602 'std::ranges::_Count_fn::operator ()': the associated constraints are not satisfied D:\Test\Code\Ranges\Ranges.cpp
and it points me to the std algorithm header. I'm clearly not understanding the indirect_binary_predicate that is the only constraint listed for the count function. Reading cppreference.com is...unhelpful :-).
What am I missing here?