I have a vector std::vector<std::pair<int, bool>> vec
and I would like to know how many elemnts have the boolean set to true. The following code works:
std::count_if(vec.begin(), vec.end(), [](const auto& x) { return std::get<bool>(x); });
However, it bothers me that I'm creating a lambda that does nothing more than call another function with the exact same parameter. I expected that I would be able to write:
std::count_if(vec.begin(), vec.end(), std::get<bool>);
But I get a message that the compiler cannot resolve the _Predicate
template. I understand this to be because the compiler cannot resolve the highly overloaded std::get
function in this context. Is there a way to specify the correct version of std::get
beyond wrapping it inside the lambda?