summaryrefslogtreecommitdiff
path: root/absl/meta
diff options
context:
space:
mode:
Diffstat (limited to 'absl/meta')
-rw-r--r--absl/meta/type_traits.h36
1 files changed, 19 insertions, 17 deletions
diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h
index b1b14914..fbdc921f 100644
--- a/absl/meta/type_traits.h
+++ b/absl/meta/type_traits.h
@@ -483,16 +483,17 @@ inline void AssertHashEnabled() {
} // namespace type_traits_internal
-} // namespace absl
-
// An internal namespace that is required to implement the C++17 swap traits.
-//
-// NOTE: This is its own top-level namespace to avoid subtleties due to
-// functions named "swap" that may appear in the absl namespace.
-namespace absl_internal_swap {
+// It is not further nested in type_traits_internal to avoid long symbol names.
+namespace swap_internal {
+// Necessary for the traits.
using std::swap;
+// This declaration prevents global `swap` and `absl::swap` overloads from being
+// considered unless ADL picks them up.
+void swap();
+
template <class T>
using IsSwappableImpl = decltype(swap(std::declval<T&>(), std::declval<T&>()));
@@ -520,22 +521,13 @@ struct IsNothrowSwappable
// Swap()
//
-// Performs the swap idiom from a namespace with no additional `swap` overloads.
+// Performs the swap idiom from a namespace where valid candidates may only be
+// found in `std` or via ADL.
template <class T, absl::enable_if_t<IsSwappable<T>::value, int> = 0>
void Swap(T& lhs, T& rhs) noexcept(IsNothrowSwappable<T>::value) {
swap(lhs, rhs);
}
-} // namespace absl_internal_swap
-
-namespace absl {
-namespace type_traits_internal {
-
-// Make the swap-related traits/function accessible from this namespace.
-using absl_internal_swap::IsNothrowSwappable;
-using absl_internal_swap::IsSwappable;
-using absl_internal_swap::Swap;
-
// StdSwapIsUnconstrained
//
// Some standard library implementations are broken in that they do not
@@ -543,6 +535,16 @@ using absl_internal_swap::Swap;
// one of those implementations.
using StdSwapIsUnconstrained = IsSwappable<void()>;
+} // namespace swap_internal
+
+namespace type_traits_internal {
+
+// Make the swap-related traits/function accessible from this namespace.
+using swap_internal::IsNothrowSwappable;
+using swap_internal::IsSwappable;
+using swap_internal::Swap;
+using swap_internal::StdSwapIsUnconstrained;
+
} // namespace type_traits_internal
} // namespace absl