[tuple][hash] Hashing a tuple question

Hello, I'm looking for advice on hashing the tuples. For my task it seems to be enough to just take every element from the tuple and apply boost::hash_combine to each of the elements. However I am currently thinking of a clever way of writing it in a generic form. Has anyone done something like that and could give some hints? Cheers, Milosz

AMDG Milosz Marian Hulboj wrote:
I'm looking for advice on hashing the tuples. For my task it seems to be enough to just take every element from the tuple and apply boost::hash_combine to each of the elements. However I am currently thinking of a clever way of writing it in a generic form. Has anyone done something like that and could give some hints?
#include <iostream> #include <cstddef> #include <boost/fusion/algorithm/iteration/fold.hpp> #include <boost/fusion/adapted/boost_tuple.hpp> #include <boost/functional/hash.hpp> struct hash_combine { typedef std::size_t result_type; template<class T> std::size_t operator()(const T& arg, std::size_t current) { boost::hash_combine(current, arg); return(current); } }; int main() { boost::tuple<int, char, std::string> t1(2, 'x', "a string"); std::size_t hash = boost::fusion::fold(t1, 0, hash_combine()); std::cout << hash << std::endl; } In Christ, Steven Watanabe
participants (2)
-
Milosz Marian Hulboj
-
Steven Watanabe