From 4b5b5a1ed50dc6af370896c08eedb4cb67955a21 Mon Sep 17 00:00:00 2001 From: Dmitry Kobets <89153909+dmitrykobets-msft@users.noreply.github.com> Date: Wed, 10 May 2023 11:25:04 -0700 Subject: [PATCH] Disable std::hash> if std::hash is not enabled. (#1109) Resolves #914 --- include/gsl/pointers | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/include/gsl/pointers b/include/gsl/pointers index 9c65a96..0759c53 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -215,14 +215,28 @@ not_null operator+(const not_null&, std::ptrdiff_t) = delete; template not_null operator+(std::ptrdiff_t, const not_null&) = delete; + +template ().get()), bool = std::is_default_constructible>::value> +struct not_null_hash +{ + std::size_t operator()(const T& value) const { return std::hash{}(value.get()); } +}; + +template +struct not_null_hash +{ + not_null_hash() = delete; + not_null_hash(const not_null_hash&) = delete; + not_null_hash& operator=(const not_null_hash&) = delete; +}; + } // namespace gsl namespace std { template -struct hash> +struct hash> : gsl::not_null_hash> { - std::size_t operator()(const gsl::not_null& value) const { return hash{}(value.get()); } }; } // namespace std @@ -323,12 +337,8 @@ strict_not_null(T) -> strict_not_null; namespace std { template -struct hash> +struct hash> : gsl::not_null_hash> { - std::size_t operator()(const gsl::strict_not_null& value) const - { - return hash{}(value.get()); - } }; } // namespace std