[NFC][libc++] Moves transitive includes location.

As discussed in D132284 they will be moved to the end.

Reviewed By: #libc, Mordante

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

NOKEYCHECK=True
GitOrigin-RevId: e31c2a1b1a643861f25ba0145cb4701c999fc6c2
diff --git a/include/algorithm b/include/algorithm
index 0b54fb9..f036fd0 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -1899,15 +1899,6 @@
 #include <__algorithm/unwrap_iter.h>
 #include <__algorithm/upper_bound.h>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
-#  include <chrono> // IGNORE-CYCLE due to <format>
-#endif
-
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iterator>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 #include <initializer_list>
 
@@ -1919,4 +1910,13 @@
 #   include <__pstl_algorithm>
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
+#  include <chrono> // IGNORE-CYCLE due to <format>
+#endif
+
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iterator>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_ALGORITHM
diff --git a/include/any b/include/any
index a70c6f1..ec12cfa 100644
--- a/include/any
+++ b/include/any
@@ -94,10 +94,6 @@
 #include <typeinfo>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
-#  include <chrono> // IGNORE-CYCLE due to <format>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -695,4 +691,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
+#  include <chrono> // IGNORE-CYCLE due to <format>
+#endif
+
 #endif // _LIBCPP_ANY
diff --git a/include/array b/include/array
index 415ac16..4b91569 100644
--- a/include/array
+++ b/include/array
@@ -123,12 +123,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <iterator>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -535,4 +529,10 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <iterator>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_ARRAY
diff --git a/include/atomic b/include/atomic
index 2e92088..571e34b 100644
--- a/include/atomic
+++ b/include/atomic
@@ -534,15 +534,6 @@
 # include <__threading_support>
 #endif
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
-#  include <chrono> // IGNORE-CYCLE due to <format>
-#endif
-
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <cmath>
-#  include <compare>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -2707,4 +2698,13 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
+#  include <chrono> // IGNORE-CYCLE due to <format>
+#endif
+
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <cmath>
+#  include <compare>
+#endif
+
 #endif // _LIBCPP_ATOMIC
diff --git a/include/bit b/include/bit
index 1505c9b..e3fb6e3 100644
--- a/include/bit
+++ b/include/bit
@@ -71,10 +71,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iosfwd>
-#endif
-
 #if defined(_LIBCPP_COMPILER_MSVC)
 #  include <intrin.h>
 #endif
@@ -256,4 +252,8 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iosfwd>
+#endif
+
 #endif // _LIBCPP_BIT
diff --git a/include/charconv b/include/charconv
index d77cf3a..6d6a7db 100644
--- a/include/charconv
+++ b/include/charconv
@@ -97,10 +97,6 @@
 #include <limits>
 #include <type_traits>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iosfwd>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -824,4 +820,8 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iosfwd>
+#endif
+
 #endif // _LIBCPP_CHARCONV
diff --git a/include/coroutine b/include/coroutine
index d7ed44e..a81d68f 100644
--- a/include/coroutine
+++ b/include/coroutine
@@ -46,10 +46,6 @@
 #include <__coroutine/trivial_awaitables.h>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iosfwd>
-#endif
-
 // standard-mandated includes
 #include <compare>
 
@@ -57,4 +53,8 @@
 #  pragma GCC system_header
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iosfwd>
+#endif
+
 #endif // _LIBCPP_COROUTINE
diff --git a/include/deque b/include/deque
index c38b544..9a26f16 100644
--- a/include/deque
+++ b/include/deque
@@ -185,12 +185,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <functional>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -2932,4 +2926,10 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_DEQUE
diff --git a/include/experimental/simd b/include/experimental/simd
index 532bc64..4a52358 100644
--- a/include/experimental/simd
+++ b/include/experimental/simd
@@ -656,11 +656,6 @@
 #include <experimental/__config>
 #include <tuple>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <functional>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -1581,4 +1576,9 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <functional>
+#endif
+
 #endif /* _LIBCPP_EXPERIMENTAL_SIMD */
diff --git a/include/experimental/unordered_map b/include/experimental/unordered_map
index db114dc..d280182 100644
--- a/include/experimental/unordered_map
+++ b/include/experimental/unordered_map
@@ -45,14 +45,6 @@
 #include <experimental/memory_resource>
 #include <unordered_map>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <array>
