Skip to content

Commit

Permalink
In HashState::Create, require that T is a subclass of HashStateBase i…
Browse files Browse the repository at this point in the history
…n order to discourage users from defining their own HashState types.

PiperOrigin-RevId: 712577158
Change-Id: Iae6d23d03f291b18104f3c6d5a5b17e0af7f222a
  • Loading branch information
ezbr authored and copybara-github committed Jan 6, 2025
1 parent 3ee08f3 commit 506f107
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions absl/hash/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@

#include <cstddef>
#include <tuple>
#include <type_traits>
#include <utility>

#include "absl/base/config.h"
#include "absl/functional/function_ref.h"
#include "absl/hash/internal/hash.h"
#include "absl/meta/type_traits.h"

namespace absl {
ABSL_NAMESPACE_BEGIN
Expand Down Expand Up @@ -321,8 +323,12 @@ class HashState : public hash_internal::HashStateBase<HashState> {
// Create a new `HashState` instance that wraps `state`. All calls to
// `combine()` and `combine_contiguous()` on the new instance will be
// redirected to the original `state` object. The `state` object must outlive
// the `HashState` instance.
template <typename T>
// the `HashState` instance. `T` must be a subclass of `HashStateBase<T>` -
// users should not define their own HashState types.
template <
typename T,
absl::enable_if_t<
std::is_base_of<hash_internal::HashStateBase<T>, T>::value, int> = 0>
static HashState Create(T* state) {
HashState s;
s.Init(state);
Expand Down

0 comments on commit 506f107

Please sign in to comment.