I am trying to make one of my classes hash-able and saw this: How to specialize std::hash<Key>::operator() for user-defined type in unordered containers?
namespace std {
template <> struct hash<Foo>
{
size_t operator()(const Foo & x) const
{
/* your code here, e.g. "return hash<int>()(x.value);" */
}
};
}
With the above code, everything works fine. But I am trying to understand the mechanism better.
Why do we have to add an extra pair of parentheses in the middle of hash<int>()(...)
? It looks ugly. Why can't we design it so that it is just hash<int>(...)
?