-#  include <bit>
-#  include <functional>
-#  include <vector>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -75,4 +67,12 @@
 
 _LIBCPP_END_NAMESPACE_LFTS_PMR
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <array>
+#  include <bit>
+#  include <functional>
+#  include <vector>
+#endif
+
 #endif /* _LIBCPP_EXPERIMENTAL_UNORDERED_MAP */
diff --git a/include/ext/hash_map b/include/ext/hash_map
index ab5a896..b7830e8 100644
--- a/include/ext/hash_map
+++ b/include/ext/hash_map
@@ -210,10 +210,6 @@
 #include <stdexcept>
 #include <type_traits>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iterator>
-#endif
-
 #if defined(__DEPRECATED) && __DEPRECATED
 #if defined(_LIBCPP_WARNING)
     _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>")
@@ -987,4 +983,8 @@
 
 } // namespace __gnu_cxx
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_HASH_MAP
diff --git a/include/ext/hash_set b/include/ext/hash_set
index 332d609..68b449d 100644
--- a/include/ext/hash_set
+++ b/include/ext/hash_set
@@ -199,10 +199,6 @@
 #include <ext/__hash>
 #include <functional>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iterator>
-#endif
-
 #if defined(__DEPRECATED) && __DEPRECATED
 #if defined(_LIBCPP_WARNING)
     _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>")
@@ -666,4 +662,8 @@
 
 } // namespace __gnu_cxx
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_HASH_SET
diff --git a/include/forward_list b/include/forward_list
index c9fc20b..d5ea3ec 100644
--- a/include/forward_list
+++ b/include/forward_list
@@ -195,12 +195,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <functional>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -1788,4 +1782,10 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_FORWARD_LIST
diff --git a/include/functional b/include/functional
index c969d7f..60f6514 100644
--- a/include/functional
+++ b/include/functional
@@ -539,12 +539,12 @@
 #include <typeinfo>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <utility>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_FUNCTIONAL
diff --git a/include/future b/include/future
index 643600a..716daa7 100644
--- a/include/future
+++ b/include/future
@@ -378,10 +378,6 @@
 #include <thread>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
-#  include <chrono> // IGNORE-CYCLE due to <format>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -2436,4 +2432,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
+#  include <chrono> // IGNORE-CYCLE due to <format>
+#endif
+
 #endif // _LIBCPP_FUTURE
diff --git a/include/iterator b/include/iterator
index 6555b6d..be544b8 100644
--- a/include/iterator
+++ b/include/iterator
@@ -724,6 +724,10 @@
 #include <type_traits>
 #include <version>
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #  include <exception>
 #  include <new>
@@ -731,8 +735,4 @@
 #  include <utility>
 #endif
 
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
 #endif // _LIBCPP_ITERATOR
diff --git a/include/list b/include/list
index 668875b..a4e6def 100644
--- a/include/list
+++ b/include/list
@@ -203,12 +203,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <functional>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -2364,4 +2358,10 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_LIST
diff --git a/include/locale b/include/locale
index c7da783..3fe8f5d 100644
--- a/include/locale
+++ b/include/locale
@@ -211,10 +211,6 @@
 #include <streambuf>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iterator>
-#endif
-
 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
 // Most unix variants have catopen.  These are the specific ones that don't.
 #  if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
@@ -4356,4 +4352,8 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_LOCALE
diff --git a/include/map b/include/map
index 1e619b9..20e6126 100644
--- a/include/map
+++ b/include/map
@@ -546,12 +546,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#  include <iterator>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -2335,4 +2329,10 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#  include <iterator>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_MAP
diff --git a/include/memory b/include/memory
index 47134a0..0da19ee 100644
--- a/include/memory
+++ b/include/memory
@@ -887,11 +887,6 @@
 #include <typeinfo>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iterator>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 #include <compare>
 
@@ -1044,4 +1039,9 @@
 #   include <__pstl_memory>
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iterator>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_MEMORY
diff --git a/include/mutex b/include/mutex
index a8334ba..3aea375 100644
--- a/include/mutex
+++ b/include/mutex
@@ -198,10 +198,6 @@
 #endif
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -706,4 +702,8 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#endif
+
 #endif // _LIBCPP_MUTEX
