I am trying to put an unordered_set<pair<int, int>> as a struct member, which requires a custom hash function. I don't want to overload std::hash<pair<int, int>>, so I tried the following:
test.hpp
#ifndef TEST_HPP
#define TEST_HPP
#include <unordered_set>
struct myStruct {
constexpr static auto pair_hash = [](const std::pair<int, int>& p) -> size_t {
return std::hash<int>{}(p.first) ^ (std::hash<int>{}(p.second) << 1);
};
std::unordered_set<std::pair<int, int>, decltype(pair_hash)> mySet;
};
#endif
test.cpp:
#include "test.hpp"
int main() {
myStruct s;
return 0;
}
This compiles and works, but gives the warning:
‘myStruct’ has a field ‘std::unordered_set<std::pair<int, int>, const myStruct::<lambda(const std::pair<int, int>&)> > myStruct::mySet’ whose type has internal linkage [-Wsubobject-linkage]
What is the problem, and how do I fix it?