#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));
}
這個程序編譯失敗(GCC 4.4):測試用的std :: equal_to特定結構的數據成員等
error: no match for call to ‘(std::equal_to<blah>) (blah&, std::_Mem_fn<int blah::*>&)’
除了編碼環路自己,有什麼檢查的正確方法基於數據成員的等價性?
你想一般檢查的'blah's平等或者你只是想檢查一個平等的成員?如果前者爲'struct'實現'operator =='。 – 2012-02-29 09:32:15
我正在查看特定數據成員。 – 2012-02-29 12:13:56