diff --git a/include/numeric b/include/numeric
index ba030aa..64cd45b 100644
--- a/include/numeric
+++ b/include/numeric
@@ -163,11 +163,6 @@
 #include <__numeric/transform_inclusive_scan.h>
 #include <__numeric/transform_reduce.h>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#  include <iterator>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -176,4 +171,9 @@
 #   include <__pstl_numeric>
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_NUMERIC
diff --git a/include/optional b/include/optional
index d75b1fe..38412af 100644
--- a/include/optional
+++ b/include/optional
@@ -177,24 +177,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
-#  include <chrono> // IGNORE-CYCLE due to <format>
-#endif
-
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <atomic>
-#  include <climits>
-#  include <concepts>
-#  include <ctime>
-#  include <iterator>
-#  include <memory>
-#  include <ratio>
-#  include <tuple>
-#  include <typeinfo>
-#  include <utility>
-#  include <variant>
-#endif
-
 // standard-mandated includes
 #include <compare>
 
@@ -1590,4 +1572,22 @@
 
 #endif // _LIBCPP_STD_VER > 14
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
+#  include <chrono> // IGNORE-CYCLE due to <format>
+#endif
+
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <atomic>
+#  include <climits>
+#  include <concepts>
+#  include <ctime>
+#  include <iterator>
+#  include <memory>
+#  include <ratio>
+#  include <tuple>
+#  include <typeinfo>
+#  include <utility>
+#  include <variant>
+#endif
+
 #endif // _LIBCPP_OPTIONAL
diff --git a/include/ostream b/include/ostream
index 216e583..19fe7b0 100644
--- a/include/ostream
+++ b/include/ostream
@@ -171,10 +171,6 @@
 #include <streambuf>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iterator>
-#endif
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -1189,4 +1185,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_OSTREAM
diff --git a/include/queue b/include/queue
index 9a5cfb3..5e4b6ba 100644
--- a/include/queue
+++ b/include/queue
@@ -231,10 +231,6 @@
 #include <vector>
 #include <version>
 
-#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
-#  include <functional>
-#endif
-
 // standard-mandated includes
 #include <compare>
 #include <initializer_list>
@@ -960,4 +956,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
+#  include <functional>
+#endif
+
 #endif // _LIBCPP_QUEUE
diff --git a/include/random b/include/random
index 1193d0d..cc246f9 100644
--- a/include/random
+++ b/include/random
@@ -1718,10 +1718,6 @@
 #include <__random/weibull_distribution.h>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#endif
-
 // standard-mandated includes
 #include <initializer_list>
 
@@ -1739,4 +1735,8 @@
 #  pragma GCC system_header
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#endif
+
 #endif // _LIBCPP_RANDOM
diff --git a/include/regex b/include/regex
index 3899892..95a211f 100644
--- a/include/regex
+++ b/include/regex
@@ -778,11 +778,6 @@
 #include <vector>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iterator>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -6844,4 +6839,9 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iterator>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_REGEX
diff --git a/include/set b/include/set
index f97ae2a..e251857 100644
--- a/include/set
+++ b/include/set
@@ -485,11 +485,6 @@
 #include <__utility/forward.h>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -1578,4 +1573,9 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_SET
diff --git a/include/span b/include/span
index 42fbd91..337a674 100644
--- a/include/span
+++ b/include/span
@@ -148,11 +148,6 @@
 #include <type_traits>  // for remove_cv, etc
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -594,4 +589,9 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_SPAN
diff --git a/include/stack b/include/stack
index a4a76e5..8f0a997 100644
--- a/include/stack
+++ b/include/stack
@@ -107,10 +107,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#endif
-
 // standard-mandated includes
 #include <compare>
 #include <initializer_list>
@@ -363,4 +359,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#endif
+
 #endif // _LIBCPP_STACK
diff --git a/include/string b/include/string
index 6010177..26e55ce 100644
--- a/include/string
+++ b/include/string
@@ -569,16 +569,6 @@
 #  include <cwchar>
 #endif
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <functional>
-#  include <iterator>
-#  include <new>
-#  include <typeinfo>
-#  include <utility>
-#  include <vector>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -4765,4 +4755,14 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <functional>
+#  include <iterator>
+#  include <new>
+#  include <typeinfo>
+#  include <utility>
+#  include <vector>
+#endif
+
 #endif // _LIBCPP_STRING
