[Nie jestem pewny mojej odpowiedzi, dopiero co wróciłem z wakacji :v]
W C++11 w nagłówku <functional> pojawił się szablon klasy std::hash. Klasa ta posiada przeładowany operator wywołania funkcji, czyli tworząc obiekt tej klasy, możesz z nich korzystać jak ze zwykłych funkcji. Jakiś przykładzik:
#include <iostream>
#include <string>
#include <functional>
int main() {
std::hash<std::string> string_hash;
std::hash<int> int_hash;
std::string text = "Hello World";
int magic = 42;
std::cout << "String: " << string_hash(text) << std::endl
<< "Int: " << int_hash(magic) << std::endl;
}
http://en.cppreference.com/w/cpp/utility/hash
EDIT: masz jeszcze przykład jak zrobić funkcję haszującą dla zdefiniowanego typu:
#include <iostream>
#include <string>
#include <functional>
struct sexy_char {
char me;
int format;
int size;
};
namespace std {
template<> struct hash<::sexy_char> {
typedef ::sexy_char argument_type;
typedef size_t result_type;
result_type operator()(const argument_type& sc) {
return ~(((sc.me << 2) & sc.size) | sc.format);
}
};
}
int main() {
sexy_char so_sexy = {'c', 18, 12};
std::cout << "Sexy char: " << std::hash<sexy_char>()(so_sexy) << std::endl;
}