Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ set(files
__type_traits/is_trivially_relocatable.h
__type_traits/is_unbounded_array.h
__type_traits/is_union.h
__type_traits/is_unqualified.h
__type_traits/is_unsigned.h
__type_traits/is_valid_expansion.h
__type_traits/is_void.h
Expand Down
14 changes: 10 additions & 4 deletions libcxx/include/__functional/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <__type_traits/is_enum.h>
#include <__type_traits/is_floating_point.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/is_unqualified.h>
#include <__type_traits/underlying_type.h>
#include <__utility/pair.h>
#include <__utility/swap.h>
Expand Down Expand Up @@ -355,25 +356,30 @@ struct __hash_impl {
};

template <class _Tp>
struct __hash_impl<_Tp, __enable_if_t<is_enum<_Tp>::value> > : __unary_function<_Tp, size_t> {
struct __hash_impl<_Tp, __enable_if_t<is_enum<_Tp>::value && __is_unqualified_v<_Tp> > >
: __unary_function<_Tp, size_t> {
_LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT {
using type = __underlying_type_t<_Tp>;
return hash<type>()(static_cast<type>(__v));
}
};

template <class _Tp>
struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) <= sizeof(size_t))> >
struct __hash_impl<
_Tp,
__enable_if_t<is_integral<_Tp>::value && __is_unqualified_v<_Tp> && (sizeof(_Tp) <= sizeof(size_t))> >
: __unary_function<_Tp, size_t> {
_LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
};

template <class _Tp>
struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) > sizeof(size_t))> >
struct __hash_impl<_Tp,
__enable_if_t<is_integral<_Tp>::value && __is_unqualified_v<_Tp> && (sizeof(_Tp) > sizeof(size_t))> >
: __scalar_hash<_Tp> {};

template <class _Tp>
struct __hash_impl<_Tp, __enable_if_t<is_floating_point<_Tp>::value> > : __scalar_hash<_Tp> {
struct __hash_impl<_Tp, __enable_if_t<is_floating_point<_Tp>::value && __is_unqualified_v<_Tp> > >
: __scalar_hash<_Tp> {
_LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT {
// -0.0 and 0.0 should return same hash
if (__v == 0.0f)
Expand Down
25 changes: 25 additions & 0 deletions libcxx/include/__type_traits/is_unqualified.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___TYPE_TRAITS_IS_UNQUALIFIED_H
#define _LIBCPP___TYPE_TRAITS_IS_UNQUALIFIED_H

#include <__config>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Tp>
inline const bool __is_unqualified_v = __is_same(_Tp, __remove_cvref(_Tp));

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___TYPE_TRAITS_IS_UNQUALIFIED_H
1 change: 1 addition & 0 deletions libcxx/include/module.modulemap.in
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ module std_core [system] {
header "__type_traits/is_union.h"
export std_core.type_traits.integral_constant
}
module is_unqualified { header "__type_traits/is_unqualified.h" }
module is_unsigned {
header "__type_traits/is_unsigned.h"
export std_core.type_traits.integral_constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

#include "test_macros.h"

#if TEST_STD_VER >= 11
# include "poisoned_hash_helper.h"
#endif

enum class Colors { red, orange, yellow, green, blue, indigo, violet };
enum class Cardinals { zero, one, two, three, five=5 };
enum class LongColors : short { red, orange, yellow, green, blue, indigo, violet };
Expand All @@ -33,6 +37,12 @@ template <class T>
void
test()
{
#if TEST_STD_VER >= 11
test_hash_disabled<const T>();
test_hash_disabled<volatile T>();
test_hash_disabled<const volatile T>();
#endif

typedef std::hash<T> H;
#if TEST_STD_VER <= 17
static_assert((std::is_same<typename H::argument_type, T>::value), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@

#include "test_macros.h"

#if TEST_STD_VER >= 11
# include "poisoned_hash_helper.h"
#endif

template <class T>
void
test()
{
#if TEST_STD_VER >= 11
test_hash_disabled<const T>();
test_hash_disabled<volatile T>();
test_hash_disabled<const volatile T>();
#endif

typedef std::hash<T> H;
#if TEST_STD_VER <= 17
static_assert((std::is_same<typename H::argument_type, T>::value), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@

#include "test_macros.h"

#if TEST_STD_VER >= 11
# include "poisoned_hash_helper.h"
#endif

template <class T>
void
test()
{
#if TEST_STD_VER >= 11
test_hash_disabled<const T>();
test_hash_disabled<volatile T>();
test_hash_disabled<const volatile T>();
#endif

typedef std::hash<T> H;
#if TEST_STD_VER <= 17
static_assert((std::is_same<typename H::argument_type, T>::value), "");
Expand Down
Loading