Standard library implements std::hash as a template struct that is specialized for different types. It is used like this:
#include
#include
int main()
{
std::hash hasher;
std::cout << hasher(1337) <<…
Can the C++11 std::hash type be used to hash function pointers? There is a hash partial specialization defined as
template struct hash;
but since function pointers are different from other pointer types in C++ (e.g. they can't be…
I'm trying to use QString as the key in a std::unordered_map, however I get the error:
error C2280: 'std::hash<_Kty>::hash(const std::hash<_Kty> &)': attempting to reference a deleted function
I can't switch to QHash because the value-type of the…
I know hashing infinite number of string into 32b int must generate collision, but I expect from hashing function some nice distribution.
Isn't it weird that these 2 strings have the same hash?
size_t hash0 =…
With a Regular Type, I mean the definition of Stepanov in Elements of Programming, basically, that there's the concept of equality and that objects which are copies of each other compare equal.
So when you have a Regular Type T, and the equality…
I thought it would have been, but I can't find this in my standard library implementation (gcc-4.8.2).
Why is std::hash not already specialised for std::reference_wrapper?
#pragma once
#include
namespace std
{
template
Why doesn't the C++ standard specify that std::hash is specialized for char*, const char*, unsigned char*, const unsigned char*, etc? I.e., it would hash the contents of the C string until the terminating null is found.
Any harm in injecting my…
I'm guessing std::hash is defined as a template struct in order to avoid implicit type conversions done during overloaded function resolution. Is it a correct thing to say?
I mean, I would prefer to write
std::string s;
size_t hash =…
If I did std::hash using libstdc++ and then did one on the upcoming C++11 VS 2012 library - would they match?
I assume that hash implementations are not part of the C++ specification and can vary by distribution?
I have an abstract base class Hashable that classes that can be hashed derive from. I would now like to extend std::hash to all classes that derive from Hashable.
The following code is supposed to do exactly that.
#include
#include…
Is the floating point specialisation of std::hash (say, for doubles or floats) reliable regarding almost-equality? That is, if two values (such as (1./std::sqrt(5.)/std::sqrt(5.)) and .2) should compare equal but will not do so with the == operator,…
I have some random test parameters for which I need to calculate a hash to detect if I ran with same parameters. I might run the test using the same source recompiled at a different time or run on a different machine.
Even so I want to detect…
I can replace the actual implementation of std::hash with my own definition of std::hash in C++ 11 ?
I mean from my codebase, without touching the standard library.
I can't see any use for virtual function/polymorphism in this case, so I suppose…
I was trying to specialize hash for my own type, a templated key.
I was basing it off cppreference.
I get the compile error "The C++ Standard doesn't provide a hash for this type". I figure I just did it wrong. Could the compiler even support this…