diff --git a/include/string_view b/include/string_view
index 1e1abc7..c3df8c4 100644
--- a/include/string_view
+++ b/include/string_view
@@ -224,12 +224,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <functional>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -1034,4 +1028,10 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_STRING_VIEW
diff --git a/include/thread b/include/thread
index 85a845c..85e9275 100644
--- a/include/thread
+++ b/include/thread
@@ -99,14 +99,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
-#  include <chrono> // IGNORE-CYCLE due to <format>
-#endif
-
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#endif
-
 // standard-mandated includes
 #include <compare>
 
@@ -416,4 +408,12 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
+#  include <chrono> // IGNORE-CYCLE due to <format>
+#endif
+
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#endif
+
 #endif // _LIBCPP_THREAD
diff --git a/include/tuple b/include/tuple
index 01c59b3..7bf2f91 100644
--- a/include/tuple
+++ b/include/tuple
@@ -220,14 +220,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <exception>
-#  include <iosfwd>
-#  include <new>
-#  include <typeinfo>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 #include <compare>
 
@@ -1825,4 +1817,12 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <exception>
+#  include <iosfwd>
+#  include <new>
+#  include <typeinfo>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_TUPLE
diff --git a/include/typeindex b/include/typeindex
index d1b750d..e3132c8 100644
--- a/include/typeindex
+++ b/include/typeindex
@@ -51,12 +51,6 @@
 #include <typeinfo>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iosfwd>
-#  include <new>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 #include <compare>
 
@@ -123,4 +117,10 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iosfwd>
+#  include <new>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_TYPEINDEX
diff --git a/include/unordered_map b/include/unordered_map
index e0d659a..38de4d8 100644
--- a/include/unordered_map
+++ b/include/unordered_map
@@ -531,12 +531,6 @@
 #include <tuple>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <bit>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -2625,4 +2619,10 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <bit>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_UNORDERED_MAP
diff --git a/include/unordered_set b/include/unordered_set
index e294885..2440450 100644
--- a/include/unordered_set
+++ b/include/unordered_set
@@ -474,11 +474,6 @@
 #include <__utility/forward.h>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <functional>
-#  include <iterator>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -1801,4 +1796,9 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <functional>
+#  include <iterator>
+#endif
+
 #endif // _LIBCPP_UNORDERED_SET
diff --git a/include/utility b/include/utility
index d3a9aa4..41bcaf3 100644
--- a/include/utility
+++ b/include/utility
@@ -248,10 +248,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <iosfwd>
-#endif
-
 // standard-mandated includes
 #include <compare>
 #include <initializer_list>
@@ -260,4 +256,8 @@
 #  pragma GCC system_header
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <iosfwd>
+#endif
+
 #endif // _LIBCPP_UTILITY
diff --git a/include/valarray b/include/valarray
index b47807c..ff745d3 100644
--- a/include/valarray
+++ b/include/valarray
@@ -360,11 +360,6 @@
 #include <new>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <functional>
-#endif
-
 // standard-mandated includes
 #include <initializer_list>
 
@@ -4932,4 +4927,9 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <functional>
+#endif
+
 #endif // _LIBCPP_VALARRAY
diff --git a/include/variant b/include/variant
index a4a3c5b..f1d36e2 100644
--- a/include/variant
+++ b/include/variant
@@ -228,11 +228,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <typeinfo>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 #include <compare>
 
@@ -1818,4 +1813,9 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <typeinfo>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_VARIANT
diff --git a/include/vector b/include/vector
index 0786a51..8b27eaa 100644
--- a/include/vector
+++ b/include/vector
@@ -307,12 +307,6 @@
 #include <type_traits>
 #include <version>
 
-#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
-#  include <algorithm>
-#  include <typeinfo>
-#  include <utility>
-#endif
-
 // standard-mandated includes
 
 // [iterator.range]
@@ -3324,4 +3318,10 @@
 
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <typeinfo>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_VECTOR