[#absl-HashState] = xref:absl.adoc[absl]::HashState :relfileprefix: ../ :mrdocs: A type‐erased version of the hash state concept. == Synopsis Declared in `<absl/hash/hash.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- 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 [cols="1,4"] |=== | Name| Description | `hash_internal::HashStateBase<HashState>` | |=== == Type Aliases [cols="1"] |=== | Name | xref:absl/HashState/AbslInternalPiecewiseCombiner.adoc[`AbslInternalPiecewiseCombiner`] | xref:absl/HashState/is_hashable.adoc[`is_hashable`] |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/HashState/2constructor-00.adoc[`HashState`] [.small]#[constructor]# | Constructors | xref:absl/HashState/operator_assign-07.adoc[`operator=`] | Assignment operators |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/HashState/Create.adoc[`Create`] | Create a new `HashState` instance that wraps `state`. | xref:absl/HashState/combine-0e0.adoc[`combine`] | | xref:absl/HashState/combine_contiguous-0a.adoc[`combine_contiguous`] | Combine a contiguous array of elements into a hash state. | xref:absl/HashState/combine_unordered.adoc[`combine_unordered`] | | xref:absl/HashState/combine_weakly_mixed_integer.adoc[`combine_weakly_mixed_integer`] | Combine a weakly‐mixed integer into a hash state. |=== == Using Declarations [cols="1,4"] |=== | Name| Description | xref:absl/HashState/combine-0e5.adoc[`combine`] | Combine an arbitrary number of values into a hash state. | xref:absl/HashState/combine_contiguous-0b.adoc[`combine_contiguous`] | Combine a contiguous range of elements into a hash state. |=== == Friends [cols="1,4"] |=== | Name| Description | `absl::hash_internal::CombineRaw` | | `absl::hash_internal::HashStateBase` | |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#