In C++11, it is possible to get a hashed value for a string
variable as follows:
std::size_t h1 = std::hash<std::string>{}("Some_String");
It is clean and simple. However, I have two questions:
The curly braces are used to value-initialize an object of type std::hash<std::string>
. That object can then be called, since it has an overloaded operator()
. Alternatively, you could create a named object:
std::hash<std::string> H;
auto h1 = H("Some_String");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With