#include <algorithm>
#include <functional>
#include <vector>
struct blah {
int member;
};
int main (int argc, const char* argv[])
{
blah a = { 1 };
auto are_same = std::bind(
std::equal_to<blah>(),
a,
std::mem_fn(&blah::member) // Obviously not a function, but I tried.
);
std::vector<blah> blahs = { {0}, {1}, {2} };
return static_cast<int>(std::any_of(blahs.begin(), blahs.end(), are_same));
}
This program fails to compile (GCC 4.4):
error: no match for call to ‘(std::equal_to<blah>) (blah&, std::_Mem_fn<int blah::*>&)’
Aside from coding the loop myself, what’s the correct way to check for equivalence based on a data member?
If you’re already using C++11, why not use a lambda?
If you can’t use lambdas, you can use bind to do function composition: