Standard library implements std::hash as a template struct that is specialized for different types. It is used like this:
#include <iostream>
#include <functional>
int main()
{
std::hash<int> hasher;
std::cout << hasher(1337) << std::endl;
return 0;
}
My question is what is the reasoning behind this design choice. Why it isn't implemented as a template function and used like this:
#include <iostream>
#include <functional>
int main()
{
std::cout << std::hash<int>(1337) << std::endl;
return 0;
}
std::hash<int>()(1337)
to use an unnamed temporary struct. – Laurielaurier