Make AddConstRefIfExpensive work with void PiperOrigin-RevId: 1008245917
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index 8f07678..9a025f7 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h
@@ -2408,9 +2408,9 @@ // callers that may be passing incomplete types. template <class T> struct AddConstRefIfExpensive - : std::conditional< - type_traits_internal::ShouldPreferPassByValueOverRRef<T>::value, T, - const T&> { + : std::conditional_t< + type_traits_internal::ShouldPreferPassByValueOverRRef<T>::value, + type_identity<T>, std::add_lvalue_reference<std::add_const_t<T>>> { static_assert(std::is_same_v<remove_cvref_t<T>, T>, "passed types must be unqualified"); };
diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h index 51dfb27..397e917 100644 --- a/absl/meta/type_traits.h +++ b/absl/meta/type_traits.h
@@ -35,6 +35,8 @@ #ifndef ABSL_META_TYPE_TRAITS_H_ #define ABSL_META_TYPE_TRAITS_H_ +#include <limits.h> + #include <array> #include <cstddef> #include <functional> @@ -645,20 +647,15 @@ alignof(T) * 2 >= sizeof(T) && sizeof(T) <= sizeof(std::pair<void*, size_t>)>; -template <class T> -using ShouldSemanticallyPreferPassByValue = - std::bool_constant<std::is_trivially_move_constructible_v<T> && - std::is_trivially_destructible_v<T>>; - // Checks the given type to see if it is a good candidate for accepting by value // instead of by rvalue-reference. This includes both a semantic constraint // (to ensure correctness), as well as a structural constraint (to ensure // performance). template <class T> -using ShouldPreferPassByValueOverRRef = - std::bool_constant<ShouldSemanticallyPreferPassByValue<T>::value && - ShouldStructurallyPreferPassByValue<std::conditional_t< - std::is_void_v<T>, char, T>>::value>; +using ShouldPreferPassByValueOverRRef = ShouldStructurallyPreferPassByValue< + std::conditional_t<std::is_trivially_move_constructible_v<T> && + std::is_trivially_destructible_v<T>, + T, char[SHRT_MAX]>>; } // namespace type_traits_internal