[libcxx-commits] [libcxx] 6adbc83 - [libcxx][modularisation] moves <utility> content out of <type_traits>

Christopher Di Bella via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 24 11:02:30 PDT 2021


Author: Christopher Di Bella
Date: 2021-06-24T17:57:29Z
New Revision: 6adbc83ee9e46b476e0f75d5671c3a21f675a936

URL: https://github.com/llvm/llvm-project/commit/6adbc83ee9e46b476e0f75d5671c3a21f675a936
DIFF: https://github.com/llvm/llvm-project/commit/6adbc83ee9e46b476e0f75d5671c3a21f675a936.diff

LOG: [libcxx][modularisation] moves <utility> content out of <type_traits>

Moves:

* `std::move`, `std::forward`, `std::declval`, and `std::swap` into
  `__utility/${FUNCTION_NAME}`.
* `std::swap_ranges` and `std::iter_swap` into
  `__algorithm/${FUNCTION_NAME}`

Differential Revision: https://reviews.llvm.org/D103734

Added: 
    libcxx/include/__algorithm/iter_swap.h
    libcxx/include/__algorithm/swap_ranges.h
    libcxx/include/__utility/__decay_copy.h
    libcxx/include/__utility/declval.h
    libcxx/include/__utility/forward.h
    libcxx/include/__utility/move.h
    libcxx/include/__utility/swap.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/__algorithm/inplace_merge.h
    libcxx/include/__algorithm/move.h
    libcxx/include/__algorithm/next_permutation.h
    libcxx/include/__algorithm/nth_element.h
    libcxx/include/__algorithm/partial_sort.h
    libcxx/include/__algorithm/partition.h
    libcxx/include/__algorithm/pop_heap.h
    libcxx/include/__algorithm/prev_permutation.h
    libcxx/include/__algorithm/push_heap.h
    libcxx/include/__algorithm/remove.h
    libcxx/include/__algorithm/reverse.h
    libcxx/include/__algorithm/rotate.h
    libcxx/include/__algorithm/shift_right.h
    libcxx/include/__algorithm/shuffle.h
    libcxx/include/__algorithm/sift_down.h
    libcxx/include/__algorithm/sort.h
    libcxx/include/__algorithm/stable_partition.h
    libcxx/include/__algorithm/stable_sort.h
    libcxx/include/__algorithm/unique.h
    libcxx/include/__iterator/concepts.h
    libcxx/include/__iterator/iter_move.h
    libcxx/include/__memory/allocator.h
    libcxx/include/__memory/allocator_traits.h
    libcxx/include/__memory/compressed_pair.h
    libcxx/include/__memory/construct_at.h
    libcxx/include/__memory/shared_ptr.h
    libcxx/include/__memory/unique_ptr.h
    libcxx/include/__ranges/access.h
    libcxx/include/__ranges/all.h
    libcxx/include/__ranges/data.h
    libcxx/include/__ranges/empty.h
    libcxx/include/__ranges/size.h
    libcxx/include/__split_buffer
    libcxx/include/__tree
    libcxx/include/algorithm
    libcxx/include/any
    libcxx/include/deque
    libcxx/include/exception
    libcxx/include/experimental/iterator
    libcxx/include/filesystem
    libcxx/include/forward_list
    libcxx/include/functional
    libcxx/include/future
    libcxx/include/istream
    libcxx/include/iterator
    libcxx/include/list
    libcxx/include/map
    libcxx/include/module.modulemap
    libcxx/include/mutex
    libcxx/include/queue
    libcxx/include/scoped_allocator
    libcxx/include/set
    libcxx/include/stack
    libcxx/include/thread
    libcxx/include/tuple
    libcxx/include/type_traits
    libcxx/include/unordered_map
    libcxx/include/unordered_set
    libcxx/include/utility
    libcxx/include/variant
    libcxx/include/vector
    libcxx/test/std/utilities/utility/forward/forward.fail.cpp
    libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp
    libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
    libcxx/test/support/poisoned_hash_helper.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 6773ec38289a4..faaf9325fad68 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -34,6 +34,7 @@ set(files
   __algorithm/is_permutation.h
   __algorithm/is_sorted.h
   __algorithm/is_sorted_until.h
+  __algorithm/iter_swap.h
   __algorithm/lexicographical_compare.h
   __algorithm/lower_bound.h
   __algorithm/make_heap.h
@@ -85,6 +86,7 @@ set(files
   __algorithm/sort_heap.h
   __algorithm/stable_partition.h
   __algorithm/stable_sort.h
+  __algorithm/swap_ranges.h
   __algorithm/transform.h
   __algorithm/unique_copy.h
   __algorithm/unique.h
@@ -157,6 +159,11 @@ set(files
   __tree
   __tuple
   __undef_macros
+  __utility/__decay_copy.h
+  __utility/declval.h
+  __utility/forward.h
+  __utility/move.h
+  __utility/swap.h
   __utility/to_underlying.h
   algorithm
   any

diff  --git a/libcxx/include/__algorithm/inplace_merge.h b/libcxx/include/__algorithm/inplace_merge.h
index 81db69244bf06..24ad36300fd04 100644
--- a/libcxx/include/__algorithm/inplace_merge.h
+++ b/libcxx/include/__algorithm/inplace_merge.h
@@ -17,6 +17,7 @@
 #include <__algorithm/min.h>
 #include <__algorithm/upper_bound.h>
 #include <__iterator/iterator_traits.h>
+#include <__utility/swap.h>
 #include <memory>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__algorithm/iter_swap.h b/libcxx/include/__algorithm/iter_swap.h
new file mode 100644
index 0000000000000..b63bce62cc0cf
--- /dev/null
+++ b/libcxx/include/__algorithm/iter_swap.h
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_ITER_SWAP_H
+#define _LIBCPP___ALGORITHM_ITER_SWAP_H
+
+#include <__config>
+#include <__utility/declval.h>
+#include <__utility/swap.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void iter_swap(_ForwardIterator1 __a,
+                                                                              _ForwardIterator2 __b)
+    //                                  _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
+    _NOEXCEPT_(_NOEXCEPT_(swap(*declval<_ForwardIterator1>(), *declval<_ForwardIterator2>()))) {
+  swap(*__a, *__b);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_ITER_SWAP_H

diff  --git a/libcxx/include/__algorithm/move.h b/libcxx/include/__algorithm/move.h
index 120f00f586df9..f5fc74854f05c 100644
--- a/libcxx/include/__algorithm/move.h
+++ b/libcxx/include/__algorithm/move.h
@@ -11,6 +11,7 @@
 
 #include <__config>
 #include <__algorithm/unwrap_iter.h>
+#include <__utility/move.h>
 #include <cstring>
 #include <utility>
 #include <type_traits>

diff  --git a/libcxx/include/__algorithm/next_permutation.h b/libcxx/include/__algorithm/next_permutation.h
index 91eef92544b99..a337e5efa0989 100644
--- a/libcxx/include/__algorithm/next_permutation.h
+++ b/libcxx/include/__algorithm/next_permutation.h
@@ -14,7 +14,7 @@
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/reverse.h>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#include <__utility/swap.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/nth_element.h b/libcxx/include/__algorithm/nth_element.h
index 622c669ba71ca..67a03cfc37b02 100644
--- a/libcxx/include/__algorithm/nth_element.h
+++ b/libcxx/include/__algorithm/nth_element.h
@@ -14,7 +14,7 @@
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/sort.h>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#include <__utility/swap.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/partial_sort.h b/libcxx/include/__algorithm/partial_sort.h
index 377f6d4351bc2..4f9872c4922b2 100644
--- a/libcxx/include/__algorithm/partial_sort.h
+++ b/libcxx/include/__algorithm/partial_sort.h
@@ -16,7 +16,7 @@
 #include <__algorithm/sift_down.h>
 #include <__algorithm/sort_heap.h>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#include <__utility/swap.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/partition.h b/libcxx/include/__algorithm/partition.h
index 9b6f37c4f2d09..c859eaca28a35 100644
--- a/libcxx/include/__algorithm/partition.h
+++ b/libcxx/include/__algorithm/partition.h
@@ -11,6 +11,8 @@
 
 #include <__config>
 #include <__iterator/iterator_traits.h>
+#include <__utility/swap.h>
+#include <utility> // pair
 #include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__algorithm/pop_heap.h b/libcxx/include/__algorithm/pop_heap.h
index 356a43333915b..7ebbef25e0ba1 100644
--- a/libcxx/include/__algorithm/pop_heap.h
+++ b/libcxx/include/__algorithm/pop_heap.h
@@ -14,7 +14,7 @@
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/sift_down.h>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#include <__utility/swap.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/prev_permutation.h b/libcxx/include/__algorithm/prev_permutation.h
index 24945b288b690..d6daa73ada000 100644
--- a/libcxx/include/__algorithm/prev_permutation.h
+++ b/libcxx/include/__algorithm/prev_permutation.h
@@ -14,7 +14,7 @@
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/reverse.h>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#include <__utility/swap.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/push_heap.h b/libcxx/include/__algorithm/push_heap.h
index c2ce07d7b0df7..82a7c123d834c 100644
--- a/libcxx/include/__algorithm/push_heap.h
+++ b/libcxx/include/__algorithm/push_heap.h
@@ -13,7 +13,7 @@
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/remove.h b/libcxx/include/__algorithm/remove.h
index f8a6f27ab2849..4717d7d973106 100644
--- a/libcxx/include/__algorithm/remove.h
+++ b/libcxx/include/__algorithm/remove.h
@@ -11,8 +11,8 @@
 
 #include <__config>
 #include <__algorithm/find.h>
-#include <utility>
-#include <type_traits>
+#include <__algorithm/find_if.h>
+#include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/reverse.h b/libcxx/include/__algorithm/reverse.h
index 210a3325717e2..e538de11472e8 100644
--- a/libcxx/include/__algorithm/reverse.h
+++ b/libcxx/include/__algorithm/reverse.h
@@ -10,8 +10,8 @@
 #define _LIBCPP___ALGORITHM_REVERSE_H
 
 #include <__config>
+#include <__algorithm/iter_swap.h>
 #include <__iterator/iterator_traits.h>
-#include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/rotate.h b/libcxx/include/__algorithm/rotate.h
index 812e40091827c..0c9ccd7bf7b09 100644
--- a/libcxx/include/__algorithm/rotate.h
+++ b/libcxx/include/__algorithm/rotate.h
@@ -11,11 +11,13 @@
 
 #include <__algorithm/move.h>
 #include <__algorithm/move_backward.h>
+#include <__algorithm/swap_ranges.h>
 #include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/next.h>
 #include <__iterator/prev.h>
-#include <type_traits>
+#include <__utility/swap.h>
+#include <iterator>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/shift_right.h b/libcxx/include/__algorithm/shift_right.h
index 983252d70e4d6..5cb41950642cf 100644
--- a/libcxx/include/__algorithm/shift_right.h
+++ b/libcxx/include/__algorithm/shift_right.h
@@ -12,6 +12,7 @@
 #include <__config>
 #include <__algorithm/move.h>
 #include <__algorithm/move_backward.h>
+#include <__algorithm/swap_ranges.h>
 #include <__iterator/iterator_traits.h>
 #include <type_traits> // swap
 

diff  --git a/libcxx/include/__algorithm/shuffle.h b/libcxx/include/__algorithm/shuffle.h
index 0b4d3d49f3e4c..637fca5388579 100644
--- a/libcxx/include/__algorithm/shuffle.h
+++ b/libcxx/include/__algorithm/shuffle.h
@@ -12,9 +12,9 @@
 #include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__random/uniform_int_distribution.h>
+#include <__utility/swap.h>
 #include <cstddef>
 #include <cstdint>
-#include <type_traits> // swap
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/sift_down.h b/libcxx/include/__algorithm/sift_down.h
index ce38d7fd0feb1..dd4b54ed8e5fb 100644
--- a/libcxx/include/__algorithm/sift_down.h
+++ b/libcxx/include/__algorithm/sift_down.h
@@ -11,8 +11,7 @@
 
 #include <__config>
 #include <__iterator/iterator_traits.h>
-#include <utility>
-#include <type_traits>
+#include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header

diff  --git a/libcxx/include/__algorithm/sort.h b/libcxx/include/__algorithm/sort.h
index eb3a5de68cee7..39ec21302d20c 100644
--- a/libcxx/include/__algorithm/sort.h
+++ b/libcxx/include/__algorithm/sort.h
@@ -15,6 +15,7 @@
 #include <__algorithm/min_element.h>
 #include <__algorithm/partial_sort.h>
 #include <__algorithm/unwrap_iter.h>
+#include <__utility/swap.h>
 #include <memory>
 #include <type_traits> // swap
 

diff  --git a/libcxx/include/__algorithm/stable_partition.h b/libcxx/include/__algorithm/stable_partition.h
index 7ed8c1e16ebff..931335f444746 100644
--- a/libcxx/include/__algorithm/stable_partition.h
+++ b/libcxx/include/__algorithm/stable_partition.h
@@ -12,6 +12,7 @@
 #include <__config>
 #include <__algorithm/rotate.h>
 #include <__iterator/iterator_traits.h>
+#include <__utility/swap.h>
 #include <memory>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__algorithm/stable_sort.h b/libcxx/include/__algorithm/stable_sort.h
index e94a8e0cad71b..32b239a0d72f7 100644
--- a/libcxx/include/__algorithm/stable_sort.h
+++ b/libcxx/include/__algorithm/stable_sort.h
@@ -15,6 +15,7 @@
 #include <__algorithm/inplace_merge.h>
 #include <__algorithm/sort.h>
 #include <__iterator/iterator_traits.h>
+#include <__utility/swap.h>
 #include <memory>
 #include <type_traits> // swap
 

diff  --git a/libcxx/include/__algorithm/swap_ranges.h b/libcxx/include/__algorithm/swap_ranges.h
new file mode 100644
index 0000000000000..3c72dbd24c63b
--- /dev/null
+++ b/libcxx/include/__algorithm/swap_ranges.h
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___ALGORITHM_SWAP_RANGES_H
+#define _LIBCPP___ALGORITHM_SWAP_RANGES_H
+
+#include <__config>
+#include <__utility/swap.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator2
+swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
+  for (; __first1 != __last1; ++__first1, (void)++__first2)
+    swap(*__first1, *__first2);
+  return __first2;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H

diff  --git a/libcxx/include/__algorithm/unique.h b/libcxx/include/__algorithm/unique.h
index c4ac0525af6a3..fb6251a39a821 100644
--- a/libcxx/include/__algorithm/unique.h
+++ b/libcxx/include/__algorithm/unique.h
@@ -13,7 +13,7 @@
 #include <__algorithm/comp.h>
 #include <__algorithm/adjacent_find.h>
 #include <__iterator/iterator_traits.h>
-#include <utility>
+#include <__utility/move.h>
 #include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__iterator/concepts.h b/libcxx/include/__iterator/concepts.h
index 95f68914836b0..e3664db14ae26 100644
--- a/libcxx/include/__iterator/concepts.h
+++ b/libcxx/include/__iterator/concepts.h
@@ -16,6 +16,7 @@
 #include <__iterator/iterator_traits.h>
 #include <__iterator/readable_traits.h>
 #include <__memory/pointer_traits.h>
+#include <__utility/forward.h>
 #include <concepts>
 #include <type_traits>
 

diff  --git a/libcxx/include/__iterator/iter_move.h b/libcxx/include/__iterator/iter_move.h
index c83eb77218daf..e384c56af76c0 100644
--- a/libcxx/include/__iterator/iter_move.h
+++ b/libcxx/include/__iterator/iter_move.h
@@ -12,6 +12,7 @@
 
 #include <__config>
 #include <__iterator/iterator_traits.h>
+#include <__utility/forward.h>
 #include <concepts> // __class_or_enum
 #include <type_traits>
 #include <utility>

diff  --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index cbce817d6d28d..2c21a16e7e849 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -12,6 +12,7 @@
 
 #include <__config>
 #include <__memory/allocator_traits.h>
+#include <__utility/forward.h>
 #include <cstddef>
 #include <new>
 #include <stdexcept>

diff  --git a/libcxx/include/__memory/allocator_traits.h b/libcxx/include/__memory/allocator_traits.h
index dfef264a6492a..a02af0deafc97 100644
--- a/libcxx/include/__memory/allocator_traits.h
+++ b/libcxx/include/__memory/allocator_traits.h
@@ -13,6 +13,7 @@
 #include <__config>
 #include <__memory/construct_at.h>
 #include <__memory/pointer_traits.h>
+#include <__utility/forward.h>
 #include <limits>
 #include <type_traits>
 

diff  --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h
index fcdfaf2146b68..08f0318a10f4c 100644
--- a/libcxx/include/__memory/compressed_pair.h
+++ b/libcxx/include/__memory/compressed_pair.h
@@ -11,6 +11,7 @@
 #define _LIBCPP___MEMORY_COMPRESSED_PAIR_H
 
 #include <__config>
+#include <__utility/forward.h>
 #include <tuple> // needed in c++03 for some constructors
 #include <type_traits>
 #include <utility>

diff  --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index 8cd7d5e5d67a7..7ab19315dcd8b 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -12,6 +12,7 @@
 
 #include <__config>
 #include <__debug>
+#include <__utility/forward.h>
 #include <utility>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index ab92651f50d86..64f5b06ac26b2 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -20,6 +20,7 @@
 #include <__memory/compressed_pair.h>
 #include <__memory/pointer_traits.h>
 #include <__memory/unique_ptr.h>
+#include <__utility/forward.h>
 #include <cstddef>
 #include <cstdlib> // abort
 #include <iosfwd>

diff  --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h
index 9442e54fe98ff..56a363779c88d 100644
--- a/libcxx/include/__memory/unique_ptr.h
+++ b/libcxx/include/__memory/unique_ptr.h
@@ -14,6 +14,7 @@
 #include <__functional_base> // std::less
 #include <__memory/allocator_traits.h> // __pointer
 #include <__memory/compressed_pair.h>
+#include <__utility/forward.h>
 #include <cstddef>
 #include <type_traits>
 #include <utility>

diff  --git a/libcxx/include/__ranges/access.h b/libcxx/include/__ranges/access.h
index 9e9fb52477d74..528dba1a0df75 100644
--- a/libcxx/include/__ranges/access.h
+++ b/libcxx/include/__ranges/access.h
@@ -13,6 +13,8 @@
 #include <__iterator/concepts.h>
 #include <__iterator/readable_traits.h>
 #include <__ranges/enable_borrowed_range.h>
+#include <__utility/__decay_copy.h>
+#include <__utility/forward.h>
 #include <concepts>
 #include <type_traits>
 

diff  --git a/libcxx/include/__ranges/all.h b/libcxx/include/__ranges/all.h
index 2dfdb780cdc58..d1312d1a213d5 100644
--- a/libcxx/include/__ranges/all.h
+++ b/libcxx/include/__ranges/all.h
@@ -16,6 +16,8 @@
 #include <__ranges/concepts.h>
 #include <__ranges/ref_view.h>
 #include <__ranges/subrange.h>
+#include <__utility/__decay_copy.h>
+#include <__utility/forward.h>
 #include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__ranges/data.h b/libcxx/include/__ranges/data.h
index 99d1811f2c243..f001178586d29 100644
--- a/libcxx/include/__ranges/data.h
+++ b/libcxx/include/__ranges/data.h
@@ -14,6 +14,7 @@
 #include <__iterator/iterator_traits.h>
 #include <__memory/pointer_traits.h>
 #include <__ranges/access.h>
+#include <__utility/forward.h>
 #include <concepts>
 #include <type_traits>
 

diff  --git a/libcxx/include/__ranges/empty.h b/libcxx/include/__ranges/empty.h
index 05f492c5ddbf6..186be9676b6f5 100644
--- a/libcxx/include/__ranges/empty.h
+++ b/libcxx/include/__ranges/empty.h
@@ -13,6 +13,7 @@
 #include <__iterator/concepts.h>
 #include <__ranges/access.h>
 #include <__ranges/size.h>
+#include <__utility/forward.h>
 #include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__ranges/size.h b/libcxx/include/__ranges/size.h
index 0d3685adf5c6b..999d2113d276d 100644
--- a/libcxx/include/__ranges/size.h
+++ b/libcxx/include/__ranges/size.h
@@ -13,6 +13,8 @@
 #include <__iterator/concepts.h>
 #include <__iterator/iterator_traits.h>
 #include <__ranges/access.h>
+#include <__utility/__decay_copy.h>
+#include <__utility/forward.h>
 #include <concepts>
 #include <type_traits>
 

diff  --git a/libcxx/include/__split_buffer b/libcxx/include/__split_buffer
index 85cc0db3e909c..901c0374aa1c4 100644
--- a/libcxx/include/__split_buffer
+++ b/libcxx/include/__split_buffer
@@ -3,6 +3,7 @@
 #define _LIBCPP_SPLIT_BUFFER
 
 #include <__config>
+#include <__utility/forward.h>
 #include <algorithm>
 #include <type_traits>
 

diff  --git a/libcxx/include/__tree b/libcxx/include/__tree
index b599a0449adf0..5f9ba8be79711 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -11,6 +11,7 @@
 #define _LIBCPP___TREE
 
 #include <__config>
+#include <__utility/forward.h>
 #include <algorithm>
 #include <iterator>
 #include <memory>

diff  --git a/libcxx/include/__utility/__decay_copy.h b/libcxx/include/__utility/__decay_copy.h
new file mode 100644
index 0000000000000..eda8db6a60f5a
--- /dev/null
+++ b/libcxx/include/__utility/__decay_copy.h
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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_DECAY_COPY_H
+#define _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
+
+#include <__config>
+#include <__utility/forward.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY typename decay<_Tp>::type __decay_copy(_Tp&& __t)
+#if _LIBCPP_STD_VER > 17
+    noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp> >)
+#endif
+{
+  return _VSTD::forward<_Tp>(__t);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___TYPE_TRAITS_DECAY_COPY_H

diff  --git a/libcxx/include/__utility/declval.h b/libcxx/include/__utility/declval.h
new file mode 100644
index 0000000000000..185527cc6cb5b
--- /dev/null
+++ b/libcxx/include/__utility/declval.h
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___UTILITY_DECLVAL_H
+#define _LIBCPP___UTILITY_DECLVAL_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// Suppress deprecation notice for volatile-qualified return type resulting
+// from volatile-qualified types _Tp.
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+template <class _Tp>
+_Tp&& __declval(int);
+template <class _Tp>
+_Tp __declval(long);
+_LIBCPP_SUPPRESS_DEPRECATED_POP
+
+template <class _Tp>
+decltype(__declval<_Tp>(0)) declval() _NOEXCEPT;
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___UTILITY_DECLVAL_H

diff  --git a/libcxx/include/__utility/forward.h b/libcxx/include/__utility/forward.h
new file mode 100644
index 0000000000000..c994f129007b9
--- /dev/null
+++ b/libcxx/include/__utility/forward.h
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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___UTILITY_FORWARD_H
+#define _LIBCPP___UTILITY_FORWARD_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp&&
+forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT {
+  return static_cast<_Tp&&>(__t);
+}
+
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp&&
+forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT {
+  static_assert(!is_lvalue_reference<_Tp>::value, "cannot forward an rvalue as an lvalue");
+  return static_cast<_Tp&&>(__t);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___UTILITY_FORWARD_H

diff  --git a/libcxx/include/__utility/move.h b/libcxx/include/__utility/move.h
new file mode 100644
index 0000000000000..d3c56f93ef918
--- /dev/null
+++ b/libcxx/include/__utility/move.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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___UTILITY_MOVE_H
+#define _LIBCPP___UTILITY_MOVE_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename remove_reference<_Tp>::type&&
+move(_Tp&& __t) _NOEXCEPT {
+  typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
+  return static_cast<_Up&&>(__t);
+}
+
+#ifndef _LIBCPP_CXX03_LANG
+template <class _Tp>
+using __move_if_noexcept_result_t =
+    typename conditional<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&,
+                         _Tp&&>::type;
+#else // _LIBCPP_CXX03_LANG
+template <class _Tp>
+using __move_if_noexcept_result_t = const _Tp&;
+#endif
+
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 __move_if_noexcept_result_t<_Tp>
+move_if_noexcept(_Tp& __x) _NOEXCEPT {
+  return _VSTD::move(__x);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___UTILITY_MOVE_H

diff  --git a/libcxx/include/__utility/swap.h b/libcxx/include/__utility/swap.h
new file mode 100644
index 0000000000000..8af83a9a0f451
--- /dev/null
+++ b/libcxx/include/__utility/swap.h
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___UTILITY_SWAP_H
+#define _LIBCPP___UTILITY_SWAP_H
+
+#include <__config>
+#include <__utility/declval.h>
+#include <__utility/move.h>
+#include <type_traits>
+#include <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#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;
+#else
+template <class>
+using __swap_result_t = void;
+#endif
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY __swap_result_t<_Tp> _LIBCPP_CONSTEXPR_AFTER_CXX17 swap(_Tp& __x, _Tp& __y)
+    _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value&& is_nothrow_move_assignable<_Tp>::value) {
+  _Tp __t(_VSTD::move(__x));
+  __x = _VSTD::move(__y);
+  __y = _VSTD::move(__t);
+}
+
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if<__is_swappable<_Tp>::value>::type
+swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
+  for (size_t __i = 0; __i != _Np; ++__i) {
+    swap(__a[__i], __b[__i]);
+  }
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___UTILITY_SWAP_H

diff  --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index c040eded772bb..849302a7d5da3 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -695,6 +695,7 @@ template <class BidirectionalIterator, class Compare>
 #include <__algorithm/is_permutation.h>
 #include <__algorithm/is_sorted.h>
 #include <__algorithm/is_sorted_until.h>
+#include <__algorithm/iter_swap.h>
 #include <__algorithm/lexicographical_compare.h>
 #include <__algorithm/lower_bound.h>
 #include <__algorithm/make_heap.h>
@@ -746,6 +747,7 @@ template <class BidirectionalIterator, class Compare>
 #include <__algorithm/sort_heap.h>
 #include <__algorithm/stable_partition.h>
 #include <__algorithm/stable_sort.h>
+#include <__algorithm/swap_ranges.h>
 #include <__algorithm/transform.h>
 #include <__algorithm/unique_copy.h>
 #include <__algorithm/unique.h>

diff  --git a/libcxx/include/any b/libcxx/include/any
index f844800f32cae..3a826c4d50b44 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -82,6 +82,7 @@ namespace std {
 
 #include <__availability>
 #include <__config>
+#include <__utility/forward.h>
 #include <cstdlib>
 #include <memory>
 #include <type_traits>

diff  --git a/libcxx/include/deque b/libcxx/include/deque
index 526a1c83c6d00..1f23ef0c78696 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -163,6 +163,7 @@ template <class T, class Allocator, class Predicate>
 #include <__config>
 #include <__debug>
 #include <__split_buffer>
+#include <__utility/forward.h>
 #include <algorithm>
 #include <compare>
 #include <initializer_list>

diff  --git a/libcxx/include/exception b/libcxx/include/exception
index 353ebf7441833..816f259f878b2 100644
--- a/libcxx/include/exception
+++ b/libcxx/include/exception
@@ -266,7 +266,7 @@ struct __throw_with_nested<_Tp, _Up, true> {
     _LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void
     __do_throw(_Tp&& __t)
     {
-        throw __nested<_Up>(_VSTD::forward<_Tp>(__t));
+        throw __nested<_Up>(static_cast<_Tp&&>(__t));
     }
 };
 
@@ -279,7 +279,7 @@ struct __throw_with_nested<_Tp, _Up, false> {
     __do_throw (_Tp& __t)
 #endif // _LIBCPP_CXX03_LANG
     {
-        throw _VSTD::forward<_Tp>(__t);
+        throw static_cast<_Tp&&>(__t);
     }
 };
 #endif
@@ -296,7 +296,7 @@ throw_with_nested(_Tp&& __t)
         is_class<_Up>::value &&
         !is_base_of<nested_exception, _Up>::value &&
         !__libcpp_is_final<_Up>::value>::
-            __do_throw(_VSTD::forward<_Tp>(__t));
+            __do_throw(static_cast<_Tp&&>(__t));
 #else
     ((void)__t);
     // FIXME: Make this abort

diff  --git a/libcxx/include/experimental/iterator b/libcxx/include/experimental/iterator
index 10b0599138c68..09ea2cbcc7dc4 100644
--- a/libcxx/include/experimental/iterator
+++ b/libcxx/include/experimental/iterator
@@ -56,6 +56,9 @@ namespace std {
 
 #if _LIBCPP_STD_VER > 11
 
+#include <__memory/addressof.h>
+#include <__utility/move.h>
+#include <__utility/forward.h>
 #include <iterator>
 
 _LIBCPP_BEGIN_NAMESPACE_LFTS

diff  --git a/libcxx/include/filesystem b/libcxx/include/filesystem
index a652eede4ff0f..61d6c659cb473 100644
--- a/libcxx/include/filesystem
+++ b/libcxx/include/filesystem
@@ -232,6 +232,7 @@
 #include <__availability>
 #include <__config>
 #include <__debug>
+#include <__utility/forward.h>
 #include <chrono>
 #include <compare>
 #include <cstddef>

diff  --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 9622d9d8f6016..0ae8f19ec20c9 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -180,6 +180,7 @@ template <class T, class Allocator, class Predicate>
 */
 
 #include <__config>
+#include <__utility/forward.h>
 #include <algorithm>
 #include <initializer_list>
 #include <iterator>

diff  --git a/libcxx/include/functional b/libcxx/include/functional
index 68ed22e59cbfd..249c0dc02be6b 100644
--- a/libcxx/include/functional
+++ b/libcxx/include/functional
@@ -491,6 +491,7 @@ POLICY:  For non-variadic implementations, the number of arguments is limited
 #include <__debug>
 #include <__functional_base>
 #include <__functional/search.h>
+#include <__utility/forward.h>
 #include <concepts>
 #include <exception>
 #include <memory>

diff  --git a/libcxx/include/future b/libcxx/include/future
index d794fae7dc259..5d2732b73cf61 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -364,6 +364,8 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #include <__availability>
 #include <__config>
 #include <__debug>
+#include <__utility/__decay_copy.h>
+#include <__utility/forward.h>
 #include <chrono>
 #include <exception>
 #include <memory>

diff  --git a/libcxx/include/istream b/libcxx/include/istream
index 7f827bbe07fb1..c83b025b146f0 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -159,6 +159,7 @@ template <class Stream, class T>
 */
 
 #include <__config>
+#include <__utility/forward.h>
 #include <ostream>
 #include <version>
 

diff  --git a/libcxx/include/iterator b/libcxx/include/iterator
index 0b5c4eedca180..092e5898fc26a 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -570,6 +570,7 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
 #include <__iterator/readable_traits.h>
 #include <__memory/addressof.h>
 #include <__memory/pointer_traits.h>
+#include <__utility/forward.h>
 #include <compare>
 #include <concepts> // Mandated by the Standard.
 #include <cstddef>

diff  --git a/libcxx/include/list b/libcxx/include/list
index f5980570901ad..23da5fcfc92d6 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -182,6 +182,7 @@ template <class T, class Allocator, class Predicate>
 
 #include <__config>
 #include <__debug>
+#include <__utility/forward.h>
 #include <algorithm>
 #include <initializer_list>
 #include <iterator>

diff  --git a/libcxx/include/map b/libcxx/include/map
index c7f7df2fc9b9c..0da590fd71148 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -493,6 +493,7 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);  // C++20
 #include <__debug>
 #include <__node_handle>
 #include <__tree>
+#include <__utility/forward.h>
 #include <compare>
 #include <functional>
 #include <initializer_list>

diff  --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index dc8984325e7b8..c5f9f43b87068 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -666,9 +666,12 @@ module std [system] {
     export *
 
     module __utility {
-      module to_underlying {
-        header "__utility/to_underlying.h"
-      }
+      module __decay_copy  { header "__utility/__decay_copy.h"  }
+      module declval       { header "__utility/declval.h"       }
+      module forward       { header "__utility/forward.h"       }
+      module move          { header "__utility/move.h"          }
+      module swap          { header "__utility/swap.h"          }
+      module to_underlying { header "__utility/to_underlying.h" }
     }
   }
   module valarray {

diff  --git a/libcxx/include/mutex b/libcxx/include/mutex
index a23c213f4b959..eb8e54ad44214 100644
--- a/libcxx/include/mutex
+++ b/libcxx/include/mutex
@@ -189,6 +189,7 @@ template<class Callable, class ...Args>
 #include <__config>
 #include <__mutex_base>
 #include <__threading_support>
+#include <__utility/forward.h>
 #include <cstdint>
 #include <functional>
 #include <memory>

diff  --git a/libcxx/include/queue b/libcxx/include/queue
index 9470a75102a67..3c7bbf2f6adb7 100644
--- a/libcxx/include/queue
+++ b/libcxx/include/queue
@@ -179,6 +179,7 @@ template <class T, class Container, class Compare>
 */
 
 #include <__config>
+#include <__utility/forward.h>
 #include <algorithm>
 #include <compare>
 #include <deque>

diff  --git a/libcxx/include/scoped_allocator b/libcxx/include/scoped_allocator
index d9de95dbc0862..dc24d30b510fa 100644
--- a/libcxx/include/scoped_allocator
+++ b/libcxx/include/scoped_allocator
@@ -106,6 +106,7 @@ template <class OuterA1, class OuterA2, class... InnerAllocs>
 */
 
 #include <__config>
+#include <__utility/forward.h>
 #include <memory>
 #include <version>
 

diff  --git a/libcxx/include/set b/libcxx/include/set
index b9d2895fa7c8a..0da484b2248d1 100644
--- a/libcxx/include/set
+++ b/libcxx/include/set
@@ -437,6 +437,7 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred);  // C++20
 #include <__debug>
 #include <__node_handle>
 #include <__tree>
+#include <__utility/forward.h>
 #include <compare>
 #include <functional>
 #include <initializer_list>

diff  --git a/libcxx/include/stack b/libcxx/include/stack
index c1b2cbeafa07d..6dd055e86860f 100644
--- a/libcxx/include/stack
+++ b/libcxx/include/stack
@@ -88,6 +88,7 @@ template <class T, class Container>
 */
 
 #include <__config>
+#include <__utility/forward.h>
 #include <deque>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/thread b/libcxx/include/thread
index 09a1f02a04c4b..acfc20bce2dde 100644
--- a/libcxx/include/thread
+++ b/libcxx/include/thread
@@ -87,6 +87,8 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
 #include <__functional_base>
 #include <__mutex_base>
 #include <__threading_support>
+#include <__utility/__decay_copy.h>
+#include <__utility/forward.h>
 #include <chrono>
 #include <cstddef>
 #include <functional>

diff  --git a/libcxx/include/tuple b/libcxx/include/tuple
index 58f72b15d767a..3a4b0dfec5f00 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -151,6 +151,8 @@ template <class... Types>
 
 #include <__config>
 #include <__functional_base>
+#include <__utility/forward.h>
+#include <__utility/move.h>
 #include <__tuple>
 #include <compare>
 #include <cstddef>

diff  --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index f257fa3ee05ba..09b66c7871d80 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -2818,46 +2818,6 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v
 
 #endif // __has_keyword(__is_destructible)
 
-// move
-
-template <class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename remove_reference<_Tp>::type&&
-move(_Tp&& __t) _NOEXCEPT
-{
-    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
-    return static_cast<_Up&&>(__t);
-}
-
-template <class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-_Tp&&
-forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
-{
-    return static_cast<_Tp&&>(__t);
-}
-
-template <class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-_Tp&&
-forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT
-{
-    static_assert(!is_lvalue_reference<_Tp>::value,
-                  "cannot forward an rvalue as an lvalue");
-    return static_cast<_Tp&&>(__t);
-}
-
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-typename decay<_Tp>::type
-__decay_copy(_Tp&& __t)
-#if _LIBCPP_STD_VER > 17
-noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp>>)
-#endif
-{
-    return static_cast<_Tp&&>(__t);
-}
-
 template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
 struct __member_pointer_traits_imp
 {
@@ -4185,10 +4145,11 @@ _LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
 
 #endif // _LIBCPP_STD_VER > 14
 
+// __swappable
+
 template <class _Tp> struct __is_swappable;
 template <class _Tp> struct __is_nothrow_swappable;
 
-// swap, swap_ranges
 
 #ifndef _LIBCPP_CXX03_LANG
 template <class _Tp>
@@ -4202,49 +4163,14 @@ template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp>
 swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
-                                    is_nothrow_move_assignable<_Tp>::value)
-{
-    _Tp __t(_VSTD::move(__x));
-    __x = _VSTD::move(__y);
-    __y = _VSTD::move(__t);
-}
+                                    is_nothrow_move_assignable<_Tp>::value);
 
 template<class _Tp, size_t _Np>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 typename enable_if<
     __is_swappable<_Tp>::value
 >::type
-swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
-{
-    for (size_t __i = 0; __i != _Np; ++__i) {
-        swap(__a[__i], __b[__i]);
-    }
-}
-
-template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_ForwardIterator2
-swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
-{
-    for(; __first1 != __last1; ++__first1, (void) ++__first2)
-        swap(*__first1, *__first2);
-    return __first2;
-}
-
-// iter_swap
-
-template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-void
-iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
-    //                                  _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
-               _NOEXCEPT_(_NOEXCEPT_(swap(*declval<_ForwardIterator1>(),
-                                          *declval<_ForwardIterator2>())))
-{
-    swap(*__a, *__b);
-}
-
-// __swappable
+swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
 
 namespace __detail
 {

diff  --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index 66fd5205a2c0b..6e58fa9bf4fbe 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -435,6 +435,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
 #include <__debug>
 #include <__hash_table>
 #include <__node_handle>
+#include <__utility/forward.h>
 #include <compare>
 #include <functional>
 #include <iterator> // __libcpp_erase_if_container

diff  --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set
index f44dcacbfc609..0e4901d6c8190 100644
--- a/libcxx/include/unordered_set
+++ b/libcxx/include/unordered_set
@@ -390,6 +390,7 @@ template <class Value, class Hash, class Pred, class Alloc>
 #include <__debug>
 #include <__hash_table>
 #include <__node_handle>
+#include <__utility/forward.h>
 #include <compare>
 #include <functional>
 #include <iterator> // __libcpp_erase_if_container

diff  --git a/libcxx/include/utility b/libcxx/include/utility
index c536a1a2c81fc..49e7b3e85c671 100644
--- a/libcxx/include/utility
+++ b/libcxx/include/utility
@@ -210,6 +210,10 @@ template <class T>
 #include <__config>
 #include <__debug>
 #include <__tuple>
+#include <__utility/declval.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include <__utility/swap.h>
 #include <__utility/to_underlying.h>
 #include <compare>
 #include <cstddef>
@@ -266,29 +270,6 @@ operator>=(const _Tp& __x, const _Tp& __y)
 
 }  // rel_ops
 
-// swap_ranges is defined in <type_traits>`
-
-// swap is defined in <type_traits>
-
-// move_if_noexcept
-
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Tp>
-using __move_if_noexcept_result_t =
-    typename conditional<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&,
-                         _Tp&&>::type;
-#else // _LIBCPP_CXX03_LANG
-template <class _Tp>
-using __move_if_noexcept_result_t = const _Tp&;
-#endif
-
-template <class _Tp>
-_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-__move_if_noexcept_result_t<_Tp> move_if_noexcept(_Tp& __x) _NOEXCEPT
-{
-    return _VSTD::move(__x);
-}
-
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
 _LIBCPP_NODISCARD_EXT constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }

diff  --git a/libcxx/include/variant b/libcxx/include/variant
index 5a431c35ea327..2145700e5a68a 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -201,6 +201,7 @@ namespace std {
 
 #include <__availability>
 #include <__config>
+#include <__utility/forward.h>
 #include <__tuple>
 #include <array>
 #include <compare>

diff  --git a/libcxx/include/vector b/libcxx/include/vector
index 95ef4391806af..bf193e5ba4c90 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -276,6 +276,7 @@ erase_if(vector<T, Allocator>& c, Predicate pred);    // C++20
 #include <__debug>
 #include <__functional_base>
 #include <__split_buffer>
+#include <__utility/forward.h>
 #include <algorithm>
 #include <climits>
 #include <compare>

diff  --git a/libcxx/test/std/utilities/utility/forward/forward.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward.fail.cpp
index 90287dc88de1f..4d7790a751481 100644
--- a/libcxx/test/std/utilities/utility/forward/forward.fail.cpp
+++ b/libcxx/test/std/utilities/utility/forward/forward.fail.cpp
@@ -23,7 +23,7 @@ int main(int, char**)
 {
     {
         std::forward<A&>(source());  // expected-note {{requested here}}
-        // expected-error-re at type_traits:* 1 {{static_assert failed{{.*}} "cannot forward an rvalue as an lvalue"}}
+        // expected-error-re@*:* 1 {{static_assert failed{{.*}} "cannot forward an rvalue as an lvalue"}}
     }
     {
         const A ca = A();

diff  --git a/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp b/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp
index c9146ee7637d8..3c9439b33d699 100644
--- a/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp
+++ b/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp
@@ -13,9 +13,10 @@
 //   void
 //   swap(T& a, T& b);
 
-#include <utility>
 #include <cassert>
 #include <memory>
+#include <type_traits>
+#include <utility>
 
 #include "test_macros.h"
 

diff  --git a/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp b/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
index 512505b78f08c..3d562ddd3fc61 100644
--- a/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
+++ b/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
@@ -13,9 +13,11 @@
 //   void
 //   swap(T (&a)[N], T (&b)[N]);
 
-#include <utility>
+#include <algorithm>
 #include <cassert>
 #include <memory>
+#include <type_traits>
+#include <utility>
 
 #include "test_macros.h"
 

diff  --git a/libcxx/test/support/poisoned_hash_helper.h b/libcxx/test/support/poisoned_hash_helper.h
index 60ce6f9d35b50..a1f5f79162e63 100644
--- a/libcxx/test/support/poisoned_hash_helper.h
+++ b/libcxx/test/support/poisoned_hash_helper.h
@@ -9,8 +9,9 @@
 #ifndef SUPPORT_POISONED_HASH_HELPER_H
 #define SUPPORT_POISONED_HASH_HELPER_H
 
-#include <type_traits>
+#include <__utility/move.h> // TODO: replace with <utility> when std::hash is moved out of the header
 #include <cassert>
+#include <type_traits>
 
 #include "test_macros.h"
 #include "test_workarounds.h"


        


More information about the libcxx-commits mailing list