Boost Unordered_Set Compile Error with Is_Always_Equal: Solution and Example
If you're encountering a compilation error with 'boost::unordered_set' and 'is_always_equal', it's likely due to 'is_always_equal' not being a supported type for 'boost::unordered_set'.
'is_always_equal' is a type trait provided by the C++ standard library to determine if a hash function object is always equal to another hash function object. However, 'boost::unordered_set' requires the hash function object to be copy constructible and assignable, which 'is_always_equal' is not.
To resolve the compilation error, use a hash function object that meets the requirements of 'boost::unordered_set'. You can either create your own hash function object or use one of the predefined ones provided by Boost, such as 'boost::hash'.
Here's an example using 'boost::hash' with 'boost::unordered_set':
#include <boost/unordered_set.hpp>
#include <boost/functional/hash.hpp>
int main() {
boost::unordered_set<int, boost::hash<int>> mySet;
mySet.insert(1);
mySet.insert(2);
mySet.insert(3);
for (const auto& element : mySet) {
std::cout << element << ' ';
}
return 0;
}
In this example, 'boost::hash
原文地址: https://www.cveoy.top/t/topic/qvfI 著作权归作者所有。请勿转载和采集!