A type‐erased version of the hash state concept.
Synopsis
Declared in <absl/hash/hash.h>
class HashState
: public hash_internal::HashStateBase<HashState>
Description
A type erased version of the hash state concept, for use in user‐defined AbslHashValue implementations that can't use templates (such as PImpl classes, virtual functions, etc.). The type erasure adds overhead so it should be avoided unless necessary.
Note: This wrapper will only erase calls to combine_contiguous(H, const unsigned char*, size_t) RunCombineUnordered(H, CombinerF)
All other calls will be handled internally and will not invoke overloads provided by the wrapped class.
Users of this class should still define a template AbslHashValue function, but can use absl::HashState::Create(&state) to erase the type of the hash state and dispatch to their private hashing logic.
This state can be used like any other hash state. In particular, you can call HashState::combine() and HashState::combine_contiguous() on it.
Example:
class Interface { public: template <typename H> friend H AbslHashValue(H state, const Interface& value) { state = H::combine(std::move(state), std::type_index(typeid(*this))); value.HashValue(absl::HashState::Create(&state)); return state; } private: virtual void HashValue(absl::HashState state) const = 0; };
class Impl : Interface { private: void HashValue(absl::HashState state) const override { absl::HashState::combine(std::move(state), v1_, v2_); } int v1_; std::string v2_; };
Base Classes
Name |
Description |
|
Type Aliases
Member Functions
Name |
Description |
|
Constructors |
Assignment operators |
Static Member Functions
Name |
Description |
Create a new |
|
Combine a contiguous array of elements into a hash state. |
|
Combine a weakly‐mixed integer into a hash state. |
Using Declarations
Name |
Description |
Combine an arbitrary number of values into a hash state. |
|
Combine a contiguous range of elements into a hash state. |
Friends
Name |
Description |
|
|
|
Created with MrDocs