mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Disable std::hash<gsl::not_null<T>> if std::hash<T> is not enabled. (#1109)
Resolves #914
This commit is contained in:
parent
5dc7fae119
commit
4b5b5a1ed5
@ -215,14 +215,28 @@ not_null<T> operator+(const not_null<T>&, std::ptrdiff_t) = delete;
|
|||||||
template <class T>
|
template <class T>
|
||||||
not_null<T> operator+(std::ptrdiff_t, const not_null<T>&) = delete;
|
not_null<T> operator+(std::ptrdiff_t, const not_null<T>&) = delete;
|
||||||
|
|
||||||
|
|
||||||
|
template <class T, class U = decltype(std::declval<const T&>().get()), bool = std::is_default_constructible<std::hash<U>>::value>
|
||||||
|
struct not_null_hash
|
||||||
|
{
|
||||||
|
std::size_t operator()(const T& value) const { return std::hash<U>{}(value.get()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class U>
|
||||||
|
struct not_null_hash<T, U, false>
|
||||||
|
{
|
||||||
|
not_null_hash() = delete;
|
||||||
|
not_null_hash(const not_null_hash&) = delete;
|
||||||
|
not_null_hash& operator=(const not_null_hash&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace gsl
|
} // namespace gsl
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
template <class T>
|
template <class T>
|
||||||
struct hash<gsl::not_null<T>>
|
struct hash<gsl::not_null<T>> : gsl::not_null_hash<gsl::not_null<T>>
|
||||||
{
|
{
|
||||||
std::size_t operator()(const gsl::not_null<T>& value) const { return hash<T>{}(value.get()); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace std
|
} // namespace std
|
||||||
@ -323,12 +337,8 @@ strict_not_null(T) -> strict_not_null<T>;
|
|||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
template <class T>
|
template <class T>
|
||||||
struct hash<gsl::strict_not_null<T>>
|
struct hash<gsl::strict_not_null<T>> : gsl::not_null_hash<gsl::strict_not_null<T>>
|
||||||
{
|
{
|
||||||
std::size_t operator()(const gsl::strict_not_null<T>& value) const
|
|
||||||
{
|
|
||||||
return hash<T>{}(value.get());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
Loading…
Reference in New Issue
Block a user