Using mutable to allow modification of object in unordered_set
问题 Please consider the following code: #include <iostream> #include <unordered_set> struct MyStruct { int x, y; double mutable z; MyStruct(int x, int y) : x{ x }, y{ y }, z{ 0.0 } { } }; struct MyStructHash { inline size_t operator()(MyStruct const &s) const { size_t ret = s.x; ret *= 2654435761U; return ret ^ s.y; } }; struct MyStructEqual { inline bool operator()(MyStruct const &s1, MyStruct const &s2) const { return s1.x == s2.x && s1.y == s2.y; } }; int main() { std::unordered_set<MyStruct,