On Sun, Dec 9, 2012 at 3:37 PM, Scott Smedley <scott@smedleyfamily.net> wrote:

Hi all,

How can I implement a hash function for a __uint128_t type that is compatible with Boost?

I tried this:

#include <boost/functional/hash.hpp>
#include <unordered_set>

#ifdef USE_64
typedef uint64_t MyId; // works fine
#else
typedef __uint128_t MyId;
#endif

inline std::size_t hash_value (const MyId &x)
{
    // not a very good hash function, but I just want to get it working first!
    return static_cast<std::size_t>(x);
}

int main (int argc, char *argv[])
{
    std::unordered_set<MyId, boost::hash<MyId>> s;
    s.insert(42);
}
but I get 144 lines of errors (!) using g++-4.7.2 with Boost v1.51.0 on 64-bit Scientific Linux 6.2:
error: no matching function for call to 'hash_value(const __int128 unsigned&)'
Any pointers/help would be muchly appreciated.
Scott. :)

Try rearranging and putting the hash inclusion after your custom definition of hash_value? I'm guessing since your custom hash_value isn't findable by ADL, you'd need it declared prior to its use with hash.hpp...?

- Jeff