[libcxx-commits] [libcxx] d87f159 - [libcxx][NFC] removes `swap`'s dependency on `swap_ranges`
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 24 11:02:28 PDT 2021
Author: Christopher Di Bella
Date: 2021-06-24T17:57:29Z
New Revision: d87f159ab675153ef58eae138d6ca223c45f14c8
URL: https://github.com/llvm/llvm-project/commit/d87f159ab675153ef58eae138d6ca223c45f14c8
DIFF: https://github.com/llvm/llvm-project/commit/d87f159ab675153ef58eae138d6ca223c45f14c8.diff
LOG: [libcxx][NFC] removes `swap`'s dependency on `swap_ranges`
Under the as-if rule, we can directly implement the array overload for
`std::swap`. By removing this circular dependency where `swap` is
implemented in terms of `swap_ranges` and `swap_ranges` is defined in
terms of `swap`, we can split them into their own headers. This will:
* limit the surface area in which Hyrum's law can bite us;
* force users to include the correct headers;
* make finding the definitions trivial (`swap` is a utility;
`swap_ranges` is an algorithm).
Differential Revision: https://reviews.llvm.org/D104760
Added:
Modified:
libcxx/include/type_traits
Removed:
################################################################################
diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index 259354996562..f257fa3ee05b 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -4190,11 +4190,6 @@ template <class _Tp> struct __is_nothrow_swappable;
// swap, swap_ranges
-template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_ForwardIterator2
-swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2);
-
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
using __swap_result_t = typename enable_if<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>::type;
@@ -4221,7 +4216,9 @@ typename enable_if<
>::type
swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
{
- _VSTD::swap_ranges(__a, __a + _Np, __b);
+ for (size_t __i = 0; __i != _Np; ++__i) {
+ swap(__a[__i], __b[__i]);
+ }
}
template <class _ForwardIterator1, class _ForwardIterator2>
More information about the libcxx-commits
mailing list