jeudi 29 octobre 2015

Hashing own String type with C++11

So I am trying to compile some codebase with clang (with libc++), but I keep finding uses of internal functions from libstdc++. Does anyone know some good method using standard library or boost/etc to hash custom string? Of course I could make std::string from it, but I don't use special string to make additional copies.

namespace std
{

template<>
struct hash<ct::String> : public __hash_base<size_t, ct::String>
{
    size_t operator()(const ct::String& __s) const noexcept
    { 
        return std::_Hash_impl::hash(__s.begin(), __s.end() - __s.begin()); 
    }
};

template<>
struct __is_fast_hash<hash<ct::String>> : std::false_type
{ };

}

Aucun commentaire:

Enregistrer un commentaire