Commit bd680139d0

Andrew Kelley <andrew@ziglang.org>
2022-07-02 01:31:47
update libcxx to llvm 14.0.6
1 parent c89dd15
Changed files (583)
lib
libcxx
include
__algorithm
__bit
__charconv
__chrono
__compare
__concepts
__coroutine
__filesystem
__format
__functional
__iterator
__memory
__numeric
__random
__ranges
__support
__thread
__utility
__variant
experimental
ext
src
src
lib/libcxx/include/__algorithm/adjacent_find.h
@@ -10,17 +10,14 @@
 #ifndef _LIBCPP___ALGORITHM_ADJACENT_FIND_H
 #define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _ForwardIterator, class _BinaryPredicate>
@@ -46,6 +43,4 @@ adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_ADJACENT_FIND_H
lib/libcxx/include/__algorithm/all_of.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Predicate>
@@ -32,6 +29,4 @@ all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_ALL_OF_H
lib/libcxx/include/__algorithm/any_of.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Predicate>
@@ -32,6 +29,4 @@ any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_ANY_OF_H
lib/libcxx/include/__algorithm/binary_search.h
@@ -9,19 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_BINARY_SEARCH_H
 #define _LIBCPP___ALGORITHM_BINARY_SEARCH_H
 
-#include <__config>
 #include <__algorithm/comp.h>
-#include <__algorithm/lower_bound.h>
 #include <__algorithm/comp_ref_type.h>
+#include <__algorithm/lower_bound.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _ForwardIterator, class _Tp>
@@ -53,9 +50,6 @@ binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __va
                              __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
 }
 
-
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_BINARY_SEARCH_H
lib/libcxx/include/__algorithm/clamp.h
@@ -9,21 +9,17 @@
 #ifndef _LIBCPP___ALGORITHM_CLAMP_H
 #define _LIBCPP___ALGORITHM_CLAMP_H
 
+#include <__algorithm/comp.h>
 #include <__config>
 #include <__debug>
-#include <__algorithm/comp.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
-// clamp
 template<class _Tp, class _Compare>
 _LIBCPP_NODISCARD_EXT inline
 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
@@ -47,6 +43,4 @@ clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_CLAMP_H
lib/libcxx/include/__algorithm/comp.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // I'd like to replace these with _VSTD::equal_to<void>, but can't because:
@@ -92,6 +89,4 @@ struct __less<_T1, const _T1>
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COMP_H
lib/libcxx/include/__algorithm/comp_ref_type.h
@@ -10,15 +10,16 @@
 #define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
 
 #include <__config>
-#include <type_traits>
+
+#ifdef _LIBCPP_DEBUG
+#  include <__debug>
+#  include <__utility/declval.h>
+#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #ifdef _LIBCPP_DEBUG
@@ -27,11 +28,11 @@ template <class _Compare>
 struct __debug_less
 {
     _Compare &__comp_;
-    _LIBCPP_CONSTEXPR_AFTER_CXX17
+    _LIBCPP_CONSTEXPR_AFTER_CXX11
     __debug_less(_Compare& __c) : __comp_(__c) {}
 
     template <class _Tp, class _Up>
-    _LIBCPP_CONSTEXPR_AFTER_CXX17
+    _LIBCPP_CONSTEXPR_AFTER_CXX11
     bool operator()(const _Tp& __x,  const _Up& __y)
     {
         bool __r = __comp_(__x, __y);
@@ -41,7 +42,7 @@ struct __debug_less
     }
 
     template <class _Tp, class _Up>
-    _LIBCPP_CONSTEXPR_AFTER_CXX17
+    _LIBCPP_CONSTEXPR_AFTER_CXX11
     bool operator()(_Tp& __x,  _Up& __y)
     {
         bool __r = __comp_(__x, __y);
@@ -51,7 +52,7 @@ struct __debug_less
     }
 
     template <class _LHS, class _RHS>
-    _LIBCPP_CONSTEXPR_AFTER_CXX17
+    _LIBCPP_CONSTEXPR_AFTER_CXX11
     inline _LIBCPP_INLINE_VISIBILITY
     decltype((void)declval<_Compare&>()(
         declval<_LHS &>(), declval<_RHS &>()))
@@ -61,7 +62,7 @@ struct __debug_less
     }
 
     template <class _LHS, class _RHS>
-    _LIBCPP_CONSTEXPR_AFTER_CXX17
+    _LIBCPP_CONSTEXPR_AFTER_CXX11
     inline _LIBCPP_INLINE_VISIBILITY
     void __do_compare_assert(long, _LHS &, _RHS &) {}
 };
@@ -73,15 +74,12 @@ struct __comp_ref_type {
   // Pass the comparator by lvalue reference. Or in debug mode, using a
   // debugging wrapper that stores a reference.
 #ifndef _LIBCPP_DEBUG
-  typedef typename add_lvalue_reference<_Comp>::type type;
+  typedef _Comp& type;
 #else
   typedef __debug_less<_Comp> type;
 #endif
 };
 
-
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
lib/libcxx/include/__algorithm/copy.h
@@ -9,8 +9,8 @@
 #ifndef _LIBCPP___ALGORITHM_COPY_H
 #define _LIBCPP___ALGORITHM_COPY_H
 
-#include <__config>
 #include <__algorithm/unwrap_iter.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <cstring>
 #include <type_traits>
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // copy
@@ -77,6 +74,4 @@ copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COPY_H
lib/libcxx/include/__algorithm/copy_backward.h
@@ -9,8 +9,8 @@
 #ifndef _LIBCPP___ALGORITHM_COPY_BACKWARD_H
 #define _LIBCPP___ALGORITHM_COPY_BACKWARD_H
 
-#include <__config>
 #include <__algorithm/unwrap_iter.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <cstring>
 #include <type_traits>
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _BidirectionalIterator, class _OutputIterator>
@@ -79,6 +76,4 @@ copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COPY_BACKWARD_H
lib/libcxx/include/__algorithm/copy_if.h
@@ -10,18 +10,11 @@
 #define _LIBCPP___ALGORITHM_COPY_IF_H
 
 #include <__config>
-#include <__algorithm/unwrap_iter.h>
-#include <__iterator/iterator_traits.h>
-#include <cstring>
-#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 _InputIterator, class _OutputIterator, class _Predicate>
@@ -43,6 +36,4 @@ copy_if(_InputIterator __first, _InputIterator __last,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COPY_IF_H
lib/libcxx/include/__algorithm/copy_n.h
@@ -9,20 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_COPY_N_H
 #define _LIBCPP___ALGORITHM_COPY_N_H
 
-#include <__config>
 #include <__algorithm/copy.h>
-#include <__algorithm/unwrap_iter.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
-#include <cstring>
 #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 _InputIterator, class _Size, class _OutputIterator>
@@ -60,13 +55,12 @@ typename enable_if
 >::type
 copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
 {
+    typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
     typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
     _IntegralSize __n = __orig_n;
-    return _VSTD::copy(__first, __first + __n, __result);
+    return _VSTD::copy(__first, __first + difference_type(__n), __result);
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COPY_N_H
lib/libcxx/include/__algorithm/count.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Tp>
@@ -35,6 +32,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_C
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COUNT_H
lib/libcxx/include/__algorithm/count_if.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Predicate>
@@ -35,6 +32,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_C
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_COUNT_IF_H
lib/libcxx/include/__algorithm/equal.h
@@ -10,18 +10,15 @@
 #ifndef _LIBCPP___ALGORITHM_EQUAL_H
 #define _LIBCPP___ALGORITHM_EQUAL_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
+#include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
-#include <iterator> // FIXME: replace with <__iterator/distance.h> when it lands
 
 #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 _InputIterator1, class _InputIterator2, class _BinaryPredicate>
@@ -60,14 +57,14 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random
   if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
     return false;
   return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2,
-                      typename add_lvalue_reference<_BinaryPredicate>::type>(__first1, __last1, __first2, __pred);
+                      _BinaryPredicate&>(__first1, __last1, __first2, __pred);
 }
 
 template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
 equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
       _BinaryPredicate __pred) {
-  return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type>(
+  return _VSTD::__equal<_BinaryPredicate&>(
       __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(),
       typename iterator_traits<_InputIterator2>::iterator_category());
 }
@@ -85,6 +82,4 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_EQUAL_H
lib/libcxx/include/__algorithm/equal_range.h
@@ -9,21 +9,18 @@
 #ifndef _LIBCPP___ALGORITHM_EQUAL_RANGE_H
 #define _LIBCPP___ALGORITHM_EQUAL_RANGE_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/half_positive.h>
 #include <__algorithm/lower_bound.h>
 #include <__algorithm/upper_bound.h>
+#include <__config>
 #include <iterator>
 
 #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 _Compare, class _ForwardIterator, class _Tp>
@@ -82,6 +79,4 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_EQUAL_RANGE_H
lib/libcxx/include/__algorithm/fill.h
@@ -9,8 +9,8 @@
 #ifndef _LIBCPP___ALGORITHM_FILL_H
 #define _LIBCPP___ALGORITHM_FILL_H
 
-#include <__config>
 #include <__algorithm/fill_n.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <type_traits>
 
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator, class _Tp>
@@ -50,6 +47,4 @@ fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FILL_H
lib/libcxx/include/__algorithm/fill_n.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _OutputIterator, class _Size, class _Tp>
@@ -42,6 +39,4 @@ fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FILL_N_H
lib/libcxx/include/__algorithm/find.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Tp>
@@ -32,6 +29,4 @@ find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FIND_H
lib/libcxx/include/__algorithm/find_end.h
@@ -10,18 +10,14 @@
 #ifndef _LIBCPP___ALGORITHM_FIND_END_OF_H
 #define _LIBCPP___ALGORITHM_FIND_END_OF_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
@@ -99,14 +95,16 @@ template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAcc
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(
     _RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
     _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) {
+  typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
+  typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
   // Take advantage of knowing source and pattern lengths.  Stop short when source is smaller than pattern
-  typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2;
+  _D2 __len2 = __last2 - __first2;
   if (__len2 == 0)
     return __last1;
-  typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1;
+  _D1 __len1 = __last1 - __first1;
   if (__len1 < __len2)
     return __last1;
-  const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here
+  const _RandomAccessIterator1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
   _RandomAccessIterator1 __l1 = __last1;
   _RandomAccessIterator2 __l2 = __last2;
   --__l2;
@@ -134,7 +132,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
          _BinaryPredicate __pred) {
-  return _VSTD::__find_end<typename add_lvalue_reference<_BinaryPredicate>::type>(
+  return _VSTD::__find_end<_BinaryPredicate&>(
       __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
       typename iterator_traits<_ForwardIterator2>::iterator_category());
 }
@@ -149,6 +147,4 @@ find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FIND_END_OF_H
lib/libcxx/include/__algorithm/find_first_of.h
@@ -10,17 +10,14 @@
 #ifndef _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
 #define _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.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, class _BinaryPredicate>
@@ -52,6 +49,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_C
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
lib/libcxx/include/__algorithm/find_if.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Predicate>
@@ -32,6 +29,4 @@ find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FIND_IF_H
lib/libcxx/include/__algorithm/find_if_not.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Predicate>
@@ -32,6 +29,4 @@ find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FIND_IF_NOT_H
lib/libcxx/include/__algorithm/for_each.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Function>
@@ -32,6 +29,4 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Function for_eac
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FOR_EACH_H
lib/libcxx/include/__algorithm/for_each_n.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -42,6 +39,4 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator fo
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_FOR_EACH_N_H
lib/libcxx/include/__algorithm/generate.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator, class _Generator>
@@ -31,6 +28,4 @@ generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_GENERATE_H
lib/libcxx/include/__algorithm/generate_n.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _OutputIterator, class _Size, class _Generator>
@@ -35,6 +32,4 @@ generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_GENERATE_N_H
lib/libcxx/include/__algorithm/half_positive.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // Perform division by two quickly for positive integers (llvm.org/PR39129)
@@ -49,6 +46,4 @@ __half_positive(_Tp __value)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_HALF_POSITIVE_H
lib/libcxx/include/__algorithm/in_in_out_result.h
@@ -0,0 +1,54 @@
+// -*- 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___ALGORITHM_IN_IN_OUT_RESULT_H
+#define _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+
+template <class _I1, class _I2, class _O1>
+struct in_in_out_result {
+  [[no_unique_address]] _I1 in1;
+  [[no_unique_address]] _I2 in2;
+  [[no_unique_address]] _O1 out;
+
+  template <class _II1, class _II2, class _OO1>
+    requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2> && convertible_to<const _O1&, _OO1>
+  _LIBCPP_HIDE_FROM_ABI constexpr
+  operator in_in_out_result<_II1, _II2, _OO1>() const& {
+    return {in1, in2, out};
+  }
+
+  template <class _II1, class _II2, class _OO1>
+    requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2> && convertible_to<_O1, _OO1>
+  _LIBCPP_HIDE_FROM_ABI constexpr
+  operator in_in_out_result<_II1, _II2, _OO1>() && {
+    return {_VSTD::move(in1), _VSTD::move(in2), _VSTD::move(out)};
+  }
+};
+
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H
lib/libcxx/include/__algorithm/in_in_result.h
@@ -0,0 +1,51 @@
+// -*- 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___ALGORITHM_IN_IN_RESULT_H
+#define _LIBCPP___ALGORITHM_IN_IN_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace ranges {
+
+template <class _I1, class _I2>
+struct in_in_result {
+  [[no_unique_address]] _I1 in1;
+  [[no_unique_address]] _I2 in2;
+
+  template <class _II1, class _II2>
+    requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2>
+   _LIBCPP_HIDE_FROM_ABI constexpr
+   operator in_in_result<_II1, _II2>() const & {
+    return {in1, in2};
+  }
+
+  template <class _II1, class _II2>
+    requires convertible_to<_I1, _II1> && convertible_to<_I2, _II2>
+  _LIBCPP_HIDE_FROM_ABI constexpr
+  operator in_in_result<_II1, _II2>() && { return {_VSTD::move(in1), _VSTD::move(in2)}; }
+};
+
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___ALGORITHM_IN_IN_RESULT_H
lib/libcxx/include/__algorithm/in_out_result.h
@@ -0,0 +1,54 @@
+// -*- 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___ALGORITHM_IN_OUT_RESULT_H
+#define _LIBCPP___ALGORITHM_IN_OUT_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+
+template<class _InputIterator, class _OutputIterator>
+struct in_out_result {
+  [[no_unique_address]] _InputIterator in;
+  [[no_unique_address]] _OutputIterator out;
+
+  template <class _InputIterator2, class _OutputIterator2>
+    requires convertible_to<const _InputIterator&, _InputIterator2> && convertible_to<const _OutputIterator&,
+                           _OutputIterator2>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() const & {
+    return {in, out};
+  }
+
+  template <class _InputIterator2, class _OutputIterator2>
+    requires convertible_to<_InputIterator, _InputIterator2> && convertible_to<_OutputIterator, _OutputIterator2>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr operator in_out_result<_InputIterator2, _OutputIterator2>() && {
+    return {_VSTD::move(in), _VSTD::move(out)};
+  }
+};
+
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___ALGORITHM_IN_OUT_RESULT_H
lib/libcxx/include/__algorithm/includes.h
@@ -9,18 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_INCLUDES_H
 #define _LIBCPP___ALGORITHM_INCLUDES_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _InputIterator1, class _InputIterator2>
@@ -62,6 +59,4 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_INCLUDES_H
lib/libcxx/include/__algorithm/inplace_merge.h
@@ -9,14 +9,14 @@
 #ifndef _LIBCPP___ALGORITHM_INPLACE_MERGE_H
 #define _LIBCPP___ALGORITHM_INPLACE_MERGE_H
 
-#include <__config>
-#include <__algorithm/comp_ref_type.h>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
 #include <__algorithm/lower_bound.h>
 #include <__algorithm/min.h>
 #include <__algorithm/move.h>
 #include <__algorithm/rotate.h>
 #include <__algorithm/upper_bound.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 #include <memory>
lib/libcxx/include/__algorithm/is_heap.h
@@ -9,18 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_IS_HEAP_H
 #define _LIBCPP___ALGORITHM_IS_HEAP_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
 #include <__algorithm/is_heap_until.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _RandomAccessIterator, class _Compare>
@@ -29,7 +27,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
-    return _VSTD::is_heap_until(__first, __last, __comp) == __last;
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp) == __last;
 }
 
 template<class _RandomAccessIterator>
@@ -43,6 +42,4 @@ is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_IS_HEAP_H
lib/libcxx/include/__algorithm/is_heap_until.h
@@ -9,22 +9,20 @@
 #ifndef _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H
 #define _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _RandomAccessIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
-is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+template <class _Compare, class _RandomAccessIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
+__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
     typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
     difference_type __len = __last - __first;
@@ -49,17 +47,21 @@ is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp
     return __last;
 }
 
+template <class _RandomAccessIterator, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
+is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return _VSTD::__is_heap_until<_Comp_ref>(__first, __last, __comp);
+}
+
 template<class _RandomAccessIterator>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_RandomAccessIterator
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
 is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
 {
-    return _VSTD::is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+    return _VSTD::__is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_IS_HEAP_UNTIL_H
lib/libcxx/include/__algorithm/is_partitioned.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Predicate>
@@ -38,6 +35,4 @@ is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_IS_PARTITIONED_H
lib/libcxx/include/__algorithm/is_permutation.h
@@ -12,17 +12,14 @@
 
 #include <__algorithm/comp.h>
 #include <__config>
+#include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/next.h>
-#include <iterator> // FIXME: replace with <__iterator/distance.h> when it lands
 
 #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, class _BinaryPredicate>
@@ -136,15 +133,14 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __is_permutation(_RandomAccessIterator1 __fir
   if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
     return false;
   return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2,
-                               typename add_lvalue_reference<_BinaryPredicate>::type>(__first1, __last1, __first2,
-                                                                                      __pred);
+                               _BinaryPredicate&>(__first1, __last1, __first2, __pred);
 }
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
                _ForwardIterator2 __last2, _BinaryPredicate __pred) {
-  return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type>(
+  return _VSTD::__is_permutation<_BinaryPredicate&>(
       __first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
       typename iterator_traits<_ForwardIterator2>::iterator_category());
 }
@@ -163,6 +159,4 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_IS_PERMUTATION_H
lib/libcxx/include/__algorithm/is_sorted.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___ALGORITHM_IS_SORTED_H
 
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
 #include <__algorithm/is_sorted_until.h>
 #include <__config>
 #include <__iterator/iterator_traits.h>
@@ -18,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator, class _Compare>
@@ -29,7 +27,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
-    return _VSTD::is_sorted_until(__first, __last, __comp) == __last;
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return _VSTD::__is_sorted_until<_Comp_ref>(__first, __last, __comp) == __last;
 }
 
 template<class _ForwardIterator>
@@ -43,6 +42,4 @@ is_sorted(_ForwardIterator __first, _ForwardIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_IS_SORTED_H
lib/libcxx/include/__algorithm/is_sorted_until.h
@@ -9,22 +9,20 @@
 #ifndef _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
 #define _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _ForwardIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
-is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+template <class _Compare, class _ForwardIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
+__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
     if (__first != __last)
     {
@@ -39,10 +37,16 @@ is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __co
     return __last;
 }
 
+template <class _ForwardIterator, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
+is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return _VSTD::__is_sorted_until<_Comp_ref>(__first, __last, __comp);
+}
+
 template<class _ForwardIterator>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_ForwardIterator
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
 {
     return _VSTD::is_sorted_until(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
@@ -50,6 +54,4 @@ is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_IS_SORTED_UNTIL_H
lib/libcxx/include/__algorithm/iter_swap.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator1, class _ForwardIterator2>
@@ -32,6 +29,4 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void iter_swap(_F
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_ITER_SWAP_H
lib/libcxx/include/__algorithm/lexicographical_compare.h
@@ -9,18 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
 #define _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _InputIterator1, class _InputIterator2>
@@ -63,6 +60,4 @@ lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
lib/libcxx/include/__algorithm/lower_bound.h
@@ -9,18 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_LOWER_BOUND_H
 #define _LIBCPP___ALGORITHM_LOWER_BOUND_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/half_positive.h>
+#include <__config>
 #include <iterator>
 
 #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 _Compare, class _ForwardIterator, class _Tp>
@@ -51,8 +48,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
-    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
-    return _VSTD::__lower_bound<_Comp_ref>(__first, __last, __value_, __comp);
+    return _VSTD::__lower_bound<_Compare&>(__first, __last, __value_, __comp);
 }
 
 template <class _ForwardIterator, class _Tp>
@@ -67,6 +63,4 @@ lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_LOWER_BOUND_H
lib/libcxx/include/__algorithm/make_heap.h
@@ -9,19 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_MAKE_HEAP_H
 #define _LIBCPP___ALGORITHM_MAKE_HEAP_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/sift_down.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _RandomAccessIterator>
@@ -35,7 +32,7 @@ __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compar
         // start from the first parent, there is no need to consider children
         for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start)
         {
-            _VSTD::__sift_down<_Compare>(__first, __last, __comp, __n, __first + __start);
+            _VSTD::__sift_down<_Compare>(__first, __comp, __n, __first + __start);
         }
     }
 }
@@ -59,6 +56,4 @@ make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MAKE_HEAP_H
lib/libcxx/include/__algorithm/max.h
@@ -9,9 +9,10 @@
 #ifndef _LIBCPP___ALGORITHM_MAX_H
 #define _LIBCPP___ALGORITHM_MAX_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
 #include <__algorithm/max_element.h>
+#include <__config>
 #include <initializer_list>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -49,7 +50,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp
 max(initializer_list<_Tp> __t, _Compare __comp)
 {
-    return *_VSTD::max_element(__t.begin(), __t.end(), __comp);
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return *_VSTD::__max_element<_Comp_ref>(__t.begin(), __t.end(), __comp);
 }
 
 template<class _Tp>
lib/libcxx/include/__algorithm/max_element.h
@@ -9,24 +9,20 @@
 #ifndef _LIBCPP___ALGORITHM_MAX_ELEMENT_H
 #define _LIBCPP___ALGORITHM_MAX_ELEMENT_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _ForwardIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-_ForwardIterator
-max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+template <class _Compare, class _ForwardIterator>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
+__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
     static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
         "std::max_element requires a ForwardIterator");
@@ -40,11 +36,17 @@ max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
     return __first;
 }
 
+template <class _ForwardIterator, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
+max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return _VSTD::__max_element<_Comp_ref>(__first, __last, __comp);
+}
+
 
 template <class _ForwardIterator>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-_ForwardIterator
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
 max_element(_ForwardIterator __first, _ForwardIterator __last)
 {
     return _VSTD::max_element(__first, __last,
@@ -53,6 +55,4 @@ max_element(_ForwardIterator __first, _ForwardIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MAX_ELEMENT_H
lib/libcxx/include/__algorithm/merge.h
@@ -9,19 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_MERGE_H
 #define _LIBCPP___ALGORITHM_MERGE_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/copy.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
@@ -71,6 +68,4 @@ merge(_InputIterator1 __first1, _InputIterator1 __last1,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MERGE_H
lib/libcxx/include/__algorithm/min.h
@@ -9,9 +9,10 @@
 #ifndef _LIBCPP___ALGORITHM_MIN_H
 #define _LIBCPP___ALGORITHM_MIN_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
 #include <__algorithm/min_element.h>
+#include <__config>
 #include <initializer_list>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -49,7 +50,8 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp
 min(initializer_list<_Tp> __t, _Compare __comp)
 {
-    return *_VSTD::min_element(__t.begin(), __t.end(), __comp);
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return *_VSTD::__min_element<_Comp_ref>(__t.begin(), __t.end(), __comp);
 }
 
 template<class _Tp>
lib/libcxx/include/__algorithm/min_element.h
@@ -9,24 +9,20 @@
 #ifndef _LIBCPP___ALGORITHM_MIN_ELEMENT_H
 #define _LIBCPP___ALGORITHM_MIN_ELEMENT_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _ForwardIterator, class _Compare>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-_ForwardIterator
-min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+template <class _Compare, class _ForwardIterator>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
+__min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
     static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
         "std::min_element requires a ForwardIterator");
@@ -40,10 +36,16 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
     return __first;
 }
 
+template <class _ForwardIterator, class _Compare>
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
+min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+    return _VSTD::__min_element<_Comp_ref>(__first, __last, __comp);
+}
+
 template <class _ForwardIterator>
-_LIBCPP_NODISCARD_EXT inline
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-_ForwardIterator
+_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator
 min_element(_ForwardIterator __first, _ForwardIterator __last)
 {
     return _VSTD::min_element(__first, __last,
@@ -52,6 +54,4 @@ min_element(_ForwardIterator __first, _ForwardIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MIN_ELEMENT_H
lib/libcxx/include/__algorithm/minmax.h
@@ -9,19 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_MINMAX_H
 #define _LIBCPP___ALGORITHM_MINMAX_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <initializer_list>
 #include <utility>
 
-
 #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, class _Compare>
@@ -96,6 +92,4 @@ minmax(initializer_list<_Tp> __t)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MINMAX_H
lib/libcxx/include/__algorithm/minmax_element.h
@@ -9,8 +9,8 @@
 #ifndef _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
 #define _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <utility>
 
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator, class _Compare>
@@ -85,6 +82,4 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MINMAX_ELEMENT_H
lib/libcxx/include/__algorithm/mismatch.h
@@ -10,8 +10,8 @@
 #ifndef _LIBCPP___ALGORITHM_MISMATCH_H
 #define _LIBCPP___ALGORITHM_MISMATCH_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <utility>
 
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
@@ -67,6 +64,4 @@ _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MISMATCH_H
lib/libcxx/include/__algorithm/move.h
@@ -9,20 +9,17 @@
 #ifndef _LIBCPP___ALGORITHM_MOVE_H
 #define _LIBCPP___ALGORITHM_MOVE_H
 
-#include <__config>
 #include <__algorithm/unwrap_iter.h>
+#include <__config>
 #include <__utility/move.h>
 #include <cstring>
-#include <utility>
 #include <type_traits>
+#include <utility>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // move
@@ -78,6 +75,4 @@ move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MOVE_H
lib/libcxx/include/__algorithm/move_backward.h
@@ -9,19 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
 #define _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
 
-#include <__config>
 #include <__algorithm/unwrap_iter.h>
+#include <__config>
 #include <cstring>
-#include <utility>
 #include <type_traits>
+#include <utility>
 
 #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 _InputIterator, class _OutputIterator>
@@ -79,6 +76,4 @@ move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
lib/libcxx/include/__algorithm/next_permutation.h
@@ -9,10 +9,10 @@
 #ifndef _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
 #define _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/reverse.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Compare, class _BidirectionalIterator>
@@ -72,6 +69,4 @@ next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H
lib/libcxx/include/__algorithm/none_of.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _Predicate>
@@ -32,6 +29,4 @@ none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_NONE_OF_H
lib/libcxx/include/__algorithm/nth_element.h
@@ -9,20 +9,21 @@
 #ifndef _LIBCPP___ALGORITHM_NTH_ELEMENT_H
 #define _LIBCPP___ALGORITHM_NTH_ELEMENT_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/sort.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 
+#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
+#  include <__algorithm/shuffle.h>
+#endif
+
 #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 _Compare, class _RandomAccessIterator>
@@ -225,8 +226,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 void
 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
 {
-    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
-    _VSTD::__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
+  _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
+  typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+  _VSTD::__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
+  _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __nth);
+  if (__nth != __last) {
+    _LIBCPP_DEBUG_RANDOMIZE_RANGE(++__nth, __last);
+  }
 }
 
 template <class _RandomAccessIterator>
@@ -239,6 +245,4 @@ nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomA
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_NTH_ELEMENT_H
lib/libcxx/include/__algorithm/partial_sort.h
@@ -9,29 +9,32 @@
 #ifndef _LIBCPP___ALGORITHM_PARTIAL_SORT_H
 #define _LIBCPP___ALGORITHM_PARTIAL_SORT_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/make_heap.h>
 #include <__algorithm/sift_down.h>
 #include <__algorithm/sort_heap.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 
+#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
+#  include <__algorithm/shuffle.h>
+#endif
+
 #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 _Compare, class _RandomAccessIterator>
 _LIBCPP_CONSTEXPR_AFTER_CXX17 void
 __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
-             _Compare __comp)
+               _Compare __comp)
 {
+    if (__first == __middle)
+        return;
     _VSTD::__make_heap<_Compare>(__first, __middle, __comp);
     typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
     for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)
@@ -39,7 +42,7 @@ __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _R
         if (__comp(*__i, *__first))
         {
             swap(*__i, *__first);
-            _VSTD::__sift_down<_Compare>(__first, __middle, __comp, __len, __first);
+            _VSTD::__sift_down<_Compare>(__first, __comp, __len, __first);
         }
     }
     _VSTD::__sort_heap<_Compare>(__first, __middle, __comp);
@@ -51,8 +54,10 @@ void
 partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
              _Compare __comp)
 {
-    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
-    _VSTD::__partial_sort<_Comp_ref>(__first, __middle, __last, __comp);
+  _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
+  typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+  _VSTD::__partial_sort<_Comp_ref>(__first, __middle, __last, __comp);
+  _LIBCPP_DEBUG_RANDOMIZE_RANGE(__middle, __last);
 }
 
 template <class _RandomAccessIterator>
@@ -61,11 +66,9 @@ void
 partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
 {
     _VSTD::partial_sort(__first, __middle, __last,
-                       __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+                        __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_H
lib/libcxx/include/__algorithm/partial_sort_copy.h
@@ -9,22 +9,18 @@
 #ifndef _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
 #define _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/make_heap.h>
 #include <__algorithm/sift_down.h>
 #include <__algorithm/sort_heap.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
 
 #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 _Compare, class _InputIterator, class _RandomAccessIterator>
@@ -43,7 +39,7 @@ __partial_sort_copy(_InputIterator __first, _InputIterator __last,
             if (__comp(*__first, *__result_first))
             {
                 *__result_first = *__first;
-                _VSTD::__sift_down<_Compare>(__result_first, __r, __comp, __len, __result_first);
+                _VSTD::__sift_down<_Compare>(__result_first, __comp, __len, __result_first);
             }
         _VSTD::__sort_heap<_Compare>(__result_first, __r, __comp);
     }
@@ -72,6 +68,4 @@ partial_sort_copy(_InputIterator __first, _InputIterator __last,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H
lib/libcxx/include/__algorithm/partition.h
@@ -12,16 +12,11 @@
 #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)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Predicate, class _ForwardIterator>
@@ -77,12 +72,10 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    return _VSTD::__partition<typename add_lvalue_reference<_Predicate>::type>
-                            (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+    return _VSTD::__partition<_Predicate&>(
+        __first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_PARTITION_H
lib/libcxx/include/__algorithm/partition_copy.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _OutputIterator1,
@@ -47,6 +44,4 @@ partition_copy(_InputIterator __first, _InputIterator __last,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_PARTITION_COPY_H
lib/libcxx/include/__algorithm/partition_point.h
@@ -9,17 +9,14 @@
 #ifndef _LIBCPP___ALGORITHM_PARTITION_POINT_H
 #define _LIBCPP___ALGORITHM_PARTITION_POINT_H
 
-#include <__config>
 #include <__algorithm/half_positive.h>
+#include <__config>
 #include <iterator>
 
 #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 _ForwardIterator, class _Predicate>
@@ -46,6 +43,4 @@ partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_PARTITION_POINT_H
lib/libcxx/include/__algorithm/pop_heap.h
@@ -9,10 +9,10 @@
 #ifndef _LIBCPP___ALGORITHM_POP_HEAP_H
 #define _LIBCPP___ALGORITHM_POP_HEAP_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/sift_down.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Compare, class _RandomAccessIterator>
@@ -34,7 +31,7 @@ __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare
     if (__len > 1)
     {
         swap(*__first, *--__last);
-        _VSTD::__sift_down<_Compare>(__first, __last, __comp, __len - 1, __first);
+        _VSTD::__sift_down<_Compare>(__first, __comp, __len - 1, __first);
     }
 }
 
@@ -57,6 +54,4 @@ pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_POP_HEAP_H
lib/libcxx/include/__algorithm/prev_permutation.h
@@ -9,10 +9,10 @@
 #ifndef _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
 #define _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/reverse.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Compare, class _BidirectionalIterator>
@@ -72,6 +69,4 @@ prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_PREV_PERMUTATION_H
lib/libcxx/include/__algorithm/push_heap.h
@@ -9,9 +9,9 @@
 #ifndef _LIBCPP___ALGORITHM_PUSH_HEAP_H
 #define _LIBCPP___ALGORITHM_PUSH_HEAP_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/move.h>
 
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Compare, class _RandomAccessIterator>
@@ -70,6 +67,4 @@ push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_PUSH_HEAP_H
lib/libcxx/include/__algorithm/remove.h
@@ -9,18 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_REMOVE_H
 #define _LIBCPP___ALGORITHM_REMOVE_H
 
-#include <__config>
 #include <__algorithm/find.h>
 #include <__algorithm/find_if.h>
+#include <__config>
 #include <__utility/move.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 _ForwardIterator, class _Tp>
@@ -45,6 +42,4 @@ remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REMOVE_H
lib/libcxx/include/__algorithm/remove_copy.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _OutputIterator, class _Tp>
@@ -38,6 +35,4 @@ remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __res
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REMOVE_COPY_H
lib/libcxx/include/__algorithm/remove_copy_if.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _OutputIterator, class _Predicate>
@@ -38,6 +35,4 @@ remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REMOVE_COPY_IF_H
lib/libcxx/include/__algorithm/remove_if.h
@@ -9,26 +9,21 @@
 #ifndef _LIBCPP___ALGORITHM_REMOVE_IF_H
 #define _LIBCPP___ALGORITHM_REMOVE_IF_H
 
-#include <__config>
 #include <__algorithm/find_if.h>
+#include <__config>
 #include <utility>
-#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 _ForwardIterator, class _Predicate>
 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type>
-                           (__first, __last, __pred);
+    __first = _VSTD::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
     if (__first != __last)
     {
         _ForwardIterator __i = __first;
@@ -46,6 +41,4 @@ remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REMOVE_IF_H
lib/libcxx/include/__algorithm/replace.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator, class _Tp>
@@ -32,6 +29,4 @@ replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_valu
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REPLACE_H
lib/libcxx/include/__algorithm/replace_copy.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _OutputIterator, class _Tp>
@@ -36,6 +33,4 @@ replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __re
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REPLACE_COPY_H
lib/libcxx/include/__algorithm/replace_copy_if.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp>
@@ -36,6 +33,4 @@ replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator _
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REPLACE_COPY_IF_H
lib/libcxx/include/__algorithm/replace_if.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator, class _Predicate, class _Tp>
@@ -32,6 +29,4 @@ replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REPLACE_IF_H
lib/libcxx/include/__algorithm/reverse.h
@@ -9,17 +9,14 @@
 #ifndef _LIBCPP___ALGORITHM_REVERSE_H
 #define _LIBCPP___ALGORITHM_REVERSE_H
 
-#include <__config>
 #include <__algorithm/iter_swap.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _BidirectionalIterator>
@@ -56,6 +53,4 @@ reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REVERSE_H
lib/libcxx/include/__algorithm/reverse_copy.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _BidirectionalIterator, class _OutputIterator>
@@ -32,6 +29,4 @@ reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _Out
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_REVERSE_COPY_H
lib/libcxx/include/__algorithm/rotate.h
@@ -23,9 +23,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator>
@@ -200,6 +197,4 @@ rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __l
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_ROTATE_H
lib/libcxx/include/__algorithm/rotate_copy.h
@@ -9,18 +9,13 @@
 #ifndef _LIBCPP___ALGORITHM_ROTATE_COPY_H
 #define _LIBCPP___ALGORITHM_ROTATE_COPY_H
 
-#include <__config>
 #include <__algorithm/copy.h>
-#include <iterator>
-#include <type_traits>
+#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
 
 template <class _ForwardIterator, class _OutputIterator>
@@ -33,6 +28,4 @@ rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterato
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_ROTATE_COPY_H
lib/libcxx/include/__algorithm/sample.h
@@ -9,8 +9,9 @@
 #ifndef _LIBCPP___ALGORITHM_SAMPLE_H
 #define _LIBCPP___ALGORITHM_SAMPLE_H
 
-#include <__config>
 #include <__algorithm/min.h>
+#include <__config>
+#include <__debug>
 #include <__random/uniform_int_distribution.h>
 #include <iterator>
 
lib/libcxx/include/__algorithm/search.h
@@ -13,16 +13,12 @@
 #include <__algorithm/comp.h>
 #include <__config>
 #include <__iterator/iterator_traits.h>
-#include <type_traits>
 #include <utility>
 
 #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 _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
@@ -72,7 +68,7 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Rando
   const _D1 __len1 = __last1 - __first1;
   if (__len1 < __len2)
     return _VSTD::make_pair(__last1, __last1);
-  const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
+  const _RandomAccessIterator1 __s = __last1 - _D1(__len2 - 1); // Start of pattern match can't go beyond here
 
   while (true) {
     while (true) {
@@ -87,7 +83,7 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Rando
     _RandomAccessIterator2 __m2 = __first2;
     while (true) {
       if (++__m2 == __last2)
-        return _VSTD::make_pair(__first1, __first1 + __len2);
+        return _VSTD::make_pair(__first1, __first1 + _D1(__len2));
       ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
       if (!__pred(*__m1, *__m2)) {
         ++__first1;
@@ -101,7 +97,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
        _BinaryPredicate __pred) {
-  return _VSTD::__search<typename add_lvalue_reference<_BinaryPredicate>::type>(
+  return _VSTD::__search<_BinaryPredicate&>(
              __first1, __last1, __first2, __last2, __pred,
              typename iterator_traits<_ForwardIterator1>::iterator_category(),
              typename iterator_traits<_ForwardIterator2>::iterator_category()).first;
@@ -126,6 +122,4 @@ search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher& __s) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SEARCH_H
lib/libcxx/include/__algorithm/search_n.h
@@ -10,18 +10,15 @@
 #ifndef _LIBCPP___ALGORITHM_SEARCH_N_H
 #define _LIBCPP___ALGORITHM_SEARCH_N_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
-#include <type_traits>
+#include <type_traits>  // __convert_to_integral
 
 #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 _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp>
@@ -62,12 +59,13 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator __search_n(_RandomAccessIter
                                                                _RandomAccessIterator __last, _Size __count,
                                                                const _Tp& __value_, _BinaryPredicate __pred,
                                                                random_access_iterator_tag) {
+  typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
   if (__count <= 0)
     return __first;
   _Size __len = static_cast<_Size>(__last - __first);
   if (__len < __count)
     return __last;
-  const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here
+  const _RandomAccessIterator __s = __last - difference_type(__count - 1); // Start of pattern match can't go beyond here
   while (true) {
     // Find first element in sequence that matchs __value_, with a mininum of loop checks
     while (true) {
@@ -97,7 +95,7 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator __search_n(_RandomAccessIter
 template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator search_n(
     _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred) {
-  return _VSTD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type>(
+  return _VSTD::__search_n<_BinaryPredicate&>(
       __first, __last, _VSTD::__convert_to_integral(__count), __value_, __pred,
       typename iterator_traits<_ForwardIterator>::iterator_category());
 }
@@ -111,6 +109,4 @@ search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SEARCH_N_H
lib/libcxx/include/__algorithm/set_difference.h
@@ -9,19 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_SET_DIFFERENCE_H
 #define _LIBCPP___ALGORITHM_SET_DIFFERENCE_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/copy.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
@@ -72,6 +69,4 @@ set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SET_DIFFERENCE_H
lib/libcxx/include/__algorithm/set_intersection.h
@@ -9,18 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_SET_INTERSECTION_H
 #define _LIBCPP___ALGORITHM_SET_INTERSECTION_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
@@ -69,6 +66,4 @@ set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SET_INTERSECTION_H
lib/libcxx/include/__algorithm/set_symmetric_difference.h
@@ -9,19 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
 #define _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/copy.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
@@ -77,6 +74,4 @@ set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
lib/libcxx/include/__algorithm/set_union.h
@@ -9,19 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_SET_UNION_H
 #define _LIBCPP___ALGORITHM_SET_UNION_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/copy.h>
+#include <__config>
 #include <__iterator/iterator_traits.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 _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
@@ -72,6 +69,4 @@ set_union(_InputIterator1 __first1, _InputIterator1 __last1,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SET_UNION_H
lib/libcxx/include/__algorithm/shift_left.h
@@ -9,18 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_SHIFT_LEFT_H
 #define _LIBCPP___ALGORITHM_SHIFT_LEFT_H
 
-#include <__config>
 #include <__algorithm/move.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#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
 
 #if _LIBCPP_STD_VER > 17
@@ -56,6 +53,4 @@ shift_left(_ForwardIterator __first, _ForwardIterator __last,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SHIFT_LEFT_H
lib/libcxx/include/__algorithm/shift_right.h
@@ -9,20 +9,18 @@
 #ifndef _LIBCPP___ALGORITHM_SHIFT_RIGHT_H
 #define _LIBCPP___ALGORITHM_SHIFT_RIGHT_H
 
-#include <__config>
 #include <__algorithm/move.h>
 #include <__algorithm/move_backward.h>
 #include <__algorithm/swap_ranges.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
-#include <type_traits> // swap
+#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
 
 #if _LIBCPP_STD_VER > 17
@@ -101,6 +99,4 @@ shift_right(_ForwardIterator __first, _ForwardIterator __last,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SHIFT_RIGHT_H
lib/libcxx/include/__algorithm/shuffle.h
@@ -25,6 +25,39 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+class _LIBCPP_TYPE_VIS __libcpp_debug_randomizer {
+public:
+  __libcpp_debug_randomizer() {
+    __state = __seed();
+    __inc = __state + 0xda3e39cb94b95bdbULL;
+    __inc = (__inc << 1) | 1;
+  }
+  typedef uint_fast32_t result_type;
+
+  static const result_type _Min = 0;
+  static const result_type _Max = 0xFFFFFFFF;
+
+  _LIBCPP_HIDE_FROM_ABI result_type operator()() {
+    uint_fast64_t __oldstate = __state;
+    __state = __oldstate * 6364136223846793005ULL + __inc;
+    return __oldstate >> 32;
+  }
+
+  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type min() { return _Min; }
+  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR result_type max() { return _Max; }
+
+private:
+  uint_fast64_t __state;
+  uint_fast64_t __inc;
+  _LIBCPP_HIDE_FROM_ABI static uint_fast64_t __seed() {
+#ifdef _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED
+    return _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED;
+#else
+    static char __x;
+    return reinterpret_cast<uintptr_t>(&__x);
+#endif
+  }
+};
 
 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \
   || defined(_LIBCPP_BUILDING_LIBRARY)
lib/libcxx/include/__algorithm/sift_down.h
@@ -17,15 +17,11 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Compare, class _RandomAccessIterator>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 void
-__sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
-            _Compare __comp,
+__sift_down(_RandomAccessIterator __first, _Compare __comp,
             typename iterator_traits<_RandomAccessIterator>::difference_type __len,
             _RandomAccessIterator __start)
 {
@@ -41,7 +37,7 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
     __child = 2 * __child + 1;
     _RandomAccessIterator __child_i = __first + __child;
 
-    if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
+    if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
         // right-child exists and is greater than left-child
         ++__child_i;
         ++__child;
@@ -49,7 +45,7 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
 
     // check if we are in heap-order
     if (__comp(*__child_i, *__start))
-        // we are, __start is larger than it's largest child
+        // we are, __start is larger than its largest child
         return;
 
     value_type __top(_VSTD::move(*__start));
@@ -66,7 +62,7 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
         __child = 2 * __child + 1;
         __child_i = __first + __child;
 
-        if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
+        if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1)))) {
             // right-child exists and is greater than left-child
             ++__child_i;
             ++__child;
@@ -79,6 +75,4 @@ __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SIFT_DOWN_H
lib/libcxx/include/__algorithm/sort.h
@@ -9,23 +9,23 @@
 #ifndef _LIBCPP___ALGORITHM_SORT_H
 #define _LIBCPP___ALGORITHM_SORT_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/min_element.h>
 #include <__algorithm/partial_sort.h>
 #include <__algorithm/unwrap_iter.h>
+#include <__config>
 #include <__utility/swap.h>
 #include <memory>
-#include <type_traits> // swap
+
+#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
+#  include <__algorithm/shuffle.h>
+#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // stable, 2-3 compares, 0-2 swaps
@@ -131,9 +131,7 @@ __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last,
     _BidirectionalIterator __lm1 = __last;
     for (--__lm1; __first != __lm1; ++__first)
     {
-        _BidirectionalIterator __i = _VSTD::min_element<_BidirectionalIterator,
-                                                        typename add_lvalue_reference<_Compare>::type>
-                                                       (__first, __last, __comp);
+        _BidirectionalIterator __i = _VSTD::min_element(__first, __last, __comp);
         if (__i != __first)
             swap(*__first, *__i);
     }
@@ -162,10 +160,11 @@ template <class _Compare, class _RandomAccessIterator>
 void
 __insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
     typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
-    _RandomAccessIterator __j = __first+2;
-    _VSTD::__sort3<_Compare>(__first, __first+1, __j, __comp);
-    for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
+    _RandomAccessIterator __j = __first+difference_type(2);
+    _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), __j, __comp);
+    for (_RandomAccessIterator __i = __j+difference_type(1); __i != __last; ++__i)
     {
         if (__comp(*__i, *__j))
         {
@@ -187,6 +186,7 @@ template <class _Compare, class _RandomAccessIterator>
 bool
 __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
     switch (__last - __first)
     {
     case 0:
@@ -197,21 +197,21 @@ __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator
             swap(*__first, *__last);
         return true;
     case 3:
-        _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
+        _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp);
         return true;
     case 4:
-        _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
+        _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp);
         return true;
     case 5:
-        _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
+        _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp);
         return true;
     }
     typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
-    _RandomAccessIterator __j = __first+2;
-    _VSTD::__sort3<_Compare>(__first, __first+1, __j, __comp);
+    _RandomAccessIterator __j = __first+difference_type(2);
+    _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), __j, __comp);
     const unsigned __limit = 8;
     unsigned __count = 0;
-    for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
+    for (_RandomAccessIterator __i = __j+difference_type(1); __i != __last; ++__i)
     {
         if (__comp(*__i, *__j))
         {
@@ -269,7 +269,8 @@ __insertion_sort_move(_BidirectionalIterator __first1, _BidirectionalIterator __
 
 template <class _Compare, class _RandomAccessIterator>
 void
-__sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+__introsort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+            typename iterator_traits<_RandomAccessIterator>::difference_type __depth)
 {
     typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
     typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
@@ -289,13 +290,13 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
                 swap(*__first, *__last);
             return;
         case 3:
-            _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
+            _VSTD::__sort3<_Compare>(__first, __first+difference_type(1), --__last, __comp);
             return;
         case 4:
-            _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
+            _VSTD::__sort4<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), --__last, __comp);
             return;
         case 5:
-            _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
+            _VSTD::__sort5<_Compare>(__first, __first+difference_type(1), __first+difference_type(2), __first+difference_type(3), --__last, __comp);
             return;
         }
         if (__len <= __limit)
@@ -304,6 +305,13 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
             return;
         }
         // __len > 5
+        if (__depth == 0)
+        {
+          // Fallback to heap sort as Introsort suggests.
+          _VSTD::__partial_sort<_Compare>(__first, __last, __last, __comp);
+          return;
+        }
+        --__depth;
         _RandomAccessIterator __m = __first;
         _RandomAccessIterator __lm1 = __last;
         --__lm1;
@@ -427,7 +435,7 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
         if (__n_swaps == 0)
         {
             bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp);
-            if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp))
+            if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+difference_type(1), __last, __comp))
             {
                 if (__fs)
                     return;
@@ -446,19 +454,34 @@ __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __c
         // sort smaller range with recursive call and larger with tail recursion elimination
         if (__i - __first < __last - __i)
         {
-            _VSTD::__sort<_Compare>(__first, __i, __comp);
-            // _VSTD::__sort<_Compare>(__i+1, __last, __comp);
-            __first = ++__i;
+          _VSTD::__introsort<_Compare>(__first, __i, __comp, __depth);
+          __first = ++__i;
         }
         else
         {
-            _VSTD::__sort<_Compare>(__i+1, __last, __comp);
-            // _VSTD::__sort<_Compare>(__first, __i, __comp);
-            __last = __i;
+          _VSTD::__introsort<_Compare>(__i + difference_type(1), __last, __comp, __depth);
+          __last = __i;
         }
     }
 }
 
+template <typename _Number>
+inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) {
+  _Number __log2 = 0;
+  while (__n > 1) {
+    __log2++;
+    __n >>= 1;
+  }
+  return __log2;
+}
+
+template <class _Compare, class _RandomAccessIterator>
+void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+  typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+  difference_type __depth_limit = 2 * __log2i(__last - __first);
+  _VSTD::__introsort<_Compare>(__first, __last, __comp, __depth_limit);
+}
+
 template <class _Compare, class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 void
@@ -469,7 +492,9 @@ __sort(_Tp** __first, _Tp** __last, __less<_Tp*>&)
 }
 
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&))
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
+#endif
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<short>&, short*>(short*, short*, __less<short>&))
@@ -485,7 +510,9 @@ _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<double>&, double*>(d
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
 
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&))
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
+#endif
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&))
@@ -507,12 +534,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 void
 sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
-    typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
-    if (__libcpp_is_constant_evaluated()) {
-        _VSTD::__partial_sort<_Comp_ref>(__first, __last, __last, _Comp_ref(__comp));
-    } else {
-        _VSTD::__sort<_Comp_ref>(_VSTD::__unwrap_iter(__first), _VSTD::__unwrap_iter(__last), _Comp_ref(__comp));
-    }
+  _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
+  typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+  if (__libcpp_is_constant_evaluated()) {
+    _VSTD::__partial_sort<_Comp_ref>(__first, __last, __last, _Comp_ref(__comp));
+  } else {
+    _VSTD::__sort<_Comp_ref>(_VSTD::__unwrap_iter(__first), _VSTD::__unwrap_iter(__last), _Comp_ref(__comp));
+  }
 }
 
 template <class _RandomAccessIterator>
@@ -525,6 +553,4 @@ sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SORT_H
lib/libcxx/include/__algorithm/sort_heap.h
@@ -9,10 +9,10 @@
 #ifndef _LIBCPP___ALGORITHM_SORT_HEAP_H
 #define _LIBCPP___ALGORITHM_SORT_HEAP_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/pop_heap.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <type_traits> // swap
 
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Compare, class _RandomAccessIterator>
@@ -53,6 +50,4 @@ sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SORT_HEAP_H
lib/libcxx/include/__algorithm/stable_partition.h
@@ -9,8 +9,8 @@
 #ifndef _LIBCPP___ALGORITHM_STABLE_PARTITION_H
 #define _LIBCPP___ALGORITHM_STABLE_PARTITION_H
 
-#include <__config>
 #include <__algorithm/rotate.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 #include <memory>
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
@@ -85,8 +82,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
     // recurse on [__first, __m), *__first know to be false
     // F?????????????????
     // f       m         l
-    typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
-    _ForwardIterator __first_false = _VSTD::__stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit);
+    _ForwardIterator __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m, __pred, __len2, __p, __fit);
     // TTTFFFFF??????????
     // f  ff   m         l
     // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
@@ -101,7 +97,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
     }
     // TTTFFFFFTTTF??????
     // f  ff   m  m1     l
-    __second_false = _VSTD::__stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit);
+    __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __fit);
 __second_half_done:
     // TTTFFFFFTTTTTFFFFF
     // f  ff   m    sf   l
@@ -137,8 +133,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
         __p = _VSTD::get_temporary_buffer<value_type>(__len);
         __h.reset(__p.first);
     }
-    return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
-                             (__first, __last, __pred, __len, __p, forward_iterator_tag());
+    return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, forward_iterator_tag());
 }
 
 template <class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
@@ -222,8 +217,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
     }
     // F???TFFF?????????T
     // f   m1  m        l
-    typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
-    __first_false = _VSTD::__stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit);
+    __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m1, __pred, __len_half, __p, __bit);
 __first_half_done:
     // TTTFFFFF?????????T
     // f  ff   m        l
@@ -240,7 +234,7 @@ __first_half_done:
     }
     // TTTFFFFFTTTF?????T
     // f  ff   m  m1    l
-    __second_false = _VSTD::__stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit);
+    __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __bit);
 __second_half_done:
     // TTTFFFFFTTTTTFFFFF
     // f  ff   m    sf  l
@@ -285,8 +279,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
         __p = _VSTD::get_temporary_buffer<value_type>(__len);
         __h.reset(__p.first);
     }
-    return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
-                             (__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
+    return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
 }
 
 template <class _ForwardIterator, class _Predicate>
@@ -294,12 +287,9 @@ inline _LIBCPP_INLINE_VISIBILITY
 _ForwardIterator
 stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
-                             (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+    return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_STABLE_PARTITION_H
lib/libcxx/include/__algorithm/stable_sort.h
@@ -9,23 +9,20 @@
 #ifndef _LIBCPP___ALGORITHM_STABLE_SORT_H
 #define _LIBCPP___ALGORITHM_STABLE_SORT_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/comp_ref_type.h>
 #include <__algorithm/inplace_merge.h>
 #include <__algorithm/sort.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 #include <memory>
-#include <type_traits> // swap
+#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 _Compare, class _InputIterator1, class _InputIterator2>
@@ -41,14 +38,14 @@ __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
     {
         if (__first1 == __last1)
         {
-            for (; __first2 != __last2; ++__first2, ++__result, (void)__d.template __incr<value_type>())
+            for (; __first2 != __last2; ++__first2, (void) ++__result, __d.template __incr<value_type>())
                 ::new ((void*)__result) value_type(_VSTD::move(*__first2));
             __h.release();
             return;
         }
         if (__first2 == __last2)
         {
-            for (; __first1 != __last1; ++__first1, ++__result, (void)__d.template __incr<value_type>())
+            for (; __first1 != __last1; ++__first1, (void) ++__result, __d.template __incr<value_type>())
                 ::new ((void*)__result) value_type(_VSTD::move(*__first1));
             __h.release();
             return;
@@ -230,6 +227,4 @@ stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_STABLE_SORT_H
lib/libcxx/include/__algorithm/swap_ranges.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _ForwardIterator1, class _ForwardIterator2>
@@ -32,6 +29,4 @@ swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardItera
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H
lib/libcxx/include/__algorithm/transform.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIterator, class _OutputIterator, class _UnaryOperation>
@@ -43,6 +40,4 @@ transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __f
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_TRANSFORM_H
lib/libcxx/include/__algorithm/unique.h
@@ -9,20 +9,16 @@
 #ifndef _LIBCPP___ALGORITHM_UNIQUE_H
 #define _LIBCPP___ALGORITHM_UNIQUE_H
 
-#include <__config>
-#include <__algorithm/comp.h>
 #include <__algorithm/adjacent_find.h>
+#include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <__utility/move.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
 
 // unique
@@ -31,8 +27,7 @@ template <class _ForwardIterator, class _BinaryPredicate>
 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
 {
-    __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type>
-                                 (__first, __last, __pred);
+    __first = _VSTD::adjacent_find<_ForwardIterator, _BinaryPredicate&>(__first, __last, __pred);
     if (__first != __last)
     {
         // ...  a  a  ?  ...
@@ -58,6 +53,4 @@ unique(_ForwardIterator __first, _ForwardIterator __last)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_UNIQUE_H
lib/libcxx/include/__algorithm/unique_copy.h
@@ -9,19 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_UNIQUE_COPY_H
 #define _LIBCPP___ALGORITHM_UNIQUE_COPY_H
 
-#include <__config>
 #include <__algorithm/comp.h>
+#include <__config>
 #include <__iterator/iterator_traits.h>
 #include <utility>
-#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 _BinaryPredicate, class _InputIterator, class _OutputIterator>
@@ -91,8 +87,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _OutputIterator
 unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred)
 {
-    return _VSTD::__unique_copy<typename add_lvalue_reference<_BinaryPredicate>::type>
-                              (__first, __last, __result, __pred,
+    return _VSTD::__unique_copy<_BinaryPredicate&>(__first, __last, __result, __pred,
                                typename iterator_traits<_InputIterator>::iterator_category(),
                                typename iterator_traits<_OutputIterator>::iterator_category());
 }
@@ -109,6 +104,4 @@ unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __res
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_UNIQUE_COPY_H
lib/libcxx/include/__algorithm/unwrap_iter.h
@@ -10,17 +10,14 @@
 #define _LIBCPP___ALGORITHM_UNWRAP_ITER_H
 
 #include <__config>
-#include <iterator>
 #include <__memory/pointer_traits.h>
+#include <iterator>
 #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
 
 // The job of __unwrap_iter is to lower contiguous iterators (such as
@@ -67,12 +64,14 @@ __unwrap_iter(_Iter __i) _NOEXCEPT
 }
 
 template<class _OrigIter>
+_LIBCPP_HIDE_FROM_ABI
 _OrigIter __rewrap_iter(_OrigIter, _OrigIter __result)
 {
     return __result;
 }
 
 template<class _OrigIter, class _UnwrappedIter>
+_LIBCPP_HIDE_FROM_ABI
 _OrigIter __rewrap_iter(_OrigIter __first, _UnwrappedIter __result)
 {
     // Precondition: __result is reachable from __first
@@ -82,6 +81,4 @@ _OrigIter __rewrap_iter(_OrigIter __first, _UnwrappedIter __result)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_UNWRAP_ITER_H
lib/libcxx/include/__algorithm/upper_bound.h
@@ -9,18 +9,15 @@
 #ifndef _LIBCPP___ALGORITHM_UPPER_BOUND_H
 #define _LIBCPP___ALGORITHM_UPPER_BOUND_H
 
-#include <__config>
 #include <__algorithm/comp.h>
 #include <__algorithm/half_positive.h>
+#include <__config>
 #include <iterator>
 
 #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 _Compare, class _ForwardIterator, class _Tp>
@@ -51,8 +48,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
-    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
-    return _VSTD::__upper_bound<_Comp_ref>(__first, __last, __value_, __comp);
+    return _VSTD::__upper_bound<_Compare&>(__first, __last, __value_, __comp);
 }
 
 template <class _ForwardIterator, class _Tp>
@@ -67,6 +63,4 @@ upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ALGORITHM_UPPER_BOUND_H
lib/libcxx/include/__utility/__decay_copy.h โ†’ lib/libcxx/include/__bit/bit_cast.h
@@ -7,33 +7,32 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
-#define _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
+#ifndef _LIBCPP___BIT_BIT_CAST_H
+#define _LIBCPP___BIT_BIT_CAST_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);
+
+template<class _ToType, class _FromType, class = enable_if_t<
+  sizeof(_ToType) == sizeof(_FromType) &&
+  is_trivially_copyable_v<_ToType> &&
+  is_trivially_copyable_v<_FromType>
+>>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI
+constexpr _ToType bit_cast(_FromType const& __from) noexcept {
+    return __builtin_bit_cast(_ToType, __from);
 }
 
-_LIBCPP_END_NAMESPACE_STD
+#endif // _LIBCPP_STD_VER > 17
 
-_LIBCPP_POP_MACROS
+_LIBCPP_END_NAMESPACE_STD
 
-#endif // _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
+#endif // _LIBCPP___BIT_BIT_CAST_H
lib/libcxx/include/__bit/byteswap.h
@@ -0,0 +1,55 @@
+// -*- 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___BIT_BYTESWAP_H
+#define _LIBCPP___BIT_BYTESWAP_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <cstdint>
+#include <cstdlib>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <integral _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
+
+  if constexpr (sizeof(_Tp) == 1) {
+    return __val;
+  } else if constexpr (sizeof(_Tp) == 2) {
+    return __builtin_bswap16(__val);
+  } else if constexpr (sizeof(_Tp) == 4) {
+    return __builtin_bswap32(__val);
+  } else if constexpr (sizeof(_Tp) == 8) {
+    return __builtin_bswap64(__val);
+#ifndef _LIBCPP_HAS_NO_INT128
+  } else if constexpr (sizeof(_Tp) == 16) {
+#if __has_builtin(__builtin_bswap128)
+    return __builtin_bswap128(__val);
+#else
+    return static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val))) << 64 |
+           static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val >> 64)));
+#endif // __has_builtin(__builtin_bswap128)
+#endif // _LIBCPP_HAS_NO_INT128
+  } else {
+    static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size");
+  }
+}
+
+#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_BYTESWAP_H
lib/libcxx/include/__charconv/chars_format.h
@@ -0,0 +1,77 @@
+// -*- 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___CHARCONV_CHARS_FORMAT_H
+#define _LIBCPP___CHARCONV_CHARS_FORMAT_H
+
+#include <__config>
+#include <__utility/to_underlying.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+
+enum class _LIBCPP_ENUM_VIS chars_format
+{
+    scientific = 0x1,
+    fixed = 0x2,
+    hex = 0x4,
+    general = fixed | scientific
+};
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator~(chars_format __x) {
+  return chars_format(~_VSTD::__to_underlying(__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator&(chars_format __x, chars_format __y) {
+  return chars_format(_VSTD::__to_underlying(__x) &
+                      _VSTD::__to_underlying(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator|(chars_format __x, chars_format __y) {
+  return chars_format(_VSTD::__to_underlying(__x) |
+                      _VSTD::__to_underlying(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator^(chars_format __x, chars_format __y) {
+  return chars_format(_VSTD::__to_underlying(__x) ^
+                      _VSTD::__to_underlying(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
+operator&=(chars_format& __x, chars_format __y) {
+  __x = __x & __y;
+  return __x;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
+operator|=(chars_format& __x, chars_format __y) {
+  __x = __x | __y;
+  return __x;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
+operator^=(chars_format& __x, chars_format __y) {
+  __x = __x ^ __y;
+  return __x;
+}
+
+#endif // _LIBCPP_CXX03_LANG
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHARCONV_CHARS_FORMAT_H
lib/libcxx/include/__charconv/from_chars_result.h
@@ -0,0 +1,37 @@
+// -*- 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___CHARCONV_FROM_CHARS_RESULT_H
+#define _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
+
+#include <__config>
+#include <__errc>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+
+struct _LIBCPP_TYPE_VIS from_chars_result
+{
+    const char* ptr;
+    errc ec;
+#  if _LIBCPP_STD_VER > 17
+    _LIBCPP_HIDE_FROM_ABI friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
+#  endif
+};
+
+#endif // _LIBCPP_CXX03_LANG
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
lib/libcxx/include/__charconv/to_chars_result.h
@@ -0,0 +1,37 @@
+// -*- 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___CHARCONV_TO_CHARS_RESULT_H
+#define _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
+
+#include <__config>
+#include <__errc>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+
+struct _LIBCPP_TYPE_VIS to_chars_result
+{
+    char* ptr;
+    errc ec;
+#  if _LIBCPP_STD_VER > 17
+    _LIBCPP_HIDE_FROM_ABI friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
+#  endif
+};
+
+#endif // _LIBCPP_CXX03_LANG
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
lib/libcxx/include/__chrono/calendar.h
@@ -0,0 +1,1276 @@
+// -*- 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___CHRONO_CALENDAR_H
+#define _LIBCPP___CHRONO_CALENDAR_H
+
+#include <__chrono/duration.h>
+#include <__chrono/system_clock.h>
+#include <__chrono/time_point.h>
+#include <__config>
+#include <limits>
+#include <ratio>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER > 17
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace chrono
+{
+
+struct local_t {};
+template<class Duration>
+using local_time  = time_point<local_t, Duration>;
+using local_seconds = local_time<seconds>;
+using local_days    = local_time<days>;
+
+struct last_spec { explicit last_spec() = default; };
+
+class day {
+private:
+    unsigned char __d;
+public:
+    day() = default;
+    explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
+    inline constexpr day& operator++()    noexcept { ++__d; return *this; }
+    inline constexpr day  operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
+    inline constexpr day& operator--()    noexcept { --__d; return *this; }
+    inline constexpr day  operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
+           constexpr day& operator+=(const days& __dd) noexcept;
+           constexpr day& operator-=(const days& __dd) noexcept;
+    explicit inline constexpr operator unsigned() const noexcept { return __d; }
+    inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
+  };
+
+
+inline constexpr
+bool operator==(const day& __lhs, const day& __rhs) noexcept
+{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
+
+inline constexpr
+bool operator!=(const day& __lhs, const day& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const day& __lhs, const day& __rhs) noexcept
+{ return static_cast<unsigned>(__lhs) <  static_cast<unsigned>(__rhs); }
+
+inline constexpr
+bool operator> (const day& __lhs, const day& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const day& __lhs, const day& __rhs) noexcept
+{ return !(__rhs < __lhs);}
+
+inline constexpr
+bool operator>=(const day& __lhs, const day& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+inline constexpr
+day operator+ (const day& __lhs, const days& __rhs) noexcept
+{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
+
+inline constexpr
+day operator+ (const days& __lhs, const day& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+day operator- (const day& __lhs, const days& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+inline constexpr
+days operator-(const day& __lhs, const day& __rhs) noexcept
+{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
+              static_cast<int>(static_cast<unsigned>(__rhs))); }
+
+inline constexpr day& day::operator+=(const days& __dd) noexcept
+{ *this = *this + __dd; return *this; }
+
+inline constexpr day& day::operator-=(const days& __dd) noexcept
+{ *this = *this - __dd; return *this; }
+
+
+class month {
+private:
+    unsigned char __m;
+public:
+    month() = default;
+    explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
+    inline constexpr month& operator++()    noexcept { ++__m; return *this; }
+    inline constexpr month  operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
+    inline constexpr month& operator--()    noexcept { --__m; return *this; }
+    inline constexpr month  operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
+           constexpr month& operator+=(const months& __m1) noexcept;
+           constexpr month& operator-=(const months& __m1) noexcept;
+    explicit inline constexpr operator unsigned() const noexcept { return __m; }
+    inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
+};
+
+
+inline constexpr
+bool operator==(const month& __lhs, const month& __rhs) noexcept
+{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
+
+inline constexpr
+bool operator!=(const month& __lhs, const month& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const month& __lhs, const month& __rhs) noexcept
+{ return static_cast<unsigned>(__lhs)  < static_cast<unsigned>(__rhs); }
+
+inline constexpr
+bool operator> (const month& __lhs, const month& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const month& __lhs, const month& __rhs) noexcept
+{ return !(__rhs < __lhs); }
+
+inline constexpr
+bool operator>=(const month& __lhs, const month& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+inline constexpr
+month operator+ (const month& __lhs, const months& __rhs) noexcept
+{
+    auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
+    auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
+    return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
+}
+
+inline constexpr
+month operator+ (const months& __lhs, const month& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+month operator- (const month& __lhs, const months& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+inline constexpr
+months operator-(const month& __lhs, const month& __rhs) noexcept
+{
+    auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
+    return months(__dm <= 11 ? __dm : __dm + 12);
+}
+
+inline constexpr month& month::operator+=(const months& __dm) noexcept
+{ *this = *this + __dm; return *this; }
+
+inline constexpr month& month::operator-=(const months& __dm) noexcept
+{ *this = *this - __dm; return *this; }
+
+
+class year {
+private:
+    short __y;
+public:
+    year() = default;
+    explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
+
+    inline constexpr year& operator++()    noexcept { ++__y; return *this; }
+    inline constexpr year  operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
+    inline constexpr year& operator--()    noexcept { --__y; return *this; }
+    inline constexpr year  operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
+           constexpr year& operator+=(const years& __dy) noexcept;
+           constexpr year& operator-=(const years& __dy) noexcept;
+    inline constexpr year operator+() const noexcept { return *this; }
+    inline constexpr year operator-() const noexcept { return year{-__y}; }
+
+    inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
+    explicit inline constexpr operator int() const noexcept { return __y; }
+           constexpr bool ok() const noexcept;
+    static inline constexpr year min() noexcept { return year{-32767}; }
+    static inline constexpr year max() noexcept { return year{ 32767}; }
+};
+
+
+inline constexpr
+bool operator==(const year& __lhs, const year& __rhs) noexcept
+{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
+
+inline constexpr
+bool operator!=(const year& __lhs, const year& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const year& __lhs, const year& __rhs) noexcept
+{ return static_cast<int>(__lhs)  < static_cast<int>(__rhs); }
+
+inline constexpr
+bool operator> (const year& __lhs, const year& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const year& __lhs, const year& __rhs) noexcept
+{ return !(__rhs < __lhs); }
+
+inline constexpr
+bool operator>=(const year& __lhs, const year& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+inline constexpr
+year operator+ (const year& __lhs, const years& __rhs) noexcept
+{ return year(static_cast<int>(__lhs) + __rhs.count()); }
+
+inline constexpr
+year operator+ (const years& __lhs, const year& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year operator- (const year& __lhs, const years& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+inline constexpr
+years operator-(const year& __lhs, const year& __rhs) noexcept
+{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
+
+
+inline constexpr year& year::operator+=(const years& __dy) noexcept
+{ *this = *this + __dy; return *this; }
+
+inline constexpr year& year::operator-=(const years& __dy) noexcept
+{ *this = *this - __dy; return *this; }
+
+inline constexpr bool year::ok() const noexcept
+{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
+
+class weekday_indexed;
+class weekday_last;
+
+class weekday {
+private:
+    unsigned char __wd;
+    static constexpr unsigned char __weekday_from_days(int __days) noexcept;
+public:
+  weekday() = default;
+  inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
+  inline constexpr          weekday(const sys_days& __sysd) noexcept
+          : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
+  inline explicit constexpr weekday(const local_days& __locd) noexcept
+          : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
+
+  inline constexpr weekday& operator++()    noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
+  inline constexpr weekday  operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
+  inline constexpr weekday& operator--()    noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
+  inline constexpr weekday  operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
+         constexpr weekday& operator+=(const days& __dd) noexcept;
+         constexpr weekday& operator-=(const days& __dd) noexcept;
+  inline constexpr unsigned c_encoding()   const noexcept { return __wd; }
+  inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; }
+  inline constexpr bool ok() const noexcept { return __wd <= 6; }
+         constexpr weekday_indexed operator[](unsigned __index) const noexcept;
+         constexpr weekday_last    operator[](last_spec) const noexcept;
+};
+
+
+// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
+inline constexpr
+unsigned char weekday::__weekday_from_days(int __days) noexcept
+{
+    return static_cast<unsigned char>(
+              static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
+           );
+}
+
+inline constexpr
+bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
+{ return __lhs.c_encoding() == __rhs.c_encoding(); }
+
+inline constexpr
+bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
+{ return __lhs.c_encoding() < __rhs.c_encoding(); }
+
+inline constexpr
+bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
+{ return !(__rhs < __lhs);}
+
+inline constexpr
+bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
+{
+    auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
+    auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
+    return weekday{static_cast<unsigned>(__mu - __yr * 7)};
+}
+
+constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
+{
+    const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
+    const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
+    return days{__wdu - __wk * 7};
+}
+
+inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
+{ *this = *this + __dd; return *this; }
+
+inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
+{ *this = *this - __dd; return *this; }
+
+
+class weekday_indexed {
+private:
+    chrono::weekday __wd;
+    unsigned char          __idx;
+public:
+    weekday_indexed() = default;
+    inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept
+        : __wd{__wdval}, __idx(__idxval) {}
+    inline constexpr chrono::weekday weekday() const noexcept { return __wd; }
+    inline constexpr unsigned                 index() const noexcept { return __idx; }
+    inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
+};
+
+inline constexpr
+bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
+{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
+
+inline constexpr
+bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+
+class weekday_last {
+private:
+    chrono::weekday __wd;
+public:
+    explicit constexpr weekday_last(const chrono::weekday& __val) noexcept
+        : __wd{__val} {}
+    constexpr chrono::weekday weekday() const noexcept { return __wd; }
+    constexpr bool ok() const noexcept { return __wd.ok(); }
+};
+
+inline constexpr
+bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
+{ return __lhs.weekday() == __rhs.weekday(); }
+
+inline constexpr
+bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
+
+inline constexpr
+weekday_last    weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
+
+
+inline constexpr last_spec last{};
+inline constexpr weekday   Sunday{0};
+inline constexpr weekday   Monday{1};
+inline constexpr weekday   Tuesday{2};
+inline constexpr weekday   Wednesday{3};
+inline constexpr weekday   Thursday{4};
+inline constexpr weekday   Friday{5};
+inline constexpr weekday   Saturday{6};
+
+inline constexpr month January{1};
+inline constexpr month February{2};
+inline constexpr month March{3};
+inline constexpr month April{4};
+inline constexpr month May{5};
+inline constexpr month June{6};
+inline constexpr month July{7};
+inline constexpr month August{8};
+inline constexpr month September{9};
+inline constexpr month October{10};
+inline constexpr month November{11};
+inline constexpr month December{12};
+
+
+class month_day {
+private:
+   chrono::month __m;
+   chrono::day   __d;
+public:
+    month_day() = default;
+    constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
+        : __m{__mval}, __d{__dval} {}
+    inline constexpr chrono::month month() const noexcept { return __m; }
+    inline constexpr chrono::day   day()   const noexcept { return __d; }
+    constexpr bool ok() const noexcept;
+};
+
+inline constexpr
+bool month_day::ok() const noexcept
+{
+    if (!__m.ok()) return false;
+    const unsigned __dval = static_cast<unsigned>(__d);
+    if (__dval < 1 || __dval > 31) return false;
+    if (__dval <= 29) return true;
+//  Now we've got either 30 or 31
+    const unsigned __mval = static_cast<unsigned>(__m);
+    if (__mval == 2) return false;
+    if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
+        return __dval == 30;
+    return true;
+}
+
+inline constexpr
+bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
+{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
+
+inline constexpr
+bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+month_day operator/(const month& __lhs, const day& __rhs) noexcept
+{ return month_day{__lhs, __rhs}; }
+
+constexpr
+month_day operator/(const day& __lhs, const month& __rhs) noexcept
+{ return __rhs / __lhs; }
+
+inline constexpr
+month_day operator/(const month& __lhs, int __rhs) noexcept
+{ return __lhs / day(__rhs); }
+
+constexpr
+month_day operator/(int __lhs, const day& __rhs) noexcept
+{ return month(__lhs) / __rhs; }
+
+constexpr
+month_day operator/(const day& __lhs, int __rhs) noexcept
+{ return month(__rhs) / __lhs; }
+
+
+inline constexpr
+bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
+{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
+
+inline constexpr
+bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
+{ return !(__rhs < __lhs);}
+
+inline constexpr
+bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+
+
+class month_day_last {
+private:
+    chrono::month __m;
+public:
+    explicit constexpr month_day_last(const chrono::month& __val) noexcept
+        : __m{__val} {}
+    inline constexpr chrono::month month() const noexcept { return __m; }
+    inline constexpr bool ok() const noexcept { return __m.ok(); }
+};
+
+inline constexpr
+bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
+{ return __lhs.month() == __rhs.month(); }
+
+inline constexpr
+bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
+{ return __lhs.month() < __rhs.month(); }
+
+inline constexpr
+bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
+{ return !(__rhs < __lhs);}
+
+inline constexpr
+bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+inline constexpr
+month_day_last operator/(const month& __lhs, last_spec) noexcept
+{ return month_day_last{__lhs}; }
+
+inline constexpr
+month_day_last operator/(last_spec, const month& __rhs) noexcept
+{ return month_day_last{__rhs}; }
+
+inline constexpr
+month_day_last operator/(int __lhs, last_spec) noexcept
+{ return month_day_last{month(__lhs)}; }
+
+inline constexpr
+month_day_last operator/(last_spec, int __rhs) noexcept
+{ return month_day_last{month(__rhs)}; }
+
+
+class month_weekday {
+private:
+    chrono::month __m;
+    chrono::weekday_indexed __wdi;
+public:
+    constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
+        : __m{__mval}, __wdi{__wdival} {}
+    inline constexpr chrono::month                     month() const noexcept { return __m; }
+    inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
+    inline constexpr bool                                 ok() const noexcept { return __m.ok() && __wdi.ok(); }
+};
+
+inline constexpr
+bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
+{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
+
+inline constexpr
+bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
+{ return month_weekday{__lhs, __rhs}; }
+
+inline constexpr
+month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
+{ return month_weekday{month(__lhs), __rhs}; }
+
+inline constexpr
+month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
+{ return month_weekday{__rhs, __lhs}; }
+
+inline constexpr
+month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
+{ return month_weekday{month(__rhs), __lhs}; }
+
+
+class month_weekday_last {
+    chrono::month        __m;
+    chrono::weekday_last __wdl;
+  public:
+    constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
+        : __m{__mval}, __wdl{__wdlval} {}
+    inline constexpr chrono::month               month() const noexcept { return __m; }
+    inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
+    inline constexpr bool                           ok() const noexcept { return __m.ok() && __wdl.ok(); }
+};
+
+inline constexpr
+bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
+{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
+
+inline constexpr
+bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+
+inline constexpr
+month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
+{ return month_weekday_last{__lhs, __rhs}; }
+
+inline constexpr
+month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
+{ return month_weekday_last{month(__lhs), __rhs}; }
+
+inline constexpr
+month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
+{ return month_weekday_last{__rhs, __lhs}; }
+
+inline constexpr
+month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
+{ return month_weekday_last{month(__rhs), __lhs}; }
+
+
+class year_month {
+    chrono::year  __y;
+    chrono::month __m;
+public:
+    year_month() = default;
+    constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
+        : __y{__yval}, __m{__mval} {}
+    inline constexpr chrono::year  year()  const noexcept { return __y; }
+    inline constexpr chrono::month month() const noexcept { return __m; }
+    inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
+    inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
+    inline constexpr year_month& operator+=(const years& __dy)  noexcept { this->__y += __dy; return *this; }
+    inline constexpr year_month& operator-=(const years& __dy)  noexcept { this->__y -= __dy; return *this; }
+    inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
+};
+
+inline constexpr
+year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
+
+inline constexpr
+year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
+
+inline constexpr
+bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
+{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
+
+inline constexpr
+bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
+{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
+
+inline constexpr
+bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
+{ return !(__rhs < __lhs);}
+
+inline constexpr
+bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
+{
+    int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
+    const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
+    __dmi = __dmi - __dy * 12 + 1;
+    return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
+}
+
+constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
+{ return (__lhs.year() + __rhs) / __lhs.month(); }
+
+constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+constexpr months     operator-(const year_month& __lhs, const year_month& __rhs) noexcept
+{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
+
+constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+class year_month_day_last;
+
+class year_month_day {
+private:
+    chrono::year  __y;
+    chrono::month __m;
+    chrono::day   __d;
+public:
+     year_month_day() = default;
+     inline constexpr year_month_day(
+            const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
+            : __y{__yval}, __m{__mval}, __d{__dval} {}
+            constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
+     inline constexpr year_month_day(const sys_days& __sysd) noexcept
+            : year_month_day(__from_days(__sysd.time_since_epoch())) {}
+     inline explicit constexpr year_month_day(const local_days& __locd) noexcept
+            : year_month_day(__from_days(__locd.time_since_epoch())) {}
+
+            constexpr year_month_day& operator+=(const months& __dm) noexcept;
+            constexpr year_month_day& operator-=(const months& __dm) noexcept;
+            constexpr year_month_day& operator+=(const years& __dy)  noexcept;
+            constexpr year_month_day& operator-=(const years& __dy)  noexcept;
+
+     inline constexpr chrono::year   year() const noexcept { return __y; }
+     inline constexpr chrono::month month() const noexcept { return __m; }
+     inline constexpr chrono::day     day() const noexcept { return __d; }
+     inline constexpr operator   sys_days() const noexcept          { return   sys_days{__to_days()}; }
+     inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
+
+            constexpr bool             ok() const noexcept;
+
+     static constexpr year_month_day __from_days(days __d) noexcept;
+     constexpr days __to_days() const noexcept;
+};
+
+
+// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
+inline constexpr
+year_month_day
+year_month_day::__from_days(days __d) noexcept
+{
+    static_assert(numeric_limits<unsigned>::digits >= 18, "");
+    static_assert(numeric_limits<int>::digits >= 20     , "");
+    const int      __z = __d.count() + 719468;
+    const int      __era = (__z >= 0 ? __z : __z - 146096) / 146097;
+    const unsigned __doe = static_cast<unsigned>(__z - __era * 146097);              // [0, 146096]
+    const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365;  // [0, 399]
+    const int      __yr = static_cast<int>(__yoe) + __era * 400;
+    const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100);              // [0, 365]
+    const unsigned __mp = (5 * __doy + 2)/153;                                       // [0, 11]
+    const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1;                            // [1, 31]
+    const unsigned __mth = __mp + (__mp < 10 ? 3 : -9);                              // [1, 12]
+    return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
+}
+
+// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
+inline constexpr days year_month_day::__to_days() const noexcept
+{
+    static_assert(numeric_limits<unsigned>::digits >= 18, "");
+    static_assert(numeric_limits<int>::digits >= 20     , "");
+
+    const int      __yr  = static_cast<int>(__y) - (__m <= February);
+    const unsigned __mth = static_cast<unsigned>(__m);
+    const unsigned __dy  = static_cast<unsigned>(__d);
+
+    const int      __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
+    const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400);                // [0, 399]
+    const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1;  // [0, 365]
+    const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy;                // [0, 146096]
+    return days{__era * 146097 + static_cast<int>(__doe) - 719468};
+}
+
+inline constexpr
+bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
+{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
+
+inline constexpr
+bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
+{
+    if (__lhs.year() < __rhs.year()) return true;
+    if (__lhs.year() > __rhs.year()) return false;
+    if (__lhs.month() < __rhs.month()) return true;
+    if (__lhs.month() > __rhs.month()) return false;
+    return __lhs.day() < __rhs.day();
+}
+
+inline constexpr
+bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
+{ return !(__rhs < __lhs);}
+
+inline constexpr
+bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+inline constexpr
+year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
+{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
+
+inline constexpr
+year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
+{ return __lhs / day(__rhs); }
+
+inline constexpr
+year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
+{ return __lhs / __rhs.month() / __rhs.day(); }
+
+inline constexpr
+year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
+{ return year(__lhs) / __rhs; }
+
+inline constexpr
+year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
+{ return __rhs / __lhs; }
+
+inline constexpr
+year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
+{ return year(__rhs) / __lhs; }
+
+
+inline constexpr
+year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
+{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
+
+inline constexpr
+year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+inline constexpr
+year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
+{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
+
+inline constexpr
+year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
+{ return __lhs + -__rhs; }
+
+inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
+inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
+inline constexpr year_month_day& year_month_day::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
+inline constexpr year_month_day& year_month_day::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
+
+class year_month_day_last {
+private:
+    chrono::year           __y;
+    chrono::month_day_last __mdl;
+public:
+     constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
+        : __y{__yval}, __mdl{__mdlval} {}
+
+     constexpr year_month_day_last& operator+=(const months& __m) noexcept;
+     constexpr year_month_day_last& operator-=(const months& __m) noexcept;
+     constexpr year_month_day_last& operator+=(const years& __y)  noexcept;
+     constexpr year_month_day_last& operator-=(const years& __y)  noexcept;
+
+     inline constexpr chrono::year                     year() const noexcept { return __y; }
+     inline constexpr chrono::month                   month() const noexcept { return __mdl.month(); }
+     inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
+            constexpr chrono::day                       day() const noexcept;
+     inline constexpr operator                     sys_days() const noexcept { return   sys_days{year()/month()/day()}; }
+     inline explicit constexpr operator          local_days() const noexcept { return local_days{year()/month()/day()}; }
+     inline constexpr bool                               ok() const noexcept { return __y.ok() && __mdl.ok(); }
+};
+
+inline constexpr
+chrono::day year_month_day_last::day() const noexcept
+{
+    constexpr chrono::day __d[] =
+    {
+        chrono::day(31), chrono::day(28), chrono::day(31),
+        chrono::day(30), chrono::day(31), chrono::day(30),
+        chrono::day(31), chrono::day(31), chrono::day(30),
+        chrono::day(31), chrono::day(30), chrono::day(31)
+    };
+    return (month() != February || !__y.is_leap()) && month().ok() ?
+        __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
+}
+
+inline constexpr
+bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
+{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
+
+inline constexpr
+bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
+{
+    if (__lhs.year() < __rhs.year()) return true;
+    if (__lhs.year() > __rhs.year()) return false;
+    return __lhs.month_day_last() < __rhs.month_day_last();
+}
+
+inline constexpr
+bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
+{ return __rhs < __lhs; }
+
+inline constexpr
+bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
+{ return !(__rhs < __lhs);}
+
+inline constexpr
+bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
+{ return !(__lhs < __rhs); }
+
+inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
+{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
+
+inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
+{ return year_month_day_last{__lhs, __rhs}; }
+
+inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
+{ return year_month_day_last{year{__lhs}, __rhs}; }
+
+inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
+{ return __rhs / __lhs; }
+
+inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
+{ return year{__rhs} / __lhs; }
+
+
+inline constexpr
+year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
+{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
+
+inline constexpr
+year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
+{ return __lhs + (-__rhs); }
+
+inline constexpr
+year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
+{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
+
+inline constexpr
+year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
+{ return __lhs + (-__rhs); }
+
+inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
+inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
+inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
+inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
+
+inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
+    : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
+
+inline constexpr bool year_month_day::ok() const noexcept
+{
+    if (!__y.ok() || !__m.ok()) return false;
+    return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
+}
+
+class year_month_weekday {
+    chrono::year            __y;
+    chrono::month           __m;
+    chrono::weekday_indexed __wdi;
+public:
+    year_month_weekday() = default;
+    constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
+                               const chrono::weekday_indexed& __wdival) noexcept
+        : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
+    constexpr year_month_weekday(const sys_days& __sysd) noexcept
+            : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
+    inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
+            : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
+    constexpr year_month_weekday& operator+=(const months& m) noexcept;
+    constexpr year_month_weekday& operator-=(const months& m) noexcept;
+    constexpr year_month_weekday& operator+=(const years& y)  noexcept;
+    constexpr year_month_weekday& operator-=(const years& y)  noexcept;
+
+    inline constexpr chrono::year                       year() const noexcept { return __y; }
+    inline constexpr chrono::month                     month() const noexcept { return __m; }
+    inline constexpr chrono::weekday                 weekday() const noexcept { return __wdi.weekday(); }
+    inline constexpr unsigned                          index() const noexcept { return __wdi.index(); }
+    inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
+
+    inline constexpr                       operator sys_days() const noexcept { return   sys_days{__to_days()}; }
+    inline explicit constexpr operator            local_days() const noexcept { return local_days{__to_days()}; }
+    inline constexpr bool ok() const noexcept
+    {
+        if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
+        if (__wdi.index() <= 4) return true;
+        auto __nth_weekday_day =
+            __wdi.weekday() -
+            chrono::weekday{static_cast<sys_days>(__y / __m / 1)} +
+            days{(__wdi.index() - 1) * 7 + 1};
+        return static_cast<unsigned>(__nth_weekday_day.count()) <=
+               static_cast<unsigned>((__y / __m / last).day());
+    }
+
+    static constexpr year_month_weekday __from_days(days __d) noexcept;
+    constexpr days __to_days() const noexcept;
+};
+
+inline constexpr
+year_month_weekday year_month_weekday::__from_days(days __d) noexcept
+{
+    const sys_days      __sysd{__d};
+    const chrono::weekday __wd = chrono::weekday(__sysd);
+    const year_month_day __ymd = year_month_day(__sysd);
+    return year_month_weekday{__ymd.year(), __ymd.month(),
+                              __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
+}
+
+inline constexpr
+days year_month_weekday::__to_days() const noexcept
+{
+    const sys_days __sysd = sys_days(__y/__m/1);
+    return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
+                .time_since_epoch();
+}
+
+inline constexpr
+bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
+{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
+
+inline constexpr
+bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+inline constexpr
+year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
+{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
+
+inline constexpr
+year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
+{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
+
+inline constexpr
+year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
+{ return year(__lhs) / __rhs; }
+
+inline constexpr
+year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
+{ return __rhs / __lhs; }
+
+inline constexpr
+year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
+{ return year(__rhs) / __lhs; }
+
+
+inline constexpr
+year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
+{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
+
+inline constexpr
+year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
+{ return __lhs + (-__rhs); }
+
+inline constexpr
+year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
+{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
+
+inline constexpr
+year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
+{ return __lhs + (-__rhs); }
+
+
+inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
+inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
+inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
+inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
+
+class year_month_weekday_last {
+private:
+    chrono::year         __y;
+    chrono::month        __m;
+    chrono::weekday_last __wdl;
+public:
+    constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
+                                      const chrono::weekday_last& __wdlval) noexcept
+                : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
+    constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
+    constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
+    constexpr year_month_weekday_last& operator+=(const years& __dy)  noexcept;
+    constexpr year_month_weekday_last& operator-=(const years& __dy)  noexcept;
+
+    inline constexpr chrono::year                 year() const noexcept { return __y; }
+    inline constexpr chrono::month               month() const noexcept { return __m; }
+    inline constexpr chrono::weekday           weekday() const noexcept { return __wdl.weekday(); }
+    inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
+    inline constexpr operator                 sys_days() const noexcept { return   sys_days{__to_days()}; }
+    inline explicit constexpr operator      local_days() const noexcept { return local_days{__to_days()}; }
+    inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
+
+    constexpr days __to_days() const noexcept;
+
+};
+
+inline constexpr
+days year_month_weekday_last::__to_days() const noexcept
+{
+    const sys_days __last = sys_days{__y/__m/last};
+    return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
+
+}
+
+inline constexpr
+bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
+{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
+
+inline constexpr
+bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
+{ return !(__lhs == __rhs); }
+
+
+inline constexpr
+year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
+{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
+
+inline constexpr
+year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
+{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
+
+inline constexpr
+year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
+{ return year(__lhs) / __rhs; }
+
+inline constexpr
+year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
+{ return __rhs / __lhs; }
+
+inline constexpr
+year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
+{ return year(__rhs) / __lhs; }
+
+
+inline constexpr
+year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
+{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
+
+inline constexpr
+year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
+{ return __lhs + (-__rhs); }
+
+inline constexpr
+year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
+{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
+
+inline constexpr
+year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
+{ return __rhs + __lhs; }
+
+inline constexpr
+year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
+{ return __lhs + (-__rhs); }
+
+inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
+inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
+inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
+inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
+
+
+template <class _Duration>
+class hh_mm_ss
+{
+private:
+    static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
+    using __CommonType = common_type_t<_Duration, chrono::seconds>;
+
+    static constexpr uint64_t __pow10(unsigned __exp)
+    {
+        uint64_t __ret = 1;
+        for (unsigned __i = 0; __i < __exp; ++__i)
+            __ret *= 10U;
+        return __ret;
+    }
+
+    static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0)
+    {
+        if (__n >= 2 && __d != 0 && __w < 19)
+            return 1 + __width(__n, __d % __n * 10, __w+1);
+        return 0;
+    }
+
+public:
+    static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ?
+                                                 __width(__CommonType::period::den) : 6u;
+    using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
+
+    constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
+
+    constexpr explicit hh_mm_ss(_Duration __d) noexcept :
+        __is_neg(__d < _Duration(0)),
+        __h(duration_cast<chrono::hours>  (abs(__d))),
+        __m(duration_cast<chrono::minutes>(abs(__d) - hours())),
+        __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())),
+        __f(duration_cast<precision>      (abs(__d) - hours() - minutes() - seconds()))
+        {}
+
+    constexpr bool is_negative()        const noexcept { return __is_neg; }
+    constexpr chrono::hours hours()     const noexcept { return __h; }
+    constexpr chrono::minutes minutes() const noexcept { return __m; }
+    constexpr chrono::seconds seconds() const noexcept { return __s; }
+    constexpr precision subseconds()    const noexcept { return __f; }
+
+    constexpr precision to_duration() const noexcept
+    {
+        auto __dur = __h + __m + __s + __f;
+        return __is_neg ? -__dur : __dur;
+    }
+
+    constexpr explicit operator precision() const noexcept { return to_duration(); }
+
+private:
+    bool            __is_neg;
+    chrono::hours   __h;
+    chrono::minutes __m;
+    chrono::seconds __s;
+    precision       __f;
+};
+
+constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
+constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
+
+constexpr hours make12(const hours& __h) noexcept
+{
+    if      (__h == hours( 0)) return hours(12);
+    else if (__h <= hours(12)) return __h;
+    else                       return __h - hours(12);
+}
+
+constexpr hours make24(const hours& __h, bool __is_pm) noexcept
+{
+    if (__is_pm)
+        return __h == hours(12) ? __h : __h + hours(12);
+    else
+        return __h == hours(12) ? hours(0) : __h;
+}
+
+} // namespace chrono
+
+inline namespace literals
+{
+  inline namespace chrono_literals
+  {
+    constexpr chrono::day operator ""d(unsigned long long __d) noexcept
+    {
+        return chrono::day(static_cast<unsigned>(__d));
+    }
+
+    constexpr chrono::year operator ""y(unsigned long long __y) noexcept
+    {
+        return chrono::year(static_cast<int>(__y));
+    }
+} // namespace chrono_literals
+} // namespace literals
+
+namespace chrono { // hoist the literals into namespace std::chrono
+   using namespace literals::chrono_literals;
+} // namespace chrono
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___CHRONO_CALENDAR_H
lib/libcxx/include/__chrono/convert_to_timespec.h
@@ -0,0 +1,55 @@
+// -*- 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___CHRONO_CONVERT_TO_TIMESPEC_H
+#define _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H
+
+#include <__chrono/duration.h>
+#include <__config>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// Convert a nanoseconds duration to the given TimeSpec type, which must have
+// the same properties as std::timespec.
+template <class _TimeSpec>
+_LIBCPP_HIDE_FROM_ABI inline
+_TimeSpec __convert_to_timespec(const chrono::nanoseconds& __ns)
+{
+  using namespace chrono;
+  seconds __s = duration_cast<seconds>(__ns);
+  _TimeSpec __ts;
+  typedef decltype(__ts.tv_sec) __ts_sec;
+  const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
+
+  if (__s.count() < __ts_sec_max)
+  {
+    __ts.tv_sec = static_cast<__ts_sec>(__s.count());
+    __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
+  }
+  else
+  {
+    __ts.tv_sec = __ts_sec_max;
+    __ts.tv_nsec = 999999999; // (10^9 - 1)
+  }
+
+  return __ts;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___CHRONO_CONVERT_TO_TIMESPEC_H
lib/libcxx/include/__chrono/duration.h
@@ -0,0 +1,615 @@
+// -*- 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___CHRONO_DURATION_H
+#define _LIBCPP___CHRONO_DURATION_H
+
+#include <__config>
+#include <limits>
+#include <ratio>
+#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
+
+namespace chrono
+{
+
+template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
+
+template <class _Tp>
+struct __is_duration : false_type {};
+
+template <class _Rep, class _Period>
+struct __is_duration<duration<_Rep, _Period> > : true_type  {};
+
+template <class _Rep, class _Period>
+struct __is_duration<const duration<_Rep, _Period> > : true_type  {};
+
+template <class _Rep, class _Period>
+struct __is_duration<volatile duration<_Rep, _Period> > : true_type  {};
+
+template <class _Rep, class _Period>
+struct __is_duration<const volatile duration<_Rep, _Period> > : true_type  {};
+
+} // namespace chrono
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
+                                         chrono::duration<_Rep2, _Period2> >
+{
+    typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
+                             typename __ratio_gcd<_Period1, _Period2>::type> type;
+};
+
+namespace chrono {
+
+// duration_cast
+
+template <class _FromDuration, class _ToDuration,
+          class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
+          bool = _Period::num == 1,
+          bool = _Period::den == 1>
+struct __duration_cast;
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
+    }
+};
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
+        return _ToDuration(static_cast<typename _ToDuration::rep>(
+                           static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
+    }
+};
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
+        return _ToDuration(static_cast<typename _ToDuration::rep>(
+                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
+    }
+};
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
+        return _ToDuration(static_cast<typename _ToDuration::rep>(
+                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
+                                                          / static_cast<_Ct>(_Period::den)));
+    }
+};
+
+template <class _ToDuration, class _Rep, class _Period>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    _ToDuration
+>::type
+duration_cast(const duration<_Rep, _Period>& __fd)
+{
+    return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
+}
+
+template <class _Rep>
+struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
+
+#if _LIBCPP_STD_VER > 14
+template <class _Rep>
+inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>::value;
+#endif
+
+template <class _Rep>
+struct _LIBCPP_TEMPLATE_VIS duration_values
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max()  _NOEXCEPT {return numeric_limits<_Rep>::max();}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min()  _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
+};
+
+#if _LIBCPP_STD_VER > 14
+template <class _ToDuration, class _Rep, class _Period>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    _ToDuration
+>::type
+floor(const duration<_Rep, _Period>& __d)
+{
+    _ToDuration __t = duration_cast<_ToDuration>(__d);
+    if (__t > __d)
+        __t = __t - _ToDuration{1};
+    return __t;
+}
+
+template <class _ToDuration, class _Rep, class _Period>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    _ToDuration
+>::type
+ceil(const duration<_Rep, _Period>& __d)
+{
+    _ToDuration __t = duration_cast<_ToDuration>(__d);
+    if (__t < __d)
+        __t = __t + _ToDuration{1};
+    return __t;
+}
+
+template <class _ToDuration, class _Rep, class _Period>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    _ToDuration
+>::type
+round(const duration<_Rep, _Period>& __d)
+{
+    _ToDuration __lower = floor<_ToDuration>(__d);
+    _ToDuration __upper = __lower + _ToDuration{1};
+    auto __lowerDiff = __d - __lower;
+    auto __upperDiff = __upper - __d;
+    if (__lowerDiff < __upperDiff)
+        return __lower;
+    if (__lowerDiff > __upperDiff)
+        return __upper;
+    return __lower.count() & 1 ? __upper : __lower;
+}
+#endif
+
+// duration
+
+template <class _Rep, class _Period>
+class _LIBCPP_TEMPLATE_VIS duration
+{
+    static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
+    static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
+    static_assert(_Period::num > 0, "duration period must be positive");
+
+    template <class _R1, class _R2>
+    struct __no_overflow
+    {
+    private:
+        static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
+        static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
+        static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
+        static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
+        static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
+        static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
+        static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
+
+        template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
+        struct __mul    // __overflow == false
+        {
+            static const intmax_t value = _Xp * _Yp;
+        };
+
+        template <intmax_t _Xp, intmax_t _Yp>
+        struct __mul<_Xp, _Yp, true>
+        {
+            static const intmax_t value = 1;
+        };
+
+    public:
+        static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
+        typedef ratio<__mul<__n1, __d2, !value>::value,
+                      __mul<__n2, __d1, !value>::value> type;
+    };
+
+public:
+    typedef _Rep rep;
+    typedef typename _Period::type period;
+private:
+    rep __rep_;
+public:
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+#ifndef _LIBCPP_CXX03_LANG
+        duration() = default;
+#else
+        duration() {}
+#endif
+
+    template <class _Rep2>
+        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+        explicit duration(const _Rep2& __r,
+            typename enable_if
+            <
+               is_convertible<const _Rep2&, rep>::value &&
+               (treat_as_floating_point<rep>::value ||
+               !treat_as_floating_point<_Rep2>::value)
+            >::type* = nullptr)
+                : __rep_(__r) {}
+
+    // conversions
+    template <class _Rep2, class _Period2>
+        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+        duration(const duration<_Rep2, _Period2>& __d,
+            typename enable_if
+            <
+                __no_overflow<_Period2, period>::value && (
+                treat_as_floating_point<rep>::value ||
+                (__no_overflow<_Period2, period>::type::den == 1 &&
+                 !treat_as_floating_point<_Rep2>::value))
+            >::type* = nullptr)
+                : __rep_(chrono::duration_cast<duration>(__d).count()) {}
+
+    // observer
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
+
+    // arithmetic
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++()      {++__rep_; return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator++(int)   {return duration(__rep_++);}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--()      {--__rep_; return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator--(int)   {return duration(__rep_--);}
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
+
+    // special values
+
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min()  _NOEXCEPT {return duration(duration_values<rep>::min());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max()  _NOEXCEPT {return duration(duration_values<rep>::max());}
+};
+
+typedef duration<long long,         nano> nanoseconds;
+typedef duration<long long,        micro> microseconds;
+typedef duration<long long,        milli> milliseconds;
+typedef duration<long long              > seconds;
+typedef duration<     long, ratio<  60> > minutes;
+typedef duration<     long, ratio<3600> > hours;
+#if _LIBCPP_STD_VER > 17
+typedef duration<     int, ratio_multiply<ratio<24>, hours::period>>         days;
+typedef duration<     int, ratio_multiply<ratio<7>,   days::period>>         weeks;
+typedef duration<     int, ratio_multiply<ratio<146097, 400>, days::period>> years;
+typedef duration<     int, ratio_divide<years::period, ratio<12>>>           months;
+#endif
+// Duration ==
+
+template <class _LhsDuration, class _RhsDuration>
+struct __duration_eq
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
+        {
+            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
+            return _Ct(__lhs).count() == _Ct(__rhs).count();
+        }
+};
+
+template <class _LhsDuration>
+struct __duration_eq<_LhsDuration, _LhsDuration>
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
+        {return __lhs.count() == __rhs.count();}
+};
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+bool
+operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
+}
+
+// Duration !=
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+bool
+operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return !(__lhs == __rhs);
+}
+
+// Duration <
+
+template <class _LhsDuration, class _RhsDuration>
+struct __duration_lt
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
+        {
+            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
+            return _Ct(__lhs).count() < _Ct(__rhs).count();
+        }
+};
+
+template <class _LhsDuration>
+struct __duration_lt<_LhsDuration, _LhsDuration>
+{
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
+        {return __lhs.count() < __rhs.count();}
+};
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+bool
+operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
+}
+
+// Duration >
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+bool
+operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return __rhs < __lhs;
+}
+
+// Duration <=
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+bool
+operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return !(__rhs < __lhs);
+}
+
+// Duration >=
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+bool
+operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return !(__lhs < __rhs);
+}
+
+// Duration +
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
+operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
+    return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
+}
+
+// Duration -
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
+operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
+    return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
+}
+
+// Duration *
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename enable_if
+<
+    is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
+    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+>::type
+operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
+{
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    typedef duration<_Cr, _Period> _Cd;
+    return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
+}
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename enable_if
+<
+    is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
+    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+>::type
+operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
+{
+    return __d * __s;
+}
+
+// Duration /
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename enable_if
+<
+    !__is_duration<_Rep2>::value &&
+      is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
+    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+>::type
+operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
+{
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    typedef duration<_Cr, _Period> _Cd;
+    return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
+}
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename common_type<_Rep1, _Rep2>::type
+operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
+    return _Ct(__lhs).count() / _Ct(__rhs).count();
+}
+
+// Duration %
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename enable_if
+<
+    !__is_duration<_Rep2>::value &&
+      is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
+    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+>::type
+operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
+{
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    typedef duration<_Cr, _Period> _Cd;
+    return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
+}
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
+operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
+    return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
+}
+
+} // namespace chrono
+
+#if _LIBCPP_STD_VER > 11
+// Suffixes for duration literals [time.duration.literals]
+inline namespace literals
+{
+  inline namespace chrono_literals
+  {
+
+    constexpr chrono::hours operator""h(unsigned long long __h)
+    {
+        return chrono::hours(static_cast<chrono::hours::rep>(__h));
+    }
+
+    constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
+    {
+        return chrono::duration<long double, ratio<3600,1>>(__h);
+    }
+
+
+    constexpr chrono::minutes operator""min(unsigned long long __m)
+    {
+        return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
+    }
+
+    constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
+    {
+        return chrono::duration<long double, ratio<60,1>> (__m);
+    }
+
+
+    constexpr chrono::seconds operator""s(unsigned long long __s)
+    {
+        return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
+    }
+
+    constexpr chrono::duration<long double> operator""s(long double __s)
+    {
+        return chrono::duration<long double> (__s);
+    }
+
+
+    constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
+    {
+        return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
+    }
+
+    constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
+    {
+        return chrono::duration<long double, milli>(__ms);
+    }
+
+
+    constexpr chrono::microseconds operator""us(unsigned long long __us)
+    {
+        return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
+    }
+
+    constexpr chrono::duration<long double, micro> operator""us(long double __us)
+    {
+        return chrono::duration<long double, micro> (__us);
+    }
+
+
+    constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
+    {
+        return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
+    }
+
+    constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
+    {
+        return chrono::duration<long double, nano> (__ns);
+    }
+
+} // namespace chrono_literals
+} // namespace literals
+
+namespace chrono { // hoist the literals into namespace std::chrono
+   using namespace literals::chrono_literals;
+} // namespace chrono
+
+#endif // _LIBCPP_STD_VER > 11
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___CHRONO_DURATION_H
lib/libcxx/include/__chrono/file_clock.h
@@ -0,0 +1,85 @@
+// -*- 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___CHRONO_FILE_CLOCK_H
+#define _LIBCPP___CHRONO_FILE_CLOCK_H
+
+#include <__availability>
+#include <__chrono/duration.h>
+#include <__chrono/system_clock.h>
+#include <__chrono/time_point.h>
+#include <__config>
+#include <ratio>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_CXX03_LANG
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+struct _FilesystemClock;
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+#endif // !_LIBCPP_CXX03_LANG
+
+#if _LIBCPP_STD_VER > 17
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace chrono
+{
+
+// [time.clock.file], type file_clock
+using file_clock = _VSTD_FS::_FilesystemClock;
+
+template<class _Duration>
+using file_time = time_point<file_clock, _Duration>;
+
+} // namespace chrono
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER > 17
+
+#ifndef _LIBCPP_CXX03_LANG
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+struct _FilesystemClock {
+#if !defined(_LIBCPP_HAS_NO_INT128)
+  typedef __int128_t rep;
+  typedef nano period;
+#else
+  typedef long long rep;
+  typedef nano period;
+#endif
+
+  typedef chrono::duration<rep, period> duration;
+  typedef chrono::time_point<_FilesystemClock> time_point;
+
+  _LIBCPP_EXPORTED_FROM_ABI
+  static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
+
+  _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
+
+#if _LIBCPP_STD_VER > 17
+  template <class _Duration>
+  _LIBCPP_HIDE_FROM_ABI
+  static chrono::sys_time<_Duration> to_sys(const chrono::file_time<_Duration>& __t) {
+    return chrono::sys_time<_Duration>(__t.time_since_epoch());
+  }
+
+  template <class _Duration>
+  _LIBCPP_HIDE_FROM_ABI
+  static chrono::file_time<_Duration> from_sys(const chrono::sys_time<_Duration>& __t) {
+    return chrono::file_time<_Duration>(__t.time_since_epoch());
+  }
+#endif // _LIBCPP_STD_VER > 17
+};
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+#endif // !_LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___CHRONO_FILE_CLOCK_H
lib/libcxx/include/__chrono/high_resolution_clock.h
@@ -0,0 +1,36 @@
+// -*- 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___CHRONO_HIGH_RESOLUTION_CLOCK_H
+#define _LIBCPP___CHRONO_HIGH_RESOLUTION_CLOCK_H
+
+#include <__chrono/steady_clock.h>
+#include <__chrono/system_clock.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace chrono
+{
+
+#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+typedef steady_clock high_resolution_clock;
+#else
+typedef system_clock high_resolution_clock;
+#endif
+
+} // namespace chrono
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHRONO_HIGH_RESOLUTION_CLOCK_H
lib/libcxx/include/__chrono/steady_clock.h
@@ -0,0 +1,44 @@
+// -*- 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___CHRONO_STEADY_CLOCK_H
+#define _LIBCPP___CHRONO_STEADY_CLOCK_H
+
+#include <__chrono/duration.h>
+#include <__chrono/time_point.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace chrono
+{
+
+#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+class _LIBCPP_TYPE_VIS steady_clock
+{
+public:
+    typedef nanoseconds                                   duration;
+    typedef duration::rep                                 rep;
+    typedef duration::period                              period;
+    typedef chrono::time_point<steady_clock, duration>    time_point;
+    static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
+
+    static time_point now() _NOEXCEPT;
+};
+#endif
+
+} // namespace chrono
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHRONO_STEADY_CLOCK_H
lib/libcxx/include/__chrono/system_clock.h
@@ -0,0 +1,54 @@
+// -*- 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___CHRONO_SYSTEM_CLOCK_H
+#define _LIBCPP___CHRONO_SYSTEM_CLOCK_H
+
+#include <__chrono/duration.h>
+#include <__chrono/time_point.h>
+#include <__config>
+#include <ctime>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace chrono
+{
+
+class _LIBCPP_TYPE_VIS system_clock
+{
+public:
+    typedef microseconds                     duration;
+    typedef duration::rep                    rep;
+    typedef duration::period                 period;
+    typedef chrono::time_point<system_clock> time_point;
+    static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
+
+    static time_point now() _NOEXCEPT;
+    static time_t     to_time_t  (const time_point& __t) _NOEXCEPT;
+    static time_point from_time_t(time_t __t) _NOEXCEPT;
+};
+
+#if _LIBCPP_STD_VER > 17
+
+template <class _Duration>
+using sys_time    = time_point<system_clock, _Duration>;
+using sys_seconds = sys_time<seconds>;
+using sys_days    = sys_time<days>;
+
+#endif
+
+} // namespace chrono
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHRONO_SYSTEM_CLOCK_H
lib/libcxx/include/__chrono/time_point.h
@@ -0,0 +1,249 @@
+// -*- 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___CHRONO_TIME_POINT_H
+#define _LIBCPP___CHRONO_TIME_POINT_H
+
+#include <__chrono/duration.h>
+#include <__config>
+#include <limits>
+#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
+
+namespace chrono
+{
+
+template <class _Clock, class _Duration = typename _Clock::duration>
+class _LIBCPP_TEMPLATE_VIS time_point
+{
+    static_assert(__is_duration<_Duration>::value,
+                  "Second template parameter of time_point must be a std::chrono::duration");
+public:
+    typedef _Clock                    clock;
+    typedef _Duration                 duration;
+    typedef typename duration::rep    rep;
+    typedef typename duration::period period;
+private:
+    duration __d_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
+
+    // conversions
+    template <class _Duration2>
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    time_point(const time_point<clock, _Duration2>& t,
+        typename enable_if
+        <
+            is_convertible<_Duration2, duration>::value
+        >::type* = nullptr)
+            : __d_(t.time_since_epoch()) {}
+
+    // observer
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
+
+    // arithmetic
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
+
+    // special values
+
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
+};
+
+} // namespace chrono
+
+template <class _Clock, class _Duration1, class _Duration2>
+struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
+                                         chrono::time_point<_Clock, _Duration2> >
+{
+    typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
+};
+
+namespace chrono {
+
+template <class _ToDuration, class _Clock, class _Duration>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+time_point<_Clock, _ToDuration>
+time_point_cast(const time_point<_Clock, _Duration>& __t)
+{
+    return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
+}
+
+#if _LIBCPP_STD_VER > 14
+template <class _ToDuration, class _Clock, class _Duration>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    time_point<_Clock, _ToDuration>
+>::type
+floor(const time_point<_Clock, _Duration>& __t)
+{
+    return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
+}
+
+template <class _ToDuration, class _Clock, class _Duration>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    time_point<_Clock, _ToDuration>
+>::type
+ceil(const time_point<_Clock, _Duration>& __t)
+{
+    return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
+}
+
+template <class _ToDuration, class _Clock, class _Duration>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    time_point<_Clock, _ToDuration>
+>::type
+round(const time_point<_Clock, _Duration>& __t)
+{
+    return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
+}
+
+template <class _Rep, class _Period>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename enable_if
+<
+    numeric_limits<_Rep>::is_signed,
+    duration<_Rep, _Period>
+>::type
+abs(duration<_Rep, _Period> __d)
+{
+    return __d >= __d.zero() ? +__d : -__d;
+}
+#endif // _LIBCPP_STD_VER > 14
+
+// time_point ==
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+bool
+operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __lhs.time_since_epoch() == __rhs.time_since_epoch();
+}
+
+// time_point !=
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+bool
+operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return !(__lhs == __rhs);
+}
+
+// time_point <
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+bool
+operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __lhs.time_since_epoch() < __rhs.time_since_epoch();
+}
+
+// time_point >
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+bool
+operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __rhs < __lhs;
+}
+
+// time_point <=
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+bool
+operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return !(__rhs < __lhs);
+}
+
+// time_point >=
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+bool
+operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return !(__lhs < __rhs);
+}
+
+// time_point operator+(time_point x, duration y);
+
+template <class _Clock, class _Duration1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
+operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
+    return _Tr (__lhs.time_since_epoch() + __rhs);
+}
+
+// time_point operator+(duration x, time_point y);
+
+template <class _Rep1, class _Period1, class _Clock, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
+operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __rhs + __lhs;
+}
+
+// time_point operator-(time_point x, duration y);
+
+template <class _Clock, class _Duration1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
+operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
+    return _Ret(__lhs.time_since_epoch() -__rhs);
+}
+
+// duration operator-(time_point x, time_point y);
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+typename common_type<_Duration1, _Duration2>::type
+operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __lhs.time_since_epoch() - __rhs.time_since_epoch();
+}
+
+} // namespace chrono
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___CHRONO_TIME_POINT_H
lib/libcxx/include/__compare/common_comparison_category.h
@@ -0,0 +1,94 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_COMMON_COMPARISON_CATEGORY_H
+#define _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H
+
+#include <__compare/ordering.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+namespace __comp_detail {
+
+enum _ClassifyCompCategory : unsigned {
+  _None,
+  _PartialOrd,
+  _WeakOrd,
+  _StrongOrd,
+  _CCC_Size
+};
+
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI
+constexpr _ClassifyCompCategory __type_to_enum() noexcept {
+  if (is_same_v<_Tp, partial_ordering>)
+    return _PartialOrd;
+  if (is_same_v<_Tp, weak_ordering>)
+    return _WeakOrd;
+  if (is_same_v<_Tp, strong_ordering>)
+    return _StrongOrd;
+  return _None;
+}
+
+template <size_t _Size>
+_LIBCPP_HIDE_FROM_ABI
+constexpr _ClassifyCompCategory
+__compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
+  int __seen[_CCC_Size] = {};
+  for (auto __type : __types)
+    ++__seen[__type];
+  if (__seen[_None])
+    return _None;
+  if (__seen[_PartialOrd])
+    return _PartialOrd;
+  if (__seen[_WeakOrd])
+    return _WeakOrd;
+  return _StrongOrd;
+}
+
+template <class ..._Ts, bool _False = false>
+_LIBCPP_HIDE_FROM_ABI
+constexpr auto __get_comp_type() {
+  using _CCC = _ClassifyCompCategory;
+  constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
+  constexpr _CCC _Cat = __compute_comp_type(__type_kinds);
+  if constexpr (_Cat == _None)
+    return void();
+  else if constexpr (_Cat == _PartialOrd)
+    return partial_ordering::equivalent;
+  else if constexpr (_Cat == _WeakOrd)
+    return weak_ordering::equivalent;
+  else if constexpr (_Cat == _StrongOrd)
+    return strong_ordering::equivalent;
+  else
+    static_assert(_False, "unhandled case");
+}
+} // namespace __comp_detail
+
+// [cmp.common], common comparison category type
+template<class... _Ts>
+struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
+  using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
+};
+
+template<class... _Ts>
+using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_COMMON_COMPARISON_CATEGORY_H
lib/libcxx/include/__compare/compare_partial_order_fallback.h
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK
+#define _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK
+
+#include <__compare/ordering.h>
+#include <__compare/partial_order.h>
+#include <__config>
+#include <__utility/forward.h>
+#include <__utility/priority_tag.h>
+#include <type_traits>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [cmp.alg]
+namespace __compare_partial_order_fallback {
+    struct __fn {
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
+            noexcept(noexcept(_VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            -> decltype(      _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
+            { return          _VSTD::partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
+            noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
+                              _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
+                              partial_ordering::unordered))
+            -> decltype(      _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
+                              _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
+                              partial_ordering::unordered)
+        {
+            return            _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? partial_ordering::equivalent :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? partial_ordering::less :
+                              _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t) ? partial_ordering::greater :
+                              partial_ordering::unordered;
+        }
+
+        template<class _Tp, class _Up>
+        _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
+            noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
+            -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
+            { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
+    };
+} // namespace __compare_partial_order_fallback
+
+inline namespace __cpo {
+    inline constexpr auto compare_partial_order_fallback = __compare_partial_order_fallback::__fn{};
+} // namespace __cpo
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_COMPARE_PARTIAL_ORDER_FALLBACK
lib/libcxx/include/__compare/compare_strong_order_fallback.h
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_COMPARE_STRONG_ORDER_FALLBACK
+#define _LIBCPP___COMPARE_COMPARE_STRONG_ORDER_FALLBACK
+
+#include <__compare/ordering.h>
+#include <__compare/strong_order.h>
+#include <__config>
+#include <__utility/forward.h>
+#include <__utility/priority_tag.h>
+#include <type_traits>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [cmp.alg]
+namespace __compare_strong_order_fallback {
+    struct __fn {
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
+            noexcept(noexcept(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            -> decltype(      _VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
+            { return          _VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
+            noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
+                              strong_ordering::greater))
+            -> decltype(      _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
+                              strong_ordering::greater)
+        {
+            return            _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? strong_ordering::equal :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? strong_ordering::less :
+                              strong_ordering::greater;
+        }
+
+        template<class _Tp, class _Up>
+        _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
+            noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
+            -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
+            { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
+    };
+} // namespace __compare_strong_order_fallback
+
+inline namespace __cpo {
+    inline constexpr auto compare_strong_order_fallback = __compare_strong_order_fallback::__fn{};
+} // namespace __cpo
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_COMPARE_STRONG_ORDER_FALLBACK
lib/libcxx/include/__compare/compare_three_way.h
@@ -0,0 +1,41 @@
+// -*- 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___COMPARE_COMPARE_THREE_WAY_H
+#define _LIBCPP___COMPARE_COMPARE_THREE_WAY_H
+
+#include <__compare/three_way_comparable.h>
+#include <__config>
+#include <__utility/forward.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+struct _LIBCPP_TEMPLATE_VIS compare_three_way
+{
+    template<class _T1, class _T2>
+        requires three_way_comparable_with<_T1, _T2>
+    constexpr _LIBCPP_HIDE_FROM_ABI
+    auto operator()(_T1&& __t, _T2&& __u) const
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u)))
+        { return          _VSTD::forward<_T1>(__t) <=> _VSTD::forward<_T2>(__u); }
+
+    using is_transparent = void;
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_H
lib/libcxx/include/__compare/compare_three_way_result.h
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_COMPARE_THREE_WAY_RESULT_H
+#define _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+template<class, class, class>
+struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result { };
+
+template<class _Tp, class _Up>
+struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<_Tp, _Up, decltype(
+  declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>(), void()
+)> {
+    using type = decltype(declval<__make_const_lvalue_ref<_Tp>>() <=> declval<__make_const_lvalue_ref<_Up>>());
+};
+
+template<class _Tp, class _Up = _Tp>
+struct _LIBCPP_TEMPLATE_VIS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> { };
+
+template<class _Tp, class _Up = _Tp>
+using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type;
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_COMPARE_THREE_WAY_RESULT_H
lib/libcxx/include/__compare/compare_weak_order_fallback.h
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
+#define _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
+
+#include <__compare/ordering.h>
+#include <__compare/weak_order.h>
+#include <__config>
+#include <__utility/forward.h>
+#include <__utility/priority_tag.h>
+#include <type_traits>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [cmp.alg]
+namespace __compare_weak_order_fallback {
+    struct __fn {
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
+            noexcept(noexcept(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            -> decltype(      _VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))
+            { return          _VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)); }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
+            noexcept(noexcept(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
+                              weak_ordering::greater))
+            -> decltype(      _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
+                              weak_ordering::greater)
+        {
+            return            _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u) ? weak_ordering::equivalent :
+                              _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u) ? weak_ordering::less :
+                              weak_ordering::greater;
+        }
+
+        template<class _Tp, class _Up>
+        _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
+            noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>())))
+            -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()))
+            { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<1>()); }
+    };
+} // namespace __compare_weak_order_fallback
+
+inline namespace __cpo {
+    inline constexpr auto compare_weak_order_fallback = __compare_weak_order_fallback::__fn{};
+} // namespace __cpo
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_COMPARE_WEAK_ORDER_FALLBACK
lib/libcxx/include/__compare/is_eq.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_IS_EQ_H
+#define _LIBCPP___COMPARE_IS_EQ_H
+
+#include <__compare/ordering.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_eq(partial_ordering __c) noexcept { return __c == 0; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_neq(partial_ordering __c) noexcept { return __c != 0; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_lt(partial_ordering __c) noexcept { return __c < 0; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_lteq(partial_ordering __c) noexcept { return __c <= 0; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_gt(partial_ordering __c) noexcept { return __c > 0; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_gteq(partial_ordering __c) noexcept { return __c >= 0; }
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_IS_EQ_H
lib/libcxx/include/__compare/ordering.h
@@ -0,0 +1,319 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_ORDERING_H
+#define _LIBCPP___COMPARE_ORDERING_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// exposition only
+enum class _LIBCPP_ENUM_VIS _OrdResult : signed char {
+  __less = -1,
+  __equiv = 0,
+  __greater = 1
+};
+
+enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {
+  __unordered = -127
+};
+
+class partial_ordering;
+class weak_ordering;
+class strong_ordering;
+
+template<class _Tp, class... _Args>
+inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
+
+struct _CmpUnspecifiedParam {
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEVAL
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+
+  template<class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
+  _CmpUnspecifiedParam(_Tp) = delete;
+};
+
+class partial_ordering {
+  using _ValueT = signed char;
+
+  _LIBCPP_HIDE_FROM_ABI
+  explicit constexpr partial_ordering(_OrdResult __v) noexcept
+      : __value_(_ValueT(__v)) {}
+
+  _LIBCPP_HIDE_FROM_ABI
+  explicit constexpr partial_ordering(_NCmpResult __v) noexcept
+      : __value_(_ValueT(__v)) {}
+
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr bool __is_ordered() const noexcept {
+    return __value_ != _ValueT(_NCmpResult::__unordered);
+  }
+public:
+  // valid values
+  static const partial_ordering less;
+  static const partial_ordering equivalent;
+  static const partial_ordering greater;
+  static const partial_ordering unordered;
+
+  // comparisons
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__is_ordered() && __v.__value_ == 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__is_ordered() && __v.__value_ < 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
+    return __v.__is_ordered() && __v.__value_ <= 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
+    return __v.__is_ordered() && __v.__value_ > 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
+    return __v.__is_ordered() && __v.__value_ >= 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
+    return __v.__is_ordered() && 0 < __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
+    return __v.__is_ordered() && 0 <= __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
+    return __v.__is_ordered() && 0 > __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
+    return __v.__is_ordered() && 0 >= __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
+    return __v;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
+    return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
+  }
+private:
+  _ValueT __value_;
+};
+
+inline constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
+inline constexpr partial_ordering partial_ordering::equivalent(_OrdResult::__equiv);
+inline constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
+inline constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
+
+class weak_ordering {
+  using _ValueT = signed char;
+
+  _LIBCPP_HIDE_FROM_ABI
+  explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
+
+public:
+  static const weak_ordering less;
+  static const weak_ordering equivalent;
+  static const weak_ordering greater;
+
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr operator partial_ordering() const noexcept {
+    return __value_ == 0 ? partial_ordering::equivalent
+        : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
+  }
+
+  // comparisons
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ == 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ < 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ <= 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ > 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ >= 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
+    return 0 < __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
+    return 0 <= __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
+    return 0 > __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
+    return 0 >= __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
+    return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
+  }
+
+private:
+  _ValueT __value_;
+};
+
+inline constexpr weak_ordering weak_ordering::less(_OrdResult::__less);
+inline constexpr weak_ordering weak_ordering::equivalent(_OrdResult::__equiv);
+inline constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
+
+class strong_ordering {
+  using _ValueT = signed char;
+
+  _LIBCPP_HIDE_FROM_ABI
+  explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
+
+public:
+  static const strong_ordering less;
+  static const strong_ordering equal;
+  static const strong_ordering equivalent;
+  static const strong_ordering greater;
+
+  // conversions
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr operator partial_ordering() const noexcept {
+    return __value_ == 0 ? partial_ordering::equivalent
+        : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr operator weak_ordering() const noexcept {
+    return __value_ == 0 ? weak_ordering::equivalent
+        : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
+  }
+
+  // comparisons
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ == 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ < 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ <= 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ > 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v.__value_ >= 0;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
+    return 0 < __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
+    return 0 <= __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
+    return 0 > __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
+    return 0 >= __v.__value_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
+    return __v;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
+    return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
+  }
+
+private:
+  _ValueT __value_;
+};
+
+inline constexpr strong_ordering strong_ordering::less(_OrdResult::__less);
+inline constexpr strong_ordering strong_ordering::equal(_OrdResult::__equiv);
+inline constexpr strong_ordering strong_ordering::equivalent(_OrdResult::__equiv);
+inline constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater);
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_ORDERING_H
lib/libcxx/include/__compare/partial_order.h
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_PARTIAL_ORDER
+#define _LIBCPP___COMPARE_PARTIAL_ORDER
+
+#include <__compare/compare_three_way.h>
+#include <__compare/ordering.h>
+#include <__compare/weak_order.h>
+#include <__config>
+#include <__utility/forward.h>
+#include <__utility/priority_tag.h>
+#include <type_traits>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [cmp.alg]
+namespace __partial_order {
+    struct __fn {
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
+            noexcept(noexcept(partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          partial_ordering(partial_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
+            noexcept(noexcept(partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          partial_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
+            noexcept(noexcept(partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          partial_ordering(_VSTD::weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up>
+        _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
+            noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
+            -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
+            { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
+    };
+} // namespace __partial_order
+
+inline namespace __cpo {
+    inline constexpr auto partial_order = __partial_order::__fn{};
+} // namespace __cpo
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_PARTIAL_ORDER
lib/libcxx/include/__compare/strong_order.h
@@ -0,0 +1,136 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_STRONG_ORDER
+#define _LIBCPP___COMPARE_STRONG_ORDER
+
+#include <__bit/bit_cast.h>
+#include <__compare/compare_three_way.h>
+#include <__compare/ordering.h>
+#include <__config>
+#include <__utility/forward.h>
+#include <__utility/priority_tag.h>
+#include <cmath>
+#include <cstdint>
+#include <limits>
+#include <type_traits>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [cmp.alg]
+namespace __strong_order {
+    struct __fn {
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<2>)
+            noexcept(noexcept(strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          strong_ordering(strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up, class _Dp = decay_t<_Tp>>
+            requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
+        _LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<1>) noexcept
+        {
+            if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int32_t)) {
+                int32_t __rx = _VSTD::bit_cast<int32_t>(__t);
+                int32_t __ry = _VSTD::bit_cast<int32_t>(__u);
+                __rx = (__rx < 0) ? (numeric_limits<int32_t>::min() - __rx - 1) : __rx;
+                __ry = (__ry < 0) ? (numeric_limits<int32_t>::min() - __ry - 1) : __ry;
+                return (__rx <=> __ry);
+            } else if constexpr (numeric_limits<_Dp>::is_iec559 && sizeof(_Dp) == sizeof(int64_t)) {
+                int64_t __rx = _VSTD::bit_cast<int64_t>(__t);
+                int64_t __ry = _VSTD::bit_cast<int64_t>(__u);
+                __rx = (__rx < 0) ? (numeric_limits<int64_t>::min() - __rx - 1) : __rx;
+                __ry = (__ry < 0) ? (numeric_limits<int64_t>::min() - __ry - 1) : __ry;
+                return (__rx <=> __ry);
+            } else if (__t < __u) {
+                return strong_ordering::less;
+            } else if (__t > __u) {
+                return strong_ordering::greater;
+            } else if (__t == __u) {
+                if constexpr (numeric_limits<_Dp>::radix == 2) {
+                    return _VSTD::signbit(__u) <=> _VSTD::signbit(__t);
+                } else {
+                    // This is bullet 3 of the IEEE754 algorithm, relevant
+                    // only for decimal floating-point;
+                    // see https://stackoverflow.com/questions/69068075/
+                    if (__t == 0 || _VSTD::isinf(__t)) {
+                        return _VSTD::signbit(__u) <=> _VSTD::signbit(__t);
+                    } else {
+                        int __texp, __uexp;
+                        (void)_VSTD::frexp(__t, &__texp);
+                        (void)_VSTD::frexp(__u, &__uexp);
+                        return (__t < 0) ? (__texp <=> __uexp) : (__uexp <=> __texp);
+                    }
+                }
+            } else {
+                // They're unordered, so one of them must be a NAN.
+                // The order is -QNAN, -SNAN, numbers, +SNAN, +QNAN.
+                bool __t_is_nan = _VSTD::isnan(__t);
+                bool __u_is_nan = _VSTD::isnan(__u);
+                bool __t_is_negative = _VSTD::signbit(__t);
+                bool __u_is_negative = _VSTD::signbit(__u);
+                using _IntType = conditional_t<
+                    sizeof(__t) == sizeof(int32_t), int32_t, conditional_t<
+                    sizeof(__t) == sizeof(int64_t), int64_t, void>
+                >;
+                if constexpr (is_same_v<_IntType, void>) {
+                    static_assert(sizeof(_Dp) == 0, "std::strong_order is unimplemented for this floating-point type");
+                } else if (__t_is_nan && __u_is_nan) {
+                    // Order by sign bit, then by "payload bits" (we'll just use bit_cast).
+                    if (__t_is_negative != __u_is_negative) {
+                        return (__u_is_negative <=> __t_is_negative);
+                    } else {
+                        return _VSTD::bit_cast<_IntType>(__t) <=> _VSTD::bit_cast<_IntType>(__u);
+                    }
+                } else if (__t_is_nan) {
+                    return __t_is_negative ? strong_ordering::less : strong_ordering::greater;
+                } else {
+                    return __u_is_negative ? strong_ordering::greater : strong_ordering::less;
+                }
+            }
+        }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
+            noexcept(noexcept(strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          strong_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up>
+        _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
+            noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>())))
+            -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()))
+            { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<2>()); }
+    };
+} // namespace __strong_order
+
+inline namespace __cpo {
+    inline constexpr auto strong_order = __strong_order::__fn{};
+} // namespace __cpo
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___COMPARE_STRONG_ORDER
lib/libcxx/include/__compare/synth_three_way.h
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_SYNTH_THREE_WAY_H
+#define _LIBCPP___COMPARE_SYNTH_THREE_WAY_H
+
+#include <__compare/ordering.h>
+#include <__compare/three_way_comparable.h>
+#include <__concepts/boolean_testable.h>
+#include <__config>
+#include <__utility/declval.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [expos.only.func]
+
+_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
+  []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
+    requires requires {
+      { __t < __u } -> __boolean_testable;
+      { __u < __t } -> __boolean_testable;
+    }
+  {
+    if constexpr (three_way_comparable_with<_Tp, _Up>) {
+      return __t <=> __u;
+    } else {
+      if (__t < __u) return weak_ordering::less;
+      if (__u < __t) return weak_ordering::greater;
+      return weak_ordering::equivalent;
+    }
+  };
+
+template <class _Tp, class _Up = _Tp>
+using __synth_three_way_result = decltype(__synth_three_way(declval<_Tp&>(), declval<_Up&>()));
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_SYNTH_THREE_WAY_H
lib/libcxx/include/__compare/three_way_comparable.h
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_THREE_WAY_COMPARABLE_H
+#define _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H
+
+#include <__compare/common_comparison_category.h>
+#include <__compare/ordering.h>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/same_as.h>
+#include <__concepts/totally_ordered.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template<class _Tp, class _Cat>
+concept __compares_as =
+  same_as<common_comparison_category_t<_Tp, _Cat>, _Cat>;
+
+template<class _Tp, class _Cat = partial_ordering>
+concept three_way_comparable =
+  __weakly_equality_comparable_with<_Tp, _Tp> &&
+  __partially_ordered_with<_Tp, _Tp> &&
+  requires(__make_const_lvalue_ref<_Tp> __a, __make_const_lvalue_ref<_Tp> __b) {
+    { __a <=> __b } -> __compares_as<_Cat>;
+  };
+
+template<class _Tp, class _Up, class _Cat = partial_ordering>
+concept three_way_comparable_with =
+  three_way_comparable<_Tp, _Cat> &&
+  three_way_comparable<_Up, _Cat> &&
+  common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
+  three_way_comparable<common_reference_t<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>>, _Cat> &&
+  __weakly_equality_comparable_with<_Tp, _Up> &&
+  __partially_ordered_with<_Tp, _Up> &&
+  requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
+    { __t <=> __u } -> __compares_as<_Cat>;
+    { __u <=> __t } -> __compares_as<_Cat>;
+  };
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_THREE_WAY_COMPARABLE_H
lib/libcxx/include/__compare/weak_order.h
@@ -0,0 +1,100 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COMPARE_WEAK_ORDER
+#define _LIBCPP___COMPARE_WEAK_ORDER
+
+#include <__compare/compare_three_way.h>
+#include <__compare/ordering.h>
+#include <__compare/strong_order.h>
+#include <__config>
+#include <__utility/forward.h>
+#include <__utility/priority_tag.h>
+#include <cmath>
+#include <type_traits>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [cmp.alg]
+namespace __weak_order {
+    struct __fn {
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<3>)
+            noexcept(noexcept(weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          weak_ordering(weak_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up, class _Dp = decay_t<_Tp>>
+            requires is_same_v<_Dp, decay_t<_Up>> && is_floating_point_v<_Dp>
+        _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<2>) noexcept
+        {
+            partial_ordering __po = (__t <=> __u);
+            if (__po == partial_ordering::less) {
+                return weak_ordering::less;
+            } else if (__po == partial_ordering::equivalent) {
+                return weak_ordering::equivalent;
+            } else if (__po == partial_ordering::greater) {
+                return weak_ordering::greater;
+            } else {
+                // Otherwise, at least one of them is a NaN.
+                bool __t_is_nan = _VSTD::isnan(__t);
+                bool __u_is_nan = _VSTD::isnan(__u);
+                bool __t_is_negative = _VSTD::signbit(__t);
+                bool __u_is_negative = _VSTD::signbit(__u);
+                if (__t_is_nan && __u_is_nan) {
+                    return (__u_is_negative <=> __t_is_negative);
+                } else if (__t_is_nan) {
+                    return __t_is_negative ? weak_ordering::less : weak_ordering::greater;
+                } else {
+                    return __u_is_negative ? weak_ordering::greater : weak_ordering::less;
+                }
+            }
+        }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<1>)
+            noexcept(noexcept(weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          weak_ordering(compare_three_way()(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up>
+            requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
+        _LIBCPP_HIDE_FROM_ABI static constexpr auto
+        __go(_Tp&& __t, _Up&& __u, __priority_tag<0>)
+            noexcept(noexcept(weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u)))))
+            -> decltype(      weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+            { return          weak_ordering(_VSTD::strong_order(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))); }
+
+        template<class _Tp, class _Up>
+        _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t, _Up&& __u) const
+            noexcept(noexcept(__go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>())))
+            -> decltype(      __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>()))
+            { return          __go(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u), __priority_tag<3>()); }
+    };
+} // namespace __weak_order
+
+inline namespace __cpo {
+    inline constexpr auto weak_order = __weak_order::__fn{};
+} // namespace __cpo
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___COMPARE_WEAK_ORDER
lib/libcxx/include/__concepts/arithmetic.h
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_ARITHMETIC_H
+#define _LIBCPP___CONCEPTS_ARITHMETIC_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concepts.arithmetic], arithmetic concepts
+
+template<class _Tp>
+concept integral = is_integral_v<_Tp>;
+
+template<class _Tp>
+concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
+
+template<class _Tp>
+concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
+
+template<class _Tp>
+concept floating_point = is_floating_point_v<_Tp>;
+
+// Concept helpers for the internal type traits for the fundamental types.
+
+template <class _Tp>
+concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
+template <class _Tp>
+concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_ARITHMETIC_H
lib/libcxx/include/__concepts/assignable.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_ASSIGNABLE_H
+#define _LIBCPP___CONCEPTS_ASSIGNABLE_H
+
+#include <__concepts/common_reference_with.h>
+#include <__concepts/same_as.h>
+#include <__config>
+#include <__utility/forward.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.assignable]
+
+template<class _Lhs, class _Rhs>
+concept assignable_from =
+  is_lvalue_reference_v<_Lhs> &&
+  common_reference_with<__make_const_lvalue_ref<_Lhs>, __make_const_lvalue_ref<_Rhs>> &&
+  requires (_Lhs __lhs, _Rhs&& __rhs) {
+    { __lhs = _VSTD::forward<_Rhs>(__rhs) } -> same_as<_Lhs>;
+  };
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_ASSIGNABLE_H
lib/libcxx/include/__concepts/boolean_testable.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_BOOLEAN_TESTABLE_H
+#define _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/forward.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concepts.booleantestable]
+
+template<class _Tp>
+concept __boolean_testable_impl = convertible_to<_Tp, bool>;
+
+template<class _Tp>
+concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t) {
+  { !_VSTD::forward<_Tp>(__t) } -> __boolean_testable_impl;
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_BOOLEAN_TESTABLE_H
lib/libcxx/include/__concepts/class_or_enum.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_CLASS_OR_ENUM_H
+#define _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// Whether a type is a class type or enumeration type according to the Core wording.
+
+template<class _Tp>
+concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
+
+// Work around Clang bug https://llvm.org/PR52970
+template<class _Tp>
+concept __workaround_52970 = is_class_v<__uncvref_t<_Tp>> || is_union_v<__uncvref_t<_Tp>>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H
lib/libcxx/include/__concepts/common_reference_with.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___CONCEPTS_COMMON_REFERENCE_WITH_H
+#define _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H
+
+#include <__concepts/convertible_to.h>
+#include <__concepts/same_as.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.commonref]
+
+template<class _Tp, class _Up>
+concept common_reference_with =
+  same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>> &&
+  convertible_to<_Tp, common_reference_t<_Tp, _Up>> &&
+  convertible_to<_Up, common_reference_t<_Tp, _Up>>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_COMMON_REFERENCE_WITH_H
lib/libcxx/include/__concepts/common_with.h
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_COMMON_WITH_H
+#define _LIBCPP___CONCEPTS_COMMON_WITH_H
+
+#include <__concepts/common_reference_with.h>
+#include <__concepts/same_as.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.common]
+
+template<class _Tp, class _Up>
+concept common_with =
+  same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>> &&
+  requires {
+    static_cast<common_type_t<_Tp, _Up>>(declval<_Tp>());
+    static_cast<common_type_t<_Tp, _Up>>(declval<_Up>());
+  } &&
+  common_reference_with<
+    add_lvalue_reference_t<const _Tp>,
+    add_lvalue_reference_t<const _Up>> &&
+  common_reference_with<
+    add_lvalue_reference_t<common_type_t<_Tp, _Up>>,
+    common_reference_t<
+      add_lvalue_reference_t<const _Tp>,
+      add_lvalue_reference_t<const _Up>>>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_COMMON_WITH_H
lib/libcxx/include/__concepts/constructible.h
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_CONSTRUCTIBLE_H
+#define _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H
+
+#include <__concepts/convertible_to.h>
+#include <__concepts/destructible.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.constructible]
+template<class _Tp, class... _Args>
+concept constructible_from =
+    destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
+
+// [concept.default.init]
+
+template<class _Tp>
+concept __default_initializable = requires { ::new _Tp; };
+
+template<class _Tp>
+concept default_initializable = constructible_from<_Tp> &&
+    requires { _Tp{}; } && __default_initializable<_Tp>;
+
+// [concept.moveconstructible]
+template<class _Tp>
+concept move_constructible =
+  constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
+
+// [concept.copyconstructible]
+template<class _Tp>
+concept copy_constructible =
+  move_constructible<_Tp> &&
+  constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
+  constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
+  constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H
lib/libcxx/include/__concepts/convertible_to.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___CONCEPTS_CONVERTIBLE_TO_H
+#define _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H
+
+#include <__config>
+#include <__utility/declval.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.convertible]
+
+template<class _From, class _To>
+concept convertible_to =
+  is_convertible_v<_From, _To> &&
+  requires {
+    static_cast<_To>(declval<_From>());
+  };
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_CONVERTIBLE_TO_H
lib/libcxx/include/__concepts/copyable.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___CONCEPTS_COPYABLE_H
+#define _LIBCPP___CONCEPTS_COPYABLE_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/constructible.h>
+#include <__concepts/movable.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concepts.object]
+
+template<class _Tp>
+concept copyable =
+  copy_constructible<_Tp> &&
+  movable<_Tp> &&
+  assignable_from<_Tp&, _Tp&> &&
+  assignable_from<_Tp&, const _Tp&> &&
+  assignable_from<_Tp&, const _Tp>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_COPYABLE_H
lib/libcxx/include/__concepts/derived_from.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_DERIVED_FROM_H
+#define _LIBCPP___CONCEPTS_DERIVED_FROM_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.derived]
+
+template<class _Dp, class _Bp>
+concept derived_from =
+  is_base_of_v<_Bp, _Dp> &&
+  is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_DERIVED_FROM_H
lib/libcxx/include/__concepts/destructible.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_DESTRUCTIBLE_H
+#define _LIBCPP___CONCEPTS_DESTRUCTIBLE_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.destructible]
+
+template<class _Tp>
+concept destructible = is_nothrow_destructible_v<_Tp>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_DESTRUCTIBLE_H
lib/libcxx/include/__concepts/different_from.h
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_DIFFERENT_FROM_H
+#define _LIBCPP___CONCEPTS_DIFFERENT_FROM_H
+
+#include <__concepts/same_as.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template<class _Tp, class _Up>
+concept __different_from = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_DIFFERENT_FROM_H
lib/libcxx/include/__concepts/equality_comparable.h
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_EQUALITY_COMPARABLE_H
+#define _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H
+
+#include <__concepts/boolean_testable.h>
+#include <__concepts/common_reference_with.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.equalitycomparable]
+
+template<class _Tp, class _Up>
+concept __weakly_equality_comparable_with =
+  requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
+    { __t == __u } -> __boolean_testable;
+    { __t != __u } -> __boolean_testable;
+    { __u == __t } -> __boolean_testable;
+    { __u != __t } -> __boolean_testable;
+  };
+
+template<class _Tp>
+concept equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>;
+
+template<class _Tp, class _Up>
+concept equality_comparable_with =
+  equality_comparable<_Tp> && equality_comparable<_Up> &&
+  common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
+  equality_comparable<
+    common_reference_t<
+      __make_const_lvalue_ref<_Tp>,
+      __make_const_lvalue_ref<_Up>>> &&
+  __weakly_equality_comparable_with<_Tp, _Up>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H
lib/libcxx/include/__concepts/invocable.h
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_INVOCABLE_H
+#define _LIBCPP___CONCEPTS_INVOCABLE_H
+
+#include <__config>
+#include <__functional/invoke.h>
+#include <__utility/forward.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.invocable]
+
+template<class _Fn, class... _Args>
+concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
+  _VSTD::invoke(_VSTD::forward<_Fn>(__fn), _VSTD::forward<_Args>(__args)...); // not required to be equality preserving
+};
+
+// [concept.regular.invocable]
+
+template<class _Fn, class... _Args>
+concept regular_invocable = invocable<_Fn, _Args...>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_INVOCABLE_H
lib/libcxx/include/__concepts/movable.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___CONCEPTS_MOVABLE_H
+#define _LIBCPP___CONCEPTS_MOVABLE_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/constructible.h>
+#include <__concepts/swappable.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concepts.object]
+
+template<class _Tp>
+concept movable =
+  is_object_v<_Tp> &&
+  move_constructible<_Tp> &&
+  assignable_from<_Tp&, _Tp> &&
+  swappable<_Tp>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_MOVABLE_H
lib/libcxx/include/__concepts/predicate.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_PREDICATE_H
+#define _LIBCPP___CONCEPTS_PREDICATE_H
+
+#include <__concepts/boolean_testable.h>
+#include <__concepts/invocable.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.predicate]
+
+template<class _Fn, class... _Args>
+concept predicate =
+  regular_invocable<_Fn, _Args...> && __boolean_testable<invoke_result_t<_Fn, _Args...>>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_PREDICATE_H
lib/libcxx/include/__concepts/regular.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_REGULAR_H
+#define _LIBCPP___CONCEPTS_REGULAR_H
+
+#include <__concepts/equality_comparable.h>
+#include <__concepts/semiregular.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.object]
+
+template<class _Tp>
+concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_REGULAR_H
lib/libcxx/include/__concepts/relation.h
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_RELATION_H
+#define _LIBCPP___CONCEPTS_RELATION_H
+
+#include <__concepts/predicate.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.relation]
+
+template<class _Rp, class _Tp, class _Up>
+concept relation =
+  predicate<_Rp, _Tp, _Tp> && predicate<_Rp, _Up, _Up> &&
+  predicate<_Rp, _Tp, _Up> && predicate<_Rp, _Up, _Tp>;
+
+// [concept.equiv]
+
+template<class _Rp, class _Tp, class _Up>
+concept equivalence_relation = relation<_Rp, _Tp, _Up>;
+
+// [concept.strictweakorder]
+
+template<class _Rp, class _Tp, class _Up>
+concept strict_weak_order = relation<_Rp, _Tp, _Up>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_RELATION_H
lib/libcxx/include/__concepts/same_as.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_SAME_AS_H
+#define _LIBCPP___CONCEPTS_SAME_AS_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.same]
+
+template<class _Tp, class _Up>
+concept __same_as_impl = _IsSame<_Tp, _Up>::value;
+
+template<class _Tp, class _Up>
+concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_SAME_AS_H
lib/libcxx/include/__concepts/semiregular.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_SEMIREGULAR_H
+#define _LIBCPP___CONCEPTS_SEMIREGULAR_H
+
+#include <__concepts/constructible.h>
+#include <__concepts/copyable.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.object]
+
+template<class _Tp>
+concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_SEMIREGULAR_H
lib/libcxx/include/__concepts/swappable.h
@@ -0,0 +1,116 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_SWAPPABLE_H
+#define _LIBCPP___CONCEPTS_SWAPPABLE_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/class_or_enum.h>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/constructible.h>
+#include <__config>
+#include <__utility/exchange.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.swappable]
+
+namespace ranges {
+namespace __swap {
+
+  template<class _Tp>
+  void swap(_Tp&, _Tp&) = delete;
+
+  template<class _Tp, class _Up>
+  concept __unqualified_swappable_with =
+    (__class_or_enum<remove_cvref_t<_Tp>> || __class_or_enum<remove_cvref_t<_Up>>) &&
+    requires(_Tp&& __t, _Up&& __u) {
+      swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
+    };
+
+  struct __fn;
+
+  template<class _Tp, class _Up, size_t _Size>
+  concept __swappable_arrays =
+    !__unqualified_swappable_with<_Tp(&)[_Size], _Up(&)[_Size]> &&
+    extent_v<_Tp> == extent_v<_Up> &&
+    requires(_Tp(& __t)[_Size], _Up(& __u)[_Size], const __fn& __swap) {
+      __swap(__t[0], __u[0]);
+    };
+
+  template<class _Tp>
+  concept __exchangeable =
+    !__unqualified_swappable_with<_Tp&, _Tp&> &&
+    move_constructible<_Tp> &&
+    assignable_from<_Tp&, _Tp>;
+
+  struct __fn {
+    // 2.1   `S` is `(void)swap(E1, E2)`* if `E1` or `E2` has class or enumeration type and...
+    // *The name `swap` is used here unqualified.
+    template<class _Tp, class _Up>
+      requires __unqualified_swappable_with<_Tp, _Up>
+    constexpr void operator()(_Tp&& __t, _Up&& __u) const
+      noexcept(noexcept(swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
+    {
+      swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
+    }
+
+    // 2.2   Otherwise, if `E1` and `E2` are lvalues of array types with equal extent and...
+    template<class _Tp, class _Up, size_t _Size>
+      requires __swappable_arrays<_Tp, _Up, _Size>
+    constexpr void operator()(_Tp(& __t)[_Size], _Up(& __u)[_Size]) const
+      noexcept(noexcept((*this)(*__t, *__u)))
+    {
+      // TODO(cjdb): replace with `ranges::swap_ranges`.
+      for (size_t __i = 0; __i < _Size; ++__i) {
+        (*this)(__t[__i], __u[__i]);
+      }
+    }
+
+    // 2.3   Otherwise, if `E1` and `E2` are lvalues of the same type `T` that models...
+    template<__exchangeable _Tp>
+    constexpr void operator()(_Tp& __x, _Tp& __y) const
+      noexcept(is_nothrow_move_constructible_v<_Tp> && is_nothrow_move_assignable_v<_Tp>)
+    {
+      __y = _VSTD::exchange(__x, _VSTD::move(__y));
+    }
+  };
+} // namespace __swap
+
+inline namespace __cpo {
+  inline constexpr auto swap = __swap::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+template<class _Tp>
+concept swappable = requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); };
+
+template<class _Tp, class _Up>
+concept swappable_with =
+  common_reference_with<_Tp, _Up> &&
+  requires(_Tp&& __t, _Up&& __u) {
+    ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Tp>(__t));
+    ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Up>(__u));
+    ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
+    ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Tp>(__t));
+  };
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_SWAPPABLE_H
lib/libcxx/include/__concepts/totally_ordered.h
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___CONCEPTS_TOTALLY_ORDERED_H
+#define _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H
+
+#include <__concepts/boolean_testable.h>
+#include <__concepts/equality_comparable.h>
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [concept.totallyordered]
+
+template<class _Tp, class _Up>
+concept __partially_ordered_with =
+  requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
+    { __t <  __u } -> __boolean_testable;
+    { __t >  __u } -> __boolean_testable;
+    { __t <= __u } -> __boolean_testable;
+    { __t >= __u } -> __boolean_testable;
+    { __u <  __t } -> __boolean_testable;
+    { __u >  __t } -> __boolean_testable;
+    { __u <= __t } -> __boolean_testable;
+    { __u >= __t } -> __boolean_testable;
+  };
+
+template<class _Tp>
+concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>;
+
+template<class _Tp, class _Up>
+concept totally_ordered_with =
+  totally_ordered<_Tp> && totally_ordered<_Up> &&
+  equality_comparable_with<_Tp, _Up> &&
+  totally_ordered<
+    common_reference_t<
+      __make_const_lvalue_ref<_Tp>,
+      __make_const_lvalue_ref<_Up>>> &&
+  __partially_ordered_with<_Tp, _Up>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CONCEPTS_TOTALLY_ORDERED_H
lib/libcxx/include/__coroutine/coroutine_handle.h
@@ -0,0 +1,202 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COROUTINE_COROUTINE_HANDLE_H
+#define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
+
+#include <__config>
+#include <__debug>
+#include <__functional/hash.h>
+#include <__memory/addressof.h>
+#include <compare>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// [coroutine.handle]
+template <class _Promise = void>
+struct _LIBCPP_TEMPLATE_VIS coroutine_handle;
+
+template <>
+struct _LIBCPP_TEMPLATE_VIS coroutine_handle<void> {
+public:
+    // [coroutine.handle.con], construct/reset
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr coroutine_handle() noexcept = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr coroutine_handle(nullptr_t) noexcept {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    coroutine_handle& operator=(nullptr_t) noexcept {
+        __handle_ = nullptr;
+        return *this;
+    }
+
+    // [coroutine.handle.export.import], export/import
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void* address() const noexcept { return __handle_; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    static constexpr coroutine_handle from_address(void* __addr) noexcept {
+        coroutine_handle __tmp;
+        __tmp.__handle_ = __addr;
+        return __tmp;
+    }
+
+    // [coroutine.handle.observers], observers
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit operator bool() const noexcept {
+        return __handle_ != nullptr;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    bool done() const {
+        _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines");
+        return __builtin_coro_done(__handle_);
+    }
+
+    // [coroutine.handle.resumption], resumption
+    _LIBCPP_HIDE_FROM_ABI
+    void operator()() const { resume(); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    void resume() const {
+        _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines");
+        _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done");
+        __builtin_coro_resume(__handle_);
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    void destroy() const {
+        _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines");
+        __builtin_coro_destroy(__handle_);
+    }
+
+private:
+    bool __is_suspended() const {
+        // FIXME actually implement a check for if the coro is suspended.
+        return __handle_ != nullptr;
+    }
+
+    void* __handle_ = nullptr;
+};
+
+// [coroutine.handle.compare]
+inline _LIBCPP_HIDE_FROM_ABI
+constexpr bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) noexcept {
+    return __x.address() == __y.address();
+}
+inline _LIBCPP_HIDE_FROM_ABI
+constexpr strong_ordering operator<=>(coroutine_handle<> __x, coroutine_handle<> __y) noexcept {
+    return compare_three_way()(__x.address(), __y.address());
+}
+
+template <class _Promise>
+struct _LIBCPP_TEMPLATE_VIS coroutine_handle {
+public:
+    // [coroutine.handle.con], construct/reset
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr coroutine_handle() noexcept = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr coroutine_handle(nullptr_t) noexcept {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    static coroutine_handle from_promise(_Promise& __promise) {
+        using _RawPromise = typename remove_cv<_Promise>::type;
+        coroutine_handle __tmp;
+        __tmp.__handle_ =
+            __builtin_coro_promise(_VSTD::addressof(const_cast<_RawPromise&>(__promise)), alignof(_Promise), true);
+        return __tmp;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    coroutine_handle& operator=(nullptr_t) noexcept {
+        __handle_ = nullptr;
+        return *this;
+    }
+
+    // [coroutine.handle.export.import], export/import
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void* address() const noexcept { return __handle_; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    static constexpr coroutine_handle from_address(void* __addr) noexcept {
+        coroutine_handle __tmp;
+        __tmp.__handle_ = __addr;
+        return __tmp;
+    }
+
+    // [coroutine.handle.conv], conversion
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr operator coroutine_handle<>() const noexcept {
+        return coroutine_handle<>::from_address(address());
+    }
+
+    // [coroutine.handle.observers], observers
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit operator bool() const noexcept {
+        return __handle_ != nullptr;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    bool done() const {
+        _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines");
+        return __builtin_coro_done(__handle_);
+    }
+
+    // [coroutine.handle.resumption], resumption
+    _LIBCPP_HIDE_FROM_ABI
+    void operator()() const { resume(); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    void resume() const {
+        _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines");
+        _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done");
+        __builtin_coro_resume(__handle_);
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    void destroy() const {
+        _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines");
+        __builtin_coro_destroy(__handle_);
+    }
+
+    // [coroutine.handle.promise], promise access
+    _LIBCPP_HIDE_FROM_ABI
+    _Promise& promise() const {
+        return *static_cast<_Promise*>(__builtin_coro_promise(this->__handle_, alignof(_Promise), false));
+    }
+
+private:
+    bool __is_suspended() const {
+        // FIXME actually implement a check for if the coro is suspended.
+        return __handle_ != nullptr;
+    }
+    void* __handle_ = nullptr;
+};
+
+// [coroutine.handle.hash]
+template <class _Tp>
+struct hash<coroutine_handle<_Tp>> {
+    _LIBCPP_HIDE_FROM_ABI
+    size_t operator()(const coroutine_handle<_Tp>& __v) const noexcept { return hash<void*>()(__v.address()); }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+#endif // _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
lib/libcxx/include/__coroutine/coroutine_traits.h
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COROUTINE_COROUTINE_TRAITS_H
+#define _LIBCPP___COROUTINE_COROUTINE_TRAITS_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// [coroutine.traits]
+// [coroutine.traits.primary]
+//   The header <coroutine> defined the primary template coroutine_traits such that
+// if ArgTypes is a parameter pack of types and if the qualified-id R::promise_type
+// is valid and denotes a type ([temp.deduct]), then coroutine_traits<R, ArgTypes...>
+// has the following publicly accessible memebr:
+//
+//    using promise_type = typename R::promise_type;
+//
+// Otherwise, coroutine_traits<R, ArgTypes...> has no members.
+template <class _Tp, class = void>
+struct __coroutine_traits_sfinae {};
+
+template <class _Tp>
+struct __coroutine_traits_sfinae<
+    _Tp, typename __void_t<typename _Tp::promise_type>::type>
+{
+  using promise_type = typename _Tp::promise_type;
+};
+
+template <class _Ret, class... _Args>
+struct coroutine_traits
+    : public __coroutine_traits_sfinae<_Ret>
+{
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+#endif // _LIBCPP___COROUTINE_COROUTINE_TRAITS_H
lib/libcxx/include/__coroutine/noop_coroutine_handle.h
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COROUTINE_NOOP_COROUTINE_HANDLE_H
+#define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
+
+#include <__config>
+#include <__coroutine/coroutine_handle.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
+
+// [coroutine.noop]
+// [coroutine.promise.noop]
+struct noop_coroutine_promise {};
+
+// [coroutine.handle.noop]
+template <>
+struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> {
+public:
+    // [coroutine.handle.noop.conv], conversion
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr operator coroutine_handle<>() const noexcept {
+        return coroutine_handle<>::from_address(address());
+    }
+
+    // [coroutine.handle.noop.observers], observers
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit operator bool() const noexcept { return true; }
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr bool done() const noexcept { return false; }
+
+    // [coroutine.handle.noop.resumption], resumption
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void operator()() const noexcept {}
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void resume() const noexcept {}
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void destroy() const noexcept {}
+
+    // [coroutine.handle.noop.promise], promise access
+    _LIBCPP_HIDE_FROM_ABI
+    noop_coroutine_promise& promise() const noexcept {
+        return *static_cast<noop_coroutine_promise*>(
+            __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false));
+    }
+
+    // [coroutine.handle.noop.address], address
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void* address() const noexcept { return __handle_; }
+
+private:
+    _LIBCPP_HIDE_FROM_ABI
+    friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept;
+
+#if __has_builtin(__builtin_coro_noop)
+    _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept { 
+        this->__handle_ = __builtin_coro_noop();
+    }
+
+    void* __handle_ = nullptr;
+
+#elif defined(_LIBCPP_COMPILER_GCC)
+    // GCC doesn't implement __builtin_coro_noop().
+    // Construct the coroutine frame manually instead.
+    struct __noop_coroutine_frame_ty_ {
+        static void __dummy_resume_destroy_func() { }
+
+        void (*__resume_)() = __dummy_resume_destroy_func;
+        void (*__destroy_)() = __dummy_resume_destroy_func;
+        struct noop_coroutine_promise __promise_;
+    };
+
+    static __noop_coroutine_frame_ty_ __noop_coroutine_frame_;
+
+    void* __handle_ = &__noop_coroutine_frame_;
+
+    _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default;
+
+#endif // __has_builtin(__builtin_coro_noop)
+};
+
+using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
+
+#if defined(_LIBCPP_COMPILER_GCC)
+inline noop_coroutine_handle::__noop_coroutine_frame_ty_
+    noop_coroutine_handle::__noop_coroutine_frame_{};
+#endif
+
+// [coroutine.noop.coroutine]
+inline _LIBCPP_HIDE_FROM_ABI
+noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); }
+
+#endif // __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+#endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
lib/libcxx/include/__coroutine/trivial_awaitables.h
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___COROUTINE_TRIVIAL_AWAITABLES_H
+#define __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H
+
+#include <__config>
+#include <__coroutine/coroutine_handle.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// [coroutine.trivial.awaitables]
+struct suspend_never {
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr bool await_ready() const noexcept { return true; }
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void await_suspend(coroutine_handle<>) const noexcept {}
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void await_resume() const noexcept {}
+};
+
+struct suspend_always {
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr bool await_ready() const noexcept { return false; }
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void await_suspend(coroutine_handle<>) const noexcept {}
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void await_resume() const noexcept {}
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES)
+
+#endif // __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H
lib/libcxx/include/__filesystem/copy_options.h
@@ -0,0 +1,80 @@
+// -*- 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___FILESYSTEM_COPY_OPTIONS_H
+#define _LIBCPP___FILESYSTEM_COPY_OPTIONS_H
+
+#include <__availability>
+#include <__config>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
+  none = 0,
+  skip_existing = 1,
+  overwrite_existing = 2,
+  update_existing = 4,
+  recursive = 8,
+  copy_symlinks = 16,
+  skip_symlinks = 32,
+  directories_only = 64,
+  create_symlinks = 128,
+  create_hard_links = 256,
+  __in_recursive_copy = 512,
+};
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) {
+  return static_cast<copy_options>(static_cast<unsigned short>(_LHS) &
+                                   static_cast<unsigned short>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) {
+  return static_cast<copy_options>(static_cast<unsigned short>(_LHS) |
+                                   static_cast<unsigned short>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) {
+  return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^
+                                   static_cast<unsigned short>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr copy_options operator~(copy_options _LHS) {
+  return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
+  return _LHS = _LHS & _RHS;
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
+  return _LHS = _LHS | _RHS;
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
+  return _LHS = _LHS ^ _RHS;
+}
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_COPY_OPTIONS_H
lib/libcxx/include/__filesystem/directory_entry.h
@@ -0,0 +1,511 @@
+// -*- 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___FILESYSTEM_DIRECTORY_ENTRY_H
+#define _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H
+
+#include <__availability>
+#include <__config>
+#include <__errc>
+#include <__filesystem/file_status.h>
+#include <__filesystem/file_time_type.h>
+#include <__filesystem/file_type.h>
+#include <__filesystem/filesystem_error.h>
+#include <__filesystem/operations.h>
+#include <__filesystem/path.h>
+#include <__filesystem/perms.h>
+#include <chrono>
+#include <cstdint>
+#include <cstdlib>
+#include <iosfwd>
+#include <system_error>
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+
+class directory_entry {
+  typedef _VSTD_FS::path _Path;
+
+public:
+  // constructors and destructors
+  directory_entry() noexcept = default;
+  directory_entry(directory_entry const&) = default;
+  directory_entry(directory_entry&&) noexcept = default;
+
+  _LIBCPP_INLINE_VISIBILITY
+  explicit directory_entry(_Path const& __p) : __p_(__p) {
+    error_code __ec;
+    __refresh(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) {
+    __refresh(&__ec);
+  }
+
+  ~directory_entry() {}
+
+  directory_entry& operator=(directory_entry const&) = default;
+  directory_entry& operator=(directory_entry&&) noexcept = default;
+
+  _LIBCPP_INLINE_VISIBILITY
+  void assign(_Path const& __p) {
+    __p_ = __p;
+    error_code __ec;
+    __refresh(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void assign(_Path const& __p, error_code& __ec) {
+    __p_ = __p;
+    __refresh(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void replace_filename(_Path const& __p) {
+    __p_.replace_filename(__p);
+    error_code __ec;
+    __refresh(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void replace_filename(_Path const& __p, error_code& __ec) {
+    __p_ = __p_.parent_path() / __p;
+    __refresh(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void refresh() { __refresh(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  _Path const& path() const noexcept { return __p_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  operator const _Path&() const noexcept { return __p_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool exists(error_code& __ec) const noexcept {
+    return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_block_file() const { return __get_ft() == file_type::block; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_block_file(error_code& __ec) const noexcept {
+    return __get_ft(&__ec) == file_type::block;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_character_file() const { return __get_ft() == file_type::character; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_character_file(error_code& __ec) const noexcept {
+    return __get_ft(&__ec) == file_type::character;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_directory() const { return __get_ft() == file_type::directory; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_directory(error_code& __ec) const noexcept {
+    return __get_ft(&__ec) == file_type::directory;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_fifo() const { return __get_ft() == file_type::fifo; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_fifo(error_code& __ec) const noexcept {
+    return __get_ft(&__ec) == file_type::fifo;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_other(error_code& __ec) const noexcept {
+    return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_regular_file() const { return __get_ft() == file_type::regular; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_regular_file(error_code& __ec) const noexcept {
+    return __get_ft(&__ec) == file_type::regular;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_socket() const { return __get_ft() == file_type::socket; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_socket(error_code& __ec) const noexcept {
+    return __get_ft(&__ec) == file_type::socket;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_symlink() const { return __get_sym_ft() == file_type::symlink; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool is_symlink(error_code& __ec) const noexcept {
+    return __get_sym_ft(&__ec) == file_type::symlink;
+  }
+  _LIBCPP_INLINE_VISIBILITY
+  uintmax_t file_size() const { return __get_size(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  uintmax_t file_size(error_code& __ec) const noexcept {
+    return __get_size(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  uintmax_t hard_link_count() const { return __get_nlink(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  uintmax_t hard_link_count(error_code& __ec) const noexcept {
+    return __get_nlink(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_time_type last_write_time() const { return __get_write_time(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_time_type last_write_time(error_code& __ec) const noexcept {
+    return __get_write_time(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_status status() const { return __get_status(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_status status(error_code& __ec) const noexcept {
+    return __get_status(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_status symlink_status() const { return __get_symlink_status(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_status symlink_status(error_code& __ec) const noexcept {
+    return __get_symlink_status(&__ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool operator<(directory_entry const& __rhs) const noexcept {
+    return __p_ < __rhs.__p_;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool operator==(directory_entry const& __rhs) const noexcept {
+    return __p_ == __rhs.__p_;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool operator!=(directory_entry const& __rhs) const noexcept {
+    return __p_ != __rhs.__p_;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool operator<=(directory_entry const& __rhs) const noexcept {
+    return __p_ <= __rhs.__p_;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool operator>(directory_entry const& __rhs) const noexcept {
+    return __p_ > __rhs.__p_;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool operator>=(directory_entry const& __rhs) const noexcept {
+    return __p_ >= __rhs.__p_;
+  }
+
+  template <class _CharT, class _Traits>
+  _LIBCPP_INLINE_VISIBILITY
+  friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) {
+    return __os << __d.path();
+  }
+
+private:
+  friend class directory_iterator;
+  friend class recursive_directory_iterator;
+  friend class _LIBCPP_HIDDEN __dir_stream;
+
+  enum _CacheType : unsigned char {
+    _Empty,
+    _IterSymlink,
+    _IterNonSymlink,
+    _RefreshSymlink,
+    _RefreshSymlinkUnresolved,
+    _RefreshNonSymlink
+  };
+
+  struct __cached_data {
+    uintmax_t __size_;
+    uintmax_t __nlink_;
+    file_time_type __write_time_;
+    perms __sym_perms_;
+    perms __non_sym_perms_;
+    file_type __type_;
+    _CacheType __cache_type_;
+
+    _LIBCPP_INLINE_VISIBILITY
+    __cached_data() noexcept { __reset(); }
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __reset() {
+      __cache_type_ = _Empty;
+      __type_ = file_type::none;
+      __sym_perms_ = __non_sym_perms_ = perms::unknown;
+      __size_ = __nlink_ = uintmax_t(-1);
+      __write_time_ = file_time_type::min();
+    }
+  };
+
+  _LIBCPP_INLINE_VISIBILITY
+  static __cached_data __create_iter_result(file_type __ft) {
+    __cached_data __data;
+    __data.__type_ = __ft;
+    __data.__cache_type_ = [&]() {
+      switch (__ft) {
+      case file_type::none:
+        return _Empty;
+      case file_type::symlink:
+        return _IterSymlink;
+      default:
+        return _IterNonSymlink;
+      }
+    }();
+    return __data;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
+    __p_ = _VSTD::move(__p);
+    __data_ = __dt;
+  }
+
+  _LIBCPP_FUNC_VIS
+  error_code __do_refresh() noexcept;
+
+  _LIBCPP_INLINE_VISIBILITY
+  static bool __is_dne_error(error_code const& __ec) {
+    if (!__ec)
+      return true;
+    switch (static_cast<errc>(__ec.value())) {
+    case errc::no_such_file_or_directory:
+    case errc::not_a_directory:
+      return true;
+    default:
+      return false;
+    }
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __handle_error(const char* __msg, error_code* __dest_ec,
+                      error_code const& __ec, bool __allow_dne = false) const {
+    if (__dest_ec) {
+      *__dest_ec = __ec;
+      return;
+    }
+    if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
+      __throw_filesystem_error(__msg, __p_, __ec);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __refresh(error_code* __ec = nullptr) {
+    __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
+                   /*allow_dne*/ true);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_type __get_sym_ft(error_code* __ec = nullptr) const {
+    switch (__data_.__cache_type_) {
+    case _Empty:
+      return __symlink_status(__p_, __ec).type();
+    case _IterSymlink:
+    case _RefreshSymlink:
+    case _RefreshSymlinkUnresolved:
+      if (__ec)
+        __ec->clear();
+      return file_type::symlink;
+    case _IterNonSymlink:
+    case _RefreshNonSymlink:
+      file_status __st(__data_.__type_);
+      if (__ec && !_VSTD_FS::exists(__st))
+        *__ec = make_error_code(errc::no_such_file_or_directory);
+      else if (__ec)
+        __ec->clear();
+      return __data_.__type_;
+    }
+    _LIBCPP_UNREACHABLE();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_type __get_ft(error_code* __ec = nullptr) const {
+    switch (__data_.__cache_type_) {
+    case _Empty:
+    case _IterSymlink:
+    case _RefreshSymlinkUnresolved:
+      return __status(__p_, __ec).type();
+    case _IterNonSymlink:
+    case _RefreshNonSymlink:
+    case _RefreshSymlink: {
+      file_status __st(__data_.__type_);
+      if (__ec && !_VSTD_FS::exists(__st))
+        *__ec = make_error_code(errc::no_such_file_or_directory);
+      else if (__ec)
+        __ec->clear();
+      return __data_.__type_;
+    }
+    }
+    _LIBCPP_UNREACHABLE();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_status __get_status(error_code* __ec = nullptr) const {
+    switch (__data_.__cache_type_) {
+    case _Empty:
+    case _IterNonSymlink:
+    case _IterSymlink:
+    case _RefreshSymlinkUnresolved:
+      return __status(__p_, __ec);
+    case _RefreshNonSymlink:
+    case _RefreshSymlink:
+      return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
+    }
+    _LIBCPP_UNREACHABLE();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_status __get_symlink_status(error_code* __ec = nullptr) const {
+    switch (__data_.__cache_type_) {
+    case _Empty:
+    case _IterNonSymlink:
+    case _IterSymlink:
+      return __symlink_status(__p_, __ec);
+    case _RefreshNonSymlink:
+      return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
+    case _RefreshSymlink:
+    case _RefreshSymlinkUnresolved:
+      return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
+    }
+    _LIBCPP_UNREACHABLE();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  uintmax_t __get_size(error_code* __ec = nullptr) const {
+    switch (__data_.__cache_type_) {
+    case _Empty:
+    case _IterNonSymlink:
+    case _IterSymlink:
+    case _RefreshSymlinkUnresolved:
+      return _VSTD_FS::__file_size(__p_, __ec);
+    case _RefreshSymlink:
+    case _RefreshNonSymlink: {
+      error_code __m_ec;
+      file_status __st(__get_ft(&__m_ec));
+      __handle_error("in directory_entry::file_size", __ec, __m_ec);
+      if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
+        errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
+                                                       : errc::not_supported;
+        __handle_error("in directory_entry::file_size", __ec,
+                       make_error_code(__err_kind));
+      }
+      return __data_.__size_;
+    }
+    }
+    _LIBCPP_UNREACHABLE();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  uintmax_t __get_nlink(error_code* __ec = nullptr) const {
+    switch (__data_.__cache_type_) {
+    case _Empty:
+    case _IterNonSymlink:
+    case _IterSymlink:
+    case _RefreshSymlinkUnresolved:
+      return _VSTD_FS::__hard_link_count(__p_, __ec);
+    case _RefreshSymlink:
+    case _RefreshNonSymlink: {
+      error_code __m_ec;
+      (void)__get_ft(&__m_ec);
+      __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
+      return __data_.__nlink_;
+    }
+    }
+    _LIBCPP_UNREACHABLE();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  file_time_type __get_write_time(error_code* __ec = nullptr) const {
+    switch (__data_.__cache_type_) {
+    case _Empty:
+    case _IterNonSymlink:
+    case _IterSymlink:
+    case _RefreshSymlinkUnresolved:
+      return _VSTD_FS::__last_write_time(__p_, __ec);
+    case _RefreshSymlink:
+    case _RefreshNonSymlink: {
+      error_code __m_ec;
+      file_status __st(__get_ft(&__m_ec));
+      __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
+      if (_VSTD_FS::exists(__st) &&
+          __data_.__write_time_ == file_time_type::min())
+        __handle_error("in directory_entry::last_write_time", __ec,
+                       make_error_code(errc::value_too_large));
+      return __data_.__write_time_;
+    }
+    }
+    _LIBCPP_UNREACHABLE();
+  }
+
+private:
+  _Path __p_;
+  __cached_data __data_;
+};
+
+class __dir_element_proxy {
+public:
+  inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() {
+    return _VSTD::move(__elem_);
+  }
+
+private:
+  friend class directory_iterator;
+  friend class recursive_directory_iterator;
+  explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
+  __dir_element_proxy(__dir_element_proxy&& __o)
+      : __elem_(_VSTD::move(__o.__elem_)) {}
+  directory_entry __elem_;
+};
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H
lib/libcxx/include/__filesystem/directory_iterator.h
@@ -0,0 +1,150 @@
+// -*- 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___FILESYSTEM_DIRECTORY_ITERATOR_H
+#define _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
+
+#include <__availability>
+#include <__config>
+#include <__debug>
+#include <__filesystem/directory_entry.h>
+#include <__filesystem/directory_options.h>
+#include <__filesystem/path.h>
+#include <__iterator/iterator_traits.h>
+#include <__memory/shared_ptr.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/enable_view.h>
+#include <cstddef>
+#include <system_error>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+class _LIBCPP_HIDDEN __dir_stream;
+class directory_iterator {
+public:
+  typedef directory_entry value_type;
+  typedef ptrdiff_t difference_type;
+  typedef value_type const* pointer;
+  typedef value_type const& reference;
+  typedef input_iterator_tag iterator_category;
+
+public:
+  //ctor & dtor
+  directory_iterator() noexcept {}
+
+  explicit directory_iterator(const path& __p)
+      : directory_iterator(__p, nullptr) {}
+
+  directory_iterator(const path& __p, directory_options __opts)
+      : directory_iterator(__p, nullptr, __opts) {}
+
+  directory_iterator(const path& __p, error_code& __ec)
+      : directory_iterator(__p, &__ec) {}
+
+  directory_iterator(const path& __p, directory_options __opts,
+                     error_code& __ec)
+      : directory_iterator(__p, &__ec, __opts) {}
+
+  directory_iterator(const directory_iterator&) = default;
+  directory_iterator(directory_iterator&&) = default;
+  directory_iterator& operator=(const directory_iterator&) = default;
+
+  directory_iterator& operator=(directory_iterator&& __o) noexcept {
+    // non-default implementation provided to support self-move assign.
+    if (this != &__o) {
+      __imp_ = _VSTD::move(__o.__imp_);
+    }
+    return *this;
+  }
+
+  ~directory_iterator() = default;
+
+  const directory_entry& operator*() const {
+    _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
+    return __dereference();
+  }
+
+  const directory_entry* operator->() const { return &**this; }
+
+  directory_iterator& operator++() { return __increment(); }
+
+  __dir_element_proxy operator++(int) {
+    __dir_element_proxy __p(**this);
+    __increment();
+    return __p;
+  }
+
+  directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
+
+private:
+  inline _LIBCPP_INLINE_VISIBILITY friend bool
+  operator==(const directory_iterator& __lhs,
+             const directory_iterator& __rhs) noexcept;
+
+  // construct the dir_stream
+  _LIBCPP_FUNC_VIS
+  directory_iterator(const path&, error_code*,
+                     directory_options = directory_options::none);
+
+  _LIBCPP_FUNC_VIS
+  directory_iterator& __increment(error_code* __ec = nullptr);
+
+  _LIBCPP_FUNC_VIS
+  const directory_entry& __dereference() const;
+
+private:
+  shared_ptr<__dir_stream> __imp_;
+};
+
+inline _LIBCPP_INLINE_VISIBILITY bool
+operator==(const directory_iterator& __lhs,
+           const directory_iterator& __rhs) noexcept {
+  return __lhs.__imp_ == __rhs.__imp_;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY bool
+operator!=(const directory_iterator& __lhs,
+           const directory_iterator& __rhs) noexcept {
+  return !(__lhs == __rhs);
+}
+
+// enable directory_iterator range-based for statements
+inline _LIBCPP_INLINE_VISIBILITY directory_iterator
+begin(directory_iterator __iter) noexcept {
+  return __iter;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY directory_iterator
+end(directory_iterator) noexcept {
+  return directory_iterator();
+}
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <>
+_LIBCPP_AVAILABILITY_FILESYSTEM
+inline constexpr bool _VSTD::ranges::enable_borrowed_range<_VSTD_FS::directory_iterator> = true;
+
+template <>
+_LIBCPP_AVAILABILITY_FILESYSTEM
+inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::directory_iterator> = true;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
lib/libcxx/include/__filesystem/directory_options.h
@@ -0,0 +1,78 @@
+// -*- 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___FILESYSTEM_DIRECTORY_OPTIONS_H
+#define _LIBCPP___FILESYSTEM_DIRECTORY_OPTIONS_H
+
+#include <__availability>
+#include <__config>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
+  none = 0,
+  follow_directory_symlink = 1,
+  skip_permission_denied = 2
+};
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr directory_options operator&(directory_options _LHS,
+                                             directory_options _RHS) {
+  return static_cast<directory_options>(static_cast<unsigned char>(_LHS) &
+                                        static_cast<unsigned char>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr directory_options operator|(directory_options _LHS,
+                                             directory_options _RHS) {
+  return static_cast<directory_options>(static_cast<unsigned char>(_LHS) |
+                                        static_cast<unsigned char>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr directory_options operator^(directory_options _LHS,
+                                             directory_options _RHS) {
+  return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^
+                                        static_cast<unsigned char>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr directory_options operator~(directory_options _LHS) {
+  return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline directory_options& operator&=(directory_options& _LHS,
+                                     directory_options _RHS) {
+  return _LHS = _LHS & _RHS;
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline directory_options& operator|=(directory_options& _LHS,
+                                     directory_options _RHS) {
+  return _LHS = _LHS | _RHS;
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline directory_options& operator^=(directory_options& _LHS,
+                                     directory_options _RHS) {
+  return _LHS = _LHS ^ _RHS;
+}
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_DIRECTORY_OPTIONS_H
lib/libcxx/include/__filesystem/file_status.h
@@ -0,0 +1,68 @@
+// -*- 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___FILESYSTEM_FILE_STATUS_H
+#define _LIBCPP___FILESYSTEM_FILE_STATUS_H
+
+#include <__availability>
+#include <__config>
+#include <__filesystem/file_type.h>
+#include <__filesystem/perms.h>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+class _LIBCPP_TYPE_VIS file_status {
+public:
+  // constructors
+  _LIBCPP_INLINE_VISIBILITY
+  file_status() noexcept : file_status(file_type::none) {}
+  _LIBCPP_INLINE_VISIBILITY
+  explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept
+      : __ft_(__ft),
+        __prms_(__prms) {}
+
+  file_status(const file_status&) noexcept = default;
+  file_status(file_status&&) noexcept = default;
+
+  _LIBCPP_INLINE_VISIBILITY
+  ~file_status() {}
+
+  file_status& operator=(const file_status&) noexcept = default;
+  file_status& operator=(file_status&&) noexcept = default;
+
+  // observers
+  _LIBCPP_INLINE_VISIBILITY
+  file_type type() const noexcept { return __ft_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  perms permissions() const noexcept { return __prms_; }
+
+  // modifiers
+  _LIBCPP_INLINE_VISIBILITY
+  void type(file_type __ft) noexcept { __ft_ = __ft; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void permissions(perms __p) noexcept { __prms_ = __p; }
+
+private:
+  file_type __ft_;
+  perms __prms_;
+};
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_FILE_STATUS_H
lib/libcxx/include/__filesystem/file_time_type.h
@@ -0,0 +1,27 @@
+// -*- 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___FILESYSTEM_FILE_TIME_TYPE_H
+#define _LIBCPP___FILESYSTEM_FILE_TIME_TYPE_H
+
+#include <__availability>
+#include <__config>
+#include <chrono>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+typedef chrono::time_point<_FilesystemClock> file_time_type;
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_FILE_TIME_TYPE_H
lib/libcxx/include/__filesystem/file_type.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___FILESYSTEM_FILE_TYPE_H
+#define _LIBCPP___FILESYSTEM_FILE_TYPE_H
+
+#include <__availability>
+#include <__config>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+// On Windows, the library never identifies files as block, character, fifo
+// or socket.
+enum class _LIBCPP_ENUM_VIS file_type : signed char {
+  none = 0,
+  not_found = -1,
+  regular = 1,
+  directory = 2,
+  symlink = 3,
+  block = 4,
+  character = 5,
+  fifo = 6,
+  socket = 7,
+  unknown = 8
+};
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_FILE_TYPE_H
lib/libcxx/include/__filesystem/filesystem_error.h
@@ -0,0 +1,99 @@
+// -*- 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___FILESYSTEM_FILESYSTEM_ERROR_H
+#define _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
+
+#include <__availability>
+#include <__config>
+#include <__filesystem/path.h>
+#include <__memory/shared_ptr.h>
+#include <iosfwd>
+#include <new>
+#include <system_error>
+#include <type_traits>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
+public:
+  _LIBCPP_INLINE_VISIBILITY
+  filesystem_error(const string& __what, error_code __ec)
+      : system_error(__ec, __what),
+        __storage_(make_shared<_Storage>(path(), path())) {
+    __create_what(0);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  filesystem_error(const string& __what, const path& __p1, error_code __ec)
+      : system_error(__ec, __what),
+        __storage_(make_shared<_Storage>(__p1, path())) {
+    __create_what(1);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  filesystem_error(const string& __what, const path& __p1, const path& __p2,
+                   error_code __ec)
+      : system_error(__ec, __what),
+        __storage_(make_shared<_Storage>(__p1, __p2)) {
+    __create_what(2);
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  const path& path1() const noexcept { return __storage_->__p1_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  const path& path2() const noexcept { return __storage_->__p2_; }
+
+  filesystem_error(const filesystem_error&) = default;
+  ~filesystem_error() override; // key function
+
+  _LIBCPP_INLINE_VISIBILITY
+  const char* what() const noexcept override {
+    return __storage_->__what_.c_str();
+  }
+
+  void __create_what(int __num_paths);
+
+private:
+  struct _LIBCPP_HIDDEN _Storage {
+    _LIBCPP_INLINE_VISIBILITY
+    _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
+
+    path __p1_;
+    path __p2_;
+    string __what_;
+  };
+  shared_ptr<_Storage> __storage_;
+};
+
+// TODO(ldionne): We need to pop the pragma and push it again after
+//                filesystem_error to work around PR41078.
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+template <class... _Args>
+_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
+#ifndef _LIBCPP_NO_EXCEPTIONS
+void __throw_filesystem_error(_Args&&... __args) {
+  throw filesystem_error(_VSTD::forward<_Args>(__args)...);
+}
+#else
+void __throw_filesystem_error(_Args&&...) {
+  _VSTD::abort();
+}
+#endif
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
lib/libcxx/include/__filesystem/operations.h
@@ -0,0 +1,197 @@
+// -*- 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___FILESYSTEM_OPERATIONS_H
+#define _LIBCPP___FILESYSTEM_OPERATIONS_H
+
+#include <__availability>
+#include <__config>
+#include <__filesystem/copy_options.h>
+#include <__filesystem/file_status.h>
+#include <__filesystem/file_time_type.h>
+#include <__filesystem/file_type.h>
+#include <__filesystem/path.h>
+#include <__filesystem/perm_options.h>
+#include <__filesystem/perms.h>
+#include <__filesystem/space_info.h>
+#include <chrono>
+#include <cstdint>
+#include <system_error>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+_LIBCPP_FUNC_VIS path __absolute(const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS path __canonical(const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS bool __copy_file(const path& __from, const path& __to, copy_options __opt, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS void __copy_symlink(const path& __existing_symlink, const path& __new_symlink, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS void __copy(const path& __from, const path& __to, copy_options __opt, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS bool __create_directories(const path& p, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS void __create_directory_symlink(const path& __to, const path& __new_symlink, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS bool __create_directory(const path& p, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS bool __create_directory(const path& p, const path& attributes, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS void __create_hard_link(const path& __to, const path& __new_hard_link, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS void __create_symlink(const path& __to, const path& __new_symlink, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS path __current_path(error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS void __current_path(const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS bool __equivalent(const path&, const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS file_status __status(const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS uintmax_t __file_size(const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS file_status __symlink_status(const path&, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS file_time_type __last_write_time(const path& p, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS void __last_write_time(const path& p, file_time_type new_time, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
+_LIBCPP_FUNC_VIS path __read_symlink(const path& p, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS uintmax_t __remove_all(const path& p, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS bool __remove(const path& p, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS void __rename(const path& from, const path& to, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr);
+_LIBCPP_FUNC_VIS path __temp_directory_path(error_code* __ec = nullptr);
+
+inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) { return __absolute(__p); }
+inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p, error_code& __ec) { return __absolute(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p)                   { return __canonical(__p); }
+inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p, error_code& __ec) { return __canonical(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to) { return __copy_file(__from, __to, copy_options::none); }
+inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, error_code& __ec) { return __copy_file(__from, __to, copy_options::none, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, copy_options __opt) { return __copy_file(__from, __to, __opt); }
+inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { return __copy_file(__from, __to, __opt, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __from, const path& __to) { __copy_symlink(__from, __to); }
+inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __from, const path& __to, error_code& __ec) noexcept { __copy_symlink(__from, __to, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to) { __copy(__from, __to, copy_options::none); }
+inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, error_code& __ec) { __copy(__from, __to, copy_options::none, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, copy_options __opt) { __copy(__from, __to, __opt); }
+inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { __copy(__from, __to, __opt, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) { return __create_directories(__p); }
+inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p, error_code& __ec) { return __create_directories(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void create_directory_symlink(const path& __target, const path& __link) { __create_directory_symlink(__target, __link); }
+inline _LIBCPP_INLINE_VISIBILITY void create_directory_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { __create_directory_symlink(__target, __link, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) { return __create_directory(__p); }
+inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, error_code& __ec) noexcept { return __create_directory(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, const path& __attrs) { return __create_directory(__p, __attrs); }
+inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, const path& __attrs, error_code& __ec) noexcept { return __create_directory(__p, __attrs, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __target, const path& __link) { __create_hard_link(__target, __link); }
+inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __target, const path& __link, error_code& __ec) noexcept { __create_hard_link(__target, __link, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __target, const path& __link) { __create_symlink(__target, __link); }
+inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { return __create_symlink(__target, __link, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY path current_path() { return __current_path(); }
+inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) { return __current_path(&__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) { __current_path(__p); }
+inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p, error_code& __ec) noexcept { __current_path(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1, const path& __p2) { return __equivalent(__p1, __p2); }
+inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept { return __equivalent(__p1, __p2, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept { return __s.type() != file_type::none; }
+inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept { return status_known(__s) && __s.type() != file_type::not_found; }
+inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) { return exists(__status(__p)); }
+
+inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p, error_code& __ec) noexcept {
+  auto __s = __status(__p, &__ec);
+  if (status_known(__s))
+    __ec.clear();
+  return exists(__s);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) { return __file_size(__p); }
+inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p, error_code& __ec) noexcept { return __file_size(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) { return __hard_link_count(__p); }
+inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept { return __hard_link_count(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept { return __s.type() == file_type::block; }
+inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) { return is_block_file(__status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p, error_code& __ec) noexcept { return is_block_file(__status(__p, &__ec)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(file_status __s) noexcept { return __s.type() == file_type::character; }
+inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) { return is_character_file(__status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p, error_code& __ec) noexcept { return is_character_file(__status(__p, &__ec)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept { return __s.type() == file_type::directory; }
+inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) { return is_directory(__status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p, error_code& __ec) noexcept { return is_directory(__status(__p, &__ec)); }
+_LIBCPP_FUNC_VIS bool __fs_is_empty(const path& p, error_code* ec = nullptr);
+inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) { return __fs_is_empty(__p); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept { return __s.type() == file_type::fifo; }
+inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) { return is_fifo(__status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p, error_code& __ec) noexcept { return is_fifo(__status(__p, &__ec)); } 
+inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(file_status __s) noexcept { return __s.type() == file_type::regular; }
+inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) { return is_regular_file(__status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p, error_code& __ec) noexcept { return is_regular_file(__status(__p, &__ec)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept { return __s.type() == file_type::symlink; }
+inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) { return is_symlink(__symlink_status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p, error_code& __ec) noexcept { return is_symlink(__symlink_status(__p, &__ec)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept { return exists(__s) && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) { return is_other(__status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p, error_code& __ec) noexcept { return is_other(__status(__p, &__ec)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept { return __s.type() == file_type::socket; }
+inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) { return is_socket(__status(__p)); }
+inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p, error_code& __ec) noexcept { return is_socket(__status(__p, &__ec)); }
+inline _LIBCPP_INLINE_VISIBILITY file_time_type last_write_time(const path& __p) { return __last_write_time(__p); }
+inline _LIBCPP_INLINE_VISIBILITY file_time_type last_write_time(const path& __p, error_code& __ec) noexcept { return __last_write_time(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p, file_time_type __t) { __last_write_time(__p, __t); }
+inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p, file_time_type __t, error_code& __ec) noexcept { __last_write_time(__p, __t, &__ec); }
+_LIBCPP_FUNC_VIS void __permissions(const path&, perms, perm_options, error_code* = nullptr);
+inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, perm_options __opts = perm_options::replace) { __permissions(__p, __prms, __opts); }
+inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, error_code& __ec) noexcept { __permissions(__p, __prms, perm_options::replace, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, perm_options __opts, error_code& __ec) { __permissions(__p, __prms, __opts, &__ec); }
+
+inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, const path& __base, error_code& __ec) {
+  path __tmp = __weakly_canonical(__p, &__ec);
+  if (__ec)
+    return {};
+  path __tmp_base = __weakly_canonical(__base, &__ec);
+  if (__ec)
+    return {};
+  return __tmp.lexically_proximate(__tmp_base);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, error_code& __ec) { return proximate(__p, current_path(), __ec); }
+inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base)); }
+inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) { return __read_symlink(__p); }
+inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p, error_code& __ec) { return __read_symlink(__p, &__ec); }
+
+inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, const path& __base, error_code& __ec) {
+  path __tmp = __weakly_canonical(__p, &__ec);
+  if (__ec)
+    return path();
+  path __tmpbase = __weakly_canonical(__base, &__ec);
+  if (__ec)
+    return path();
+  return __tmp.lexically_relative(__tmpbase);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, error_code& __ec) { return relative(__p, current_path(), __ec); }
+inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base)); }
+inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) { return __remove_all(__p); }
+inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p, error_code& __ec) { return __remove_all(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) { return __remove(__p); }
+inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p, error_code& __ec) noexcept { return __remove(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from, const path& __to) { return __rename(__from, __to); }
+inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from, const path& __to, error_code& __ec) noexcept { return __rename(__from, __to, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p, uintmax_t __ns) { return __resize_file(__p, __ns); }
+inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept { return __resize_file(__p, __ns, &__ec); }
+_LIBCPP_FUNC_VIS space_info __space(const path&, error_code* __ec = nullptr);
+inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) { return __space(__p); }
+inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p, error_code& __ec) noexcept { return __space(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) { return __status(__p); }
+inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p, error_code& __ec) noexcept { return __status(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) { return __symlink_status(__p); }
+inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p, error_code& __ec) noexcept { return __symlink_status(__p, &__ec); }
+inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() { return __temp_directory_path(); }
+inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) { return __temp_directory_path(&__ec); }
+inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) { return __weakly_canonical(__p); }
+inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p, error_code& __ec) { return __weakly_canonical(__p, &__ec); }
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_OPERATIONS_H
lib/libcxx/include/__filesystem/path.h
@@ -0,0 +1,1018 @@
+// -*- 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___FILESYSTEM_PATH_H
+#define _LIBCPP___FILESYSTEM_PATH_H
+
+#include <__availability>
+#include <__config>
+#include <__iterator/back_insert_iterator.h>
+#include <__iterator/iterator_traits.h>
+#include <cstddef>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <iomanip> // for quoted
+# include <locale>
+#endif
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+template <class _Tp>
+struct __can_convert_char {
+  static const bool value = false;
+};
+template <class _Tp>
+struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
+template <>
+struct __can_convert_char<char> {
+  static const bool value = true;
+  using __char_type = char;
+};
+template <>
+struct __can_convert_char<wchar_t> {
+  static const bool value = true;
+  using __char_type = wchar_t;
+};
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+template <>
+struct __can_convert_char<char8_t> {
+  static const bool value = true;
+  using __char_type = char8_t;
+};
+#endif
+template <>
+struct __can_convert_char<char16_t> {
+  static const bool value = true;
+  using __char_type = char16_t;
+};
+template <>
+struct __can_convert_char<char32_t> {
+  static const bool value = true;
+  using __char_type = char32_t;
+};
+
+template <class _ECharT>
+typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
+__is_separator(_ECharT __e) {
+#if defined(_LIBCPP_WIN32API)
+  return __e == _ECharT('/') || __e == _ECharT('\\');
+#else
+  return __e == _ECharT('/');
+#endif
+}
+
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+typedef u8string __u8_string;
+#else
+typedef string __u8_string;
+#endif
+
+struct _NullSentinel {};
+
+template <class _Tp>
+using _Void = void;
+
+template <class _Tp, class = void>
+struct __is_pathable_string : public false_type {};
+
+template <class _ECharT, class _Traits, class _Alloc>
+struct __is_pathable_string<
+    basic_string<_ECharT, _Traits, _Alloc>,
+    _Void<typename __can_convert_char<_ECharT>::__char_type> >
+    : public __can_convert_char<_ECharT> {
+  using _Str = basic_string<_ECharT, _Traits, _Alloc>;
+  using _Base = __can_convert_char<_ECharT>;
+  static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
+  static _ECharT const* __range_end(_Str const& __s) {
+    return __s.data() + __s.length();
+  }
+  static _ECharT __first_or_null(_Str const& __s) {
+    return __s.empty() ? _ECharT{} : __s[0];
+  }
+};
+
+template <class _ECharT, class _Traits>
+struct __is_pathable_string<
+    basic_string_view<_ECharT, _Traits>,
+    _Void<typename __can_convert_char<_ECharT>::__char_type> >
+    : public __can_convert_char<_ECharT> {
+  using _Str = basic_string_view<_ECharT, _Traits>;
+  using _Base = __can_convert_char<_ECharT>;
+  static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
+  static _ECharT const* __range_end(_Str const& __s) {
+    return __s.data() + __s.length();
+  }
+  static _ECharT __first_or_null(_Str const& __s) {
+    return __s.empty() ? _ECharT{} : __s[0];
+  }
+};
+
+template <class _Source, class _DS = typename decay<_Source>::type,
+          class _UnqualPtrType =
+              typename remove_const<typename remove_pointer<_DS>::type>::type,
+          bool _IsCharPtr = is_pointer<_DS>::value&&
+              __can_convert_char<_UnqualPtrType>::value>
+struct __is_pathable_char_array : false_type {};
+
+template <class _Source, class _ECharT, class _UPtr>
+struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
+    : __can_convert_char<typename remove_const<_ECharT>::type> {
+  using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
+
+  static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
+  static _ECharT const* __range_end(const _ECharT* __b) {
+    using _Iter = const _ECharT*;
+    const _ECharT __sentinel = _ECharT{};
+    _Iter __e = __b;
+    for (; *__e != __sentinel; ++__e)
+      ;
+    return __e;
+  }
+
+  static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
+};
+
+template <class _Iter, bool _IsIt = __is_cpp17_input_iterator<_Iter>::value,
+          class = void>
+struct __is_pathable_iter : false_type {};
+
+template <class _Iter>
+struct __is_pathable_iter<
+    _Iter, true,
+    _Void<typename __can_convert_char<
+        typename iterator_traits<_Iter>::value_type>::__char_type> >
+    : __can_convert_char<typename iterator_traits<_Iter>::value_type> {
+  using _ECharT = typename iterator_traits<_Iter>::value_type;
+  using _Base = __can_convert_char<_ECharT>;
+
+  static _Iter __range_begin(_Iter __b) { return __b; }
+  static _NullSentinel __range_end(_Iter) { return _NullSentinel{}; }
+
+  static _ECharT __first_or_null(_Iter __b) { return *__b; }
+};
+
+template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
+          bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
+          bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value>
+struct __is_pathable : false_type {
+  static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
+};
+
+template <class _Tp>
+struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
+
+template <class _Tp>
+struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {
+};
+
+template <class _Tp>
+struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
+
+#if defined(_LIBCPP_WIN32API)
+typedef wstring __path_string;
+typedef wchar_t __path_value;
+#else
+typedef string __path_string;
+typedef char __path_value;
+#endif
+
+#if defined(_LIBCPP_WIN32API)
+_LIBCPP_FUNC_VIS
+size_t __wide_to_char(const wstring&, char*, size_t);
+_LIBCPP_FUNC_VIS
+size_t __char_to_wide(const string&, wchar_t*, size_t);
+#endif
+
+template <class _ECharT>
+struct _PathCVT;
+
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+template <class _ECharT>
+struct _PathCVT {
+  static_assert(__can_convert_char<_ECharT>::value,
+                "Char type not convertible");
+
+  typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower;
+#if defined(_LIBCPP_WIN32API)
+  typedef __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Widener;
+#endif
+
+  static void __append_range(__path_string& __dest, _ECharT const* __b,
+                             _ECharT const* __e) {
+#if defined(_LIBCPP_WIN32API)
+    string __utf8;
+    _Narrower()(back_inserter(__utf8), __b, __e);
+    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
+#else
+    _Narrower()(back_inserter(__dest), __b, __e);
+#endif
+  }
+
+  template <class _Iter>
+  static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
+    static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
+    if (__b == __e)
+      return;
+    basic_string<_ECharT> __tmp(__b, __e);
+#if defined(_LIBCPP_WIN32API)
+    string __utf8;
+    _Narrower()(back_inserter(__utf8), __tmp.data(),
+                __tmp.data() + __tmp.length());
+    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
+#else
+    _Narrower()(back_inserter(__dest), __tmp.data(),
+                __tmp.data() + __tmp.length());
+#endif
+  }
+
+  template <class _Iter>
+  static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
+    static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
+    const _ECharT __sentinel = _ECharT{};
+    if (*__b == __sentinel)
+      return;
+    basic_string<_ECharT> __tmp;
+    for (; *__b != __sentinel; ++__b)
+      __tmp.push_back(*__b);
+#if defined(_LIBCPP_WIN32API)
+    string __utf8;
+    _Narrower()(back_inserter(__utf8), __tmp.data(),
+                __tmp.data() + __tmp.length());
+    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
+#else
+    _Narrower()(back_inserter(__dest), __tmp.data(),
+                __tmp.data() + __tmp.length());
+#endif
+  }
+
+  template <class _Source>
+  static void __append_source(__path_string& __dest, _Source const& __s) {
+    using _Traits = __is_pathable<_Source>;
+    __append_range(__dest, _Traits::__range_begin(__s),
+                   _Traits::__range_end(__s));
+  }
+};
+#endif // !_LIBCPP_HAS_NO_LOCALIZATION
+
+template <>
+struct _PathCVT<__path_value> {
+
+  template <class _Iter>
+  static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
+  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
+    for (; __b != __e; ++__b)
+      __dest.push_back(*__b);
+  }
+
+  template <class _Iter>
+  static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
+  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
+    __dest.append(__b, __e);
+  }
+
+  template <class _Iter>
+  static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
+    const char __sentinel = char{};
+    for (; *__b != __sentinel; ++__b)
+      __dest.push_back(*__b);
+  }
+
+  template <class _Source>
+  static void __append_source(__path_string& __dest, _Source const& __s) {
+    using _Traits = __is_pathable<_Source>;
+    __append_range(__dest, _Traits::__range_begin(__s),
+                   _Traits::__range_end(__s));
+  }
+};
+
+#if defined(_LIBCPP_WIN32API)
+template <>
+struct _PathCVT<char> {
+
+  static void
+  __append_string(__path_string& __dest, const basic_string<char> &__str) {
+      size_t __size = __char_to_wide(__str, nullptr, 0);
+      size_t __pos = __dest.size();
+      __dest.resize(__pos + __size);
+      __char_to_wide(__str, const_cast<__path_value*>(__dest.data()) + __pos, __size);
+  }
+
+  template <class _Iter>
+  static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
+  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
+    basic_string<char> __tmp(__b, __e);
+    __append_string(__dest, __tmp);
+  }
+
+  template <class _Iter>
+  static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
+  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
+    basic_string<char> __tmp(__b, __e);
+    __append_string(__dest, __tmp);
+  }
+
+  template <class _Iter>
+  static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
+    const char __sentinel = char{};
+    basic_string<char> __tmp;
+    for (; *__b != __sentinel; ++__b)
+      __tmp.push_back(*__b);
+    __append_string(__dest, __tmp);
+  }
+
+  template <class _Source>
+  static void __append_source(__path_string& __dest, _Source const& __s) {
+    using _Traits = __is_pathable<_Source>;
+    __append_range(__dest, _Traits::__range_begin(__s),
+                   _Traits::__range_end(__s));
+  }
+};
+
+template <class _ECharT>
+struct _PathExport {
+  typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
+  typedef __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Widener;
+
+  template <class _Str>
+  static void __append(_Str& __dest, const __path_string& __src) {
+    string __utf8;
+    _Narrower()(back_inserter(__utf8), __src.data(), __src.data() + __src.size());
+    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
+  }
+};
+
+template <>
+struct _PathExport<char> {
+  template <class _Str>
+  static void __append(_Str& __dest, const __path_string& __src) {
+    size_t __size = __wide_to_char(__src, nullptr, 0);
+    size_t __pos = __dest.size();
+    __dest.resize(__size);
+    __wide_to_char(__src, const_cast<char*>(__dest.data()) + __pos, __size);
+  }
+};
+
+template <>
+struct _PathExport<wchar_t> {
+  template <class _Str>
+  static void __append(_Str& __dest, const __path_string& __src) {
+    __dest.append(__src.begin(), __src.end());
+  }
+};
+
+template <>
+struct _PathExport<char16_t> {
+  template <class _Str>
+  static void __append(_Str& __dest, const __path_string& __src) {
+    __dest.append(__src.begin(), __src.end());
+  }
+};
+
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+template <>
+struct _PathExport<char8_t> {
+  typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
+
+  template <class _Str>
+  static void __append(_Str& __dest, const __path_string& __src) {
+    _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size());
+  }
+};
+#endif /* !_LIBCPP_HAS_NO_CHAR8_T */
+#endif /* _LIBCPP_WIN32API */
+
+class _LIBCPP_TYPE_VIS path {
+  template <class _SourceOrIter, class _Tp = path&>
+  using _EnableIfPathable =
+      typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
+
+  template <class _Tp>
+  using _SourceChar = typename __is_pathable<_Tp>::__char_type;
+
+  template <class _Tp>
+  using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
+
+public:
+#if defined(_LIBCPP_WIN32API)
+  typedef wchar_t value_type;
+  static constexpr value_type preferred_separator = L'\\';
+#else
+  typedef char value_type;
+  static constexpr value_type preferred_separator = '/';
+#endif
+  typedef basic_string<value_type> string_type;
+  typedef basic_string_view<value_type> __string_view;
+
+  enum _LIBCPP_ENUM_VIS format : unsigned char {
+    auto_format,
+    native_format,
+    generic_format
+  };
+
+  // constructors and destructor
+  _LIBCPP_INLINE_VISIBILITY path() noexcept {}
+  _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
+  _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept
+      : __pn_(_VSTD::move(__p.__pn_)) {}
+
+  _LIBCPP_INLINE_VISIBILITY
+  path(string_type&& __s, format = format::auto_format) noexcept
+      : __pn_(_VSTD::move(__s)) {}
+
+  template <class _Source, class = _EnableIfPathable<_Source, void> >
+  path(const _Source& __src, format = format::auto_format) {
+    _SourceCVT<_Source>::__append_source(__pn_, __src);
+  }
+
+  template <class _InputIt>
+  path(_InputIt __first, _InputIt __last, format = format::auto_format) {
+    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
+    _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
+  }
+
+/*
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+  // TODO Implement locale conversions.
+  template <class _Source, class = _EnableIfPathable<_Source, void> >
+  path(const _Source& __src, const locale& __loc, format = format::auto_format);
+  template <class _InputIt>
+  path(_InputIt __first, _InputIt _last, const locale& __loc,
+       format = format::auto_format);
+#endif
+*/
+
+  _LIBCPP_INLINE_VISIBILITY
+  ~path() = default;
+
+  // assignments
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator=(const path& __p) {
+    __pn_ = __p.__pn_;
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator=(path&& __p) noexcept {
+    __pn_ = _VSTD::move(__p.__pn_);
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator=(string_type&& __s) noexcept {
+    __pn_ = _VSTD::move(__s);
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& assign(string_type&& __s) noexcept {
+    __pn_ = _VSTD::move(__s);
+    return *this;
+  }
+
+  template <class _Source>
+  _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
+  operator=(const _Source& __src) {
+    return this->assign(__src);
+  }
+
+  template <class _Source>
+  _EnableIfPathable<_Source> assign(const _Source& __src) {
+    __pn_.clear();
+    _SourceCVT<_Source>::__append_source(__pn_, __src);
+    return *this;
+  }
+
+  template <class _InputIt>
+  path& assign(_InputIt __first, _InputIt __last) {
+    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
+    __pn_.clear();
+    _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
+    return *this;
+  }
+
+public:
+  // appends
+#if defined(_LIBCPP_WIN32API)
+  path& operator/=(const path& __p) {
+    auto __p_root_name = __p.__root_name();
+    auto __p_root_name_size = __p_root_name.size();
+    if (__p.is_absolute() ||
+        (!__p_root_name.empty() && __p_root_name != __string_view(root_name().__pn_))) {
+      __pn_ = __p.__pn_;
+      return *this;
+    }
+    if (__p.has_root_directory()) {
+      path __root_name_str = root_name();
+      __pn_ = __root_name_str.native();
+      __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
+      return *this;
+    }
+    if (has_filename() || (!has_root_directory() && is_absolute()))
+      __pn_ += preferred_separator;
+    __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
+    return *this;
+  }
+  template <class _Source>
+  _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
+  operator/=(const _Source& __src) {
+    return operator/=(path(__src));
+  }
+
+  template <class _Source>
+  _EnableIfPathable<_Source> append(const _Source& __src) {
+    return operator/=(path(__src));
+  }
+
+  template <class _InputIt>
+  path& append(_InputIt __first, _InputIt __last) {
+    return operator/=(path(__first, __last));
+  }
+#else
+  path& operator/=(const path& __p) {
+    if (__p.is_absolute()) {
+      __pn_ = __p.__pn_;
+      return *this;
+    }
+    if (has_filename())
+      __pn_ += preferred_separator;
+    __pn_ += __p.native();
+    return *this;
+  }
+
+  // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
+  // is known at compile time to be "/' since the user almost certainly intended
+  // to append a separator instead of overwriting the path with "/"
+  template <class _Source>
+  _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
+  operator/=(const _Source& __src) {
+    return this->append(__src);
+  }
+
+  template <class _Source>
+  _EnableIfPathable<_Source> append(const _Source& __src) {
+    using _Traits = __is_pathable<_Source>;
+    using _CVT = _PathCVT<_SourceChar<_Source> >;
+    bool __source_is_absolute = __is_separator(_Traits::__first_or_null(__src));
+    if (__source_is_absolute)
+      __pn_.clear();
+    else if (has_filename())
+      __pn_ += preferred_separator;
+    _CVT::__append_source(__pn_, __src);
+    return *this;
+  }
+
+  template <class _InputIt>
+  path& append(_InputIt __first, _InputIt __last) {
+    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
+    static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
+    using _CVT = _PathCVT<_ItVal>;
+    if (__first != __last && __is_separator(*__first))
+      __pn_.clear();
+    else if (has_filename())
+      __pn_ += preferred_separator;
+    _CVT::__append_range(__pn_, __first, __last);
+    return *this;
+  }
+#endif
+
+  // concatenation
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator+=(const path& __x) {
+    __pn_ += __x.__pn_;
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator+=(const string_type& __x) {
+    __pn_ += __x;
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator+=(__string_view __x) {
+    __pn_ += __x;
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator+=(const value_type* __x) {
+    __pn_ += __x;
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& operator+=(value_type __x) {
+    __pn_ += __x;
+    return *this;
+  }
+
+  template <class _ECharT>
+  typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
+  operator+=(_ECharT __x) {
+    _PathCVT<_ECharT>::__append_source(__pn_,
+                                       basic_string_view<_ECharT>(&__x, 1));
+    return *this;
+  }
+
+  template <class _Source>
+  _EnableIfPathable<_Source> operator+=(const _Source& __x) {
+    return this->concat(__x);
+  }
+
+  template <class _Source>
+  _EnableIfPathable<_Source> concat(const _Source& __x) {
+    _SourceCVT<_Source>::__append_source(__pn_, __x);
+    return *this;
+  }
+
+  template <class _InputIt>
+  path& concat(_InputIt __first, _InputIt __last) {
+    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
+    _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
+    return *this;
+  }
+
+  // modifiers
+  _LIBCPP_INLINE_VISIBILITY
+  void clear() noexcept { __pn_.clear(); }
+
+  path& make_preferred() {
+#if defined(_LIBCPP_WIN32API)
+    _VSTD::replace(__pn_.begin(), __pn_.end(), L'/', L'\\');
+#endif
+    return *this;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  path& remove_filename() {
+    auto __fname = __filename();
+    if (!__fname.empty())
+      __pn_.erase(__fname.data() - __pn_.data());
+    return *this;
+  }
+
+  path& replace_filename(const path& __replacement) {
+    remove_filename();
+    return (*this /= __replacement);
+  }
+
+  path& replace_extension(const path& __replacement = path());
+
+  _LIBCPP_INLINE_VISIBILITY
+  void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
+
+  // private helper to allow reserving memory in the path
+  _LIBCPP_INLINE_VISIBILITY
+  void __reserve(size_t __s) { __pn_.reserve(__s); }
+
+  // native format observers
+  _LIBCPP_INLINE_VISIBILITY
+  const string_type& native() const noexcept { return __pn_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  const value_type* c_str() const noexcept { return __pn_.c_str(); }
+
+  _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
+
+#if defined(_LIBCPP_WIN32API)
+  _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const { return __pn_; }
+
+  _VSTD::wstring generic_wstring() const {
+    _VSTD::wstring __s;
+    __s.resize(__pn_.size());
+    _VSTD::replace_copy(__pn_.begin(), __pn_.end(), __s.begin(), '\\', '/');
+    return __s;
+  }
+
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+  template <class _ECharT, class _Traits = char_traits<_ECharT>,
+            class _Allocator = allocator<_ECharT> >
+  basic_string<_ECharT, _Traits, _Allocator>
+  string(const _Allocator& __a = _Allocator()) const {
+    using _Str = basic_string<_ECharT, _Traits, _Allocator>;
+    _Str __s(__a);
+    __s.reserve(__pn_.size());
+    _PathExport<_ECharT>::__append(__s, __pn_);
+    return __s;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const {
+    return string<char>();
+  }
+  _LIBCPP_INLINE_VISIBILITY __u8_string u8string() const {
+    using _CVT = __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
+    __u8_string __s;
+    __s.reserve(__pn_.size());
+    _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
+    return __s;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
+    return string<char16_t>();
+  }
+  _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
+    return string<char32_t>();
+  }
+
+  // generic format observers
+  template <class _ECharT, class _Traits = char_traits<_ECharT>,
+            class _Allocator = allocator<_ECharT> >
+  basic_string<_ECharT, _Traits, _Allocator>
+  generic_string(const _Allocator& __a = _Allocator()) const {
+    using _Str = basic_string<_ECharT, _Traits, _Allocator>;
+    _Str __s = string<_ECharT, _Traits, _Allocator>(__a);
+    // Note: This (and generic_u8string below) is slightly suboptimal as
+    // it iterates twice over the string; once to convert it to the right
+    // character type, and once to replace path delimiters.
+    _VSTD::replace(__s.begin(), __s.end(),
+                   static_cast<_ECharT>('\\'), static_cast<_ECharT>('/'));
+    return __s;
+  }
+
+  _VSTD::string generic_string() const { return generic_string<char>(); }
+  _VSTD::u16string generic_u16string() const { return generic_string<char16_t>(); }
+  _VSTD::u32string generic_u32string() const { return generic_string<char32_t>(); }
+  __u8_string generic_u8string() const {
+    __u8_string __s = u8string();
+    _VSTD::replace(__s.begin(), __s.end(), '\\', '/');
+    return __s;
+  }
+#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
+#else /* _LIBCPP_WIN32API */
+
+  _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const { return __pn_; }
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+  _LIBCPP_INLINE_VISIBILITY _VSTD::u8string u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
+#else
+  _LIBCPP_INLINE_VISIBILITY _VSTD::string u8string() const { return __pn_; }
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+  template <class _ECharT, class _Traits = char_traits<_ECharT>,
+            class _Allocator = allocator<_ECharT> >
+  basic_string<_ECharT, _Traits, _Allocator>
+  string(const _Allocator& __a = _Allocator()) const {
+    using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
+    using _Str = basic_string<_ECharT, _Traits, _Allocator>;
+    _Str __s(__a);
+    __s.reserve(__pn_.size());
+    _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
+    return __s;
+  }
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+  _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const {
+    return string<wchar_t>();
+  }
+#endif
+  _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
+    return string<char16_t>();
+  }
+  _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
+    return string<char32_t>();
+  }
+#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
+
+  // generic format observers
+  _VSTD::string generic_string() const { return __pn_; }
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+  _VSTD::u8string generic_u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
+#else
+  _VSTD::string generic_u8string() const { return __pn_; }
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+  template <class _ECharT, class _Traits = char_traits<_ECharT>,
+            class _Allocator = allocator<_ECharT> >
+  basic_string<_ECharT, _Traits, _Allocator>
+  generic_string(const _Allocator& __a = _Allocator()) const {
+    return string<_ECharT, _Traits, _Allocator>(__a);
+  }
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+  _VSTD::wstring generic_wstring() const { return string<wchar_t>(); }
+#endif
+  _VSTD::u16string generic_u16string() const { return string<char16_t>(); }
+  _VSTD::u32string generic_u32string() const { return string<char32_t>(); }
+#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
+#endif /* !_LIBCPP_WIN32API */
+
+private:
+  int __compare(__string_view) const;
+  __string_view __root_name() const;
+  __string_view __root_directory() const;
+  __string_view __root_path_raw() const;
+  __string_view __relative_path() const;
+  __string_view __parent_path() const;
+  __string_view __filename() const;
+  __string_view __stem() const;
+  __string_view __extension() const;
+
+public:
+  // compare
+  _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
+    return __compare(__p.__pn_);
+  }
+  _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
+    return __compare(__s);
+  }
+  _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
+    return __compare(__s);
+  }
+  _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
+    return __compare(__s);
+  }
+
+  // decomposition
+  _LIBCPP_INLINE_VISIBILITY path root_name() const {
+    return string_type(__root_name());
+  }
+  _LIBCPP_INLINE_VISIBILITY path root_directory() const {
+    return string_type(__root_directory());
+  }
+  _LIBCPP_INLINE_VISIBILITY path root_path() const {
+#if defined(_LIBCPP_WIN32API)
+    return string_type(__root_path_raw());
+#else
+    return root_name().append(string_type(__root_directory()));
+#endif
+  }
+  _LIBCPP_INLINE_VISIBILITY path relative_path() const {
+    return string_type(__relative_path());
+  }
+  _LIBCPP_INLINE_VISIBILITY path parent_path() const {
+    return string_type(__parent_path());
+  }
+  _LIBCPP_INLINE_VISIBILITY path filename() const {
+    return string_type(__filename());
+  }
+  _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
+  _LIBCPP_INLINE_VISIBILITY path extension() const {
+    return string_type(__extension());
+  }
+
+  // query
+  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
+  empty() const noexcept {
+    return __pn_.empty();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
+    return !__root_name().empty();
+  }
+  _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
+    return !__root_directory().empty();
+  }
+  _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
+    return !__root_path_raw().empty();
+  }
+  _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
+    return !__relative_path().empty();
+  }
+  _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
+    return !__parent_path().empty();
+  }
+  _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
+    return !__filename().empty();
+  }
+  _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
+  _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
+    return !__extension().empty();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
+#if defined(_LIBCPP_WIN32API)
+    __string_view __root_name_str = __root_name();
+    __string_view __root_dir = __root_directory();
+    if (__root_name_str.size() == 2 && __root_name_str[1] == ':') {
+      // A drive letter with no root directory is relative, e.g. x:example.
+      return !__root_dir.empty();
+    }
+    // If no root name, it's relative, e.g. \example is relative to the current drive
+    if (__root_name_str.empty())
+      return false;
+    if (__root_name_str.size() < 3)
+      return false;
+    // A server root name, like \\server, is always absolute
+    if (__root_name_str[0] != '/' && __root_name_str[0] != '\\')
+      return false;
+    if (__root_name_str[1] != '/' && __root_name_str[1] != '\\')
+      return false;
+    // Seems to be a server root name
+    return true;
+#else
+    return has_root_directory();
+#endif
+  }
+  _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
+
+  // relative paths
+  path lexically_normal() const;
+  path lexically_relative(const path& __base) const;
+
+  _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
+    path __result = this->lexically_relative(__base);
+    if (__result.native().empty())
+      return *this;
+    return __result;
+  }
+
+  // iterators
+  class _LIBCPP_TYPE_VIS iterator;
+  typedef iterator const_iterator;
+
+  iterator begin() const;
+  iterator end() const;
+
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+  template <class _CharT, class _Traits>
+  _LIBCPP_INLINE_VISIBILITY friend
+      typename enable_if<is_same<_CharT, value_type>::value &&
+                             is_same<_Traits, char_traits<value_type> >::value,
+                         basic_ostream<_CharT, _Traits>&>::type
+      operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
+    __os << _VSTD::__quoted(__p.native());
+    return __os;
+  }
+
+  template <class _CharT, class _Traits>
+  _LIBCPP_INLINE_VISIBILITY friend
+      typename enable_if<!is_same<_CharT, value_type>::value ||
+                             !is_same<_Traits, char_traits<value_type> >::value,
+                         basic_ostream<_CharT, _Traits>&>::type
+      operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
+    __os << _VSTD::__quoted(__p.string<_CharT, _Traits>());
+    return __os;
+  }
+
+  template <class _CharT, class _Traits>
+  _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>&
+  operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) {
+    basic_string<_CharT, _Traits> __tmp;
+    __is >> __quoted(__tmp);
+    __p = __tmp;
+    return __is;
+  }
+#endif // !_LIBCPP_HAS_NO_LOCALIZATION
+
+  friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
+    return __lhs.__compare(__rhs.__pn_) == 0;
+  }
+  friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
+    return __lhs.__compare(__rhs.__pn_) != 0;
+  }
+  friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
+    return __lhs.__compare(__rhs.__pn_) < 0;
+  }
+  friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
+    return __lhs.__compare(__rhs.__pn_) <= 0;
+  }
+  friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
+    return __lhs.__compare(__rhs.__pn_) > 0;
+  }
+  friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
+    return __lhs.__compare(__rhs.__pn_) >= 0;
+  }
+
+  friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
+                                                  const path& __rhs) {
+    path __result(__lhs);
+    __result /= __rhs;
+    return __result;
+  }
+private:
+  inline _LIBCPP_INLINE_VISIBILITY path&
+  __assign_view(__string_view const& __s) noexcept {
+    __pn_ = string_type(__s);
+    return *this;
+  }
+  string_type __pn_;
+};
+
+inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
+  __lhs.swap(__rhs);
+}
+
+_LIBCPP_FUNC_VIS
+size_t hash_value(const path& __p) noexcept;
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_PATH_H
lib/libcxx/include/__filesystem/path_iterator.h
@@ -0,0 +1,130 @@
+// -*- 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___FILESYSTEM_PATH_ITERATOR_H
+#define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
+
+#include <__availability>
+#include <__config>
+#include <__debug>
+#include <__filesystem/path.h>
+#include <__iterator/iterator_traits.h>
+#include <cstddef>
+#include <string>
+#include <string_view>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+class _LIBCPP_TYPE_VIS path::iterator {
+public:
+  enum _ParserState : unsigned char {
+    _Singular,
+    _BeforeBegin,
+    _InRootName,
+    _InRootDir,
+    _InFilenames,
+    _InTrailingSep,
+    _AtEnd
+  };
+
+public:
+  typedef input_iterator_tag iterator_category;
+  typedef bidirectional_iterator_tag iterator_concept;
+
+  typedef path value_type;
+  typedef ptrdiff_t difference_type;
+  typedef const path* pointer;
+  typedef path reference;
+
+public:
+  _LIBCPP_INLINE_VISIBILITY
+  iterator()
+      : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
+        __state_(_Singular) {}
+
+  iterator(const iterator&) = default;
+  ~iterator() = default;
+
+  iterator& operator=(const iterator&) = default;
+
+  _LIBCPP_INLINE_VISIBILITY
+  reference operator*() const { return __stashed_elem_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  pointer operator->() const { return &__stashed_elem_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  iterator& operator++() {
+    _LIBCPP_ASSERT(__state_ != _Singular,
+                   "attempting to increment a singular iterator");
+    _LIBCPP_ASSERT(__state_ != _AtEnd,
+                   "attempting to increment the end iterator");
+    return __increment();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  iterator operator++(int) {
+    iterator __it(*this);
+    this->operator++();
+    return __it;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  iterator& operator--() {
+    _LIBCPP_ASSERT(__state_ != _Singular,
+                   "attempting to decrement a singular iterator");
+    _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
+                   "attempting to decrement the begin iterator");
+    return __decrement();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  iterator operator--(int) {
+    iterator __it(*this);
+    this->operator--();
+    return __it;
+  }
+
+private:
+  friend class path;
+
+  inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
+                                                          const iterator&);
+
+  iterator& __increment();
+  iterator& __decrement();
+
+  path __stashed_elem_;
+  const path* __path_ptr_;
+  path::__string_view __entry_;
+  _ParserState __state_;
+};
+
+inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
+                                                 const path::iterator& __rhs) {
+  return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
+         __lhs.__entry_.data() == __rhs.__entry_.data();
+}
+
+inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
+                                                 const path::iterator& __rhs) {
+  return !(__lhs == __rhs);
+}
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
lib/libcxx/include/__filesystem/perm_options.h
@@ -0,0 +1,73 @@
+// -*- 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___FILESYSTEM_PERM_OPTIONS_H
+#define _LIBCPP___FILESYSTEM_PERM_OPTIONS_H
+
+#include <__availability>
+#include <__config>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
+  replace = 1,
+  add = 2,
+  remove = 4,
+  nofollow = 8
+};
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) {
+  return static_cast<perm_options>(static_cast<unsigned>(_LHS) &
+                                   static_cast<unsigned>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) {
+  return static_cast<perm_options>(static_cast<unsigned>(_LHS) |
+                                   static_cast<unsigned>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) {
+  return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^
+                                   static_cast<unsigned>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perm_options operator~(perm_options _LHS) {
+  return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
+  return _LHS = _LHS & _RHS;
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
+  return _LHS = _LHS | _RHS;
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
+  return _LHS = _LHS ^ _RHS;
+}
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_PERM_OPTIONS_H
lib/libcxx/include/__filesystem/perms.h
@@ -0,0 +1,91 @@
+// -*- 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___FILESYSTEM_PERMS_H
+#define _LIBCPP___FILESYSTEM_PERMS_H
+
+#include <__availability>
+#include <__config>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+// On Windows, these permission bits map to one single readonly flag per
+// file, and the executable bit is always returned as set. When setting
+// permissions, as long as the write bit is set for either owner, group or
+// others, the readonly flag is cleared.
+enum class _LIBCPP_ENUM_VIS perms : unsigned {
+  none = 0,
+
+  owner_read = 0400,
+  owner_write = 0200,
+  owner_exec = 0100,
+  owner_all = 0700,
+
+  group_read = 040,
+  group_write = 020,
+  group_exec = 010,
+  group_all = 070,
+
+  others_read = 04,
+  others_write = 02,
+  others_exec = 01,
+  others_all = 07,
+
+  all = 0777,
+
+  set_uid = 04000,
+  set_gid = 02000,
+  sticky_bit = 01000,
+  mask = 07777,
+  unknown = 0xFFFF,
+};
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perms operator&(perms _LHS, perms _RHS) {
+  return static_cast<perms>(static_cast<unsigned>(_LHS) &
+                            static_cast<unsigned>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perms operator|(perms _LHS, perms _RHS) {
+  return static_cast<perms>(static_cast<unsigned>(_LHS) |
+                            static_cast<unsigned>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perms operator^(perms _LHS, perms _RHS) {
+  return static_cast<perms>(static_cast<unsigned>(_LHS) ^
+                            static_cast<unsigned>(_RHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline constexpr perms operator~(perms _LHS) {
+  return static_cast<perms>(~static_cast<unsigned>(_LHS));
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
+
+_LIBCPP_INLINE_VISIBILITY
+inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
+
+_LIBCPP_INLINE_VISIBILITY
+inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_PERMS_H
lib/libcxx/include/__filesystem/recursive_directory_iterator.h
@@ -0,0 +1,181 @@
+// -*- 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___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H
+#define _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H
+
+#include <__availability>
+#include <__config>
+#include <__filesystem/directory_entry.h>
+#include <__filesystem/directory_options.h>
+#include <__filesystem/path.h>
+#include <__iterator/iterator_traits.h>
+#include <__memory/shared_ptr.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/enable_view.h>
+#include <cstddef>
+#include <system_error>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+class recursive_directory_iterator {
+public:
+  using value_type = directory_entry;
+  using difference_type = ptrdiff_t;
+  using pointer = directory_entry const*;
+  using reference = directory_entry const&;
+  using iterator_category = input_iterator_tag;
+
+public:
+  // constructors and destructor
+  _LIBCPP_INLINE_VISIBILITY
+  recursive_directory_iterator() noexcept : __rec_(false) {}
+
+  _LIBCPP_INLINE_VISIBILITY
+  explicit recursive_directory_iterator(
+      const path& __p, directory_options __xoptions = directory_options::none)
+      : recursive_directory_iterator(__p, __xoptions, nullptr) {}
+
+  _LIBCPP_INLINE_VISIBILITY
+  recursive_directory_iterator(const path& __p, directory_options __xoptions,
+                               error_code& __ec)
+      : recursive_directory_iterator(__p, __xoptions, &__ec) {}
+
+  _LIBCPP_INLINE_VISIBILITY
+  recursive_directory_iterator(const path& __p, error_code& __ec)
+      : recursive_directory_iterator(__p, directory_options::none, &__ec) {}
+
+  recursive_directory_iterator(const recursive_directory_iterator&) = default;
+  recursive_directory_iterator(recursive_directory_iterator&&) = default;
+
+  recursive_directory_iterator&
+  operator=(const recursive_directory_iterator&) = default;
+
+  _LIBCPP_INLINE_VISIBILITY
+  recursive_directory_iterator&
+  operator=(recursive_directory_iterator&& __o) noexcept {
+    // non-default implementation provided to support self-move assign.
+    if (this != &__o) {
+      __imp_ = _VSTD::move(__o.__imp_);
+      __rec_ = __o.__rec_;
+    }
+    return *this;
+  }
+
+  ~recursive_directory_iterator() = default;
+
+  _LIBCPP_INLINE_VISIBILITY
+  const directory_entry& operator*() const { return __dereference(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  const directory_entry* operator->() const { return &__dereference(); }
+
+  recursive_directory_iterator& operator++() { return __increment(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  __dir_element_proxy operator++(int) {
+    __dir_element_proxy __p(**this);
+    __increment();
+    return __p;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  recursive_directory_iterator& increment(error_code& __ec) {
+    return __increment(&__ec);
+  }
+
+  _LIBCPP_FUNC_VIS directory_options options() const;
+  _LIBCPP_FUNC_VIS int depth() const;
+
+  _LIBCPP_INLINE_VISIBILITY
+  void pop() { __pop(); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void pop(error_code& __ec) { __pop(&__ec); }
+
+  _LIBCPP_INLINE_VISIBILITY
+  bool recursion_pending() const { return __rec_; }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void disable_recursion_pending() { __rec_ = false; }
+
+private:
+  _LIBCPP_FUNC_VIS
+  recursive_directory_iterator(const path& __p, directory_options __opt,
+                               error_code* __ec);
+
+  _LIBCPP_FUNC_VIS
+  const directory_entry& __dereference() const;
+
+  _LIBCPP_FUNC_VIS
+  bool __try_recursion(error_code* __ec);
+
+  _LIBCPP_FUNC_VIS
+  void __advance(error_code* __ec = nullptr);
+
+  _LIBCPP_FUNC_VIS
+  recursive_directory_iterator& __increment(error_code* __ec = nullptr);
+
+  _LIBCPP_FUNC_VIS
+  void __pop(error_code* __ec = nullptr);
+
+  inline _LIBCPP_INLINE_VISIBILITY friend bool
+  operator==(const recursive_directory_iterator&,
+             const recursive_directory_iterator&) noexcept;
+
+  struct _LIBCPP_HIDDEN __shared_imp;
+  shared_ptr<__shared_imp> __imp_;
+  bool __rec_;
+}; // class recursive_directory_iterator
+
+inline _LIBCPP_INLINE_VISIBILITY bool
+operator==(const recursive_directory_iterator& __lhs,
+           const recursive_directory_iterator& __rhs) noexcept {
+  return __lhs.__imp_ == __rhs.__imp_;
+}
+
+_LIBCPP_INLINE_VISIBILITY
+inline bool operator!=(const recursive_directory_iterator& __lhs,
+                       const recursive_directory_iterator& __rhs) noexcept {
+  return !(__lhs == __rhs);
+}
+// enable recursive_directory_iterator range-based for statements
+inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
+begin(recursive_directory_iterator __iter) noexcept {
+  return __iter;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
+end(recursive_directory_iterator) noexcept {
+  return recursive_directory_iterator();
+}
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <>
+_LIBCPP_AVAILABILITY_FILESYSTEM
+inline constexpr bool _VSTD::ranges::enable_borrowed_range<_VSTD_FS::recursive_directory_iterator> = true;
+
+template <>
+_LIBCPP_AVAILABILITY_FILESYSTEM
+inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::recursive_directory_iterator> = true;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H
lib/libcxx/include/__filesystem/space_info.h
@@ -0,0 +1,35 @@
+// -*- 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___FILESYSTEM_SPACE_INFO_H
+#define _LIBCPP___FILESYSTEM_SPACE_INFO_H
+
+#include <__availability>
+#include <__config>
+#include <cstdint>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+struct _LIBCPP_TYPE_VIS space_info {
+  uintmax_t capacity;
+  uintmax_t free;
+  uintmax_t available;
+};
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_SPACE_INFO_H
lib/libcxx/include/__filesystem/u8path.h
@@ -0,0 +1,96 @@
+// -*- 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___FILESYSTEM_U8PATH_H
+#define _LIBCPP___FILESYSTEM_U8PATH_H
+
+#include <__availability>
+#include <__config>
+#include <__filesystem/path.h>
+#include <type_traits>
+
+#ifndef _LIBCPP_CXX03_LANG
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
+template <class _InputIt>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
+    typename enable_if<__is_pathable<_InputIt>::value, path>::type
+    u8path(_InputIt __f, _InputIt __l) {
+  static_assert(
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+      is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
+#endif
+      is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
+      "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
+      " or 'char8_t'");
+#if defined(_LIBCPP_WIN32API)
+  string __tmp(__f, __l);
+  using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
+  _VSTD::wstring __w;
+  __w.reserve(__tmp.size());
+  _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
+  return path(__w);
+#else
+  return path(__f, __l);
+#endif /* !_LIBCPP_WIN32API */
+}
+
+#if defined(_LIBCPP_WIN32API)
+template <class _InputIt>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
+    typename enable_if<__is_pathable<_InputIt>::value, path>::type
+    u8path(_InputIt __f, _NullSentinel) {
+  static_assert(
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+      is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
+#endif
+      is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
+      "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
+      " or 'char8_t'");
+  string __tmp;
+  const char __sentinel = char{};
+  for (; *__f != __sentinel; ++__f)
+    __tmp.push_back(*__f);
+  using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
+  _VSTD::wstring __w;
+  __w.reserve(__tmp.size());
+  _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
+  return path(__w);
+}
+#endif /* _LIBCPP_WIN32API */
+
+template <class _Source>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
+    typename enable_if<__is_pathable<_Source>::value, path>::type
+    u8path(const _Source& __s) {
+  static_assert(
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+      is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value ||
+#endif
+      is_same<typename __is_pathable<_Source>::__char_type, char>::value,
+      "u8path(Source const&) requires Source have a character type of type "
+      "'char' or 'char8_t'");
+#if defined(_LIBCPP_WIN32API)
+  using _Traits = __is_pathable<_Source>;
+  return u8path(_VSTD::__unwrap_iter(_Traits::__range_begin(__s)), _VSTD::__unwrap_iter(_Traits::__range_end(__s)));
+#else
+  return path(__s);
+#endif
+}
+
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // _LIBCPP_CXX03_LANG
+
+#endif // _LIBCPP___FILESYSTEM_U8PATH_H
lib/libcxx/include/__format/format_arg.h
@@ -0,0 +1,292 @@
+// -*- 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___FORMAT_FORMAT_ARG_H
+#define _LIBCPP___FORMAT_FORMAT_ARG_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/format_parse_context.h>
+#include <__functional_base>
+#include <__memory/addressof.h>
+#include <__variant/monostate.h>
+#include <string>
+#include <string_view>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format {
+/// The type stored in @ref basic_format_arg.
+///
+/// @note The 128-bit types are unconditionally in the list to avoid the values
+/// of the enums to depend on the availability of 128-bit integers.
+enum class _LIBCPP_ENUM_VIS __arg_t : uint8_t {
+  __none,
+  __boolean,
+  __char_type,
+  __int,
+  __long_long,
+  __i128,
+  __unsigned,
+  __unsigned_long_long,
+  __u128,
+  __float,
+  __double,
+  __long_double,
+  __const_char_type_ptr,
+  __string_view,
+  __ptr,
+  __handle
+};
+} // namespace __format
+
+template <class _Visitor, class _Context>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT decltype(auto)
+visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
+  switch (__arg.__type_) {
+  case __format::__arg_t::__none:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), monostate{});
+  case __format::__arg_t::__boolean:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__boolean);
+  case __format::__arg_t::__char_type:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__char_type);
+  case __format::__arg_t::__int:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__int);
+  case __format::__arg_t::__long_long:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__long_long);
+  case __format::__arg_t::__i128:
+#ifndef _LIBCPP_HAS_NO_INT128
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__i128);
+#else
+    _LIBCPP_UNREACHABLE();
+#endif
+  case __format::__arg_t::__unsigned:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__unsigned);
+  case __format::__arg_t::__unsigned_long_long:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
+                         __arg.__unsigned_long_long);
+  case __format::__arg_t::__u128:
+#ifndef _LIBCPP_HAS_NO_INT128
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__u128);
+#else
+   _LIBCPP_UNREACHABLE();
+#endif
+  case __format::__arg_t::__float:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__float);
+  case __format::__arg_t::__double:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__double);
+  case __format::__arg_t::__long_double:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__long_double);
+  case __format::__arg_t::__const_char_type_ptr:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis),
+                         __arg.__const_char_type_ptr);
+  case __format::__arg_t::__string_view:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__string_view);
+  case __format::__arg_t::__ptr:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__ptr);
+  case __format::__arg_t::__handle:
+    return _VSTD::invoke(_VSTD::forward<_Visitor>(__vis), __arg.__handle);
+  }
+  _LIBCPP_UNREACHABLE();
+}
+
+template <class _Context>
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_arg {
+public:
+  class _LIBCPP_TEMPLATE_VIS handle;
+
+  _LIBCPP_HIDE_FROM_ABI basic_format_arg() noexcept
+      : __type_{__format::__arg_t::__none} {}
+
+  _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept {
+    return __type_ != __format::__arg_t::__none;
+  }
+
+private:
+  using char_type = typename _Context::char_type;
+
+  // TODO FMT Implement constrain [format.arg]/4
+  // Constraints: The template specialization
+  //   typename Context::template formatter_type<T>
+  // meets the Formatter requirements ([formatter.requirements]).  The extent
+  // to which an implementation determines that the specialization meets the
+  // Formatter requirements is unspecified, except that as a minimum the
+  // expression
+  //   typename Context::template formatter_type<T>()
+  //    .format(declval<const T&>(), declval<Context&>())
+  // shall be well-formed when treated as an unevaluated operand.
+
+  template <class _Ctx, class... _Args>
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT friend __format_arg_store<_Ctx, _Args...>
+  make_format_args(const _Args&...);
+
+  template <class _Visitor, class _Ctx>
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT friend decltype(auto)
+  visit_format_arg(_Visitor&& __vis, basic_format_arg<_Ctx> __arg);
+
+  union {
+    bool __boolean;
+    char_type __char_type;
+    int __int;
+    unsigned __unsigned;
+    long long __long_long;
+    unsigned long long __unsigned_long_long;
+#ifndef _LIBCPP_HAS_NO_INT128
+    __int128_t __i128;
+    __uint128_t __u128;
+#endif
+    float __float;
+    double __double;
+    long double __long_double;
+    const char_type* __const_char_type_ptr;
+    basic_string_view<char_type> __string_view;
+    const void* __ptr;
+    handle __handle;
+  };
+  __format::__arg_t __type_;
+
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(bool __v) noexcept
+      : __boolean(__v), __type_(__format::__arg_t::__boolean) {}
+
+  template <class _Tp>
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp __v) noexcept
+      requires(same_as<_Tp, char_type> ||
+               (same_as<_Tp, char> && same_as<char_type, wchar_t>))
+      : __char_type(__v), __type_(__format::__arg_t::__char_type) {}
+
+  template <__libcpp_signed_integer _Tp>
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp __v) noexcept {
+    if constexpr (sizeof(_Tp) <= sizeof(int)) {
+      __int = static_cast<int>(__v);
+      __type_ = __format::__arg_t::__int;
+    } else if constexpr (sizeof(_Tp) <= sizeof(long long)) {
+      __long_long = static_cast<long long>(__v);
+      __type_ = __format::__arg_t::__long_long;
+    }
+#ifndef _LIBCPP_HAS_NO_INT128
+    else if constexpr (sizeof(_Tp) == sizeof(__int128_t)) {
+      __i128 = __v;
+      __type_ = __format::__arg_t::__i128;
+    }
+#endif
+    else
+      static_assert(sizeof(_Tp) == 0, "An unsupported signed integer was used");
+  }
+
+  template <__libcpp_unsigned_integer _Tp>
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp __v) noexcept {
+    if constexpr (sizeof(_Tp) <= sizeof(unsigned)) {
+      __unsigned = static_cast<unsigned>(__v);
+      __type_ = __format::__arg_t::__unsigned;
+    } else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long)) {
+      __unsigned_long_long = static_cast<unsigned long long>(__v);
+      __type_ = __format::__arg_t::__unsigned_long_long;
+    }
+#ifndef _LIBCPP_HAS_NO_INT128
+    else if constexpr (sizeof(_Tp) == sizeof(__int128_t)) {
+      __u128 = __v;
+      __type_ = __format::__arg_t::__u128;
+    }
+#endif
+    else
+      static_assert(sizeof(_Tp) == 0,
+                    "An unsupported unsigned integer was used");
+  }
+
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(float __v) noexcept
+      : __float(__v), __type_(__format::__arg_t::__float) {}
+
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(double __v) noexcept
+      : __double(__v), __type_(__format::__arg_t::__double) {}
+
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(long double __v) noexcept
+      : __long_double(__v), __type_(__format::__arg_t::__long_double) {}
+
+  // Note not a 'noexcept' function.
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(const char_type* __s)
+      : __const_char_type_ptr(__s),
+        __type_(__format::__arg_t::__const_char_type_ptr) {
+    _LIBCPP_ASSERT(__s, "Used a nullptr argument to initialize a C-string");
+  }
+
+  template <class _Traits>
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(
+      basic_string_view<char_type, _Traits> __s) noexcept
+      : __string_view{__s.data(), __s.size()},
+        __type_(__format::__arg_t::__string_view) {}
+
+  template <class _Traits, class _Allocator>
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(
+      const basic_string<char_type, _Traits, _Allocator>& __s) noexcept
+      : __string_view{__s.data(), __s.size()},
+        __type_(__format::__arg_t::__string_view) {}
+
+  _LIBCPP_HIDE_FROM_ABI
+  explicit basic_format_arg(nullptr_t) noexcept
+      : __ptr(nullptr), __type_(__format::__arg_t::__ptr) {}
+
+  template <class _Tp>
+  requires is_void_v<_Tp> _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(_Tp* __p) noexcept
+      : __ptr(__p), __type_(__format::__arg_t::__ptr) {}
+
+  template <class _Tp>
+  _LIBCPP_HIDE_FROM_ABI explicit basic_format_arg(const _Tp& __v) noexcept
+      : __handle(__v), __type_(__format::__arg_t::__handle) {}
+};
+
+template <class _Context>
+class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
+  friend class basic_format_arg<_Context>;
+
+public:
+  _LIBCPP_HIDE_FROM_ABI
+  void format(basic_format_parse_context<char_type>& __parse_ctx, _Context& __ctx) const {
+    __format_(__parse_ctx, __ctx, __ptr_);
+  }
+
+private:
+  const void* __ptr_;
+  void (*__format_)(basic_format_parse_context<char_type>&, _Context&, const void*);
+
+  template <class _Tp>
+  _LIBCPP_HIDE_FROM_ABI explicit handle(const _Tp& __v) noexcept
+      : __ptr_(_VSTD::addressof(__v)),
+        __format_([](basic_format_parse_context<char_type>& __parse_ctx, _Context& __ctx, const void* __ptr) {
+          typename _Context::template formatter_type<_Tp> __f;
+          __parse_ctx.advance_to(__f.parse(__parse_ctx));
+          __ctx.advance_to(__f.format(*static_cast<const _Tp*>(__ptr), __ctx));
+        }) {}
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMAT_ARG_H
lib/libcxx/include/__format/format_args.h
@@ -0,0 +1,71 @@
+// -*- 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___FORMAT_FORMAT_ARGS_H
+#define _LIBCPP___FORMAT_FORMAT_ARGS_H
+
+#include <__availability>
+#include <__config>
+#include <__format/format_fwd.h>
+#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
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <class _Context>
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_args {
+public:
+  // TODO FMT Implement [format.args]/5
+  // [Note 1: Implementations are encouraged to optimize the representation of
+  // basic_format_args for small number of formatting arguments by storing
+  // indices of type alternatives separately from values and packing the
+  // former. - end note]
+  // Note: Change  __format_arg_store to use a built-in array.
+  _LIBCPP_HIDE_FROM_ABI basic_format_args() noexcept = default;
+
+  template <class... _Args>
+  _LIBCPP_HIDE_FROM_ABI basic_format_args(
+      const __format_arg_store<_Context, _Args...>& __store) noexcept
+      : __size_(sizeof...(_Args)), __data_(__store.__args.data()) {}
+
+  _LIBCPP_HIDE_FROM_ABI
+  basic_format_arg<_Context> get(size_t __id) const noexcept {
+    return __id < __size_ ? __data_[__id] : basic_format_arg<_Context>{};
+  }
+
+  _LIBCPP_HIDE_FROM_ABI size_t __size() const noexcept { return __size_; }
+
+private:
+  size_t __size_{0};
+  const basic_format_arg<_Context>* __data_{nullptr};
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMAT_ARGS_H
lib/libcxx/include/__format/format_context.h
@@ -0,0 +1,165 @@
+// -*- 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___FORMAT_FORMAT_CONTEXT_H
+#define _LIBCPP___FORMAT_FORMAT_CONTEXT_H
+
+#include <__availability>
+#include <__config>
+#include <__format/format_args.h>
+#include <__format/format_fwd.h>
+#include <__iterator/back_insert_iterator.h>
+#include <__iterator/concepts.h>
+#include <concepts>
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#include <locale>
+#include <optional>
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <class _OutIt, class _CharT>
+requires output_iterator<_OutIt, const _CharT&>
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_context;
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+/**
+ * Helper to create a basic_format_context.
+ *
+ * This is needed since the constructor is private.
+ */
+template <class _OutIt, class _CharT>
+_LIBCPP_HIDE_FROM_ABI basic_format_context<_OutIt, _CharT>
+__format_context_create(
+    _OutIt __out_it,
+    basic_format_args<basic_format_context<_OutIt, _CharT>> __args,
+    optional<_VSTD::locale>&& __loc = nullopt) {
+  return _VSTD::basic_format_context(_VSTD::move(__out_it), __args,
+                                     _VSTD::move(__loc));
+}
+#else
+template <class _OutIt, class _CharT>
+_LIBCPP_HIDE_FROM_ABI basic_format_context<_OutIt, _CharT>
+__format_context_create(
+    _OutIt __out_it,
+    basic_format_args<basic_format_context<_OutIt, _CharT>> __args) {
+  return _VSTD::basic_format_context(_VSTD::move(__out_it), __args);
+}
+#endif
+
+// TODO FMT Implement [format.context]/4
+// [Note 1: For a given type charT, implementations are encouraged to provide a
+// single instantiation of basic_format_context for appending to
+// basic_string<charT>, vector<charT>, or any other container with contiguous
+// storage by wrapping those in temporary objects with a uniform interface
+// (such as a span<charT>) and polymorphic reallocation. - end note]
+
+using format_context = basic_format_context<back_insert_iterator<string>, char>;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+using wformat_context = basic_format_context<back_insert_iterator<wstring>, wchar_t>;
+#endif
+
+template <class _OutIt, class _CharT>
+requires output_iterator<_OutIt, const _CharT&>
+class
+    // clang-format off
+    _LIBCPP_TEMPLATE_VIS
+    _LIBCPP_AVAILABILITY_FORMAT
+    _LIBCPP_PREFERRED_NAME(format_context)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wformat_context))
+    // clang-format on
+    basic_format_context {
+public:
+  using iterator = _OutIt;
+  using char_type = _CharT;
+  template <class _Tp>
+  using formatter_type = formatter<_Tp, _CharT>;
+
+  basic_format_context(const basic_format_context&) = delete;
+  basic_format_context& operator=(const basic_format_context&) = delete;
+
+  _LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context>
+  arg(size_t __id) const {
+    return __args_.get(__id);
+  }
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+  _LIBCPP_HIDE_FROM_ABI _VSTD::locale locale() {
+    if (!__loc_)
+      __loc_ = _VSTD::locale{};
+    return *__loc_;
+  }
+#endif
+  _LIBCPP_HIDE_FROM_ABI iterator out() { return __out_it_; }
+  _LIBCPP_HIDE_FROM_ABI void advance_to(iterator __it) { __out_it_ = __it; }
+
+private:
+  iterator __out_it_;
+  basic_format_args<basic_format_context> __args_;
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+
+  // The Standard doesn't specify how the locale is stored.
+  // [format.context]/6
+  // std::locale locale();
+  //   Returns: The locale passed to the formatting function if the latter
+  //   takes one, and std::locale() otherwise.
+  // This is done by storing the locale of the constructor in this optional. If
+  // locale() is called and the optional has no value the value will be created.
+  // This allows the implementation to lazily create the locale.
+  // TODO FMT Validate whether lazy creation is the best solution.
+  optional<_VSTD::locale> __loc_;
+
+  template <class __OutIt, class __CharT>
+  friend _LIBCPP_HIDE_FROM_ABI basic_format_context<__OutIt, __CharT>
+  __format_context_create(__OutIt, basic_format_args<basic_format_context<__OutIt, __CharT>>,
+                          optional<_VSTD::locale>&&);
+
+  // Note: the Standard doesn't specify the required constructors.
+  _LIBCPP_HIDE_FROM_ABI
+  explicit basic_format_context(_OutIt __out_it,
+                                basic_format_args<basic_format_context> __args,
+                                optional<_VSTD::locale>&& __loc)
+      : __out_it_(_VSTD::move(__out_it)), __args_(__args),
+        __loc_(_VSTD::move(__loc)) {}
+#else
+  template <class __OutIt, class __CharT>
+  friend _LIBCPP_HIDE_FROM_ABI basic_format_context<__OutIt, __CharT>
+      __format_context_create(__OutIt, basic_format_args<basic_format_context<__OutIt, __CharT>>);
+
+  _LIBCPP_HIDE_FROM_ABI
+  explicit basic_format_context(_OutIt __out_it,
+                                basic_format_args<basic_format_context> __args)
+      : __out_it_(_VSTD::move(__out_it)), __args_(__args) {}
+#endif
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMAT_CONTEXT_H
lib/libcxx/include/__format/format_error.h
@@ -21,9 +21,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 17
@@ -51,6 +48,4 @@ __throw_format_error(const char* __s) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___FORMAT_FORMAT_ERROR_H
lib/libcxx/include/__format/format_fwd.h
@@ -0,0 +1,56 @@
+// -*- 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___FORMAT_FORMAT_FWD_H
+#define _LIBCPP___FORMAT_FORMAT_FWD_H
+
+#include <__availability>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__utility/forward.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <class _Context>
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_arg;
+
+template <class _Context, class... _Args>
+struct _LIBCPP_TEMPLATE_VIS __format_arg_store;
+
+template <class _Ctx, class... _Args>
+_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Ctx, _Args...>
+make_format_args(const _Args&...);
+
+template <class _Tp, class _CharT = char>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMAT_FWD_H
lib/libcxx/include/__format/format_parse_context.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 17
@@ -29,8 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 // If the compiler has no concepts support, the format header will be disabled.
 // Without concepts support enable_if needs to be used and that too much effort
 // to support compilers with partial C++20 support.
-#if !defined(_LIBCPP_HAS_NO_CONCEPTS) &&                                       \
-    !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 template <class _CharT>
 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_parse_context {
@@ -100,14 +96,14 @@ private:
 };
 
 using format_parse_context = basic_format_parse_context<char>;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 using wformat_parse_context = basic_format_parse_context<wchar_t>;
+#endif
 
-#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 #endif //_LIBCPP_STD_VER > 17
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___FORMAT_FORMAT_PARSE_CONTEXT_H
lib/libcxx/include/__format/format_string.h
@@ -0,0 +1,169 @@
+// -*- 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___FORMAT_FORMAT_STRING_H
+#define _LIBCPP___FORMAT_FORMAT_STRING_H
+
+#include <__config>
+#include <__debug>
+#include <__format/format_error.h>
+#include <cstddef>
+#include <cstdint>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format {
+
+template <class _CharT>
+struct _LIBCPP_TEMPLATE_VIS __parse_number_result {
+  const _CharT* __ptr;
+  uint32_t __value;
+};
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
+__parse_number(const _CharT* __begin, const _CharT* __end);
+
+/**
+ * The maximum value of a numeric argument.
+ *
+ * This is used for:
+ * * arg-id
+ * * width as value or arg-id.
+ * * precision as value or arg-id.
+ *
+ * The value is compatible with the maximum formatting width and precision
+ * using the `%*` syntax on a 32-bit system.
+ */
+inline constexpr uint32_t __number_max = INT32_MAX;
+
+namespace __detail {
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
+__parse_zero(const _CharT* __begin, const _CharT*, auto& __parse_ctx) {
+  __parse_ctx.check_arg_id(0);
+  return {++__begin, 0}; // can never be larger than the maximum.
+}
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
+__parse_automatic(const _CharT* __begin, const _CharT*, auto& __parse_ctx) {
+  size_t __value = __parse_ctx.next_arg_id();
+  _LIBCPP_ASSERT(__value <= __number_max,
+                 "Compilers don't support this number of arguments");
+
+  return {__begin, uint32_t(__value)};
+}
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
+__parse_manual(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
+  __parse_number_result<_CharT> __r = __parse_number(__begin, __end);
+  __parse_ctx.check_arg_id(__r.__value);
+  return __r;
+}
+
+} // namespace __detail
+
+/**
+ * Parses a number.
+ *
+ * The number is used for the 31-bit values @em width and @em precision. This
+ * allows a maximum value of 2147483647.
+ */
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
+__parse_number(const _CharT* __begin, const _CharT* __end_input) {
+  static_assert(__format::__number_max == INT32_MAX,
+                "The algorithm is implemented based on this value.");
+  /*
+   * Limit the input to 9 digits, otherwise we need two checks during every
+   * iteration:
+   * - Are we at the end of the input?
+   * - Does the value exceed width of an uint32_t? (Switching to uint64_t would
+   *   have the same issue, but with a higher maximum.)
+   */
+  const _CharT* __end = __end_input - __begin > 9 ? __begin + 9 : __end_input;
+  uint32_t __value = *__begin - _CharT('0');
+  while (++__begin != __end) {
+    if (*__begin < _CharT('0') || *__begin > _CharT('9'))
+      return {__begin, __value};
+
+    __value = __value * 10 + *__begin - _CharT('0');
+  }
+
+  if (__begin != __end_input && *__begin >= _CharT('0') &&
+      *__begin <= _CharT('9')) {
+
+    /*
+     * There are more than 9 digits, do additional validations:
+     * - Does the 10th digit exceed the maximum allowed value?
+     * - Are there more than 10 digits?
+     * (More than 10 digits always overflows the maximum.)
+     */
+    uint64_t __v = uint64_t(__value) * 10 + *__begin++ - _CharT('0');
+    if (__v > __number_max ||
+        (__begin != __end_input && *__begin >= _CharT('0') &&
+         *__begin <= _CharT('9')))
+      __throw_format_error("The numeric value of the format-spec is too large");
+
+    __value = __v;
+  }
+
+  return {__begin, __value};
+}
+
+/**
+ * Multiplexer for all parse functions.
+ *
+ * The parser will return a pointer beyond the last consumed character. This
+ * should be the closing '}' of the arg-id.
+ */
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
+__parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
+  switch (*__begin) {
+  case _CharT('0'):
+    return __detail::__parse_zero(__begin, __end, __parse_ctx);
+
+  case _CharT(':'):
+    // This case is conditionally valid. It's allowed in an arg-id in the
+    // replacement-field, but not in the std-format-spec. The caller can
+    // provide a better diagnostic, so accept it here unconditionally.
+  case _CharT('}'):
+    return __detail::__parse_automatic(__begin, __end, __parse_ctx);
+  }
+  if (*__begin < _CharT('0') || *__begin > _CharT('9'))
+    __throw_format_error(
+        "The arg-id of the format-spec starts with an invalid character");
+
+  return __detail::__parse_manual(__begin, __end, __parse_ctx);
+}
+
+} // namespace __format
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FORMAT_FORMAT_STRING_H
lib/libcxx/include/__format/format_to_n_result.h
@@ -0,0 +1,41 @@
+// -*- 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___FORMAT_FORMAT_TO_N_RESULT_H
+#define _LIBCPP___FORMAT_FORMAT_TO_N_RESULT_H
+
+#include <__config>
+#include <__iterator/incrementable_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <class _OutIt>
+struct _LIBCPP_TEMPLATE_VIS format_to_n_result {
+  _OutIt out;
+  iter_difference_t<_OutIt> size;
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FORMAT_FORMAT_TO_N_RESULT_H
lib/libcxx/include/__format/formatter.h
@@ -0,0 +1,290 @@
+// -*- 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___FORMAT_FORMATTER_H
+#define _LIBCPP___FORMAT_FORMATTER_H
+
+#include <__algorithm/copy.h>
+#include <__algorithm/fill_n.h>
+#include <__availability>
+#include <__config>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/format_string.h>
+#include <__format/parser_std_format_spec.h>
+#include <concepts>
+#include <string_view>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+/// The default formatter template.
+///
+/// [format.formatter.spec]/5
+/// If F is a disabled specialization of formatter, these values are false:
+/// - is_default_constructible_v<F>,
+/// - is_copy_constructible_v<F>,
+/// - is_move_constructible_v<F>,
+/// - is_copy_assignable<F>, and
+/// - is_move_assignable<F>.
+template <class _Tp, class _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter {
+  formatter() = delete;
+  formatter(const formatter&) = delete;
+  formatter& operator=(const formatter&) = delete;
+};
+
+namespace __format_spec {
+
+_LIBCPP_HIDE_FROM_ABI inline char* __insert_sign(char* __buf, bool __negative,
+                                                 _Flags::_Sign __sign) {
+  if (__negative)
+    *__buf++ = '-';
+  else
+    switch (__sign) {
+    case _Flags::_Sign::__default:
+    case _Flags::_Sign::__minus:
+      // No sign added.
+      break;
+    case _Flags::_Sign::__plus:
+      *__buf++ = '+';
+      break;
+    case _Flags::_Sign::__space:
+      *__buf++ = ' ';
+      break;
+    }
+
+  return __buf;
+}
+
+_LIBCPP_HIDE_FROM_ABI constexpr char __hex_to_upper(char c) {
+  switch (c) {
+  case 'a':
+    return 'A';
+  case 'b':
+    return 'B';
+  case 'c':
+    return 'C';
+  case 'd':
+    return 'D';
+  case 'e':
+    return 'E';
+  case 'f':
+    return 'F';
+  }
+  return c;
+}
+
+} // namespace __format_spec
+
+namespace __formatter {
+
+/** The character types that formatters are specialized for. */
+template <class _CharT>
+concept __char_type = same_as<_CharT, char> || same_as<_CharT, wchar_t>;
+
+struct _LIBCPP_TEMPLATE_VIS __padding_size_result {
+  size_t __before;
+  size_t __after;
+};
+
+_LIBCPP_HIDE_FROM_ABI constexpr __padding_size_result
+__padding_size(size_t __size, size_t __width,
+               __format_spec::_Flags::_Alignment __align) {
+  _LIBCPP_ASSERT(__width > __size,
+                 "Don't call this function when no padding is required");
+  _LIBCPP_ASSERT(
+      __align != __format_spec::_Flags::_Alignment::__default,
+      "Caller should adjust the default to the value required by the type");
+
+  size_t __fill = __width - __size;
+  switch (__align) {
+  case __format_spec::_Flags::_Alignment::__default:
+    _LIBCPP_UNREACHABLE();
+
+  case __format_spec::_Flags::_Alignment::__left:
+    return {0, __fill};
+
+  case __format_spec::_Flags::_Alignment::__center: {
+    // The extra padding is divided per [format.string.std]/3
+    // __before = floor(__fill, 2);
+    // __after = ceil(__fill, 2);
+    size_t __before = __fill / 2;
+    size_t __after = __fill - __before;
+    return {__before, __after};
+  }
+  case __format_spec::_Flags::_Alignment::__right:
+    return {__fill, 0};
+  }
+  _LIBCPP_UNREACHABLE();
+}
+
+/**
+ * Writes the input to the output with the required padding.
+ *
+ * Since the output column width is specified the function can be used for
+ * ASCII and Unicode input.
+ *
+ * @pre [@a __first, @a __last) is a valid range.
+ * @pre @a __size <= @a __width. Using this function when this pre-condition
+ *      doesn't hold incurs an unwanted overhead.
+ *
+ * @param __out_it    The output iterator to write to.
+ * @param __first     Pointer to the first element to write.
+ * @param __last      Pointer beyond the last element to write.
+ * @param __size      The (estimated) output column width. When the elements
+ *                    to be written are ASCII the following condition holds
+ *                    @a __size == @a __last - @a __first.
+ * @param __width     The number of output columns to write.
+ * @param __fill      The character used for the alignment of the output.
+ *                    TODO FMT Will probably change to support Unicode grapheme
+ *                    cluster.
+ * @param __alignment The requested alignment.
+ *
+ * @returns           An iterator pointing beyond the last element written.
+ *
+ * @note The type of the elements in range [@a __first, @a __last) can differ
+ * from the type of @a __fill. Integer output uses @c std::to_chars for its
+ * conversion, which means the [@a __first, @a __last) always contains elements
+ * of the type @c char.
+ */
+template <class _CharT, class _Fill>
+_LIBCPP_HIDE_FROM_ABI auto
+__write(output_iterator<const _CharT&> auto __out_it, const _CharT* __first,
+        const _CharT* __last, size_t __size, size_t __width, _Fill __fill,
+        __format_spec::_Flags::_Alignment __alignment) -> decltype(__out_it) {
+
+  _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
+  _LIBCPP_ASSERT(__size < __width, "Precondition failure");
+
+  __padding_size_result __padding =
+      __padding_size(__size, __width, __alignment);
+  __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
+  __out_it = _VSTD::copy(__first, __last, _VSTD::move(__out_it));
+  return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
+}
+
+/**
+ * @overload
+ *
+ * Writes additional zero's for the precision before the exponent.
+ * This is used when the precision requested in the format string is larger
+ * than the maximum precision of the floating-point type. These precision
+ * digits are always 0.
+ *
+ * @param __exponent           The location of the exponent character.
+ * @param __num_trailing_zeros The number of 0's to write before the exponent
+ *                             character.
+ */
+template <class _CharT, class _Fill>
+_LIBCPP_HIDE_FROM_ABI auto __write(output_iterator<const _CharT&> auto __out_it, const _CharT* __first,
+                                   const _CharT* __last, size_t __size, size_t __width, _Fill __fill,
+                                   __format_spec::_Flags::_Alignment __alignment, const _CharT* __exponent,
+                                   size_t __num_trailing_zeros) -> decltype(__out_it) {
+  _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
+  _LIBCPP_ASSERT(__num_trailing_zeros > 0, "The overload not writing trailing zeros should have been used");
+
+  __padding_size_result __padding = __padding_size(__size + __num_trailing_zeros, __width, __alignment);
+  __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
+  __out_it = _VSTD::copy(__first, __exponent, _VSTD::move(__out_it));
+  __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __num_trailing_zeros, _CharT('0'));
+  __out_it = _VSTD::copy(__exponent, __last, _VSTD::move(__out_it));
+  return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
+}
+
+/**
+ * @overload
+ *
+ * Uses a transformation operation before writing an element.
+ *
+ * TODO FMT Fill will probably change to support Unicode grapheme cluster.
+ */
+template <class _CharT, class _UnaryOperation, class _Fill>
+_LIBCPP_HIDE_FROM_ABI auto
+__write(output_iterator<const _CharT&> auto __out_it, const _CharT* __first,
+        const _CharT* __last, size_t __size, _UnaryOperation __op,
+        size_t __width, _Fill __fill,
+        __format_spec::_Flags::_Alignment __alignment) -> decltype(__out_it) {
+
+  _LIBCPP_ASSERT(__first <= __last, "Not a valid range");
+  _LIBCPP_ASSERT(__size < __width, "Precondition failure");
+
+  __padding_size_result __padding =
+      __padding_size(__size, __width, __alignment);
+  __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
+  __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it), __op);
+  return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
+}
+
+/**
+ * Writes Unicode input to the output with the required padding.
+ *
+ * This function does almost the same as the @ref __write function, but handles
+ * the width estimation of the Unicode input.
+ *
+ * @param __str       The range [@a __first, @a __last).
+ * @param __precision The width to truncate the input string to, use @c -1 for
+ *                     no limit.
+ */
+template <class _CharT, class _Fill>
+_LIBCPP_HIDE_FROM_ABI auto
+__write_unicode(output_iterator<const _CharT&> auto __out_it,
+                basic_string_view<_CharT> __str, ptrdiff_t __width,
+                ptrdiff_t __precision, _Fill __fill,
+                __format_spec::_Flags::_Alignment __alignment)
+    -> decltype(__out_it) {
+
+  // This value changes when there Unicode column width limits the output
+  // size.
+  auto __last = __str.end();
+  if (__width != 0 || __precision != -1) {
+    __format_spec::__string_alignment<_CharT> __format_traits =
+        __format_spec::__get_string_alignment(__str.begin(), __str.end(),
+                                              __width, __precision);
+
+    if (__format_traits.__align)
+      return __write(_VSTD::move(__out_it), __str.begin(),
+                     __format_traits.__last, __format_traits.__size, __width,
+                     __fill, __alignment);
+
+    // No alignment required update the output based on the precision.
+    // This might be the same as __str.end().
+    __last = __format_traits.__last;
+  }
+
+  // Copy the input to the output. The output size might be limited by the
+  // precision.
+  return _VSTD::copy(__str.begin(), __last, _VSTD::move(__out_it));
+}
+
+} // namespace __formatter
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMATTER_H
lib/libcxx/include/__format/formatter_bool.h
@@ -0,0 +1,147 @@
+// -*- 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___FORMAT_FORMATTER_BOOL_H
+#define _LIBCPP___FORMAT_FORMATTER_BOOL_H
+
+#include <__availability>
+#include <__config>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/formatter.h>
+#include <__format/formatter_integral.h>
+#include <__format/parser_std_format_spec.h>
+#include <string_view>
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#include <locale>
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format_spec {
+
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_bool : public __parser_integral<_CharT> {
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+    auto __it = __parser_integral<_CharT>::__parse(__parse_ctx);
+
+    switch (this->__type) {
+    case _Flags::_Type::__default:
+      this->__type = _Flags::_Type::__string;
+      [[fallthrough]];
+    case _Flags::_Type::__string:
+      this->__handle_bool();
+      break;
+
+    case _Flags::_Type::__char:
+      this->__handle_char();
+      break;
+
+    case _Flags::_Type::__binary_lower_case:
+    case _Flags::_Type::__binary_upper_case:
+    case _Flags::_Type::__octal:
+    case _Flags::_Type::__decimal:
+    case _Flags::_Type::__hexadecimal_lower_case:
+    case _Flags::_Type::__hexadecimal_upper_case:
+      this->__handle_integer();
+      break;
+
+    default:
+      __throw_format_error(
+          "The format-spec type has a type not supported for a bool argument");
+    }
+
+    return __it;
+  }
+};
+
+template <class _CharT>
+struct _LIBCPP_TEMPLATE_VIS __bool_strings;
+
+template <>
+struct _LIBCPP_TEMPLATE_VIS __bool_strings<char> {
+  static constexpr string_view __true{"true"};
+  static constexpr string_view __false{"false"};
+};
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+struct _LIBCPP_TEMPLATE_VIS __bool_strings<wchar_t> {
+  static constexpr wstring_view __true{L"true"};
+  static constexpr wstring_view __false{L"false"};
+};
+#endif
+
+template <class _CharT>
+using __formatter_bool = __formatter_integral<__parser_bool<_CharT>>;
+
+} //namespace __format_spec
+
+// [format.formatter.spec]/2.3
+// For each charT, for each cv-unqualified arithmetic type ArithmeticT other
+// than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
+
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<bool, _CharT>
+    : public __format_spec::__formatter_bool<_CharT> {
+  using _Base = __format_spec::__formatter_bool<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(bool __value, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    if (this->__type != __format_spec::_Flags::_Type::__string)
+      return _Base::format(static_cast<unsigned char>(__value), __ctx);
+
+    if (this->__width_needs_substitution())
+      this->__substitute_width_arg_id(__ctx.arg(this->__width));
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+    if (this->__locale_specific_form) {
+      const auto& __np = use_facet<numpunct<_CharT>>(__ctx.locale());
+      basic_string<_CharT> __str = __value ? __np.truename() : __np.falsename();
+      return __formatter::__write_unicode(
+          __ctx.out(), basic_string_view<_CharT>{__str}, this->__width, -1,
+          this->__fill, this->__alignment);
+    }
+#endif
+    basic_string_view<_CharT> __str =
+        __value ? __format_spec::__bool_strings<_CharT>::__true
+                : __format_spec::__bool_strings<_CharT>::__false;
+
+    // The output only uses ASCII so every character is one column.
+    unsigned __size = __str.size();
+    if (__size >= this->__width)
+      return _VSTD::copy(__str.begin(), __str.end(), __ctx.out());
+
+    return __formatter::__write(__ctx.out(), __str.begin(), __str.end(), __size,
+                                this->__width, this->__fill, this->__alignment);
+  }
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FORMAT_FORMATTER_BOOL_H
lib/libcxx/include/__format/formatter_char.h
@@ -0,0 +1,104 @@
+// -*- 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___FORMAT_FORMATTER_CHAR_H
+#define _LIBCPP___FORMAT_FORMATTER_CHAR_H
+
+#include <__availability>
+#include <__config>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/formatter.h>
+#include <__format/formatter_integral.h>
+#include <__format/parser_std_format_spec.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format_spec {
+
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_char : public __parser_integral<_CharT> {
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+    auto __it = __parser_integral<_CharT>::__parse(__parse_ctx);
+
+    switch (this->__type) {
+    case _Flags::_Type::__default:
+      this->__type = _Flags::_Type::__char;
+      [[fallthrough]];
+    case _Flags::_Type::__char:
+      this->__handle_char();
+      break;
+
+    case _Flags::_Type::__binary_lower_case:
+    case _Flags::_Type::__binary_upper_case:
+    case _Flags::_Type::__octal:
+    case _Flags::_Type::__decimal:
+    case _Flags::_Type::__hexadecimal_lower_case:
+    case _Flags::_Type::__hexadecimal_upper_case:
+      this->__handle_integer();
+      break;
+
+    default:
+      __throw_format_error(
+          "The format-spec type has a type not supported for a char argument");
+    }
+
+    return __it;
+  }
+};
+
+template <class _CharT>
+using __formatter_char = __formatter_integral<__parser_char<_CharT>>;
+
+} // namespace __format_spec
+
+// [format.formatter.spec]/2.1 The specializations
+
+template <>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, char>
+    : public __format_spec::__formatter_char<char> {};
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<char, wchar_t>
+    : public __format_spec::__formatter_char<wchar_t> {
+  using _Base = __format_spec::__formatter_char<wchar_t>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(char __value, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    return _Base::format(static_cast<wchar_t>(__value), __ctx);
+  }
+};
+
+template <>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<wchar_t, wchar_t>
+    : public __format_spec::__formatter_char<wchar_t> {};
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FORMAT_FORMATTER_CHAR_H
lib/libcxx/include/__format/formatter_floating_point.h
@@ -0,0 +1,717 @@
+// -*- 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___FORMAT_FORMATTER_FLOATING_POINT_H
+#define _LIBCPP___FORMAT_FORMATTER_FLOATING_POINT_H
+
+#include <__algorithm/copy.h>
+#include <__algorithm/copy_n.h>
+#include <__algorithm/fill_n.h>
+#include <__algorithm/find.h>
+#include <__algorithm/min.h>
+#include <__algorithm/rotate.h>
+#include <__algorithm/transform.h>
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__debug>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/format_string.h>
+#include <__format/formatter.h>
+#include <__format/formatter_integral.h>
+#include <__format/parser_std_format_spec.h>
+#include <__utility/move.h>
+#include <charconv>
+#include <cmath>
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#  include <locale>
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#  if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format_spec {
+
+template <floating_point _Tp>
+_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value) {
+  to_chars_result __r = _VSTD::to_chars(__first, __last, __value);
+  _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
+  return __r.ptr;
+}
+
+template <floating_point _Tp>
+_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value, chars_format __fmt) {
+  to_chars_result __r = _VSTD::to_chars(__first, __last, __value, __fmt);
+  _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
+  return __r.ptr;
+}
+
+template <floating_point _Tp>
+_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last, _Tp __value, chars_format __fmt, int __precision) {
+  to_chars_result __r = _VSTD::to_chars(__first, __last, __value, __fmt, __precision);
+  _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
+  return __r.ptr;
+}
+
+// https://en.cppreference.com/w/cpp/language/types#cite_note-1
+// float             min subnormal: +/-0x1p-149   max: +/- 3.402,823,4 10^38
+// double            min subnormal: +/-0x1p-1074  max  +/- 1.797,693,134,862,315,7 10^308
+// long double (x86) min subnormal: +/-0x1p-16446 max: +/- 1.189,731,495,357,231,765,021 10^4932
+//
+// The maximum number of digits required for the integral part is based on the
+// maximum's value power of 10. Every power of 10 requires one additional
+// decimal digit.
+// The maximum number of digits required for the fractional part is based on
+// the minimal subnormal hexadecimal output's power of 10. Every division of a
+// fraction's binary 1 by 2, requires one additional decimal digit.
+//
+// The maximum size of a formatted value depends on the selected output format.
+// Ignoring the fact the format string can request a precision larger than the
+// values maximum required, these values are:
+//
+// sign                    1 code unit
+// __max_integral
+// radix point             1 code unit
+// __max_fractional
+// exponent character      1 code unit
+// sign                    1 code unit
+// __max_fractional_value
+// -----------------------------------
+// total                   4 code units extra required.
+//
+// TODO FMT Optimize the storage to avoid storing digits that are known to be zero.
+// https://www.exploringbinary.com/maximum-number-of-decimal-digits-in-binary-floating-point-numbers/
+
+// TODO FMT Add long double specialization when to_chars has proper long double support.
+template <class _Tp>
+struct __traits;
+
+template <floating_point _Fp>
+static constexpr size_t __float_buffer_size(int __precision) {
+  using _Traits = __traits<_Fp>;
+  return 4 + _Traits::__max_integral + __precision + _Traits::__max_fractional_value;
+}
+
+template <>
+struct __traits<float> {
+  static constexpr int __max_integral = 38;
+  static constexpr int __max_fractional = 149;
+  static constexpr int __max_fractional_value = 3;
+  static constexpr size_t __stack_buffer_size = 256;
+
+  static constexpr int __hex_precision_digits = 3;
+};
+
+template <>
+struct __traits<double> {
+  static constexpr int __max_integral = 308;
+  static constexpr int __max_fractional = 1074;
+  static constexpr int __max_fractional_value = 4;
+  static constexpr size_t __stack_buffer_size = 1024;
+
+  static constexpr int __hex_precision_digits = 4;
+};
+
+/// Helper class to store the conversion buffer.
+///
+/// Depending on the maxium size required for a value, the buffer is allocated
+/// on the stack or the heap.
+template <floating_point _Fp>
+class _LIBCPP_TEMPLATE_VIS __float_buffer {
+  using _Traits = __traits<_Fp>;
+
+public:
+  // TODO FMT Improve this constructor to do a better estimate.
+  // When using a scientific formatting with a precision of 6 a stack buffer
+  // will always suffice. At the moment that isn't important since floats and
+  // doubles use a stack buffer, unless the precision used in the format string
+  // is large.
+  // When supporting long doubles the __max_integral part becomes 4932 which
+  // may be too much for some platforms. For these cases a better estimate is
+  // required.
+  explicit _LIBCPP_HIDE_FROM_ABI __float_buffer(int __precision)
+      : __precision_(__precision != -1 ? __precision : _Traits::__max_fractional) {
+
+    // When the precision is larger than _Traits::__max_fractional the digits in
+    // the range (_Traits::__max_fractional, precision] will contain the value
+    // zero. There's no need to request to_chars to write these zeros:
+    // - When the value is large a temporary heap buffer needs to be allocated.
+    // - When to_chars writes the values they need to be "copied" to the output:
+    //   - char: std::fill on the output iterator is faster than std::copy.
+    //   - wchar_t: same argument as char, but additional std::copy won't work.
+    //     The input is always a char buffer, so every char in the buffer needs
+    //     to be converted from a char to a wchar_t.
+    if (__precision_ > _Traits::__max_fractional) {
+      __num_trailing_zeros_ = __precision_ - _Traits::__max_fractional;
+      __precision_ = _Traits::__max_fractional;
+    }
+
+    __size_ = __format_spec::__float_buffer_size<_Fp>(__precision_);
+    if (__size_ > _Traits::__stack_buffer_size)
+      // The allocated buffer's contents don't need initialization.
+      __begin_ = allocator<char>{}.allocate(__size_);
+    else
+      __begin_ = __buffer_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI ~__float_buffer() {
+    if (__size_ > _Traits::__stack_buffer_size)
+      allocator<char>{}.deallocate(__begin_, __size_);
+  }
+  _LIBCPP_HIDE_FROM_ABI __float_buffer(const __float_buffer&) = delete;
+  _LIBCPP_HIDE_FROM_ABI __float_buffer& operator=(const __float_buffer&) = delete;
+
+  _LIBCPP_HIDE_FROM_ABI char* begin() const { return __begin_; }
+  _LIBCPP_HIDE_FROM_ABI char* end() const { return __begin_ + __size_; }
+
+  _LIBCPP_HIDE_FROM_ABI int __precision() const { return __precision_; }
+  _LIBCPP_HIDE_FROM_ABI int __num_trailing_zeros() const { return __num_trailing_zeros_; }
+  _LIBCPP_HIDE_FROM_ABI void __remove_trailing_zeros() { __num_trailing_zeros_ = 0; }
+
+private:
+  int __precision_;
+  int __num_trailing_zeros_{0};
+  size_t __size_;
+  char* __begin_;
+  char __buffer_[_Traits::__stack_buffer_size];
+};
+
+struct __float_result {
+  /// Points at the beginning of the integral part in the buffer.
+  ///
+  /// When there's no sign character this points at the start of the buffer.
+  char* __integral;
+
+  /// Points at the radix point, when not present it's the same as \ref __last.
+  char* __radix_point;
+
+  /// Points at the exponent character, when not present it's the same as \ref __last.
+  char* __exponent;
+
+  /// Points beyond the last written element in the buffer.
+  char* __last;
+};
+
+/// Finds the position of the exponent character 'e' at the end of the buffer.
+///
+/// Assuming there is an exponent the input will terminate with
+/// eSdd and eSdddd (S = sign, d = digit)
+///
+/// \returns a pointer to the exponent or __last when not found.
+constexpr inline _LIBCPP_HIDE_FROM_ABI char* __find_exponent(char* __first, char* __last) {
+  ptrdiff_t __size = __last - __first;
+  if (__size > 4) {
+    __first = __last - _VSTD::min(__size, ptrdiff_t(6));
+    for (; __first != __last - 3; ++__first) {
+      if (*__first == 'e')
+        return __first;
+    }
+  }
+  return __last;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_default(const __float_buffer<_Fp>& __buffer, _Tp __value,
+                                                             char* __integral) {
+  __float_result __result;
+  __result.__integral = __integral;
+  __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value);
+
+  __result.__exponent = __format_spec::__find_exponent(__result.__integral, __result.__last);
+
+  // Constrains:
+  // - There's at least one decimal digit before the radix point.
+  // - The radix point, when present, is placed before the exponent.
+  __result.__radix_point = _VSTD::find(__result.__integral + 1, __result.__exponent, '.');
+
+  // When the radix point isn't found its position is the exponent instead of
+  // __result.__last.
+  if (__result.__radix_point == __result.__exponent)
+    __result.__radix_point = __result.__last;
+
+  // clang-format off
+  _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
+                 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
+                 (__result.__exponent == __result.__last || *__result.__exponent == 'e'),
+                 "Post-condition failure.");
+  // clang-format on
+
+  return __result;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_hexadecimal_lower_case(const __float_buffer<_Fp>& __buffer,
+                                                                            _Tp __value, int __precision,
+                                                                            char* __integral) {
+  __float_result __result;
+  __result.__integral = __integral;
+  if (__precision == -1)
+    __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex);
+  else
+    __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::hex, __precision);
+
+  // H = one or more hex-digits
+  // S = sign
+  // D = one or more decimal-digits
+  // When the fractional part is zero and no precision the output is 0p+0
+  // else the output is                                              0.HpSD
+  // So testing the second position can differentiate between these two cases.
+  char* __first = __integral + 1;
+  if (*__first == '.') {
+    __result.__radix_point = __first;
+    // One digit is the minimum
+    // 0.hpSd
+    //       ^-- last
+    //     ^---- integral = end of search
+    // ^-------- start of search
+    // 0123456
+    //
+    // Four digits is the maximum
+    // 0.hpSdddd
+    //          ^-- last
+    //        ^---- integral = end of search
+    //    ^-------- start of search
+    // 0123456789
+    static_assert(__traits<_Fp>::__hex_precision_digits <= 4, "Guard against possible underflow.");
+
+    char* __last = __result.__last - 2;
+    __first = __last - __traits<_Fp>::__hex_precision_digits;
+    __result.__exponent = _VSTD::find(__first, __last, 'p');
+  } else {
+    __result.__radix_point = __result.__last;
+    __result.__exponent = __first;
+  }
+
+  // clang-format off
+  _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
+                 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
+                 (__result.__exponent != __result.__last && *__result.__exponent == 'p'),
+                 "Post-condition failure.");
+  // clang-format on
+
+  return __result;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_hexadecimal_upper_case(const __float_buffer<_Fp>& __buffer,
+                                                                            _Tp __value, int __precision,
+                                                                            char* __integral) {
+  __float_result __result =
+      __format_spec::__format_buffer_hexadecimal_lower_case(__buffer, __value, __precision, __integral);
+  _VSTD::transform(__result.__integral, __result.__exponent, __result.__integral, __hex_to_upper);
+  *__result.__exponent = 'P';
+  return __result;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_scientific_lower_case(const __float_buffer<_Fp>& __buffer,
+                                                                           _Tp __value, int __precision,
+                                                                           char* __integral) {
+  __float_result __result;
+  __result.__integral = __integral;
+  __result.__last =
+      __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::scientific, __precision);
+
+  char* __first = __integral + 1;
+  _LIBCPP_ASSERT(__first != __result.__last, "No exponent present");
+  if (*__first == '.') {
+    __result.__radix_point = __first;
+    __result.__exponent = __format_spec::__find_exponent(__first + 1, __result.__last);
+  } else {
+    __result.__radix_point = __result.__last;
+    __result.__exponent = __first;
+  }
+
+  // clang-format off
+  _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
+                 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
+                 (__result.__exponent != __result.__last && *__result.__exponent == 'e'),
+                 "Post-condition failure.");
+  // clang-format on
+  return __result;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_scientific_upper_case(const __float_buffer<_Fp>& __buffer,
+                                                                           _Tp __value, int __precision,
+                                                                           char* __integral) {
+  __float_result __result =
+      __format_spec::__format_buffer_scientific_lower_case(__buffer, __value, __precision, __integral);
+  *__result.__exponent = 'E';
+  return __result;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_fixed(const __float_buffer<_Fp>& __buffer, _Tp __value,
+                                                           int __precision, char* __integral) {
+  __float_result __result;
+  __result.__integral = __integral;
+  __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::fixed, __precision);
+
+  // When there's no precision there's no radix point.
+  // Else the radix point is placed at __precision + 1 from the end.
+  // By converting __precision to a bool the subtraction can be done
+  // unconditionally.
+  __result.__radix_point = __result.__last - (__precision + bool(__precision));
+  __result.__exponent = __result.__last;
+
+  // clang-format off
+  _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
+                 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
+                 (__result.__exponent == __result.__last),
+                 "Post-condition failure.");
+  // clang-format on
+  return __result;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_lower_case(__float_buffer<_Fp>& __buffer, _Tp __value,
+                                                                        int __precision, char* __integral) {
+
+  __buffer.__remove_trailing_zeros();
+
+  __float_result __result;
+  __result.__integral = __integral;
+  __result.__last = __format_spec::__to_buffer(__integral, __buffer.end(), __value, chars_format::general, __precision);
+
+  char* __first = __integral + 1;
+  if (__first == __result.__last) {
+    __result.__radix_point = __result.__last;
+    __result.__exponent = __result.__last;
+  } else {
+    __result.__exponent = __format_spec::__find_exponent(__first, __result.__last);
+    if (__result.__exponent != __result.__last)
+      // In scientific mode if there's a radix point it will always be after
+      // the first digit. (This is the position __first points at).
+      __result.__radix_point = *__first == '.' ? __first : __result.__last;
+    else {
+      // In fixed mode the algorithm truncates trailing spaces and possibly the
+      // radix point. There's no good guess for the position of the radix point
+      // therefore scan the output after the first digit.
+      __result.__radix_point = _VSTD::find(__first, __result.__last, '.');
+    }
+  }
+
+  // clang-format off
+  _LIBCPP_ASSERT((__result.__integral != __result.__last) &&
+                 (__result.__radix_point == __result.__last || *__result.__radix_point == '.') &&
+                 (__result.__exponent == __result.__last || *__result.__exponent == 'e'),
+                 "Post-condition failure.");
+  // clang-format on
+
+  return __result;
+}
+
+template <class _Fp, class _Tp>
+_LIBCPP_HIDE_FROM_ABI __float_result __format_buffer_general_upper_case(__float_buffer<_Fp>& __buffer, _Tp __value,
+                                                                        int __precision, char* __integral) {
+  __float_result __result =
+      __format_spec::__format_buffer_general_lower_case(__buffer, __value, __precision, __integral);
+  if (__result.__exponent != __result.__last)
+    *__result.__exponent = 'E';
+  return __result;
+}
+
+#    ifndef _LIBCPP_HAS_NO_LOCALIZATION
+template <class _OutIt, class _Fp, class _CharT>
+_LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form(_OutIt __out_it, const __float_buffer<_Fp>& __buffer,
+                                                           const __float_result& __result, _VSTD::locale __loc,
+                                                           size_t __width, _Flags::_Alignment __alignment,
+                                                           _CharT __fill) {
+  const auto& __np = use_facet<numpunct<_CharT>>(__loc);
+  string __grouping = __np.grouping();
+  char* __first = __result.__integral;
+  // When no radix point or exponent are present __last will be __result.__last.
+  char* __last = _VSTD::min(__result.__radix_point, __result.__exponent);
+
+  ptrdiff_t __digits = __last - __first;
+  if (!__grouping.empty()) {
+    if (__digits <= __grouping[0])
+      __grouping.clear();
+    else
+      __grouping = __determine_grouping(__digits, __grouping);
+  }
+
+  size_t __size = __result.__last - __buffer.begin() + // Formatted string
+                  __buffer.__num_trailing_zeros() +    // Not yet rendered zeros
+                  __grouping.size() -                  // Grouping contains one
+                  !__grouping.empty();                 // additional character
+
+  __formatter::__padding_size_result __padding = {0, 0};
+  bool __zero_padding = __alignment == _Flags::_Alignment::__default;
+  if (__size < __width) {
+    if (__zero_padding) {
+      __alignment = _Flags::_Alignment::__right;
+      __fill = _CharT('0');
+    }
+
+    __padding = __formatter::__padding_size(__size, __width, __alignment);
+  }
+
+  // sign and (zero padding or alignment)
+  if (__zero_padding && __first != __buffer.begin())
+    *__out_it++ = *__buffer.begin();
+  __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before, __fill);
+  if (!__zero_padding && __first != __buffer.begin())
+    *__out_it++ = *__buffer.begin();
+
+  // integral part
+  if (__grouping.empty()) {
+    __out_it = _VSTD::copy_n(__first, __digits, _VSTD::move(__out_it));
+  } else {
+    auto __r = __grouping.rbegin();
+    auto __e = __grouping.rend() - 1;
+    _CharT __sep = __np.thousands_sep();
+    // The output is divided in small groups of numbers to write:
+    // - A group before the first separator.
+    // - A separator and a group, repeated for the number of separators.
+    // - A group after the last separator.
+    // This loop achieves that process by testing the termination condition
+    // midway in the loop.
+    while (true) {
+      __out_it = _VSTD::copy_n(__first, *__r, _VSTD::move(__out_it));
+      __first += *__r;
+
+      if (__r == __e)
+        break;
+
+      ++__r;
+      *__out_it++ = __sep;
+    }
+  }
+
+  // fractional part
+  if (__result.__radix_point != __result.__last) {
+    *__out_it++ = __np.decimal_point();
+    __out_it = _VSTD::copy(__result.__radix_point + 1, __result.__exponent, _VSTD::move(__out_it));
+    __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __buffer.__num_trailing_zeros(), _CharT('0'));
+  }
+
+  // exponent
+  if (__result.__exponent != __result.__last)
+    __out_it = _VSTD::copy(__result.__exponent, __result.__last, _VSTD::move(__out_it));
+
+  // alignment
+  return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after, __fill);
+}
+
+#    endif // _LIBCPP_HAS_NO_LOCALIZATION
+
+template <__formatter::__char_type _CharT>
+class _LIBCPP_TEMPLATE_VIS __formatter_floating_point : public __parser_floating_point<_CharT> {
+public:
+  template <floating_point _Tp>
+  _LIBCPP_HIDE_FROM_ABI auto format(_Tp __value, auto& __ctx) -> decltype(__ctx.out()) {
+    if (this->__width_needs_substitution())
+      this->__substitute_width_arg_id(__ctx.arg(this->__width));
+
+    bool __negative = _VSTD::signbit(__value);
+
+    if (!_VSTD::isfinite(__value)) [[unlikely]]
+      return __format_non_finite(__ctx.out(), __negative, _VSTD::isnan(__value));
+
+    bool __has_precision = this->__has_precision_field();
+    if (this->__precision_needs_substitution())
+      this->__substitute_precision_arg_id(__ctx.arg(this->__precision));
+
+    // Depending on the std-format-spec string the sign and the value
+    // might not be outputted together:
+    // - zero-padding may insert additional '0' characters.
+    // Therefore the value is processed as a non negative value.
+    // The function @ref __insert_sign will insert a '-' when the value was
+    // negative.
+
+    if (__negative)
+      __value = _VSTD::copysign(__value, +1.0);
+
+    // TODO FMT _Fp should just be _Tp when to_chars has proper long double support.
+    using _Fp = conditional_t<same_as<_Tp, long double>, double, _Tp>;
+    // Force the type of the precision to avoid -1 to become an unsigned value.
+    __float_buffer<_Fp> __buffer(__has_precision ? int(this->__precision) : -1);
+    __float_result __result = __format_buffer(__buffer, __value, __negative, __has_precision);
+
+    if (this->__alternate_form && __result.__radix_point == __result.__last) {
+      *__result.__last++ = '.';
+
+      // When there is an exponent the point needs to be moved before the
+      // exponent. When there's no exponent the rotate does nothing. Since
+      // rotate tests whether the operation is a nop, call it unconditionally.
+      _VSTD::rotate(__result.__exponent, __result.__last - 1, __result.__last);
+      __result.__radix_point = __result.__exponent;
+
+      // The radix point is always placed before the exponent.
+      // - No exponent needs to point to the new last.
+      // - An exponent needs to move one position to the right.
+      // So it's safe to increment the value unconditionally.
+      ++__result.__exponent;
+    }
+
+#    ifndef _LIBCPP_HAS_NO_LOCALIZATION
+    if (this->__locale_specific_form)
+      return __format_spec::__format_locale_specific_form(__ctx.out(), __buffer, __result, __ctx.locale(),
+                                                          this->__width, this->__alignment, this->__fill);
+#    endif
+
+    ptrdiff_t __size = __result.__last - __buffer.begin();
+    int __num_trailing_zeros = __buffer.__num_trailing_zeros();
+    if (__size + __num_trailing_zeros >= this->__width) {
+      if (__num_trailing_zeros && __result.__exponent != __result.__last)
+        // Insert trailing zeros before exponent character.
+        return _VSTD::copy(__result.__exponent, __result.__last,
+                           _VSTD::fill_n(_VSTD::copy(__buffer.begin(), __result.__exponent, __ctx.out()),
+                                         __num_trailing_zeros, _CharT('0')));
+
+      return _VSTD::fill_n(_VSTD::copy(__buffer.begin(), __result.__last, __ctx.out()), __num_trailing_zeros,
+                           _CharT('0'));
+    }
+
+    auto __out_it = __ctx.out();
+    char* __first = __buffer.begin();
+    if (this->__alignment == _Flags::_Alignment::__default) {
+      // When there is a sign output it before the padding. Note the __size
+      // doesn't need any adjustment, regardless whether the sign is written
+      // here or in __formatter::__write.
+      if (__first != __result.__integral)
+        *__out_it++ = *__first++;
+      // After the sign is written, zero padding is the same a right alignment
+      // with '0'.
+      this->__alignment = _Flags::_Alignment::__right;
+      this->__fill = _CharT('0');
+    }
+
+    if (__num_trailing_zeros)
+      return __formatter::__write(_VSTD::move(__out_it), __first, __result.__last, __size, this->__width, this->__fill,
+                                  this->__alignment, __result.__exponent, __num_trailing_zeros);
+
+    return __formatter::__write(_VSTD::move(__out_it), __first, __result.__last, __size, this->__width, this->__fill,
+                                this->__alignment);
+  }
+
+private:
+  template <class _OutIt>
+  _LIBCPP_HIDE_FROM_ABI _OutIt __format_non_finite(_OutIt __out_it, bool __negative, bool __isnan) {
+    char __buffer[4];
+    char* __last = __insert_sign(__buffer, __negative, this->__sign);
+
+    // to_char can return inf, infinity, nan, and nan(n-char-sequence).
+    // The format library requires inf and nan.
+    // All in one expression to avoid dangling references.
+    __last = _VSTD::copy_n(&("infnanINFNAN"[6 * (this->__type == _Flags::_Type::__float_hexadecimal_upper_case ||
+                                                 this->__type == _Flags::_Type::__scientific_upper_case ||
+                                                 this->__type == _Flags::_Type::__fixed_upper_case ||
+                                                 this->__type == _Flags::_Type::__general_upper_case) +
+                                            3 * __isnan]),
+                           3, __last);
+
+    // [format.string.std]/13
+    // A zero (0) character preceding the width field pads the field with
+    // leading zeros (following any indication of sign or base) to the field
+    // width, except when applied to an infinity or NaN.
+    if (this->__alignment == _Flags::_Alignment::__default)
+      this->__alignment = _Flags::_Alignment::__right;
+
+    ptrdiff_t __size = __last - __buffer;
+    if (__size >= this->__width)
+      return _VSTD::copy_n(__buffer, __size, _VSTD::move(__out_it));
+
+    return __formatter::__write(_VSTD::move(__out_it), __buffer, __last, __size, this->__width, this->__fill,
+                                this->__alignment);
+  }
+
+  /// Fills the buffer with the data based on the requested formatting.
+  ///
+  /// This function, when needed, turns the characters to upper case and
+  /// determines the "interesting" locations which are returned to the caller.
+  ///
+  /// This means the caller never has to convert the contents of the buffer to
+  /// upper case or search for radix points and the location of the exponent.
+  /// This gives a bit of overhead. The original code didn't do that, but due
+  /// to the number of possible additional work needed to turn this number to
+  /// the proper output the code was littered with tests for upper cases and
+  /// searches for radix points and exponents.
+  /// - When a precision larger than the type's precision is selected
+  ///   additional zero characters need to be written before the exponent.
+  /// - alternate form needs to add a radix point when not present.
+  /// - localization needs to do grouping in the integral part.
+  template <class _Fp, class _Tp>
+  // TODO FMT _Fp should just be _Tp when to_chars has proper long double support.
+  _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer(__float_buffer<_Fp>& __buffer, _Tp __value, bool __negative,
+                                                       bool __has_precision) {
+    char* __first = __insert_sign(__buffer.begin(), __negative, this->__sign);
+    switch (this->__type) {
+    case _Flags::_Type::__default:
+      return __format_spec::__format_buffer_default(__buffer, __value, __first);
+
+    case _Flags::_Type::__float_hexadecimal_lower_case:
+      return __format_spec::__format_buffer_hexadecimal_lower_case(
+          __buffer, __value, __has_precision ? __buffer.__precision() : -1, __first);
+
+    case _Flags::_Type::__float_hexadecimal_upper_case:
+      return __format_spec::__format_buffer_hexadecimal_upper_case(
+          __buffer, __value, __has_precision ? __buffer.__precision() : -1, __first);
+
+    case _Flags::_Type::__scientific_lower_case:
+      return __format_spec::__format_buffer_scientific_lower_case(__buffer, __value, __buffer.__precision(), __first);
+
+    case _Flags::_Type::__scientific_upper_case:
+      return __format_spec::__format_buffer_scientific_upper_case(__buffer, __value, __buffer.__precision(), __first);
+
+    case _Flags::_Type::__fixed_lower_case:
+    case _Flags::_Type::__fixed_upper_case:
+      return __format_spec::__format_buffer_fixed(__buffer, __value, __buffer.__precision(), __first);
+
+    case _Flags::_Type::__general_lower_case:
+      return __format_spec::__format_buffer_general_lower_case(__buffer, __value, __buffer.__precision(), __first);
+
+    case _Flags::_Type::__general_upper_case:
+      return __format_spec::__format_buffer_general_upper_case(__buffer, __value, __buffer.__precision(), __first);
+
+    default:
+      _LIBCPP_ASSERT(false, "The parser should have validated the type");
+      _LIBCPP_UNREACHABLE();
+    }
+  }
+};
+
+} //namespace __format_spec
+
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<float, _CharT>
+    : public __format_spec::__formatter_floating_point<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<double, _CharT>
+    : public __format_spec::__formatter_floating_point<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<long double, _CharT>
+    : public __format_spec::__formatter_floating_point<_CharT> {};
+
+#  endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMATTER_FLOATING_POINT_H
lib/libcxx/include/__format/formatter_integer.h
@@ -0,0 +1,170 @@
+// -*- 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___FORMAT_FORMATTER_INTEGER_H
+#define _LIBCPP___FORMAT_FORMATTER_INTEGER_H
+
+#include <__availability>
+#include <__config>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/formatter.h>
+#include <__format/formatter_integral.h>
+#include <__format/parser_std_format_spec.h>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format_spec {
+
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_integer : public __parser_integral<_CharT> {
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+    auto __it = __parser_integral<_CharT>::__parse(__parse_ctx);
+
+    switch (this->__type) {
+    case _Flags::_Type::__default:
+      this->__type = _Flags::_Type::__decimal;
+      [[fallthrough]];
+
+    case _Flags::_Type::__binary_lower_case:
+    case _Flags::_Type::__binary_upper_case:
+    case _Flags::_Type::__octal:
+    case _Flags::_Type::__decimal:
+    case _Flags::_Type::__hexadecimal_lower_case:
+    case _Flags::_Type::__hexadecimal_upper_case:
+      this->__handle_integer();
+      break;
+
+    case _Flags::_Type::__char:
+      this->__handle_char();
+      break;
+
+    default:
+      __throw_format_error("The format-spec type has a type not supported for "
+                           "an integer argument");
+    }
+    return __it;
+  }
+};
+
+template <class _CharT>
+using __formatter_integer = __formatter_integral<__parser_integer<_CharT>>;
+
+} // namespace __format_spec
+
+// [format.formatter.spec]/2.3
+// For each charT, for each cv-unqualified arithmetic type ArithmeticT other
+// than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
+
+// Signed integral types.
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<signed char, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<short, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<int, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<long, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<long long, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+#ifndef _LIBCPP_HAS_NO_INT128
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<__int128_t, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {
+  using _Base = __format_spec::__formatter_integer<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(__int128_t __value, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    // TODO FMT Implement full 128 bit support.
+    using _To = long long;
+    if (__value < numeric_limits<_To>::min() ||
+        __value > numeric_limits<_To>::max())
+      __throw_format_error("128-bit value is outside of implemented range");
+
+    return _Base::format(static_cast<_To>(__value), __ctx);
+  }
+};
+#endif
+
+// Unsigned integral types.
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<unsigned char, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<unsigned short, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<unsigned, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<unsigned long, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<unsigned long long, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {};
+#ifndef _LIBCPP_HAS_NO_INT128
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<__uint128_t, _CharT>
+    : public __format_spec::__formatter_integer<_CharT> {
+  using _Base = __format_spec::__formatter_integer<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(__uint128_t __value, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    // TODO FMT Implement full 128 bit support.
+    using _To = unsigned long long;
+    if (__value < numeric_limits<_To>::min() ||
+        __value > numeric_limits<_To>::max())
+      __throw_format_error("128-bit value is outside of implemented range");
+
+    return _Base::format(static_cast<_To>(__value), __ctx);
+  }
+};
+#endif
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMATTER_INTEGER_H
lib/libcxx/include/__format/formatter_integral.h
@@ -0,0 +1,463 @@
+// -*- 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___FORMAT_FORMATTER_INTEGRAL_H
+#define _LIBCPP___FORMAT_FORMATTER_INTEGRAL_H
+
+#include <__algorithm/copy.h>
+#include <__algorithm/copy_n.h>
+#include <__algorithm/fill_n.h>
+#include <__algorithm/transform.h>
+#include <__config>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/formatter.h>
+#include <__format/parser_std_format_spec.h>
+#include <array>
+#include <charconv>
+#include <concepts>
+#include <limits>
+#include <string>
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#include <locale>
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+/**
+ * Integral formatting classes.
+ *
+ * There are two types used here:
+ * * C++-type, the type as used in C++.
+ * * format-type, the output type specified in the std-format-spec.
+ *
+ * Design of the integral formatters consists of several layers.
+ * * @ref __parser_integral The basic std-format-spec parser for all integral
+ *   classes. This parser does the basic sanity checks. It also contains some
+ *   helper functions that are nice to have available for all parsers.
+ * * A C++-type specific parser. These parsers must derive from
+ *   @ref __parser_integral. Their task is to validate whether the parsed
+ *   std-format-spec is valid for the C++-type and selected format-type. After
+ *   validation they need to make sure all members are properly set. For
+ *   example, when the alignment hasn't changed it needs to set the proper
+ *   default alignment for the format-type. The following parsers are available:
+ *   - @ref __parser_integer
+ *   - @ref __parser_char
+ *   - @ref __parser_bool
+ * * A general formatter for all integral types @ref __formatter_integral. This
+ *   formatter can handle all formatting of integers and characters. The class
+ *   derives from the proper formatter.
+ *   Note the boolean string format-type isn't supported in this class.
+ * * A typedef C++-type group combining the @ref __formatter_integral with a
+ *   parser:
+ *   * @ref __formatter_integer
+ *   * @ref __formatter_char
+ *   * @ref __formatter_bool
+ * * Then every C++-type has its own formatter specializations. They inherit
+ *   from the C++-type group typedef. Most specializations need nothing else.
+ *   Others need some additional specializations in this class.
+ */
+namespace __format_spec {
+
+/** Wrapper around @ref to_chars, returning the output pointer. */
+template <integral _Tp>
+_LIBCPP_HIDE_FROM_ABI char* __to_buffer(char* __first, char* __last,
+                                        _Tp __value, int __base) {
+  // TODO FMT Evaluate code overhead due to not calling the internal function
+  // directly. (Should be zero overhead.)
+  to_chars_result __r = _VSTD::to_chars(__first, __last, __value, __base);
+  _LIBCPP_ASSERT(__r.ec == errc(0), "Internal buffer too small");
+  return __r.ptr;
+}
+
+/**
+ * Helper to determine the buffer size to output a integer in Base @em x.
+ *
+ * There are several overloads for the supported bases. The function uses the
+ * base as template argument so it can be used in a constant expression.
+ */
+template <unsigned_integral _Tp, size_t _Base>
+_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
+    requires(_Base == 2) {
+  return numeric_limits<_Tp>::digits // The number of binary digits.
+         + 2                         // Reserve space for the '0[Bb]' prefix.
+         + 1;                        // Reserve space for the sign.
+}
+
+template <unsigned_integral _Tp, size_t _Base>
+_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
+    requires(_Base == 8) {
+  return numeric_limits<_Tp>::digits // The number of binary digits.
+             / 3                     // Adjust to octal.
+         + 1                         // Turn floor to ceil.
+         + 1                         // Reserve space for the '0' prefix.
+         + 1;                        // Reserve space for the sign.
+}
+
+template <unsigned_integral _Tp, size_t _Base>
+_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
+    requires(_Base == 10) {
+  return numeric_limits<_Tp>::digits10 // The floored value.
+         + 1                           // Turn floor to ceil.
+         + 1;                          // Reserve space for the sign.
+}
+
+template <unsigned_integral _Tp, size_t _Base>
+_LIBCPP_HIDE_FROM_ABI constexpr size_t __buffer_size() noexcept
+    requires(_Base == 16) {
+  return numeric_limits<_Tp>::digits // The number of binary digits.
+             / 4                     // Adjust to hexadecimal.
+         + 2                         // Reserve space for the '0[Xx]' prefix.
+         + 1;                        // Reserve space for the sign.
+}
+
+/**
+ * Determines the required grouping based on the size of the input.
+ *
+ * The grouping's last element will be repeated. For simplicity this repeating
+ * is unwrapped based on the length of the input. (When the input is short some
+ * groups are not processed.)
+ *
+ * @returns The size of the groups to write. This means the number of
+ * separator characters written is size() - 1.
+ *
+ * @note Since zero-sized groups cause issues they are silently ignored.
+ *
+ * @note The grouping field of the locale is always a @c std::string,
+ * regardless whether the @c std::numpunct's type is @c char or @c wchar_t.
+ */
+_LIBCPP_HIDE_FROM_ABI inline string
+__determine_grouping(ptrdiff_t __size, const string& __grouping) {
+  _LIBCPP_ASSERT(!__grouping.empty() && __size > __grouping[0],
+                 "The slow grouping formatting is used while there will be no "
+                 "separators written");
+  string __r;
+  auto __end = __grouping.end() - 1;
+  auto __ptr = __grouping.begin();
+
+  while (true) {
+    __size -= *__ptr;
+    if (__size > 0)
+      __r.push_back(*__ptr);
+    else {
+      // __size <= 0 so the value pushed will be <= *__ptr.
+      __r.push_back(*__ptr + __size);
+      return __r;
+    }
+
+    // Proceed to the next group.
+    if (__ptr != __end) {
+      do {
+        ++__ptr;
+        // Skip grouping with a width of 0.
+      } while (*__ptr == 0 && __ptr != __end);
+    }
+  }
+
+  _LIBCPP_UNREACHABLE();
+}
+
+template <class _Parser>
+requires __formatter::__char_type<typename _Parser::char_type>
+class _LIBCPP_TEMPLATE_VIS __formatter_integral : public _Parser {
+public:
+  using _CharT = typename _Parser::char_type;
+
+  template <integral _Tp>
+  _LIBCPP_HIDE_FROM_ABI auto format(_Tp __value, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    if (this->__width_needs_substitution())
+      this->__substitute_width_arg_id(__ctx.arg(this->__width));
+
+    if (this->__type == _Flags::_Type::__char)
+      return __format_as_char(__value, __ctx);
+
+    if constexpr (unsigned_integral<_Tp>)
+      return __format_unsigned_integral(__value, false, __ctx);
+    else {
+      // Depending on the std-format-spec string the sign and the value
+      // might not be outputted together:
+      // - alternate form may insert a prefix string.
+      // - zero-padding may insert additional '0' characters.
+      // Therefore the value is processed as a positive unsigned value.
+      // The function @ref __insert_sign will a '-' when the value was negative.
+      auto __r = __to_unsigned_like(__value);
+      bool __negative = __value < 0;
+      if (__negative)
+        __r = __complement(__r);
+
+      return __format_unsigned_integral(__r, __negative, __ctx);
+    }
+  }
+
+private:
+  /** Generic formatting for format-type c. */
+  _LIBCPP_HIDE_FROM_ABI auto __format_as_char(integral auto __value,
+                                              auto& __ctx)
+      -> decltype(__ctx.out()) {
+    if (this->__alignment == _Flags::_Alignment::__default)
+      this->__alignment = _Flags::_Alignment::__right;
+
+    using _Tp = decltype(__value);
+    if constexpr (!same_as<_CharT, _Tp>) {
+      // cmp_less and cmp_greater can't be used for character types.
+      if constexpr (signed_integral<_CharT> == signed_integral<_Tp>) {
+        if (__value < numeric_limits<_CharT>::min() ||
+            __value > numeric_limits<_CharT>::max())
+          __throw_format_error(
+              "Integral value outside the range of the char type");
+      } else if constexpr (signed_integral<_CharT>) {
+        // _CharT is signed _Tp is unsigned
+        if (__value >
+            static_cast<make_unsigned_t<_CharT>>(numeric_limits<_CharT>::max()))
+          __throw_format_error(
+              "Integral value outside the range of the char type");
+      } else {
+        // _CharT is unsigned _Tp is signed
+        if (__value < 0 || static_cast<make_unsigned_t<_Tp>>(__value) >
+                               numeric_limits<_CharT>::max())
+          __throw_format_error(
+              "Integral value outside the range of the char type");
+      }
+    }
+
+    const auto __c = static_cast<_CharT>(__value);
+    return __write(_VSTD::addressof(__c), _VSTD::addressof(__c) + 1,
+                   __ctx.out());
+  }
+
+  /**
+   * Generic formatting for format-type bBdoxX.
+   *
+   * This small wrapper allocates a buffer with the required size. Then calls
+   * the real formatter with the buffer and the prefix for the base.
+   */
+  _LIBCPP_HIDE_FROM_ABI auto
+  __format_unsigned_integral(unsigned_integral auto __value, bool __negative,
+                             auto& __ctx) -> decltype(__ctx.out()) {
+    switch (this->__type) {
+    case _Flags::_Type::__binary_lower_case: {
+      array<char, __buffer_size<decltype(__value), 2>()> __array;
+      return __format_unsigned_integral(__array.begin(), __array.end(), __value,
+                                        __negative, 2, __ctx, "0b");
+    }
+    case _Flags::_Type::__binary_upper_case: {
+      array<char, __buffer_size<decltype(__value), 2>()> __array;
+      return __format_unsigned_integral(__array.begin(), __array.end(), __value,
+                                        __negative, 2, __ctx, "0B");
+    }
+    case _Flags::_Type::__octal: {
+      // Octal is special; if __value == 0 there's no prefix.
+      array<char, __buffer_size<decltype(__value), 8>()> __array;
+      return __format_unsigned_integral(__array.begin(), __array.end(), __value,
+                                        __negative, 8, __ctx,
+                                        __value != 0 ? "0" : nullptr);
+    }
+    case _Flags::_Type::__decimal: {
+      array<char, __buffer_size<decltype(__value), 10>()> __array;
+      return __format_unsigned_integral(__array.begin(), __array.end(), __value,
+                                        __negative, 10, __ctx, nullptr);
+    }
+    case _Flags::_Type::__hexadecimal_lower_case: {
+      array<char, __buffer_size<decltype(__value), 16>()> __array;
+      return __format_unsigned_integral(__array.begin(), __array.end(), __value,
+                                        __negative, 16, __ctx, "0x");
+    }
+    case _Flags::_Type::__hexadecimal_upper_case: {
+      array<char, __buffer_size<decltype(__value), 16>()> __array;
+      return __format_unsigned_integral(__array.begin(), __array.end(), __value,
+                                        __negative, 16, __ctx, "0X");
+    }
+    default:
+      _LIBCPP_ASSERT(false, "The parser should have validated the type");
+      _LIBCPP_UNREACHABLE();
+    }
+  }
+
+  template <class _Tp>
+  requires(same_as<char, _Tp> || same_as<wchar_t, _Tp>) _LIBCPP_HIDE_FROM_ABI
+      auto __write(const _Tp* __first, const _Tp* __last, auto __out_it)
+          -> decltype(__out_it) {
+
+    unsigned __size = __last - __first;
+    if (this->__type != _Flags::_Type::__hexadecimal_upper_case) [[likely]] {
+      if (__size >= this->__width)
+        return _VSTD::copy(__first, __last, _VSTD::move(__out_it));
+
+      return __formatter::__write(_VSTD::move(__out_it), __first, __last,
+                                  __size, this->__width, this->__fill,
+                                  this->__alignment);
+    }
+
+    // this->__type == _Flags::_Type::__hexadecimal_upper_case
+    // This means all characters in the range [a-f] need to be changed to their
+    // uppercase representation. The transformation is done as transformation
+    // in the output routine instead of before. This avoids another pass over
+    // the data.
+    // TODO FMT See whether it's possible to do this transformation during the
+    // conversion. (This probably requires changing std::to_chars' alphabet.)
+    if (__size >= this->__width)
+      return _VSTD::transform(__first, __last, _VSTD::move(__out_it),
+                              __hex_to_upper);
+
+    return __formatter::__write(_VSTD::move(__out_it), __first, __last, __size,
+                                __hex_to_upper, this->__width, this->__fill,
+                                this->__alignment);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI auto
+  __format_unsigned_integral(char* __begin, char* __end,
+                             unsigned_integral auto __value, bool __negative,
+                             int __base, auto& __ctx, const char* __prefix)
+      -> decltype(__ctx.out()) {
+    char* __first = __insert_sign(__begin, __negative, this->__sign);
+    if (this->__alternate_form && __prefix)
+      while (*__prefix)
+        *__first++ = *__prefix++;
+
+    char* __last = __to_buffer(__first, __end, __value, __base);
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+    if (this->__locale_specific_form) {
+      const auto& __np = use_facet<numpunct<_CharT>>(__ctx.locale());
+      string __grouping = __np.grouping();
+      ptrdiff_t __size = __last - __first;
+      // Writing the grouped form has more overhead than the normal output
+      // routines. If there will be no separators written the locale-specific
+      // form is identical to the normal routine. Test whether to grouped form
+      // is required.
+      if (!__grouping.empty() && __size > __grouping[0])
+        return __format_grouping(__ctx.out(), __begin, __first, __last,
+                                 __determine_grouping(__size, __grouping),
+                                 __np.thousands_sep());
+    }
+#endif
+    auto __out_it = __ctx.out();
+    if (this->__alignment != _Flags::_Alignment::__default)
+      __first = __begin;
+    else {
+      // __buf contains [sign][prefix]data
+      //                              ^ location of __first
+      // The zero padding is done like:
+      // - Write [sign][prefix]
+      // - Write data right aligned with '0' as fill character.
+      __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
+      this->__alignment = _Flags::_Alignment::__right;
+      this->__fill = _CharT('0');
+      uint32_t __size = __first - __begin;
+      this->__width -= _VSTD::min(__size, this->__width);
+    }
+
+    return __write(__first, __last, _VSTD::move(__out_it));
+  }
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+  /** Format's the locale-specific form's groupings. */
+  template <class _OutIt, class _CharT>
+  _LIBCPP_HIDE_FROM_ABI _OutIt
+  __format_grouping(_OutIt __out_it, const char* __begin, const char* __first,
+                    const char* __last, string&& __grouping, _CharT __sep) {
+
+    // TODO FMT This function duplicates some functionality of the normal
+    // output routines. Evaluate whether these parts can be efficiently
+    // combined with the existing routines.
+
+    unsigned __size = (__first - __begin) +    // [sign][prefix]
+                      (__last - __first) +     // data
+                      (__grouping.size() - 1); // number of separator characters
+
+    __formatter::__padding_size_result __padding = {0, 0};
+    if (this->__alignment == _Flags::_Alignment::__default) {
+      // Write [sign][prefix].
+      __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
+
+      if (this->__width > __size) {
+        // Write zero padding.
+        __padding.__before = this->__width - __size;
+        __out_it = _VSTD::fill_n(_VSTD::move(__out_it), this->__width - __size,
+                                 _CharT('0'));
+      }
+    } else {
+      if (this->__width > __size) {
+        // Determine padding and write padding.
+        __padding = __formatter::__padding_size(__size, this->__width,
+                                                this->__alignment);
+
+        __out_it = _VSTD::fill_n(_VSTD::move(__out_it), __padding.__before,
+                                 this->__fill);
+      }
+      // Write [sign][prefix].
+      __out_it = _VSTD::copy(__begin, __first, _VSTD::move(__out_it));
+    }
+
+    auto __r = __grouping.rbegin();
+    auto __e = __grouping.rend() - 1;
+    _LIBCPP_ASSERT(__r != __e, "The slow grouping formatting is used while "
+                               "there will be no separators written.");
+    // The output is divided in small groups of numbers to write:
+    // - A group before the first separator.
+    // - A separator and a group, repeated for the number of separators.
+    // - A group after the last separator.
+    // This loop achieves that process by testing the termination condition
+    // midway in the loop.
+    //
+    // TODO FMT This loop evaluates the loop invariant `this->__type !=
+    // _Flags::_Type::__hexadecimal_upper_case` for every iteration. (This test
+    // happens in the __write call.) Benchmark whether making two loops and
+    // hoisting the invariant is worth the effort.
+    while (true) {
+      if (this->__type == _Flags::_Type::__hexadecimal_upper_case) {
+        __last = __first + *__r;
+        __out_it = _VSTD::transform(__first, __last, _VSTD::move(__out_it),
+                                    __hex_to_upper);
+        __first = __last;
+      } else {
+        __out_it = _VSTD::copy_n(__first, *__r, _VSTD::move(__out_it));
+        __first += *__r;
+      }
+
+      if (__r == __e)
+        break;
+
+      ++__r;
+      *__out_it++ = __sep;
+    }
+
+    return _VSTD::fill_n(_VSTD::move(__out_it), __padding.__after,
+                         this->__fill);
+  }
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
+};
+
+} // namespace __format_spec
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMATTER_INTEGRAL_H
lib/libcxx/include/__format/formatter_pointer.h
@@ -0,0 +1,91 @@
+// -*- 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___FORMAT_FORMATTER_POINTER_H
+#define _LIBCPP___FORMAT_FORMATTER_POINTER_H
+
+#include <__algorithm/copy.h>
+#include <__availability>
+#include <__config>
+#include <__debug>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/formatter.h>
+#include <__format/formatter_integral.h>
+#include <__format/parser_std_format_spec.h>
+#include <__iterator/access.h>
+#include <__nullptr>
+#include <cstdint>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#  if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format_spec {
+
+template <__formatter::__char_type _CharT>
+class _LIBCPP_TEMPLATE_VIS __formatter_pointer : public __parser_pointer<_CharT> {
+public:
+  _LIBCPP_HIDE_FROM_ABI auto format(const void* __ptr, auto& __ctx) -> decltype(__ctx.out()) {
+    _LIBCPP_ASSERT(this->__alignment != _Flags::_Alignment::__default,
+                   "The call to parse should have updated the alignment");
+    if (this->__width_needs_substitution())
+      this->__substitute_width_arg_id(__ctx.arg(this->__width));
+
+    // This code looks a lot like the code to format a hexadecimal integral,
+    // but that code isn't public. Making that code public requires some
+    // refactoring.
+    // TODO FMT Remove code duplication.
+    char __buffer[2 + 2 * sizeof(uintptr_t)];
+    __buffer[0] = '0';
+    __buffer[1] = 'x';
+    char* __last = __to_buffer(__buffer + 2, _VSTD::end(__buffer), reinterpret_cast<uintptr_t>(__ptr), 16);
+
+    unsigned __size = __last - __buffer;
+    if (__size >= this->__width)
+      return _VSTD::copy(__buffer, __last, __ctx.out());
+
+    return __formatter::__write(__ctx.out(), __buffer, __last, __size, this->__width, this->__fill, this->__alignment);
+  }
+};
+
+} // namespace __format_spec
+
+// [format.formatter.spec]/2.4
+// For each charT, the pointer type specializations template<>
+// - struct formatter<nullptr_t, charT>;
+// - template<> struct formatter<void*, charT>;
+// - template<> struct formatter<const void*, charT>;
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<nullptr_t, _CharT>
+    : public __format_spec::__formatter_pointer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<void*, _CharT>
+    : public __format_spec::__formatter_pointer<_CharT> {};
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const void*, _CharT>
+    : public __format_spec::__formatter_pointer<_CharT> {};
+
+#  endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FORMAT_FORMATTER_POINTER_H
lib/libcxx/include/__format/formatter_string.h
@@ -0,0 +1,162 @@
+// -*- 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___FORMAT_FORMATTER_STRING_H
+#define _LIBCPP___FORMAT_FORMATTER_STRING_H
+
+#include <__config>
+#include <__format/format_error.h>
+#include <__format/format_fwd.h>
+#include <__format/format_string.h>
+#include <__format/formatter.h>
+#include <__format/parser_std_format_spec.h>
+#include <string_view>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format_spec {
+
+template <__formatter::__char_type _CharT>
+class _LIBCPP_TEMPLATE_VIS __formatter_string : public __parser_string<_CharT> {
+public:
+  _LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT> __str,
+                                    auto& __ctx) -> decltype(__ctx.out()) {
+
+    _LIBCPP_ASSERT(this->__alignment != _Flags::_Alignment::__default,
+                   "The parser should not use these defaults");
+
+    if (this->__width_needs_substitution())
+      this->__substitute_width_arg_id(__ctx.arg(this->__width));
+
+    if (this->__precision_needs_substitution())
+      this->__substitute_precision_arg_id(__ctx.arg(this->__precision));
+
+    return __formatter::__write_unicode(
+        __ctx.out(), __str, this->__width,
+        this->__has_precision_field() ? this->__precision : -1, this->__fill,
+        this->__alignment);
+  }
+};
+
+} //namespace __format_spec
+
+// [format.formatter.spec]/2.2 For each charT, the string type specializations
+
+// Formatter const char*.
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<const _CharT*, _CharT>
+    : public __format_spec::__formatter_string<_CharT> {
+  using _Base = __format_spec::__formatter_string<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(const _CharT* __str, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    _LIBCPP_ASSERT(__str, "The basic_format_arg constructor should have "
+                          "prevented an invalid pointer.");
+
+    // When using a center or right alignment and the width option the length
+    // of __str must be known to add the padding upfront. This case is handled
+    // by the base class by converting the argument to a basic_string_view.
+    //
+    // When using left alignment and the width option the padding is added
+    // after outputting __str so the length can be determined while outputting
+    // __str. The same holds true for the precision, during outputting __str it
+    // can be validated whether the precision threshold has been reached. For
+    // now these optimizations aren't implemented. Instead the base class
+    // handles these options.
+    // TODO FMT Implement these improvements.
+    if (this->__has_width_field() || this->__has_precision_field())
+      return _Base::format(__str, __ctx);
+
+    // No formatting required, copy the string to the output.
+    auto __out_it = __ctx.out();
+    while (*__str)
+      *__out_it++ = *__str++;
+    return __out_it;
+  }
+};
+
+// Formatter char*.
+template <__formatter::__char_type _CharT>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<_CharT*, _CharT> : public formatter<const _CharT*, _CharT> {
+  using _Base = formatter<const _CharT*, _CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(_CharT* __str, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    return _Base::format(__str, __ctx);
+  }
+};
+
+// Formatter const char[].
+template <__formatter::__char_type _CharT, size_t _Size>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<const _CharT[_Size], _CharT>
+    : public __format_spec::__formatter_string<_CharT> {
+  using _Base = __format_spec::__formatter_string<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(const _CharT __str[_Size], auto& __ctx)
+      -> decltype(__ctx.out()) {
+    return _Base::format(basic_string_view<_CharT>(__str, _Size), __ctx);
+  }
+};
+
+// Formatter std::string.
+template <__formatter::__char_type _CharT, class _Traits, class _Allocator>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
+    formatter<basic_string<_CharT, _Traits, _Allocator>, _CharT>
+    : public __format_spec::__formatter_string<_CharT> {
+  using _Base = __format_spec::__formatter_string<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto
+  format(const basic_string<_CharT, _Traits, _Allocator>& __str, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    // drop _Traits and _Allocator
+    return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
+  }
+};
+
+// Formatter std::string_view.
+template <__formatter::__char_type _CharT, class _Traits>
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string_view<_CharT, _Traits>, _CharT>
+    : public __format_spec::__formatter_string<_CharT> {
+  using _Base = __format_spec::__formatter_string<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto
+  format(basic_string_view<_CharT, _Traits> __str, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    // drop _Traits
+    return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
+  }
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_FORMATTER_STRING_H
lib/libcxx/include/__format/parser_std_format_spec.h
@@ -0,0 +1,1398 @@
+// -*- 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___FORMAT_PARSER_STD_FORMAT_SPEC_H
+#define _LIBCPP___FORMAT_PARSER_STD_FORMAT_SPEC_H
+
+#include <__algorithm/find_if.h>
+#include <__algorithm/min.h>
+#include <__config>
+#include <__debug>
+#include <__format/format_arg.h>
+#include <__format/format_error.h>
+#include <__format/format_string.h>
+#include <__variant/monostate.h>
+#include <bit>
+#include <concepts>
+#include <cstdint>
+#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
+
+#if _LIBCPP_STD_VER > 17
+
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+# if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+namespace __format_spec {
+
+/**
+ * Contains the flags for the std-format-spec.
+ *
+ * Some format-options can only be used for specific C++types and may depend on
+ * the selected format-type.
+ * * The C++type filtering can be done using the proper policies for
+ *   @ref __parser_std.
+ * * The format-type filtering needs to be done post parsing in the parser
+ *   derived from @ref __parser_std.
+ */
+class _LIBCPP_TYPE_VIS _Flags {
+public:
+  enum class _LIBCPP_ENUM_VIS _Alignment : uint8_t {
+    /**
+     * No alignment is set in the format string.
+     *
+     * Zero-padding is ignored when an alignment is selected.
+     * The default alignment depends on the selected format-type.
+     */
+    __default,
+    __left,
+    __center,
+    __right
+  };
+  enum class _LIBCPP_ENUM_VIS _Sign : uint8_t {
+    /**
+     * No sign is set in the format string.
+     *
+     * The sign isn't allowed for certain format-types. By using this value
+     * it's possible to detect whether or not the user explicitly set the sign
+     * flag. For formatting purposes it behaves the same as @ref __minus.
+     */
+    __default,
+    __minus,
+    __plus,
+    __space
+  };
+
+  _Alignment __alignment : 2 {_Alignment::__default};
+  _Sign __sign : 2 {_Sign::__default};
+  uint8_t __alternate_form : 1 {false};
+  uint8_t __zero_padding : 1 {false};
+  uint8_t __locale_specific_form : 1 {false};
+
+  enum class _LIBCPP_ENUM_VIS _Type : uint8_t {
+    __default,
+    __string,
+    __binary_lower_case,
+    __binary_upper_case,
+    __octal,
+    __decimal,
+    __hexadecimal_lower_case,
+    __hexadecimal_upper_case,
+    __pointer,
+    __char,
+    __float_hexadecimal_lower_case,
+    __float_hexadecimal_upper_case,
+    __scientific_lower_case,
+    __scientific_upper_case,
+    __fixed_lower_case,
+    __fixed_upper_case,
+    __general_lower_case,
+    __general_upper_case
+  };
+
+  _Type __type{_Type::__default};
+};
+
+namespace __detail {
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr bool
+__parse_alignment(_CharT __c, _Flags& __flags) noexcept {
+  switch (__c) {
+  case _CharT('<'):
+    __flags.__alignment = _Flags::_Alignment::__left;
+    return true;
+
+  case _CharT('^'):
+    __flags.__alignment = _Flags::_Alignment::__center;
+    return true;
+
+  case _CharT('>'):
+    __flags.__alignment = _Flags::_Alignment::__right;
+    return true;
+  }
+  return false;
+}
+} // namespace __detail
+
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_fill_align {
+public:
+  // TODO FMT The standard doesn't specify this character is a Unicode
+  // character. Validate what fmt and MSVC have implemented.
+  _CharT __fill{_CharT(' ')};
+
+protected:
+  _LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+  __parse(const _CharT* __begin, const _CharT* __end, _Flags& __flags) {
+    _LIBCPP_ASSERT(__begin != __end,
+                   "When called with an empty input the function will cause "
+                   "undefined behavior by evaluating data not in the input");
+    if (__begin + 1 != __end) {
+      if (__detail::__parse_alignment(*(__begin + 1), __flags)) {
+        if (*__begin == _CharT('{') || *__begin == _CharT('}'))
+          __throw_format_error(
+              "The format-spec fill field contains an invalid character");
+        __fill = *__begin;
+        return __begin + 2;
+      }
+    }
+
+    if (__detail::__parse_alignment(*__begin, __flags))
+      return __begin + 1;
+
+    return __begin;
+  }
+};
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+__parse_sign(const _CharT* __begin, _Flags& __flags) noexcept {
+  switch (*__begin) {
+  case _CharT('-'):
+    __flags.__sign = _Flags::_Sign::__minus;
+    break;
+  case _CharT('+'):
+    __flags.__sign = _Flags::_Sign::__plus;
+    break;
+  case _CharT(' '):
+    __flags.__sign = _Flags::_Sign::__space;
+    break;
+  default:
+    return __begin;
+  }
+  return __begin + 1;
+}
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+__parse_alternate_form(const _CharT* __begin, _Flags& __flags) noexcept {
+  if (*__begin == _CharT('#')) {
+    __flags.__alternate_form = true;
+    ++__begin;
+  }
+
+  return __begin;
+}
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+__parse_zero_padding(const _CharT* __begin, _Flags& __flags) noexcept {
+  if (*__begin == _CharT('0')) {
+    __flags.__zero_padding = true;
+    ++__begin;
+  }
+
+  return __begin;
+}
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __format::__parse_number_result< _CharT>
+__parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
+  // This function is a wrapper to call the real parser. But it does the
+  // validation for the pre-conditions and post-conditions.
+  if (__begin == __end)
+    __throw_format_error("End of input while parsing format-spec arg-id");
+
+  __format::__parse_number_result __r =
+      __format::__parse_arg_id(__begin, __end, __parse_ctx);
+
+  if (__r.__ptr == __end || *__r.__ptr != _CharT('}'))
+    __throw_format_error("Invalid arg-id");
+
+  ++__r.__ptr;
+  return __r;
+}
+
+template <class _Context>
+_LIBCPP_HIDE_FROM_ABI constexpr uint32_t
+__substitute_arg_id(basic_format_arg<_Context> __arg) {
+  return visit_format_arg(
+      [](auto __arg) -> uint32_t {
+        using _Type = decltype(__arg);
+        if constexpr (integral<_Type>) {
+          if constexpr (signed_integral<_Type>) {
+            if (__arg < 0)
+              __throw_format_error("A format-spec arg-id replacement shouldn't "
+                                   "have a negative value");
+          }
+
+          using _CT = common_type_t<_Type, decltype(__format::__number_max)>;
+          if (static_cast<_CT>(__arg) >
+              static_cast<_CT>(__format::__number_max))
+            __throw_format_error("A format-spec arg-id replacement exceeds "
+                                 "the maximum supported value");
+
+          return __arg;
+        } else if constexpr (same_as<_Type, monostate>)
+          __throw_format_error("Argument index out of bounds");
+        else
+          __throw_format_error("A format-spec arg-id replacement argument "
+                               "isn't an integral type");
+      },
+      __arg);
+}
+
+class _LIBCPP_TYPE_VIS __parser_width {
+public:
+  /** Contains a width or an arg-id. */
+  uint32_t __width : 31 {0};
+  /** Determines whether the value stored is a width or an arg-id. */
+  uint32_t __width_as_arg : 1 {0};
+
+protected:
+  /**
+   * Does the supplied std-format-spec contain a width field?
+   *
+   * When the field isn't present there's no padding required. This can be used
+   * to optimize the formatting.
+   */
+  constexpr bool __has_width_field() const noexcept {
+    return __width_as_arg || __width;
+  }
+
+  /**
+   * Does the supplied width field contain an arg-id?
+   *
+   * If @c true the formatter needs to call @ref __substitute_width_arg_id.
+   */
+  constexpr bool __width_needs_substitution() const noexcept {
+    return __width_as_arg;
+  }
+
+  template <class _CharT>
+  _LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+  __parse(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
+    if (*__begin == _CharT('0'))
+      __throw_format_error(
+          "A format-spec width field shouldn't have a leading zero");
+
+    if (*__begin == _CharT('{')) {
+      __format::__parse_number_result __r =
+          __parse_arg_id(++__begin, __end, __parse_ctx);
+      __width = __r.__value;
+      __width_as_arg = 1;
+      return __r.__ptr;
+    }
+
+    if (*__begin < _CharT('0') || *__begin > _CharT('9'))
+      return __begin;
+
+    __format::__parse_number_result __r =
+        __format::__parse_number(__begin, __end);
+    __width = __r.__value;
+    _LIBCPP_ASSERT(__width != 0,
+                   "A zero value isn't allowed and should be impossible, "
+                   "due to validations in this function");
+    return __r.__ptr;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr void __substitute_width_arg_id(auto __arg) {
+    _LIBCPP_ASSERT(__width_as_arg == 1,
+                   "Substitute width called when no substitution is required");
+
+    // The clearing of the flag isn't required but looks better when debugging
+    // the code.
+    __width_as_arg = 0;
+    __width = __substitute_arg_id(__arg);
+    if (__width == 0)
+      __throw_format_error(
+          "A format-spec width field replacement should have a positive value");
+  }
+};
+
+class _LIBCPP_TYPE_VIS __parser_precision {
+public:
+  /** Contains a precision or an arg-id. */
+  uint32_t __precision : 31 {__format::__number_max};
+  /**
+   * Determines whether the value stored is a precision or an arg-id.
+   *
+   * @note Since @ref __precision == @ref __format::__number_max is a valid
+   * value, the default value contains an arg-id of INT32_MAX. (This number of
+   * arguments isn't supported by compilers.)  This is used to detect whether
+   * the std-format-spec contains a precision field.
+   */
+  uint32_t __precision_as_arg : 1 {1};
+
+protected:
+  /**
+   * Does the supplied std-format-spec contain a precision field?
+   *
+   * When the field isn't present there's no truncating required. This can be
+   * used to optimize the formatting.
+   */
+  constexpr bool __has_precision_field() const noexcept {
+
+    return __precision_as_arg == 0 ||             // Contains a value?
+           __precision != __format::__number_max; // The arg-id is valid?
+  }
+
+  /**
+   * Does the supplied precision field contain an arg-id?
+   *
+   * If @c true the formatter needs to call @ref __substitute_precision_arg_id.
+   */
+  constexpr bool __precision_needs_substitution() const noexcept {
+    return __precision_as_arg && __precision != __format::__number_max;
+  }
+
+  template <class _CharT>
+  _LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+  __parse(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) {
+    if (*__begin != _CharT('.'))
+      return __begin;
+
+    ++__begin;
+    if (__begin == __end)
+      __throw_format_error("End of input while parsing format-spec precision");
+
+    if (*__begin == _CharT('{')) {
+      __format::__parse_number_result __arg_id =
+          __parse_arg_id(++__begin, __end, __parse_ctx);
+      _LIBCPP_ASSERT(__arg_id.__value != __format::__number_max,
+                     "Unsupported number of arguments, since this number of "
+                     "arguments is used a special value");
+      __precision = __arg_id.__value;
+      return __arg_id.__ptr;
+    }
+
+    if (*__begin < _CharT('0') || *__begin > _CharT('9'))
+      __throw_format_error(
+          "The format-spec precision field doesn't contain a value or arg-id");
+
+    __format::__parse_number_result __r =
+        __format::__parse_number(__begin, __end);
+    __precision = __r.__value;
+    __precision_as_arg = 0;
+    return __r.__ptr;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr void __substitute_precision_arg_id(
+      auto __arg) {
+    _LIBCPP_ASSERT(
+        __precision_as_arg == 1 && __precision != __format::__number_max,
+        "Substitute precision called when no substitution is required");
+
+    // The clearing of the flag isn't required but looks better when debugging
+    // the code.
+    __precision_as_arg = 0;
+    __precision = __substitute_arg_id(__arg);
+  }
+};
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+__parse_locale_specific_form(const _CharT* __begin, _Flags& __flags) noexcept {
+  if (*__begin == _CharT('L')) {
+    __flags.__locale_specific_form = true;
+    ++__begin;
+  }
+
+  return __begin;
+}
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+__parse_type(const _CharT* __begin, _Flags& __flags) {
+
+  // Determines the type. It does not validate whether the selected type is
+  // valid. Most formatters have optional fields that are only allowed for
+  // certain types. These parsers need to do validation after the type has
+  // been parsed. So its easier to implement the validation for all types in
+  // the specific parse function.
+  switch (*__begin) {
+  case 'A':
+    __flags.__type = _Flags::_Type::__float_hexadecimal_upper_case;
+    break;
+  case 'B':
+    __flags.__type = _Flags::_Type::__binary_upper_case;
+    break;
+  case 'E':
+    __flags.__type = _Flags::_Type::__scientific_upper_case;
+    break;
+  case 'F':
+    __flags.__type = _Flags::_Type::__fixed_upper_case;
+    break;
+  case 'G':
+    __flags.__type = _Flags::_Type::__general_upper_case;
+    break;
+  case 'X':
+    __flags.__type = _Flags::_Type::__hexadecimal_upper_case;
+    break;
+  case 'a':
+    __flags.__type = _Flags::_Type::__float_hexadecimal_lower_case;
+    break;
+  case 'b':
+    __flags.__type = _Flags::_Type::__binary_lower_case;
+    break;
+  case 'c':
+    __flags.__type = _Flags::_Type::__char;
+    break;
+  case 'd':
+    __flags.__type = _Flags::_Type::__decimal;
+    break;
+  case 'e':
+    __flags.__type = _Flags::_Type::__scientific_lower_case;
+    break;
+  case 'f':
+    __flags.__type = _Flags::_Type::__fixed_lower_case;
+    break;
+  case 'g':
+    __flags.__type = _Flags::_Type::__general_lower_case;
+    break;
+  case 'o':
+    __flags.__type = _Flags::_Type::__octal;
+    break;
+  case 'p':
+    __flags.__type = _Flags::_Type::__pointer;
+    break;
+  case 's':
+    __flags.__type = _Flags::_Type::__string;
+    break;
+  case 'x':
+    __flags.__type = _Flags::_Type::__hexadecimal_lower_case;
+    break;
+  default:
+    return __begin;
+  }
+  return ++__begin;
+}
+
+/**
+ * Process the parsed alignment and zero-padding state of arithmetic types.
+ *
+ * [format.string.std]/13
+ *   If the 0 character and an align option both appear, the 0 character is
+ *   ignored.
+ *
+ * For the formatter a @ref __default alignment means zero-padding.
+ */
+_LIBCPP_HIDE_FROM_ABI constexpr void __process_arithmetic_alignment(_Flags& __flags) {
+  __flags.__zero_padding &= __flags.__alignment == _Flags::_Alignment::__default;
+  if (!__flags.__zero_padding && __flags.__alignment == _Flags::_Alignment::__default)
+    __flags.__alignment = _Flags::_Alignment::__right;
+}
+
+/**
+ * The parser for the std-format-spec.
+ *
+ * [format.string.std]/1 specifies the std-format-spec:
+ *   fill-and-align sign # 0 width precision L type
+ *
+ * All these fields are optional. Whether these fields can be used depend on:
+ * - The type supplied to the format string.
+ *   E.g. A string never uses the sign field so the field may not be set.
+ *   This constrain is validated by the parsers in this file.
+ * - The supplied value for the optional type field.
+ *   E.g. A int formatted as decimal uses the sign field.
+ *   When formatted as a char the sign field may no longer be set.
+ *   This constrain isn't validated by the parsers in this file.
+ *
+ * The base classes are ordered to minimize the amount of padding.
+ *
+ * This implements the parser for the string types.
+ */
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_string
+    : public __parser_width,              // provides __width(|as_arg)
+      public __parser_precision,          // provides __precision(|as_arg)
+      public __parser_fill_align<_CharT>, // provides __fill and uses __flags
+      public _Flags                       // provides __flags
+{
+public:
+  using char_type = _CharT;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr __parser_string() {
+    this->__alignment = _Flags::_Alignment::__left;
+  }
+
+  /**
+   * The low-level std-format-spec parse function.
+   *
+   * @pre __begin points at the beginning of the std-format-spec. This means
+   * directly after the ':'.
+   * @pre The std-format-spec parses the entire input, or the first unmatched
+   * character is a '}'.
+   *
+   * @returns The iterator pointing at the last parsed character.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+    auto __it = __parse(__parse_ctx);
+    __process_display_type();
+    return __it;
+  }
+
+private:
+  /**
+   * Parses the std-format-spec.
+   *
+   * @throws __throw_format_error When @a __parse_ctx contains an ill-formed
+   *                               std-format-spec.
+   *
+   * @returns An iterator to the end of input or point at the closing '}'.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+
+    auto __begin = __parse_ctx.begin();
+    auto __end = __parse_ctx.end();
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
+                                                   static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_precision::__parse(__begin, __end, __parse_ctx);
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
+
+    if (__begin != __end && *__begin != _CharT('}'))
+      __throw_format_error(
+          "The format-spec should consume the input or end with a '}'");
+
+    return __begin;
+  }
+
+  /** Processes the parsed std-format-spec based on the parsed display type. */
+  _LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type() {
+    switch (this->__type) {
+    case _Flags::_Type::__default:
+    case _Flags::_Type::__string:
+      break;
+
+    default:
+      __throw_format_error("The format-spec type has a type not supported for "
+                           "a string argument");
+    }
+  }
+};
+
+/**
+ * The parser for the std-format-spec.
+ *
+ * This implements the parser for the integral types. This includes the
+ * character type and boolean type.
+ *
+ * See @ref __parser_string.
+ */
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_integral
+    : public __parser_width,              // provides __width(|as_arg)
+      public __parser_fill_align<_CharT>, // provides __fill and uses __flags
+      public _Flags                       // provides __flags
+{
+public:
+  using char_type = _CharT;
+
+protected:
+  /**
+   * The low-level std-format-spec parse function.
+   *
+   * @pre __begin points at the beginning of the std-format-spec. This means
+   * directly after the ':'.
+   * @pre The std-format-spec parses the entire input, or the first unmatched
+   * character is a '}'.
+   *
+   * @returns The iterator pointing at the last parsed character.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+    auto __begin = __parse_ctx.begin();
+    auto __end = __parse_ctx.end();
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
+                                                   static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_sign(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_alternate_form(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_zero_padding(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
+    if (__begin == __end)
+      return __begin;
+
+    __begin =
+        __parse_locale_specific_form(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
+
+    if (__begin != __end && *__begin != _CharT('}'))
+      __throw_format_error(
+          "The format-spec should consume the input or end with a '}'");
+
+    return __begin;
+  }
+
+  /** Handles the post-parsing updates for the integer types. */
+  _LIBCPP_HIDE_FROM_ABI constexpr void __handle_integer() noexcept {
+    __process_arithmetic_alignment(static_cast<_Flags&>(*this));
+  }
+
+  /**
+   * Handles the post-parsing updates for the character types.
+   *
+   * Sets the alignment and validates the format flags set for a character type.
+   *
+   * At the moment the validation for a character and a Boolean behave the
+   * same, but this may change in the future.
+   * Specifically at the moment the locale-specific form is allowed for the
+   * char output type, but it has no effect on the output.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr void __handle_char() { __handle_bool(); }
+
+  /**
+   * Handles the post-parsing updates for the Boolean types.
+   *
+   * Sets the alignment and validates the format flags set for a Boolean type.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr void __handle_bool() {
+    if (this->__sign != _Flags::_Sign::__default)
+      __throw_format_error("A sign field isn't allowed in this format-spec");
+
+    if (this->__alternate_form)
+      __throw_format_error(
+          "An alternate form field isn't allowed in this format-spec");
+
+    if (this->__zero_padding)
+      __throw_format_error(
+          "A zero-padding field isn't allowed in this format-spec");
+
+    if (this->__alignment == _Flags::_Alignment::__default)
+      this->__alignment = _Flags::_Alignment::__left;
+  }
+};
+
+/**
+ * The parser for the std-format-spec.
+ *
+ * This implements the parser for the floating-point types.
+ *
+ * See @ref __parser_string.
+ */
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_floating_point
+    : public __parser_width,              // provides __width(|as_arg)
+      public __parser_precision,          // provides __precision(|as_arg)
+      public __parser_fill_align<_CharT>, // provides __fill and uses __flags
+      public _Flags                       // provides __flags
+{
+public:
+  using char_type = _CharT;
+
+  /**
+   * The low-level std-format-spec parse function.
+   *
+   * @pre __begin points at the beginning of the std-format-spec. This means
+   * directly after the ':'.
+   * @pre The std-format-spec parses the entire input, or the first unmatched
+   * character is a '}'.
+   *
+   * @returns The iterator pointing at the last parsed character.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+    auto __it = __parse(__parse_ctx);
+    __process_arithmetic_alignment(static_cast<_Flags&>(*this));
+    __process_display_type();
+    return __it;
+  }
+protected:
+  /**
+   * The low-level std-format-spec parse function.
+   *
+   * @pre __begin points at the beginning of the std-format-spec. This means
+   * directly after the ':'.
+   * @pre The std-format-spec parses the entire input, or the first unmatched
+   * character is a '}'.
+   *
+   * @returns The iterator pointing at the last parsed character.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx)
+      -> decltype(__parse_ctx.begin()) {
+    auto __begin = __parse_ctx.begin();
+    auto __end = __parse_ctx.end();
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_fill_align<_CharT>::__parse(__begin, __end,
+                                                   static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_sign(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_alternate_form(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_zero_padding(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_precision::__parse(__begin, __end, __parse_ctx);
+    if (__begin == __end)
+      return __begin;
+
+    __begin =
+        __parse_locale_specific_form(__begin, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
+
+    if (__begin != __end && *__begin != _CharT('}'))
+      __throw_format_error(
+          "The format-spec should consume the input or end with a '}'");
+
+    return __begin;
+  }
+
+  /** Processes the parsed std-format-spec based on the parsed display type. */
+  _LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type() {
+    switch (this->__type) {
+    case _Flags::_Type::__default:
+      // When no precision specified then it keeps default since that
+      // formatting differs from the other types.
+      if (this->__has_precision_field())
+        this->__type = _Flags::_Type::__general_lower_case;
+      break;
+    case _Flags::_Type::__float_hexadecimal_lower_case:
+    case _Flags::_Type::__float_hexadecimal_upper_case:
+      // Precision specific behavior will be handled later.
+      break;
+    case _Flags::_Type::__scientific_lower_case:
+    case _Flags::_Type::__scientific_upper_case:
+    case _Flags::_Type::__fixed_lower_case:
+    case _Flags::_Type::__fixed_upper_case:
+    case _Flags::_Type::__general_lower_case:
+    case _Flags::_Type::__general_upper_case:
+      if (!this->__has_precision_field()) {
+        // Set the default precision for the call to to_chars.
+        this->__precision = 6;
+        this->__precision_as_arg = false;
+      }
+      break;
+
+    default:
+      __throw_format_error("The format-spec type has a type not supported for "
+                           "a floating-point argument");
+    }
+  }
+};
+
+/**
+ * The parser for the std-format-spec.
+ *
+ * This implements the parser for the pointer types.
+ *
+ * See @ref __parser_string.
+ */
+template <class _CharT>
+class _LIBCPP_TEMPLATE_VIS __parser_pointer : public __parser_width,              // provides __width(|as_arg)
+                                              public __parser_fill_align<_CharT>, // provides __fill and uses __flags
+                                              public _Flags                       // provides __flags
+{
+public:
+  using char_type = _CharT;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr __parser_pointer() {
+    // Implements LWG3612 Inconsistent pointer alignment in std::format.
+    // The issue's current status is "Tentatively Ready" and libc++ status is
+    // still experimental.
+    //
+    // TODO FMT Validate this with the final resolution of LWG3612.
+    this->__alignment = _Flags::_Alignment::__right;
+  }
+
+  /**
+   * The low-level std-format-spec parse function.
+   *
+   * @pre __begin points at the beginning of the std-format-spec. This means
+   * directly after the ':'.
+   * @pre The std-format-spec parses the entire input, or the first unmatched
+   * character is a '}'.
+   *
+   * @returns The iterator pointing at the last parsed character.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr auto parse(auto& __parse_ctx) -> decltype(__parse_ctx.begin()) {
+    auto __it = __parse(__parse_ctx);
+    __process_display_type();
+    return __it;
+  }
+
+protected:
+  /**
+   * The low-level std-format-spec parse function.
+   *
+   * @pre __begin points at the beginning of the std-format-spec. This means
+   * directly after the ':'.
+   * @pre The std-format-spec parses the entire input, or the first unmatched
+   * character is a '}'.
+   *
+   * @returns The iterator pointing at the last parsed character.
+   */
+  _LIBCPP_HIDE_FROM_ABI constexpr auto __parse(auto& __parse_ctx) -> decltype(__parse_ctx.begin()) {
+    auto __begin = __parse_ctx.begin();
+    auto __end = __parse_ctx.end();
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parser_fill_align<_CharT>::__parse(__begin, __end, static_cast<_Flags&>(*this));
+    if (__begin == __end)
+      return __begin;
+
+    // An integer presentation type isn't defined in the Standard.
+    // Since a pointer is formatted as an integer it can be argued it's an
+    // integer presentation type. However there are two LWG-issues asserting it
+    // isn't an integer presentation type:
+    // - LWG3612 Inconsistent pointer alignment in std::format
+    // - LWG3644 std::format does not define "integer presentation type"
+    //
+    // There's a paper to make additional clarifications on the status of
+    // formatting pointers and proposes additional fields to be valid. That
+    // paper hasn't been reviewed by the Committee yet.
+    // - P2510 Formatting pointers
+    //
+    // The current implementation assumes formatting pointers isn't covered by
+    // "integer presentation type".
+    // TODO FMT Apply the LWG-issues/papers after approval/rejection by the Committee.
+
+    __begin = __parser_width::__parse(__begin, __end, __parse_ctx);
+    if (__begin == __end)
+      return __begin;
+
+    __begin = __parse_type(__begin, static_cast<_Flags&>(*this));
+
+    if (__begin != __end && *__begin != _CharT('}'))
+      __throw_format_error("The format-spec should consume the input or end with a '}'");
+
+    return __begin;
+  }
+
+  /** Processes the parsed std-format-spec based on the parsed display type. */
+  _LIBCPP_HIDE_FROM_ABI constexpr void __process_display_type() {
+    switch (this->__type) {
+    case _Flags::_Type::__default:
+      this->__type = _Flags::_Type::__pointer;
+      break;
+    case _Flags::_Type::__pointer:
+      break;
+    default:
+      __throw_format_error("The format-spec type has a type not supported for a pointer argument");
+    }
+  }
+};
+
+/** Helper struct returned from @ref __get_string_alignment. */
+template <class _CharT>
+struct _LIBCPP_TEMPLATE_VIS __string_alignment {
+  /** Points beyond the last character to write to the output. */
+  const _CharT* __last;
+  /**
+   * The estimated number of columns in the output or 0.
+   *
+   * Only when the output needs to be aligned it's required to know the exact
+   * number of columns in the output. So if the formatted output has only a
+   * minimum width the exact size isn't important. It's only important to know
+   * the minimum has been reached. The minimum width is the width specified in
+   * the format-spec.
+   *
+   * For example in this code @code std::format("{:10}", MyString); @endcode
+   * the width estimation can stop once the algorithm has determined the output
+   * width is 10 columns.
+   *
+   * So if:
+   * * @ref __align == @c true the @ref __size is the estimated number of
+   *   columns required.
+   * * @ref __align == @c false the @ref __size is the estimated number of
+   *   columns required or 0 when the estimation algorithm stopped prematurely.
+   */
+  ptrdiff_t __size;
+  /**
+   * Does the output need to be aligned.
+   *
+   * When alignment is needed the output algorithm needs to add the proper
+   * padding. Else the output algorithm just needs to copy the input up to
+   * @ref __last.
+   */
+  bool __align;
+};
+
+#ifndef _LIBCPP_HAS_NO_UNICODE
+namespace __detail {
+
+/**
+ * Unicode column width estimates.
+ *
+ * Unicode can be stored in several formats: UTF-8, UTF-16, and UTF-32.
+ * Depending on format the relation between the number of code units stored and
+ * the number of output columns differs. The first relation is the number of
+ * code units forming a code point. (The text assumes the code units are
+ * unsigned.)
+ * - UTF-8 The number of code units is between one and four. The first 127
+ *   Unicode code points match the ASCII character set. When the highest bit is
+ *   set it means the code point has more than one code unit.
+ * - UTF-16: The number of code units is between 1 and 2. When the first
+ *   code unit is in the range [0xd800,0xdfff) it means the code point uses two
+ *   code units.
+ * - UTF-32: The number of code units is always one.
+ *
+ * The code point to the number of columns isn't well defined. The code uses the
+ * estimations defined in [format.string.std]/11. This list might change in the
+ * future.
+ *
+ * The algorithm of @ref __get_string_alignment uses two different scanners:
+ * - The simple scanner @ref __estimate_column_width_fast. This scanner assumes
+ *   1 code unit is 1 column. This scanner stops when it can't be sure the
+ *   assumption is valid:
+ *   - UTF-8 when the code point is encoded in more than 1 code unit.
+ *   - UTF-16 and UTF-32 when the first multi-column code point is encountered.
+ *     (The code unit's value is lower than 0xd800 so the 2 code unit encoding
+ *     is irrelevant for this scanner.)
+ *   Due to these assumptions the scanner is faster than the full scanner. It
+ *   can process all text only containing ASCII. For UTF-16/32 it can process
+ *   most (all?) European languages. (Note the set it can process might be
+ *   reduced in the future, due to updates in the scanning rules.)
+ * - The full scanner @ref __estimate_column_width. This scanner, if needed,
+ *   converts multiple code units into one code point then converts the code
+ *   point to a column width.
+ *
+ * See also:
+ * - [format.string.general]/11
+ * - https://en.wikipedia.org/wiki/UTF-8#Encoding
+ * - https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF
+ */
+
+/**
+ * The first 2 column code point.
+ *
+ * This is the point where the fast UTF-16/32 scanner needs to stop processing.
+ */
+inline constexpr uint32_t __two_column_code_point = 0x1100;
+
+/** Helper concept for an UTF-8 character type. */
+template <class _CharT>
+concept __utf8_character = same_as<_CharT, char> || same_as<_CharT, char8_t>;
+
+/** Helper concept for an UTF-16 character type. */
+template <class _CharT>
+concept __utf16_character = (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2) || same_as<_CharT, char16_t>;
+
+/** Helper concept for an UTF-32 character type. */
+template <class _CharT>
+concept __utf32_character = (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 4) || same_as<_CharT, char32_t>;
+
+/** Helper concept for an UTF-16 or UTF-32 character type. */
+template <class _CharT>
+concept __utf16_or_32_character = __utf16_character<_CharT> || __utf32_character<_CharT>;
+
+/**
+ * Converts a code point to the column width.
+ *
+ * The estimations are conforming to [format.string.general]/11
+ *
+ * This version expects a value less than 0x1'0000, which is a 3-byte UTF-8
+ * character.
+ */
+_LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width_3(uint32_t __c) noexcept {
+  _LIBCPP_ASSERT(__c < 0x1'0000,
+                 "Use __column_width_4 or __column_width for larger values");
+
+  // clang-format off
+  return 1 + (__c >= 0x1100 && (__c <= 0x115f ||
+             (__c >= 0x2329 && (__c <= 0x232a ||
+             (__c >= 0x2e80 && (__c <= 0x303e ||
+             (__c >= 0x3040 && (__c <= 0xa4cf ||
+             (__c >= 0xac00 && (__c <= 0xd7a3 ||
+             (__c >= 0xf900 && (__c <= 0xfaff ||
+             (__c >= 0xfe10 && (__c <= 0xfe19 ||
+             (__c >= 0xfe30 && (__c <= 0xfe6f ||
+             (__c >= 0xff00 && (__c <= 0xff60 ||
+             (__c >= 0xffe0 && (__c <= 0xffe6
+             ))))))))))))))))))));
+  // clang-format on
+}
+
+/**
+ * @overload
+ *
+ * This version expects a value greater than or equal to 0x1'0000, which is a
+ * 4-byte UTF-8 character.
+ */
+_LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width_4(uint32_t __c) noexcept {
+  _LIBCPP_ASSERT(__c >= 0x1'0000,
+                 "Use __column_width_3 or __column_width for smaller values");
+
+  // clang-format off
+  return 1 + (__c >= 0x1'f300 && (__c <= 0x1'f64f ||
+             (__c >= 0x1'f900 && (__c <= 0x1'f9ff ||
+             (__c >= 0x2'0000 && (__c <= 0x2'fffd ||
+             (__c >= 0x3'0000 && (__c <= 0x3'fffd
+             ))))))));
+  // clang-format on
+}
+
+/**
+ * @overload
+ *
+ * The general case, accepting all values.
+ */
+_LIBCPP_HIDE_FROM_ABI inline constexpr int __column_width(uint32_t __c) noexcept {
+  if (__c < 0x1'0000)
+    return __column_width_3(__c);
+
+  return __column_width_4(__c);
+}
+
+/**
+ * Estimate the column width for the UTF-8 sequence using the fast algorithm.
+ */
+template <__utf8_character _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+__estimate_column_width_fast(const _CharT* __first,
+                             const _CharT* __last) noexcept {
+  return _VSTD::find_if(__first, __last,
+                        [](unsigned char __c) { return __c & 0x80; });
+}
+
+/**
+ * @overload
+ *
+ * The implementation for UTF-16/32.
+ */
+template <__utf16_or_32_character _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
+__estimate_column_width_fast(const _CharT* __first,
+                             const _CharT* __last) noexcept {
+  return _VSTD::find_if(__first, __last,
+                        [](uint32_t __c) { return __c >= 0x1100; });
+}
+
+template <class _CharT>
+struct _LIBCPP_TEMPLATE_VIS __column_width_result {
+  /** The number of output columns. */
+  size_t __width;
+  /**
+   * The last parsed element.
+   *
+   * This limits the original output to fit in the wanted number of columns.
+   */
+  const _CharT* __ptr;
+};
+
+/**
+ * Small helper to determine the width of malformed Unicode.
+ *
+ * @note This function's only needed for UTF-8. During scanning UTF-8 there
+ * are multiple place where it can be detected that the Unicode is malformed.
+ * UTF-16 only requires 1 test and UTF-32 requires no testing.
+ */
+template <__utf8_character _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
+__estimate_column_width_malformed(const _CharT* __first, const _CharT* __last,
+                                  size_t __maximum, size_t __result) noexcept {
+  size_t __size = __last - __first;
+  size_t __n = _VSTD::min(__size, __maximum);
+  return {__result + __n, __first + __n};
+}
+
+/**
+ * Determines the number of output columns needed to render the input.
+ *
+ * @note When the scanner encounters malformed Unicode it acts as-if every code
+ * unit at the end of the input is one output column. It's expected the output
+ * terminal will replace these malformed code units with a one column
+ * replacement characters.
+ *
+ * @param __first   Points to the first element of the input range.
+ * @param __last    Points beyond the last element of the input range.
+ * @param __maximum The maximum number of output columns. The returned number
+ *                  of estimated output columns will not exceed this value.
+ */
+template <__utf8_character _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
+__estimate_column_width(const _CharT* __first, const _CharT* __last,
+                        size_t __maximum) noexcept {
+  size_t __result = 0;
+
+  while (__first != __last) {
+    // Based on the number of leading 1 bits the number of code units in the
+    // code point can be determined. See
+    // https://en.wikipedia.org/wiki/UTF-8#Encoding
+    switch (_VSTD::countl_one(static_cast<unsigned char>(*__first))) {
+    case 0: // 1-code unit encoding: all 1 column
+      ++__result;
+      ++__first;
+      break;
+
+    case 2: // 2-code unit encoding: all 1 column
+      // Malformed Unicode.
+      if (__last - __first < 2) [[unlikely]]
+        return __estimate_column_width_malformed(__first, __last, __maximum,
+                                                 __result);
+      __first += 2;
+      ++__result;
+      break;
+
+    case 3: // 3-code unit encoding: either 1 or 2 columns
+      // Malformed Unicode.
+      if (__last - __first < 3) [[unlikely]]
+        return __estimate_column_width_malformed(__first, __last, __maximum,
+                                                 __result);
+      {
+        uint32_t __c = static_cast<unsigned char>(*__first++) & 0x0f;
+        __c <<= 6;
+        __c |= static_cast<unsigned char>(*__first++) & 0x3f;
+        __c <<= 6;
+        __c |= static_cast<unsigned char>(*__first++) & 0x3f;
+        __result += __column_width_3(__c);
+        if (__result > __maximum)
+          return {__result - 2, __first - 3};
+      }
+      break;
+    case 4: // 4-code unit encoding: either 1 or 2 columns
+      // Malformed Unicode.
+      if (__last - __first < 4) [[unlikely]]
+        return __estimate_column_width_malformed(__first, __last, __maximum,
+                                                 __result);
+      {
+        uint32_t __c = static_cast<unsigned char>(*__first++) & 0x07;
+        __c <<= 6;
+        __c |= static_cast<unsigned char>(*__first++) & 0x3f;
+        __c <<= 6;
+        __c |= static_cast<unsigned char>(*__first++) & 0x3f;
+        __c <<= 6;
+        __c |= static_cast<unsigned char>(*__first++) & 0x3f;
+        __result += __column_width_4(__c);
+        if (__result > __maximum)
+          return {__result - 2, __first - 4};
+      }
+      break;
+    default:
+      // Malformed Unicode.
+      return __estimate_column_width_malformed(__first, __last, __maximum,
+                                               __result);
+    }
+
+    if (__result >= __maximum)
+      return {__result, __first};
+  }
+  return {__result, __first};
+}
+
+template <__utf16_character _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
+__estimate_column_width(const _CharT* __first, const _CharT* __last,
+                        size_t __maximum) noexcept {
+  size_t __result = 0;
+
+  while (__first != __last) {
+    uint32_t __c = *__first;
+    // Is the code unit part of a surrogate pair? See
+    // https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF
+    if (__c >= 0xd800 && __c <= 0xDfff) {
+      // Malformed Unicode.
+      if (__last - __first < 2) [[unlikely]]
+        return {__result + 1, __first + 1};
+
+      __c -= 0xd800;
+      __c <<= 10;
+      __c += (*(__first + 1) - 0xdc00);
+      __c += 0x10'000;
+
+      __result += __column_width_4(__c);
+      if (__result > __maximum)
+        return {__result - 2, __first};
+      __first += 2;
+    } else {
+      __result += __column_width_3(__c);
+      if (__result > __maximum)
+        return {__result - 2, __first};
+      ++__first;
+    }
+
+    if (__result >= __maximum)
+      return {__result, __first};
+  }
+
+  return {__result, __first};
+}
+
+template <__utf32_character _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_CharT>
+__estimate_column_width(const _CharT* __first, const _CharT* __last,
+                        size_t __maximum) noexcept {
+  size_t __result = 0;
+
+  while (__first != __last) {
+    wchar_t __c = *__first;
+    __result += __column_width(__c);
+
+    if (__result > __maximum)
+      return {__result - 2, __first};
+
+    ++__first;
+    if (__result >= __maximum)
+      return {__result, __first};
+  }
+
+  return {__result, __first};
+}
+
+} // namespace __detail
+
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __string_alignment<_CharT>
+__get_string_alignment(const _CharT* __first, const _CharT* __last,
+                       ptrdiff_t __width, ptrdiff_t __precision) noexcept {
+  _LIBCPP_ASSERT(__width != 0 || __precision != -1,
+                 "The function has no effect and shouldn't be used");
+
+  // TODO FMT There might be more optimizations possible:
+  // If __precision == __format::__number_max and the encoding is:
+  // * UTF-8  : 4 * (__last - __first) >= __width
+  // * UTF-16 : 2 * (__last - __first) >= __width
+  // * UTF-32 : (__last - __first) >= __width
+  // In these cases it's certain the output is at least the requested width.
+  // It's unknown how often this happens in practice. For now the improvement
+  // isn't implemented.
+
+  /*
+   * First assume there are no special Unicode code units in the input.
+   * - Apply the precision (this may reduce the size of the input). When
+   *   __precison == -1 this step is omitted.
+   * - Scan for special code units in the input.
+   * If our assumption was correct the __pos will be at the end of the input.
+   */
+  const ptrdiff_t __length = __last - __first;
+  const _CharT* __limit =
+      __first +
+      (__precision == -1 ? __length : _VSTD::min(__length, __precision));
+  ptrdiff_t __size = __limit - __first;
+  const _CharT* __pos =
+      __detail::__estimate_column_width_fast(__first, __limit);
+
+  if (__pos == __limit)
+    return {__limit, __size, __size < __width};
+
+  /*
+   * Our assumption was wrong, there are special Unicode code units.
+   * The range [__first, __pos) contains a set of code units with the
+   * following property:
+   *      Every _CharT in the range will be rendered in 1 column.
+   *
+   * If there's no maximum width and the parsed size already exceeds the
+   *   minimum required width. The real size isn't important. So bail out.
+   */
+  if (__precision == -1 && (__pos - __first) >= __width)
+    return {__last, 0, false};
+
+  /* If there's a __precision, truncate the output to that width. */
+  ptrdiff_t __prefix = __pos - __first;
+  if (__precision != -1) {
+    _LIBCPP_ASSERT(__precision > __prefix, "Logic error.");
+    auto __lengh_info = __detail::__estimate_column_width(
+        __pos, __last, __precision - __prefix);
+    __size = __lengh_info.__width + __prefix;
+    return {__lengh_info.__ptr, __size, __size < __width};
+  }
+
+  /* Else use __width to determine the number of required padding characters. */
+  _LIBCPP_ASSERT(__width > __prefix, "Logic error.");
+  /*
+   * The column width is always one or two columns. For the precision the wanted
+   * column width is the maximum, for the width it's the minimum. Using the
+   * width estimation with its truncating behavior will result in the wrong
+   * result in the following case:
+   * - The last code unit processed requires two columns and exceeds the
+   *   maximum column width.
+   * By increasing the __maximum by one avoids this issue. (It means it may
+   * pass one code point more than required to determine the proper result;
+   * that however isn't a problem for the algorithm.)
+   */
+  size_t __maximum = 1 + __width - __prefix;
+  auto __lengh_info =
+      __detail::__estimate_column_width(__pos, __last, __maximum);
+  if (__lengh_info.__ptr != __last) {
+    // Consumed the width number of code units. The exact size of the string
+    // is unknown. We only know we don't need to align the output.
+    _LIBCPP_ASSERT(static_cast<ptrdiff_t>(__lengh_info.__width + __prefix) >=
+                       __width,
+                   "Logic error");
+    return {__last, 0, false};
+  }
+
+  __size = __lengh_info.__width + __prefix;
+  return {__last, __size, __size < __width};
+}
+#else  // _LIBCPP_HAS_NO_UNICODE
+template <class _CharT>
+_LIBCPP_HIDE_FROM_ABI constexpr __string_alignment<_CharT>
+__get_string_alignment(const _CharT* __first, const _CharT* __last,
+                       ptrdiff_t __width, ptrdiff_t __precision) noexcept {
+  const ptrdiff_t __length = __last - __first;
+  const _CharT* __limit =
+      __first +
+      (__precision == -1 ? __length : _VSTD::min(__length, __precision));
+  ptrdiff_t __size = __limit - __first;
+  return {__limit, __size, __size < __width};
+}
+#endif // _LIBCPP_HAS_NO_UNICODE
+
+} // namespace __format_spec
+
+# endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#endif //_LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___FORMAT_PARSER_STD_FORMAT_SPEC_H
lib/libcxx/include/__functional/bind.h
@@ -11,8 +11,8 @@
 #define _LIBCPP___FUNCTIONAL_BIND_H
 
 #include <__config>
-#include <__functional/weak_result_type.h>
 #include <__functional/invoke.h>
+#include <__functional/weak_result_type.h>
 #include <cstddef>
 #include <tuple>
 #include <type_traits>
@@ -23,22 +23,28 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template<class _Tp> struct __is_bind_expression : public false_type {};
-template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
-    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
+template<class _Tp>
+struct is_bind_expression : _If<
+    _IsSame<_Tp, typename __uncvref<_Tp>::type>::value,
+    false_type,
+    is_bind_expression<typename __uncvref<_Tp>::type>
+> {};
 
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
+inline constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
 #endif
 
-template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
-template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
-    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
+template<class _Tp>
+struct is_placeholder : _If<
+    _IsSame<_Tp, typename __uncvref<_Tp>::type>::value,
+    integral_constant<int, 0>,
+    is_placeholder<typename __uncvref<_Tp>::type>
+> {};
 
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
+inline constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
 #endif
 
 namespace placeholders
@@ -58,22 +64,22 @@ _LIBCPP_FUNC_VIS extern const __ph<8>   _8;
 _LIBCPP_FUNC_VIS extern const __ph<9>   _9;
 _LIBCPP_FUNC_VIS extern const __ph<10> _10;
 #else
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<1>   _1{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<2>   _2{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<3>   _3{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<4>   _4{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<5>   _5{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<6>   _6{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<7>   _7{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<8>   _8{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<9>   _9{};
-/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
+/* inline */ constexpr __ph<1>   _1{};
+/* inline */ constexpr __ph<2>   _2{};
+/* inline */ constexpr __ph<3>   _3{};
+/* inline */ constexpr __ph<4>   _4{};
+/* inline */ constexpr __ph<5>   _5{};
+/* inline */ constexpr __ph<6>   _6{};
+/* inline */ constexpr __ph<7>   _7{};
+/* inline */ constexpr __ph<8>   _8{};
+/* inline */ constexpr __ph<9>   _9{};
+/* inline */ constexpr __ph<10> _10{};
 #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
 
-}  // placeholders
+} // namespace placeholders
 
 template<int _Np>
-struct __is_placeholder<placeholders::__ph<_Np> >
+struct is_placeholder<placeholders::__ph<_Np> >
     : public integral_constant<int, _Np> {};
 
 
@@ -97,7 +103,7 @@ __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
 
 template <class _Ti, class ..._Uj>
 inline _LIBCPP_INLINE_VISIBILITY
-typename _EnableIf
+typename __enable_if_t
 <
     is_bind_expression<_Ti>::value,
     __invoke_of<_Ti&, _Uj...>
@@ -304,7 +310,7 @@ public:
 };
 
 template<class _Fp, class ..._BoundArgs>
-struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
+struct is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
 
 template<class _Rp, class _Fp, class ..._BoundArgs>
 class __bind_r
@@ -359,7 +365,7 @@ public:
 };
 
 template<class _Rp, class _Fp, class ..._BoundArgs>
-struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
+struct is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
 
 template<class _Fp, class ..._BoundArgs>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
lib/libcxx/include/__functional/bind_back.h
@@ -0,0 +1,65 @@
+// -*- 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___FUNCTIONAL_BIND_BACK_H
+#define _LIBCPP___FUNCTIONAL_BIND_BACK_H
+
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/perfect_forward.h>
+#include <__utility/forward.h>
+#include <__utility/integer_sequence.h>
+#include <tuple>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+template <size_t _NBound, class = make_index_sequence<_NBound>>
+struct __bind_back_op;
+
+template <size_t _NBound, size_t ..._Ip>
+struct __bind_back_op<_NBound, index_sequence<_Ip...>> {
+    template <class _Fn, class _Bound, class ..._Args>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Fn&& __f, _Bound&& __bound, _Args&& ...__args) const
+        noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...)))
+        -> decltype(      _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...))
+        { return          _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...); }
+};
+
+template <class _Fn, class _BoundArgs>
+struct __bind_back_t : __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs> {
+    using __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs>::__perfect_forward;
+};
+
+template <class _Fn, class ..._Args, class = enable_if_t<
+    _And<
+        is_constructible<decay_t<_Fn>, _Fn>,
+        is_move_constructible<decay_t<_Fn>>,
+        is_constructible<decay_t<_Args>, _Args>...,
+        is_move_constructible<decay_t<_Args>>...
+    >::value
+>>
+_LIBCPP_HIDE_FROM_ABI
+constexpr auto __bind_back(_Fn&& __f, _Args&&... __args)
+    noexcept(noexcept(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...))))
+    -> decltype(      __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)))
+    { return          __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); }
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FUNCTIONAL_BIND_BACK_H
lib/libcxx/include/__functional/bind_front.h
@@ -11,8 +11,8 @@
 #define _LIBCPP___FUNCTIONAL_BIND_FRONT_H
 
 #include <__config>
-#include <__functional/perfect_forward.h>
 #include <__functional/invoke.h>
+#include <__functional/perfect_forward.h>
 #include <type_traits>
 #include <utility>
 
@@ -24,25 +24,31 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 17
 
-struct __bind_front_op
-{
-    template<class... _Args>
-    constexpr static auto __call(_Args&&... __args)
-    noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
-    -> decltype(      _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
-    { return          _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
+struct __bind_front_op {
+    template <class ..._Args>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Args&& ...__args) const
+        noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
+        -> decltype(      _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
+        { return          _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
+};
+
+template <class _Fn, class ..._BoundArgs>
+struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> {
+    using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward;
 };
 
-template<class _Fn, class... _Args,
-         class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
-                                       is_move_constructible<decay_t<_Fn>>,
-                                       is_constructible<decay_t<_Args>, _Args>...,
-                                       is_move_constructible<decay_t<_Args>>...
-                                       >::value>>
-constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
-{
-    return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
-                                                             _VSTD::forward<_Args>(__args)...);
+template <class _Fn, class... _Args, class = enable_if_t<
+    _And<
+        is_constructible<decay_t<_Fn>, _Fn>,
+        is_move_constructible<decay_t<_Fn>>,
+        is_constructible<decay_t<_Args>, _Args>...,
+        is_move_constructible<decay_t<_Args>>...
+    >::value
+>>
+_LIBCPP_HIDE_FROM_ABI
+constexpr auto bind_front(_Fn&& __f, _Args&&... __args) {
+    return __bind_front_t<decay_t<_Fn>, decay_t<_Args>...>(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
 }
 
 #endif // _LIBCPP_STD_VER > 17
lib/libcxx/include/__functional/compose.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___FUNCTIONAL_COMPOSE_H
+#define _LIBCPP___FUNCTIONAL_COMPOSE_H
+
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/perfect_forward.h>
+#include <__utility/forward.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17
+
+struct __compose_op {
+    template<class _Fn1, class _Fn2, class ..._Args>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Fn1&& __f1, _Fn2&& __f2, _Args&&... __args) const
+        noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...))))
+        -> decltype(      _VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...)))
+        { return          _VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...)); }
+};
+
+template <class _Fn1, class _Fn2>
+struct __compose_t : __perfect_forward<__compose_op, _Fn1, _Fn2> {
+    using __perfect_forward<__compose_op, _Fn1, _Fn2>::__perfect_forward;
+};
+
+template <class _Fn1, class _Fn2>
+_LIBCPP_HIDE_FROM_ABI
+constexpr auto __compose(_Fn1&& __f1, _Fn2&& __f2)
+    noexcept(noexcept(__compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2))))
+    -> decltype(      __compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2)))
+    { return          __compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2)); }
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FUNCTIONAL_COMPOSE_H
lib/libcxx/include/__functional/function.h
@@ -11,10 +11,12 @@
 #define _LIBCPP___FUNCTIONAL_FUNCTION_H
 
 #include <__config>
+#include <__debug>
 #include <__functional/binary_function.h>
 #include <__functional/invoke.h>
 #include <__functional/unary_function.h>
 #include <__iterator/iterator_traits.h>
+#include <__memory/addressof.h>
 #include <__memory/allocator_traits.h>
 #include <__memory/compressed_pair.h>
 #include <__memory/shared_ptr.h>
@@ -34,10 +36,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 class _LIBCPP_EXCEPTION_ABI bad_function_call
     : public exception
 {
-#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
 public:
+// Note that when a key function is not used, every translation unit that uses
+// bad_function_call will end up containing a weak definition of the vtable and
+// typeinfo.
+#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
     virtual ~bad_function_call() _NOEXCEPT;
+#else
+    virtual ~bad_function_call() _NOEXCEPT {}
+#endif
 
+#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
     virtual const char* what() const _NOEXCEPT;
 #endif
 };
@@ -126,8 +135,8 @@ class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
     __compressed_pair<_Fp, _Ap> __f_;
 
   public:
-    typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
-    typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
+    typedef _LIBCPP_NODEBUG _Fp _Target;
+    typedef _LIBCPP_NODEBUG _Ap _Alloc;
 
     _LIBCPP_INLINE_VISIBILITY
     const _Target& __target() const { return __f_.first(); }
@@ -204,7 +213,7 @@ class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
   _Fp __f_;
 
 public:
-  typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
+  typedef _LIBCPP_NODEBUG _Fp _Target;
 
   _LIBCPP_INLINE_VISIBILITY
   const _Target& __target() const { return __f_; }
@@ -352,7 +361,7 @@ const void*
 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
 {
     if (__ti == typeid(_Fp))
-        return &__f_.__target();
+        return _VSTD::addressof(__f_.__target());
     return nullptr;
 }
 
@@ -938,7 +947,7 @@ public:
 
 #endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
 
-}  // __function
+} // namespace __function
 
 template<class _Rp, class ..._ArgTypes>
 class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
@@ -1044,7 +1053,7 @@ public:
 #endif // _LIBCPP_NO_RTTI
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _Rp, class ..._Ap>
 function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
 
@@ -1089,7 +1098,7 @@ struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { usin
 
 template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
 function(_Fp) -> function<_Stripped>;
-#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#endif // _LIBCPP_STD_VER >= 17
 
 template<class _Rp, class ..._ArgTypes>
 function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
@@ -1384,7 +1393,7 @@ const void*
 __func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const
 {
     if (__ti == typeid(_Fp))
-        return &__f_.first();
+        return _VSTD::addressof(__f_.first());
     return (const void*)0;
 }
 
@@ -1655,7 +1664,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const
 
 #endif // _LIBCPP_NO_RTTI
 
-}  // __function
+} // namespace __function
 
 template<class _Rp>
 class _LIBCPP_TEMPLATE_VIS function<_Rp()>
@@ -1709,13 +1718,11 @@ public:
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2>
-      bool operator==(const function<_R2()>&) const;// = delete;
+      bool operator==(const function<_R2()>&) const = delete;
     template<class _R2>
-      bool operator!=(const function<_R2()>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2()>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()() const;
 
@@ -1989,13 +1996,11 @@ public:
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2, class _B0>
-      bool operator==(const function<_R2(_B0)>&) const;// = delete;
+      bool operator==(const function<_R2(_B0)>&) const = delete;
     template<class _R2, class _B0>
-      bool operator!=(const function<_R2(_B0)>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2(_B0)>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()(_A0) const;
 
@@ -2269,13 +2274,11 @@ public:
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2, class _B0, class _B1>
-      bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
+      bool operator==(const function<_R2(_B0, _B1)>&) const = delete;
     template<class _R2, class _B0, class _B1>
-      bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2(_B0, _B1)>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()(_A0, _A1) const;
 
@@ -2548,13 +2551,11 @@ public:
     // 20.7.16.2.3, function capacity:
     _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
 
-private:
-    // deleted overloads close possible hole in the type system
     template<class _R2, class _B0, class _B1, class _B2>
-      bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
+      bool operator==(const function<_R2(_B0, _B1, _B2)>&) const = delete;
     template<class _R2, class _B0, class _B1, class _B2>
-      bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
-public:
+      bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const = delete;
+
     // 20.7.16.2.4, function invocation:
     _Rp operator()(_A0, _A1, _A2) const;
 
lib/libcxx/include/__functional/hash.h
@@ -16,9 +16,9 @@
 #include <__utility/move.h>
 #include <__utility/pair.h>
 #include <__utility/swap.h>
+#include <cstddef>
 #include <cstdint>
 #include <cstring>
-#include <cstddef>
 #include <limits>
 #include <type_traits>
 
@@ -26,9 +26,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Size>
@@ -564,6 +561,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
 
 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <>
 struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
@@ -579,6 +577,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
     _LIBCPP_INLINE_VISIBILITY
     size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <>
@@ -839,35 +838,33 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
 
 #ifndef _LIBCPP_CXX03_LANG
 template <class _Key, class _Hash>
-using __check_hash_requirements _LIBCPP_NODEBUG_TYPE  = integral_constant<bool,
+using __check_hash_requirements _LIBCPP_NODEBUG = integral_constant<bool,
     is_copy_constructible<_Hash>::value &&
     is_move_constructible<_Hash>::value &&
     __invokable_r<size_t, _Hash, _Key const&>::value
 >;
 
 template <class _Key, class _Hash = hash<_Key> >
-using __has_enabled_hash _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
+using __has_enabled_hash _LIBCPP_NODEBUG = integral_constant<bool,
     __check_hash_requirements<_Key, _Hash>::value &&
     is_default_constructible<_Hash>::value
 >;
 
 #if _LIBCPP_STD_VER > 14
 template <class _Type, class>
-using __enable_hash_helper_imp _LIBCPP_NODEBUG_TYPE  = _Type;
+using __enable_hash_helper_imp _LIBCPP_NODEBUG = _Type;
 
 template <class _Type, class ..._Keys>
-using __enable_hash_helper _LIBCPP_NODEBUG_TYPE  = __enable_hash_helper_imp<_Type,
+using __enable_hash_helper _LIBCPP_NODEBUG = __enable_hash_helper_imp<_Type,
   typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type
 >;
 #else
 template <class _Type, class ...>
-using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type;
+using __enable_hash_helper _LIBCPP_NODEBUG = _Type;
 #endif
 
 #endif // !_LIBCPP_CXX03_LANG
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___FUNCTIONAL_HASH_H
lib/libcxx/include/__functional/mem_fn.h
@@ -11,9 +11,9 @@
 #define _LIBCPP___FUNCTIONAL_MEM_FN_H
 
 #include <__config>
-#include <__functional/weak_result_type.h>
 #include <__functional/binary_function.h>
 #include <__functional/invoke.h>
+#include <__functional/weak_result_type.h>
 #include <utility>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__functional/mem_fun_ref.h
@@ -11,8 +11,8 @@
 #define _LIBCPP___FUNCTIONAL_MEM_FUN_REF_H
 
 #include <__config>
-#include <__functional/unary_function.h>
 #include <__functional/binary_function.h>
+#include <__functional/unary_function.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/__functional/not_fn.h
@@ -11,8 +11,8 @@
 #define _LIBCPP___FUNCTIONAL_NOT_FN_H
 
 #include <__config>
-#include <__functional/perfect_forward.h>
 #include <__functional/invoke.h>
+#include <__functional/perfect_forward.h>
 #include <utility>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -23,21 +23,27 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
 
-struct __not_fn_op
-{
-    template<class... _Args>
-    static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
-    noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
-    -> decltype(      !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
-    { return          !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
+struct __not_fn_op {
+    template <class... _Args>
+    _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_CONSTEXPR_AFTER_CXX17 auto operator()(_Args&&... __args) const
+        noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
+        -> decltype(      !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
+        { return          !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
+};
+
+template <class _Fn>
+struct __not_fn_t : __perfect_forward<__not_fn_op, _Fn> {
+    using __perfect_forward<__not_fn_op, _Fn>::__perfect_forward;
 };
 
-template<class _Fn,
-         class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
-                           is_move_constructible_v<_Fn>>>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
-{
-    return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
+template <class _Fn, class = enable_if_t<
+    is_constructible_v<decay_t<_Fn>, _Fn> &&
+    is_move_constructible_v<decay_t<_Fn>>
+>>
+_LIBCPP_HIDE_FROM_ABI
+_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) {
+    return __not_fn_t<decay_t<_Fn>>(_VSTD::forward<_Fn>(__f));
 }
 
 #endif // _LIBCPP_STD_VER > 14
lib/libcxx/include/__functional/operations.h
@@ -53,9 +53,9 @@ struct _LIBCPP_TEMPLATE_VIS plus<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -90,9 +90,9 @@ struct _LIBCPP_TEMPLATE_VIS minus<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -127,9 +127,9 @@ struct _LIBCPP_TEMPLATE_VIS multiplies<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -164,9 +164,9 @@ struct _LIBCPP_TEMPLATE_VIS divides<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -201,9 +201,9 @@ struct _LIBCPP_TEMPLATE_VIS modulus<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -237,9 +237,9 @@ struct _LIBCPP_TEMPLATE_VIS negate<void>
     template <class _Tp>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_Tp&& __x) const
-    _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
-    -> decltype        (- _VSTD::forward<_Tp>(__x))
-        { return        - _VSTD::forward<_Tp>(__x); }
+        noexcept(noexcept(- _VSTD::forward<_Tp>(__x)))
+        -> decltype(      - _VSTD::forward<_Tp>(__x))
+        { return          - _VSTD::forward<_Tp>(__x); }
     typedef void is_transparent;
 };
 #endif
@@ -276,9 +276,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_and<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -307,9 +307,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_not<void>
     template <class _Tp>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_Tp&& __x) const
-    _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
-    -> decltype        (~_VSTD::forward<_Tp>(__x))
-        { return        ~_VSTD::forward<_Tp>(__x); }
+        noexcept(noexcept(~_VSTD::forward<_Tp>(__x)))
+        -> decltype(      ~_VSTD::forward<_Tp>(__x))
+        { return          ~_VSTD::forward<_Tp>(__x); }
     typedef void is_transparent;
 };
 #endif
@@ -344,9 +344,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_or<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -381,9 +381,9 @@ struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -420,9 +420,9 @@ struct _LIBCPP_TEMPLATE_VIS equal_to<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -457,9 +457,9 @@ struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -494,9 +494,9 @@ struct _LIBCPP_TEMPLATE_VIS less<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -531,9 +531,9 @@ struct _LIBCPP_TEMPLATE_VIS less_equal<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -568,9 +568,9 @@ struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -605,9 +605,9 @@ struct _LIBCPP_TEMPLATE_VIS greater<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -644,9 +644,9 @@ struct _LIBCPP_TEMPLATE_VIS logical_and<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
@@ -680,9 +680,9 @@ struct _LIBCPP_TEMPLATE_VIS logical_not<void>
     template <class _Tp>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_Tp&& __x) const
-    _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
-    -> decltype        (!_VSTD::forward<_Tp>(__x))
-        { return        !_VSTD::forward<_Tp>(__x); }
+        noexcept(noexcept(!_VSTD::forward<_Tp>(__x)))
+        -> decltype(      !_VSTD::forward<_Tp>(__x))
+        { return          !_VSTD::forward<_Tp>(__x); }
     typedef void is_transparent;
 };
 #endif
@@ -717,9 +717,9 @@ struct _LIBCPP_TEMPLATE_VIS logical_or<void>
     template <class _T1, class _T2>
     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
     auto operator()(_T1&& __t, _T2&& __u) const
-    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
-    -> decltype        (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
-        { return        _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
+        noexcept(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
+        -> decltype(      _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
+        { return          _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
     typedef void is_transparent;
 };
 #endif
lib/libcxx/include/__functional/perfect_forward.h
@@ -11,9 +11,11 @@
 #define _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H
 
 #include <__config>
+#include <__utility/declval.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
 #include <tuple>
 #include <type_traits>
-#include <utility>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -23,63 +25,68 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
 
-template<class _Op, class _Tuple,
-         class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
+template <class _Op, class _Indices, class ..._Bound>
 struct __perfect_forward_impl;
 
-template<class _Op, class... _Bound, size_t... _Idxs>
-struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
-{
+template <class _Op, size_t ..._Idx, class ..._Bound>
+struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _Bound...> {
+private:
     tuple<_Bound...> __bound_;
 
-    template<class... _Args>
-    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
-    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
-    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
-    {return           _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
-
-    template<class... _Args>
-    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
-    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
-    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
-    {return           _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
-
-    template<class... _Args>
-    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
-    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
-                                  _VSTD::forward<_Args>(__args)...)))
-    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
-                                  _VSTD::forward<_Args>(__args)...))
-    {return           _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
-                                  _VSTD::forward<_Args>(__args)...);}
-
-    template<class... _Args>
-    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
-    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
-                                  _VSTD::forward<_Args>(__args)...)))
-    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
-                                  _VSTD::forward<_Args>(__args)...))
-    {return           _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
-                                  _VSTD::forward<_Args>(__args)...);}
-
-    template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
-             class = _EnableIf<is_copy_constructible_v<_Fn>>>
-    constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
-        : __bound_(__other.__bound_) {}
-
-    template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
-             class = _EnableIf<is_move_constructible_v<_Fn>>>
-    constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
-        : __bound_(_VSTD::move(__other.__bound_)) {}
-
-    template<class... _BoundArgs>
-    explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
-        __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
+public:
+    template <class ..._BoundArgs, class = enable_if_t<
+        is_constructible_v<tuple<_Bound...>, _BoundArgs&&...>
+    >>
+    explicit constexpr __perfect_forward_impl(_BoundArgs&& ...__bound)
+        : __bound_(_VSTD::forward<_BoundArgs>(__bound)...)
+    { }
+
+    __perfect_forward_impl(__perfect_forward_impl const&) = default;
+    __perfect_forward_impl(__perfect_forward_impl&&) = default;
+
+    __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default;
+    __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default;
+
+    template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound&..., _Args...>>>
+    _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &
+        noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
+        -> decltype(      _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))
+        { return          _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); }
+
+    template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound&..., _Args...>>>
+    auto operator()(_Args&&...) & = delete;
+
+    template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound const&..., _Args...>>>
+    _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&
+        noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
+        -> decltype(      _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))
+        { return          _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); }
+
+    template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound const&..., _Args...>>>
+    auto operator()(_Args&&...) const& = delete;
+
+    template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound..., _Args...>>>
+    _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &&
+        noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)))
+        -> decltype(      _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))
+        { return          _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); }
+
+    template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound..., _Args...>>>
+    auto operator()(_Args&&...) && = delete;
+
+    template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound const..., _Args...>>>
+    _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&&
+        noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)))
+        -> decltype(      _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))
+        { return          _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); }
+
+    template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound const..., _Args...>>>
+    auto operator()(_Args&&...) const&& = delete;
 };
 
-template<class _Op, class... _Args>
-using __perfect_forward =
-    __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
+// __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require].
+template <class _Op, class ..._Args>
+using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>;
 
 #endif // _LIBCPP_STD_VER > 14
 
lib/libcxx/include/__functional/ranges_operations.h
@@ -20,7 +20,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
 namespace ranges {
 
 struct equal_to {
@@ -90,7 +91,7 @@ struct greater_equal {
 };
 
 } // namespace ranges
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/__functional/reference_wrapper.h
@@ -34,25 +34,16 @@ public:
 private:
     type* __f_;
 
-#ifndef _LIBCPP_CXX03_LANG
     static void __fun(_Tp&) _NOEXCEPT;
     static void __fun(_Tp&&) = delete;
-#endif
 
 public:
-    // construct/copy/destroy
-#ifdef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    reference_wrapper(type& __f) _NOEXCEPT
-        : __f_(_VSTD::addressof(__f)) {}
-#else
-    template <class _Up, class = _EnableIf<!__is_same_uncvref<_Up, reference_wrapper>::value, decltype(__fun(declval<_Up>())) >>
+    template <class _Up, class = __enable_if_t<!__is_same_uncvref<_Up, reference_wrapper>::value, decltype(__fun(declval<_Up>())) > >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(declval<_Up>()))) {
         type& __f = static_cast<_Up&&>(__u);
         __f_ = _VSTD::addressof(__f);
     }
-#endif
 
     // access
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
@@ -176,7 +167,7 @@ public:
 #endif // _LIBCPP_CXX03_LANG
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
 reference_wrapper(_Tp&) -> reference_wrapper<_Tp>;
 #endif
@@ -194,7 +185,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 reference_wrapper<_Tp>
 ref(reference_wrapper<_Tp> __t) _NOEXCEPT
 {
-    return _VSTD::ref(__t.get());
+    return __t;
 }
 
 template <class _Tp>
@@ -210,13 +201,11 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 reference_wrapper<const _Tp>
 cref(reference_wrapper<_Tp> __t) _NOEXCEPT
 {
-    return _VSTD::cref(__t.get());
+    return __t;
 }
 
-#ifndef _LIBCPP_CXX03_LANG
 template <class _Tp> void ref(const _Tp&&) = delete;
 template <class _Tp> void cref(const _Tp&&) = delete;
-#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/__functional/unary_function.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Arg, class _Result>
@@ -29,6 +26,4 @@ struct _LIBCPP_TEMPLATE_VIS unary_function
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___FUNCTIONAL_UNARY_FUNCTION_H
lib/libcxx/include/__functional/unwrap_ref.h
@@ -15,19 +15,16 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
-struct __unwrap_reference { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
+struct __unwrap_reference { typedef _LIBCPP_NODEBUG _Tp type; };
 
 template <class _Tp>
 class reference_wrapper;
 
 template <class _Tp>
-struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; };
+struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG _Tp& type; };
 
 template <class _Tp>
 struct decay;
@@ -57,6 +54,4 @@ struct __unwrap_ref_decay
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___FUNCTIONAL_UNWRAP_REF_H
lib/libcxx/include/__functional/weak_result_type.h
@@ -89,7 +89,7 @@ struct __weak_result_type_imp // bool is true
     : public __maybe_derive_from_unary_function<_Tp>,
       public __maybe_derive_from_binary_function<_Tp>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename _Tp::result_type result_type;
+    typedef _LIBCPP_NODEBUG typename _Tp::result_type result_type;
 };
 
 template <class _Tp>
@@ -110,19 +110,19 @@ struct __weak_result_type
 template <class _Rp>
 struct __weak_result_type<_Rp ()>
 {
-    typedef _LIBCPP_NODEBUG_TYPE  _Rp result_type;
+    typedef _LIBCPP_NODEBUG _Rp result_type;
 };
 
 template <class _Rp>
 struct __weak_result_type<_Rp (&)()>
 {
-    typedef _LIBCPP_NODEBUG_TYPE  _Rp result_type;
+    typedef _LIBCPP_NODEBUG _Rp result_type;
 };
 
 template <class _Rp>
 struct __weak_result_type<_Rp (*)()>
 {
-    typedef _LIBCPP_NODEBUG_TYPE  _Rp result_type;
+    typedef _LIBCPP_NODEBUG _Rp result_type;
 };
 
 // 1 argument case
lib/libcxx/include/__iterator/access.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp, size_t _Np>
@@ -129,6 +126,4 @@ end(const _Cp& __c)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ACCESS_H
lib/libcxx/include/__iterator/advance.h
@@ -12,13 +12,12 @@
 
 #include <__config>
 #include <__debug>
-#include <__function_like.h>
 #include <__iterator/concepts.h>
 #include <__iterator/incrementable_traits.h>
 #include <__iterator/iterator_traits.h>
 #include <__utility/move.h>
-#include <cstdlib>
 #include <concepts>
+#include <cstdlib>
 #include <limits>
 #include <type_traits>
 
@@ -26,9 +25,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIter>
@@ -58,7 +54,7 @@ void __advance(_RandIter& __i, typename iterator_traits<_RandIter>::difference_t
 template <
     class _InputIter, class _Distance,
     class _IntegralDistance = decltype(_VSTD::__convert_to_integral(declval<_Distance>())),
-    class = _EnableIf<is_integral<_IntegralDistance>::value> >
+    class = __enable_if_t<is_integral<_IntegralDistance>::value> >
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
 void advance(_InputIter& __i, _Distance __orig_n) {
   typedef typename iterator_traits<_InputIter>::difference_type _Difference;
@@ -68,18 +64,15 @@ void advance(_InputIter& __i, _Distance __orig_n) {
   _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
 }
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
-namespace ranges {
 // [range.iter.op.advance]
-struct __advance_fn final : private __function_like {
-private:
-  template <class _Tp>
-  _LIBCPP_HIDE_FROM_ABI
-  static constexpr _Tp __magnitude_geq(_Tp __a, _Tp __b) noexcept {
-    return __a < 0 ? (__a <= __b) : (__a >= __b);
-  }
 
+namespace ranges {
+namespace __advance {
+
+struct __fn {
+private:
   template <class _Ip>
   _LIBCPP_HIDE_FROM_ABI
   static constexpr void __advance_forward(_Ip& __i, iter_difference_t<_Ip> __n) {
@@ -99,8 +92,6 @@ private:
   }
 
 public:
-  constexpr explicit __advance_fn(__tag __x) noexcept : __function_like(__x) {}
-
   // Preconditions: If `I` does not model `bidirectional_iterator`, `n` is not negative.
   template <input_or_output_iterator _Ip>
   _LIBCPP_HIDE_FROM_ABI
@@ -158,6 +149,12 @@ public:
     // If `S` and `I` model `sized_sentinel_for<S, I>`:
     if constexpr (sized_sentinel_for<_Sp, _Ip>) {
       // If |n| >= |bound - i|, equivalent to `ranges::advance(i, bound)`.
+      // __magnitude_geq(a, b) returns |a| >= |b|, assuming they have the same sign.
+      auto __magnitude_geq = [](auto __a, auto __b) {
+        return __a == 0 ? __b == 0 :
+               __a > 0  ? __a >= __b :
+                          __a <= __b;
+      };
       if (const auto __M = __bound - __i; __magnitude_geq(__n, __M)) {
         (*this)(__i, __bound);
         return __n - __M;
@@ -188,13 +185,15 @@ public:
   }
 };
 
-inline constexpr auto advance = __advance_fn(__function_like::__tag());
+} // namespace __advance
+
+inline namespace __cpo {
+  inline constexpr auto advance = __advance::__fn{};
+} // namespace __cpo
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ADVANCE_H
lib/libcxx/include/__iterator/back_insert_iterator.h
@@ -21,9 +21,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -48,20 +45,20 @@ public:
     typedef void reference;
     typedef _Container container_type;
 
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
         {container->push_back(__value_); return *this;}
 #ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
         {container->push_back(_VSTD::move(__value_)); return *this;}
 #endif // _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
 };
 
 template <class _Container>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
 back_insert_iterator<_Container>
 back_inserter(_Container& __x)
 {
@@ -70,6 +67,4 @@ back_inserter(_Container& __x)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_BACK_INSERT_ITERATOR_H
lib/libcxx/include/__iterator/common_iterator.h
@@ -25,12 +25,14 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template<class _Iter>
+concept __can_use_postfix_proxy =
+  constructible_from<iter_value_t<_Iter>, iter_reference_t<_Iter>> &&
+  move_constructible<iter_value_t<_Iter>>;
 
 template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent>
   requires (!same_as<_Iter, _Sent> && copyable<_Iter>)
@@ -44,7 +46,7 @@ class common_iterator {
       : __value(_VSTD::move(__x)) {}
 
   public:
-    const iter_value_t<_Iter>* operator->() const {
+    constexpr const iter_value_t<_Iter>* operator->() const noexcept {
       return _VSTD::addressof(__value);
     }
   };
@@ -57,11 +59,7 @@ class common_iterator {
       : __value(_VSTD::forward<iter_reference_t<_Iter>>(__x)) {}
 
   public:
-    constexpr static bool __valid_for_iter =
-      constructible_from<iter_value_t<_Iter>, iter_reference_t<_Iter>> &&
-      move_constructible<iter_value_t<_Iter>>;
-
-    const iter_value_t<_Iter>& operator*() const {
+    constexpr const iter_value_t<_Iter>& operator*() const noexcept {
       return __value;
     }
   };
@@ -78,7 +76,7 @@ public:
     requires convertible_to<const _I2&, _Iter> && convertible_to<const _S2&, _Sent>
   constexpr common_iterator(const common_iterator<_I2, _S2>& __other)
     : __hold_([&]() -> variant<_Iter, _Sent> {
-      _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Constructed from valueless iterator.");
+      _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Attempted to construct from a valueless common_iterator");
       if (__other.__hold_.index() == 0)
         return variant<_Iter, _Sent>{in_place_index<0>, _VSTD::__unchecked_get<0>(__other.__hold_)};
       return variant<_Iter, _Sent>{in_place_index<1>, _VSTD::__unchecked_get<1>(__other.__hold_)};
@@ -88,7 +86,7 @@ public:
     requires convertible_to<const _I2&, _Iter> && convertible_to<const _S2&, _Sent> &&
              assignable_from<_Iter&, const _I2&> && assignable_from<_Sent&, const _S2&>
   common_iterator& operator=(const common_iterator<_I2, _S2>& __other) {
-    _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Assigned from valueless iterator.");
+    _LIBCPP_ASSERT(!__other.__hold_.valueless_by_exception(), "Attempted to assign from a valueless common_iterator");
 
     auto __idx = __hold_.index();
     auto __other_idx = __other.__hold_.index();
@@ -108,18 +106,16 @@ public:
     return *this;
   }
 
-  decltype(auto) operator*()
+  constexpr decltype(auto) operator*()
   {
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
-                   "Cannot dereference sentinel. Common iterator not holding an iterator.");
+    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator");
     return *_VSTD::__unchecked_get<_Iter>(__hold_);
   }
 
-  decltype(auto) operator*() const
+  constexpr decltype(auto) operator*() const
     requires __dereferenceable<const _Iter>
   {
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
-                   "Cannot dereference sentinel. Common iterator not holding an iterator.");
+    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator");
     return *_VSTD::__unchecked_get<_Iter>(__hold_);
   }
 
@@ -130,9 +126,7 @@ public:
      is_reference_v<iter_reference_t<_I2>> ||
      constructible_from<iter_value_t<_I2>, iter_reference_t<_I2>>)
   {
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
-                   "Cannot dereference sentinel. Common iterator not holding an iterator.");
-
+    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to dereference a non-dereferenceable common_iterator");
     if constexpr (is_pointer_v<_Iter> || requires(const _Iter& __i) { __i.operator->(); })    {
       return _VSTD::__unchecked_get<_Iter>(__hold_);
     } else if constexpr (is_reference_v<iter_reference_t<_Iter>>) {
@@ -144,21 +138,18 @@ public:
   }
 
   common_iterator& operator++() {
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
-                   "Cannot increment sentinel. Common iterator not holding an iterator.");
+    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator");
     ++_VSTD::__unchecked_get<_Iter>(__hold_); return *this;
   }
 
   decltype(auto) operator++(int) {
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_),
-                   "Cannot increment sentinel. Common iterator not holding an iterator.");
-
+    _LIBCPP_ASSERT(holds_alternative<_Iter>(__hold_), "Attempted to increment a non-dereferenceable common_iterator");
     if constexpr (forward_iterator<_Iter>) {
       auto __tmp = *this;
       ++*this;
       return __tmp;
     } else if constexpr (requires (_Iter& __i) { { *__i++ } -> __referenceable; } ||
-                         !__postfix_proxy::__valid_for_iter) {
+                         !__can_use_postfix_proxy<_Iter>) {
       return _VSTD::__unchecked_get<_Iter>(__hold_)++;
     } else {
       __postfix_proxy __p(**this);
@@ -169,10 +160,9 @@ public:
 
   template<class _I2, sentinel_for<_Iter> _S2>
     requires sentinel_for<_Sent, _I2>
-  friend bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
-    _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception() &&
-                   !__y.__hold_.valueless_by_exception(),
-                   "One or both common_iterators are valueless. (Cannot compare valueless iterators.)");
+  friend constexpr bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
+    _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
+    _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
 
     auto __x_index = __x.__hold_.index();
     auto __y_index = __y.__hold_.index();
@@ -188,10 +178,9 @@ public:
 
   template<class _I2, sentinel_for<_Iter> _S2>
     requires sentinel_for<_Sent, _I2> && equality_comparable_with<_Iter, _I2>
-  friend bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
-    _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception() &&
-                   !__y.__hold_.valueless_by_exception(),
-                   "One or both common_iterators are valueless. (Cannot compare valueless iterators.)");
+  friend constexpr bool operator==(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
+    _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
+    _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to compare a valueless common_iterator");
 
     auto __x_index = __x.__hold_.index();
     auto __y_index = __y.__hold_.index();
@@ -210,10 +199,9 @@ public:
 
   template<sized_sentinel_for<_Iter> _I2, sized_sentinel_for<_Iter> _S2>
     requires sized_sentinel_for<_Sent, _I2>
-  friend iter_difference_t<_I2> operator-(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
-    _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception() &&
-                   !__y.__hold_.valueless_by_exception(),
-                   "One or both common_iterators are valueless. (Cannot subtract valueless iterators.)");
+  friend constexpr iter_difference_t<_I2> operator-(const common_iterator& __x, const common_iterator<_I2, _S2>& __y) {
+    _LIBCPP_ASSERT(!__x.__hold_.valueless_by_exception(), "Attempted to subtract from a valueless common_iterator");
+    _LIBCPP_ASSERT(!__y.__hold_.valueless_by_exception(), "Attempted to subtract a valueless common_iterator");
 
     auto __x_index = __x.__hold_.index();
     auto __y_index = __y.__hold_.index();
@@ -230,24 +218,21 @@ public:
     return _VSTD::__unchecked_get<_Sent>(__x.__hold_) - _VSTD::__unchecked_get<_I2>(__y.__hold_);
   }
 
-  friend iter_rvalue_reference_t<_Iter> iter_move(const common_iterator& __i)
+  friend constexpr iter_rvalue_reference_t<_Iter> iter_move(const common_iterator& __i)
     noexcept(noexcept(ranges::iter_move(declval<const _Iter&>())))
       requires input_iterator<_Iter>
   {
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__i.__hold_),
-                   "Cannot iter_move a sentinel. Common iterator not holding an iterator.");
+    _LIBCPP_ASSERT(holds_alternative<_Iter>(__i.__hold_), "Attempted to iter_move a non-dereferenceable common_iterator");
     return ranges::iter_move( _VSTD::__unchecked_get<_Iter>(__i.__hold_));
   }
 
   template<indirectly_swappable<_Iter> _I2, class _S2>
-  friend void iter_swap(const common_iterator& __x, const common_iterator<_I2, _S2>& __y)
+  friend constexpr void iter_swap(const common_iterator& __x, const common_iterator<_I2, _S2>& __y)
       noexcept(noexcept(ranges::iter_swap(declval<const _Iter&>(), declval<const _I2&>())))
   {
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__x.__hold_),
-                   "Cannot swap __y with a sentinel. Common iterator (__x) not holding an iterator.");
-    _LIBCPP_ASSERT(holds_alternative<_Iter>(__y.__hold_),
-                   "Cannot swap __x with a sentinel. Common iterator (__y) not holding an iterator.");
-    return ranges::iter_swap( _VSTD::__unchecked_get<_Iter>(__x.__hold_),  _VSTD::__unchecked_get<_Iter>(__y.__hold_));
+    _LIBCPP_ASSERT(holds_alternative<_Iter>(__x.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator");
+    _LIBCPP_ASSERT(holds_alternative<_I2>(__y.__hold_), "Attempted to iter_swap a non-dereferenceable common_iterator");
+    return ranges::iter_swap(_VSTD::__unchecked_get<_Iter>(__x.__hold_), _VSTD::__unchecked_get<_I2>(__y.__hold_));
   }
 };
 
@@ -274,10 +259,10 @@ struct __arrow_type_or_void {
 template<class _Iter, class _Sent>
   requires __common_iter_has_ptr_op<_Iter, _Sent>
 struct __arrow_type_or_void<_Iter, _Sent> {
-    using type = decltype(declval<const common_iterator<_Iter, _Sent>>().operator->());
+    using type = decltype(declval<const common_iterator<_Iter, _Sent>&>().operator->());
 };
 
-template<class _Iter, class _Sent>
+template<input_iterator _Iter, class _Sent>
 struct iterator_traits<common_iterator<_Iter, _Sent>> {
   using iterator_concept = _If<forward_iterator<_Iter>,
                                forward_iterator_tag,
@@ -291,11 +276,8 @@ struct iterator_traits<common_iterator<_Iter, _Sent>> {
   using reference = iter_reference_t<_Iter>;
 };
 
-
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_COMMON_ITERATOR_H
lib/libcxx/include/__iterator/concepts.h
@@ -24,14 +24,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
-
-// clang-format off
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // [iterator.concept.readable]
 template<class _In>
@@ -72,6 +67,8 @@ concept __signed_integer_like = signed_integral<_Tp>;
 
 template<class _Ip>
 concept weakly_incrementable =
+  // TODO: remove this once the clang bug is fixed (bugs.llvm.org/PR48173).
+  !same_as<_Ip, bool> && // Currently, clang does not handle bool correctly.
   movable<_Ip> &&
   requires(_Ip __i) {
     typename iter_difference_t<_Ip>;
@@ -172,7 +169,6 @@ concept contiguous_iterator =
   derived_from<_ITER_CONCEPT<_Ip>, contiguous_iterator_tag> &&
   is_lvalue_reference_v<iter_reference_t<_Ip>> &&
   same_as<iter_value_t<_Ip>, remove_cvref_t<iter_reference_t<_Ip>>> &&
-  (is_pointer_v<_Ip> || requires { sizeof(__pointer_traits_element_type<_Ip>); }) &&
   requires(const _Ip& __i) {
     { _VSTD::to_address(__i) } -> same_as<add_pointer_t<iter_reference_t<_Ip>>>;
   };
@@ -261,12 +257,8 @@ concept indirectly_movable_storable =
 // Note: indirectly_swappable is located in iter_swap.h to prevent a dependency cycle
 // (both iter_swap and indirectly_swappable require indirectly_readable).
 
-// clang-format on
-
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_CONCEPTS_H
lib/libcxx/include/__iterator/counted_iterator.h
@@ -13,12 +13,14 @@
 #include <__debug>
 #include <__iterator/concepts.h>
 #include <__iterator/default_sentinel.h>
+#include <__iterator/incrementable_traits.h>
 #include <__iterator/iter_move.h>
 #include <__iterator/iter_swap.h>
-#include <__iterator/incrementable_traits.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/readable_traits.h>
 #include <__memory/pointer_traits.h>
+#include <__utility/move.h>
+#include <compare>
 #include <concepts>
 #include <type_traits>
 
@@ -26,12 +28,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 template<class>
 struct __counted_iterator_concept {};
@@ -97,7 +96,7 @@ public:
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr const _Iter& base() const& { return __current_; }
+  constexpr const _Iter& base() const& noexcept { return __current_; }
 
   _LIBCPP_HIDE_FROM_ABI
   constexpr _Iter base() && { return _VSTD::move(__current_); }
@@ -297,10 +296,8 @@ struct iterator_traits<counted_iterator<_Iter>> : iterator_traits<_Iter> {
                                 add_pointer_t<iter_reference_t<_Iter>>, void>;
 };
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_COUNTED_ITERATOR_H
lib/libcxx/include/__iterator/data.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -51,6 +48,4 @@ constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.beg
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_DATA_H
lib/libcxx/include/__iterator/default_sentinel.h
@@ -16,20 +16,15 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 struct default_sentinel_t { };
 inline constexpr default_sentinel_t default_sentinel{};
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_DEFAULT_SENTINEL_H
lib/libcxx/include/__iterator/distance.h
@@ -11,15 +11,18 @@
 #define _LIBCPP___ITERATOR_DISTANCE_H
 
 #include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/incrementable_traits.h>
 #include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/size.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 _InputIter>
@@ -49,8 +52,56 @@ distance(_InputIter __first, _InputIter __last)
     return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
 }
 
-_LIBCPP_END_NAMESPACE_STD
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+// [range.iter.op.distance]
+
+namespace ranges {
+namespace __distance {
+
+struct __fn {
+  template<class _Ip, sentinel_for<_Ip> _Sp>
+    requires (!sized_sentinel_for<_Sp, _Ip>)
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr iter_difference_t<_Ip> operator()(_Ip __first, _Sp __last) const {
+    iter_difference_t<_Ip> __n = 0;
+    while (__first != __last) {
+      ++__first;
+      ++__n;
+    }
+    return __n;
+  }
+
+  template<class _Ip, sized_sentinel_for<decay_t<_Ip>> _Sp>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const {
+    if constexpr (sized_sentinel_for<_Sp, __uncvref_t<_Ip>>) {
+      return __last - __first;
+    } else {
+      return __last - decay_t<_Ip>(__first);
+    }
+  }
 
-_LIBCPP_POP_MACROS
+  template<range _Rp>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr range_difference_t<_Rp> operator()(_Rp&& __r) const {
+    if constexpr (sized_range<_Rp>) {
+      return static_cast<range_difference_t<_Rp>>(ranges::size(__r));
+    } else {
+      return operator()(ranges::begin(__r), ranges::end(__r));
+    }
+  }
+};
+
+} // namespace __distance
+
+inline namespace __cpo {
+  inline constexpr auto distance = __distance::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___ITERATOR_DISTANCE_H
lib/libcxx/include/__iterator/empty.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -44,6 +41,4 @@ constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() =
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_EMPTY_H
lib/libcxx/include/__iterator/erase_if_container.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Container, class _Predicate>
@@ -40,6 +37,4 @@ __libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ERASE_IF_CONTAINER_H
lib/libcxx/include/__iterator/front_insert_iterator.h
@@ -21,9 +21,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -70,6 +67,4 @@ front_inserter(_Container& __x)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H
lib/libcxx/include/__iterator/incrementable_traits.h
@@ -18,12 +18,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // [incrementable.traits]
 template<class> struct incrementable_traits {};
@@ -68,10 +65,8 @@ using iter_difference_t = typename conditional_t<__is_primary_template<iterator_
                                                  incrementable_traits<remove_cvref_t<_Ip> >,
                                                  iterator_traits<remove_cvref_t<_Ip> > >::difference_type;
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H
lib/libcxx/include/__iterator/indirectly_comparable.h
@@ -0,0 +1,30 @@
+// -*- 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___ITERATOR_INDIRECTLY_COMPARABLE_H
+#define _LIBCPP___ITERATOR_INDIRECTLY_COMPARABLE_H
+
+#include <__config>
+#include <__functional/identity.h>
+#include <__iterator/concepts.h>
+#include <__iterator/projected.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <class _I1, class _I2, class _Rp, class _P1 = identity, class _P2 = identity>
+concept indirectly_comparable =
+  indirect_binary_predicate<_Rp, projected<_I1, _P1>, projected<_I2, _P2>>;
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___ITERATOR_INDIRECTLY_COMPARABLE_H
lib/libcxx/include/__iterator/insert_iterator.h
@@ -14,6 +14,7 @@
 #include <__iterator/iterator.h>
 #include <__iterator/iterator_traits.h>
 #include <__memory/addressof.h>
+#include <__ranges/access.h>
 #include <__utility/move.h>
 #include <cstddef>
 
@@ -21,11 +22,16 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+template <class _Container>
+using __insert_iterator_iter_t = ranges::iterator_t<_Container>;
+#else
+template <class _Container>
+using __insert_iterator_iter_t = typename _Container::iterator;
+#endif
+
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <class _Container>
 class _LIBCPP_TEMPLATE_VIS insert_iterator
@@ -36,7 +42,7 @@ class _LIBCPP_TEMPLATE_VIS insert_iterator
 _LIBCPP_SUPPRESS_DEPRECATED_POP
 protected:
     _Container* container;
-    typename _Container::iterator iter; // FIXME: `ranges::iterator_t<Container>` in C++20 mode
+    __insert_iterator_iter_t<_Container> iter;
 public:
     typedef output_iterator_tag iterator_category;
     typedef void value_type;
@@ -49,7 +55,7 @@ public:
     typedef void reference;
     typedef _Container container_type;
 
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, __insert_iterator_iter_t<_Container> __i)
         : container(_VSTD::addressof(__x)), iter(__i) {}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
         {iter = container->insert(iter, __value_); ++iter; return *this;}
@@ -65,13 +71,11 @@ public:
 template <class _Container>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 insert_iterator<_Container>
-inserter(_Container& __x, typename _Container::iterator __i)
+inserter(_Container& __x, __insert_iterator_iter_t<_Container> __i)
 {
     return insert_iterator<_Container>(__x, __i);
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_INSERT_ITERATOR_H
lib/libcxx/include/__iterator/istream_iterator.h
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -70,12 +67,6 @@ public:
     bool
     operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
                const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
-
-    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
-    friend _LIBCPP_INLINE_VISIBILITY
-    bool
-    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
-               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
 };
 
 template <class _Tp, class _CharT, class _Traits, class _Distance>
@@ -98,6 +89,4 @@ operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H
lib/libcxx/include/__iterator/istreambuf_iterator.h
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -105,6 +102,4 @@ bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ISTREAMBUF_ITERATOR_H
lib/libcxx/include/__iterator/iter_move.h
@@ -21,20 +21,23 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [iterator.cust.move]
+
+namespace ranges {
+namespace __iter_move {
 
-namespace ranges::__iter_move {
 void iter_move();
 
-template<class _Ip>
-concept __unqualified_iter_move = requires(_Ip&& __i) {
-    iter_move(_VSTD::forward<_Ip>(__i));
-};
+template <class _Tp>
+concept __unqualified_iter_move =
+  __class_or_enum<remove_cvref_t<_Tp>> &&
+  requires (_Tp&& __t) {
+    iter_move(_VSTD::forward<_Tp>(__t));
+  };
 
 // [iterator.cust.move]/1
 // The name ranges::iter_move denotes a customization point object.
@@ -72,20 +75,19 @@ struct __fn {
   // [iterator.cust.move]/1.3
   // Otherwise, ranges::iter_move(E) is ill-formed.
 };
-} // namespace ranges::__iter_move
+} // namespace __iter_move
 
-namespace ranges::inline __cpo {
+inline namespace __cpo {
   inline constexpr auto iter_move = __iter_move::__fn{};
-}
+} // namespace __cpo
+} // namespace ranges
 
 template<__dereferenceable _Tp>
-requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __referenceable; }
+  requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __referenceable; }
 using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<_Tp&>()));
 
-#endif // !_LIBCPP_HAS_NO_RANGES
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ITER_MOVE_H
lib/libcxx/include/__iterator/iter_swap.h
@@ -14,7 +14,8 @@
 #include <__iterator/iter_move.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/readable_traits.h>
-#include <__ranges/access.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
 #include <concepts>
 #include <type_traits>
 
@@ -22,12 +23,11 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [iter.cust.swap]
 
 namespace ranges {
 namespace __iter_swap {
@@ -35,9 +35,11 @@ namespace __iter_swap {
   void iter_swap(_I1, _I2) = delete;
 
   template<class _T1, class _T2>
-  concept __unqualified_iter_swap = requires(_T1&& __x, _T2&& __y) {
-    iter_swap(_VSTD::forward<_T1>(__x), _VSTD::forward<_T2>(__y));
-  };
+  concept __unqualified_iter_swap =
+    (__class_or_enum<remove_cvref_t<_T1>> || __class_or_enum<remove_cvref_t<_T2>>) &&
+    requires (_T1&& __x, _T2&& __y) {
+      iter_swap(_VSTD::forward<_T1>(__x), _VSTD::forward<_T2>(__y));
+    };
 
   template<class _T1, class _T2>
   concept __readable_swappable =
@@ -80,12 +82,11 @@ namespace __iter_swap {
       *_VSTD::forward<_T1>(__x) = _VSTD::move(__old);
     }
   };
-} // end namespace __iter_swap
+} // namespace __iter_swap
 
 inline namespace __cpo {
   inline constexpr auto iter_swap = __iter_swap::__fn{};
 } // namespace __cpo
-
 } // namespace ranges
 
 template<class _I1, class _I2 = _I1>
@@ -98,10 +99,8 @@ concept indirectly_swappable =
     ranges::iter_swap(__i2, __i1);
   };
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ITER_SWAP_H
lib/libcxx/include/__iterator/iterator.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template<class _Category, class _Tp, class _Distance = ptrdiff_t,
@@ -35,6 +32,4 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ITERATOR_H
lib/libcxx/include/__iterator/iterator_traits.h
@@ -20,12 +20,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 template <class _Tp>
 using __with_reference = _Tp&;
@@ -44,7 +41,7 @@ concept __dereferenceable = requires(_Tp& __t) {
 template<__dereferenceable _Tp>
 using iter_reference_t = decltype(*declval<_Tp&>());
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 template <class _Iter>
 struct _LIBCPP_TEMPLATE_VIS iterator_traits;
@@ -79,7 +76,7 @@ struct __iter_concept_category_test {
 };
 struct __iter_concept_random_fallback {
   template <class _Iter>
-  using _Apply = _EnableIf<
+  using _Apply = __enable_if_t<
                           __is_primary_template<iterator_traits<_Iter> >::value,
                           random_access_iterator_tag
                         >;
@@ -142,7 +139,7 @@ public:
     static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
 };
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // The `cpp17-*-iterator` exposition-only concepts are easily confused with the Cpp17*Iterator tables,
 // so they've been banished to a namespace that makes it obvious they have a niche use-case.
@@ -365,7 +362,7 @@ struct iterator_traits : __iterator_traits<_Ip> {
   using __primary_template = iterator_traits;
 };
 
-#else // !defined(_LIBCPP_HAS_NO_RANGES)
+#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 template <class _Iter, bool> struct __iterator_traits {};
 
@@ -402,10 +399,10 @@ struct _LIBCPP_TEMPLATE_VIS iterator_traits
 
   using __primary_template = iterator_traits;
 };
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 template<class _Tp>
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 requires is_object_v<_Tp>
 #endif
 struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
@@ -477,7 +474,7 @@ struct __is_exactly_cpp17_input_iterator
          __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
         !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator>
 using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
 
@@ -491,10 +488,8 @@ template<class _InputIterator>
 using __iter_to_alloc_type = pair<
     add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
     typename iterator_traits<_InputIterator>::value_type::second_type>;
-#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#endif // _LIBCPP_STD_VER >= 17
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_ITERATOR_TRAITS_H
lib/libcxx/include/__iterator/move_iterator.h
@@ -12,33 +12,32 @@
 
 #include <__config>
 #include <__iterator/iterator_traits.h>
+#include <__utility/move.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 _Iter>
 class _LIBCPP_TEMPLATE_VIS move_iterator
 {
-private:
-    _Iter __i;
 public:
-    typedef _Iter                                            iterator_type;
+#if _LIBCPP_STD_VER > 17
+    typedef input_iterator_tag iterator_concept;
+#endif
+
+    typedef _Iter iterator_type;
+    typedef _If<
+        __is_cpp17_random_access_iterator<_Iter>::value,
+        random_access_iterator_tag,
+        typename iterator_traits<_Iter>::iterator_category
+    >  iterator_category;
     typedef typename iterator_traits<iterator_type>::value_type value_type;
     typedef typename iterator_traits<iterator_type>::difference_type difference_type;
     typedef iterator_type pointer;
-    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
-        random_access_iterator_tag,
-        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
-#if _LIBCPP_STD_VER > 17
-    typedef input_iterator_tag                               iterator_concept;
-#endif
 
 #ifndef _LIBCPP_CXX03_LANG
     typedef typename iterator_traits<iterator_type>::reference __reference;
@@ -51,114 +50,113 @@ public:
     typedef typename iterator_traits<iterator_type>::reference reference;
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator() : __i() {}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator() : __current_() {}
 
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    explicit move_iterator(_Iter __x) : __i(__x) {}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    explicit move_iterator(_Iter __i) : __current_(_VSTD::move(__i)) {}
 
-    template <class _Up, class = _EnableIf<
-        !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
+    template <class _Up, class = __enable_if_t<
+        !is_same<_Up, _Iter>::value && is_convertible<const _Up&, _Iter>::value
     > >
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator(const move_iterator<_Up>& __u) : __current_(__u.base()) {}
 
-    template <class _Up, class = _EnableIf<
+    template <class _Up, class = __enable_if_t<
         !is_same<_Up, _Iter>::value &&
-        is_convertible<_Up const&, _Iter>::value &&
-        is_assignable<_Iter&, _Up const&>::value
+        is_convertible<const _Up&, _Iter>::value &&
+        is_assignable<_Iter&, const _Up&>::value
     > >
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
     move_iterator& operator=(const move_iterator<_Up>& __u) {
-        __i = __u.base();
+        __current_ = __u.base();
         return *this;
     }
 
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    reference operator*() const { return static_cast<reference>(*__i); }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    pointer  operator->() const { return __i;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator& operator++() {++__i; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator& operator--() {--__i; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    _Iter base() const { return __current_; }
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    reference operator*() const { return static_cast<reference>(*__current_); }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    pointer operator->() const { return __current_; }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    reference operator[](difference_type __n) const { return static_cast<reference>(__current_[__n]); }
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator& operator++() { ++__current_; return *this; }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator operator++(int) { move_iterator __tmp(*this); ++__current_; return __tmp; }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator& operator--() { --__current_; return *this; }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator operator--(int) { move_iterator __tmp(*this); --__current_; return __tmp; }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator operator+(difference_type __n) const { return move_iterator(__current_ + __n); }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator& operator+=(difference_type __n) { __current_ += __n; return *this; }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator operator-(difference_type __n) const { return move_iterator(__current_ - __n); }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+    move_iterator& operator-=(difference_type __n) { __current_ -= __n; return *this; }
+
+private:
+    _Iter __current_;
 };
 
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-bool
-operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 {
     return __x.base() == __y.base();
 }
 
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-bool
-operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 {
-    return __x.base() < __y.base();
+    return __x.base() != __y.base();
 }
 
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-bool
-operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+bool operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 {
-    return __x.base() != __y.base();
+    return __x.base() < __y.base();
 }
 
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-bool
-operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+bool operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 {
     return __x.base() > __y.base();
 }
 
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-bool
-operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+bool operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 {
-    return __x.base() >= __y.base();
+    return __x.base() <= __y.base();
 }
 
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-bool
-operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+bool operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 {
-    return __x.base() <= __y.base();
+    return __x.base() >= __y.base();
 }
 
 #ifndef _LIBCPP_CXX03_LANG
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto
-operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
--> decltype(__x.base() - __y.base())
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+    -> decltype(__x.base() - __y.base())
 {
     return __x.base() - __y.base();
 }
 #else
 template <class _Iter1, class _Iter2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI
 typename move_iterator<_Iter1>::difference_type
 operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 {
@@ -167,7 +165,7 @@ operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
 #endif
 
 template <class _Iter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
 move_iterator<_Iter>
 operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
 {
@@ -175,15 +173,13 @@ operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterato
 }
 
 template <class _Iter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
 move_iterator<_Iter>
 make_move_iterator(_Iter __i)
 {
-    return move_iterator<_Iter>(__i);
+    return move_iterator<_Iter>(_VSTD::move(__i));
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_MOVE_ITERATOR_H
lib/libcxx/include/__iterator/next.h
@@ -12,7 +12,6 @@
 
 #include <__config>
 #include <__debug>
-#include <__function_like.h>
 #include <__iterator/advance.h>
 #include <__iterator/concepts.h>
 #include <__iterator/incrementable_traits.h>
@@ -23,9 +22,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIter>
@@ -39,13 +35,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   return __x;
 }
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+// [range.iter.op.next]
 
 namespace ranges {
-struct __next_fn final : private __function_like {
-  _LIBCPP_HIDE_FROM_ABI
-  constexpr explicit __next_fn(__tag __x) noexcept : __function_like(__x) {}
+namespace __next {
 
+struct __fn {
   template <input_or_output_iterator _Ip>
   _LIBCPP_HIDE_FROM_ABI
   constexpr _Ip operator()(_Ip __x) const {
@@ -75,13 +72,15 @@ struct __next_fn final : private __function_like {
   }
 };
 
-inline constexpr auto next = __next_fn(__function_like::__tag());
+} // namespace __next
+
+inline namespace __cpo {
+  inline constexpr auto next = __next::__fn{};
+} // namespace __cpo
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
-#endif // _LIBCPP___ITERATOR_PRIMITIVES_H
+#endif // _LIBCPP___ITERATOR_NEXT_H
lib/libcxx/include/__iterator/ostream_iterator.h
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -70,6 +67,4 @@ public:
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H
lib/libcxx/include/__iterator/ostreambuf_iterator.h
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -76,6 +73,4 @@ public:
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H
lib/libcxx/include/__iterator/prev.h
@@ -12,7 +12,6 @@
 
 #include <__config>
 #include <__debug>
-#include <__function_like.h>
 #include <__iterator/advance.h>
 #include <__iterator/concepts.h>
 #include <__iterator/incrementable_traits.h>
@@ -23,9 +22,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _InputIter>
@@ -38,13 +34,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   return __x;
 }
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+// [range.iter.op.prev]
 
 namespace ranges {
-struct __prev_fn final : private __function_like {
-  _LIBCPP_HIDE_FROM_ABI
-  constexpr explicit __prev_fn(__tag __x) noexcept : __function_like(__x) {}
+namespace __prev {
 
+struct __fn {
   template <bidirectional_iterator _Ip>
   _LIBCPP_HIDE_FROM_ABI
   constexpr _Ip operator()(_Ip __x) const {
@@ -67,13 +64,15 @@ struct __prev_fn final : private __function_like {
   }
 };
 
-inline constexpr auto prev = __prev_fn(__function_like::__tag());
+} // namespace __prev
+
+inline namespace __cpo {
+  inline constexpr auto prev = __prev::__fn{};
+} // namespace __cpo
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_PREV_H
lib/libcxx/include/__iterator/projected.h
@@ -18,12 +18,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 template<indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
 struct projected {
@@ -36,10 +33,8 @@ struct incrementable_traits<projected<_It, _Proj>> {
   using difference_type = iter_difference_t<_It>;
 };
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_PROJECTED_H
lib/libcxx/include/__iterator/readable_traits.h
@@ -18,12 +18,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // [readable.traits]
 template<class> struct __cond_value_type {};
@@ -60,14 +57,14 @@ template<__has_member_element_type _Tp>
 struct indirectly_readable_traits<_Tp>
   : __cond_value_type<typename _Tp::element_type> {};
 
-// Pre-emptively applies LWG3541
 template<__has_member_value_type _Tp>
-requires __has_member_element_type<_Tp>
+  requires __has_member_element_type<_Tp>
 struct indirectly_readable_traits<_Tp> {};
+
 template<__has_member_value_type _Tp>
-requires __has_member_element_type<_Tp> &&
-         same_as<remove_cv_t<typename _Tp::element_type>,
-                 remove_cv_t<typename _Tp::value_type>>
+  requires __has_member_element_type<_Tp> &&
+           same_as<remove_cv_t<typename _Tp::element_type>,
+                   remove_cv_t<typename _Tp::value_type>>
 struct indirectly_readable_traits<_Tp>
   : __cond_value_type<typename _Tp::value_type> {};
 
@@ -82,10 +79,8 @@ using iter_value_t = typename conditional_t<__is_primary_template<iterator_trait
                                             indirectly_readable_traits<remove_cvref_t<_Ip> >,
                                             iterator_traits<remove_cvref_t<_Ip> > >::value_type;
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_READABLE_TRAITS_H
lib/libcxx/include/__iterator/reverse_access.h
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if !defined(_LIBCPP_CXX03_LANG)
@@ -104,6 +101,4 @@ auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_REVERSE_ACCESS_H
lib/libcxx/include/__iterator/reverse_iterator.h
@@ -10,6 +10,8 @@
 #ifndef _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
 #define _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
 
+#include <__compare/compare_three_way_result.h>
+#include <__compare/three_way_comparable.h>
 #include <__config>
 #include <__iterator/iterator.h>
 #include <__iterator/iterator_traits.h>
@@ -20,18 +22,8 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Tp, class = void>
-struct __is_stashing_iterator : false_type {};
-
-template <class _Tp>
-struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
-  : true_type {};
-
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <class _Iter>
 class _LIBCPP_TEMPLATE_VIS reverse_iterator
@@ -49,10 +41,6 @@ private:
     _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
 #endif
 
-    static_assert(!__is_stashing_iterator<_Iter>::value,
-      "The specified iterator type cannot be used with reverse_iterator; "
-      "Using stashing iterators with reverse_iterator causes undefined behavior");
-
 protected:
     _Iter current;
 public:
@@ -78,7 +66,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
     explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
 
-    template <class _Up, class = _EnableIf<
+    template <class _Up, class = __enable_if_t<
         !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
     > >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
@@ -86,10 +74,10 @@ public:
         : __t(__u.base()), current(__u.base())
     { }
 
-    template <class _Up, class = _EnableIf<
+    template <class _Up, class = __enable_if_t<
         !is_same<_Up, _Iter>::value &&
         is_convertible<_Up const&, _Iter>::value &&
-        is_assignable<_Up const&, _Iter>::value
+        is_assignable<_Iter&, _Up const&>::value
     > >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
     reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
@@ -103,7 +91,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
     explicit reverse_iterator(_Iter __x) : current(__x) {}
 
-    template <class _Up, class = _EnableIf<
+    template <class _Up, class = __enable_if_t<
         !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
     > >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
@@ -111,10 +99,10 @@ public:
         : current(__u.base())
     { }
 
-    template <class _Up, class = _EnableIf<
+    template <class _Up, class = __enable_if_t<
         !is_same<_Up, _Iter>::value &&
         is_convertible<_Up const&, _Iter>::value &&
-        is_assignable<_Up const&, _Iter>::value
+        is_assignable<_Iter&, _Up const&>::value
     > >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
     reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
@@ -196,6 +184,16 @@ operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>&
     return __x.base() >= __y.base();
 }
 
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+template <class _Iter1, three_way_comparable_with<_Iter1> _Iter2>
+_LIBCPP_HIDE_FROM_ABI constexpr
+compare_three_way_result_t<_Iter1, _Iter2>
+operator<=>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __y.base() <=> __x.base();
+}
+#endif
+
 #ifndef _LIBCPP_CXX03_LANG
 template <class _Iter1, class _Iter2>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
@@ -234,6 +232,4 @@ reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
lib/libcxx/include/__iterator/size.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -53,6 +50,4 @@ constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___ITERATOR_SIZE_H
lib/libcxx/include/__iterator/unreachable_sentinel.h
@@ -0,0 +1,38 @@
+// -*- 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___ITERATOR_UNREACHABLE_SENTINEL_H
+#define _LIBCPP___ITERATOR_UNREACHABLE_SENTINEL_H
+
+#include <__config>
+#include <__iterator/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+struct unreachable_sentinel_t {
+  template<weakly_incrementable _Iter>
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr bool operator==(unreachable_sentinel_t, const _Iter&) noexcept {
+    return false;
+  }
+};
+
+inline constexpr unreachable_sentinel_t unreachable_sentinel{};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___ITERATOR_UNREACHABLE_SENTINEL_H
lib/libcxx/include/__iterator/wrap_iter.h
@@ -13,16 +13,14 @@
 #include <__config>
 #include <__debug>
 #include <__iterator/iterator_traits.h>
-#include <__memory/pointer_traits.h> // __to_address
+#include <__memory/addressof.h>
+#include <__memory/pointer_traits.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 _Iter>
@@ -42,120 +40,109 @@ public:
 private:
     iterator_type __i;
 public:
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
-#if _LIBCPP_STD_VER > 11
-                : __i{}
-#endif
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter() _NOEXCEPT
+                : __i()
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_i(this);
-#endif
+        _VSTD::__debug_db_insert_i(this);
     }
-    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+    template <class _Up> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
         __wrap_iter(const __wrap_iter<_Up>& __u,
             typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
             : __i(__u.base())
     {
 #if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__iterator_copy(this, &__u);
+      if (!__libcpp_is_constant_evaluated())
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__u));
 #endif
     }
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
     __wrap_iter(const __wrap_iter& __x)
         : __i(__x.base())
     {
-        __get_db()->__iterator_copy(this, &__x);
+      if (!__libcpp_is_constant_evaluated())
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
     }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
     __wrap_iter& operator=(const __wrap_iter& __x)
     {
-        if (this != &__x)
+        if (this != _VSTD::addressof(__x))
         {
-            __get_db()->__iterator_copy(this, &__x);
+            if (!__libcpp_is_constant_evaluated())
+                __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
             __i = __x.__i;
         }
         return *this;
     }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
     ~__wrap_iter()
     {
+      if (!__libcpp_is_constant_evaluated())
         __get_db()->__erase_i(this);
     }
 #endif
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator*() const _NOEXCEPT
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to dereference a non-dereferenceable iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to dereference a non-dereferenceable iterator");
         return *__i;
     }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pointer operator->() const _NOEXCEPT
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to dereference a non-dereferenceable iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to dereference a non-dereferenceable iterator");
         return _VSTD::__to_address(__i);
     }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator++() _NOEXCEPT
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to increment a non-incrementable iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to increment a non-incrementable iterator");
         ++__i;
         return *this;
     }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter  operator++(int) _NOEXCEPT
         {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
 
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator--() _NOEXCEPT
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
-                       "Attempted to decrement a non-decrementable iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
+                             "Attempted to decrement a non-decrementable iterator");
         --__i;
         return *this;
     }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter  operator--(int) _NOEXCEPT
         {__wrap_iter __tmp(*this); --(*this); return __tmp;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
         {__wrap_iter __w(*this); __w += __n; return __w;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
-                   "Attempted to add/subtract an iterator outside its valid range");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__addable(this, __n),
+                             "Attempted to add/subtract an iterator outside its valid range");
         __i += __n;
         return *this;
     }
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
         {return *this + (-__n);}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
         {*this += -__n; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 reference    operator[](difference_type __n) const _NOEXCEPT
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
-                   "Attempted to subscript an iterator outside its valid range");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__subscriptable(this, __n),
+                             "Attempted to subscript an iterator outside its valid range");
         return __i[__n];
     }
 
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 iterator_type base() const _NOEXCEPT {return __i;}
 
 private:
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
     {
+      if (!__libcpp_is_constant_evaluated())
         __get_db()->__insert_ic(this, __p);
     }
 #else
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
 #endif
 
     template <class _Up> friend class __wrap_iter;
@@ -165,99 +152,95 @@ private:
 };
 
 template <class _Iter1>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
 {
     return __x.base() == __y.base();
 }
 
 template <class _Iter1, class _Iter2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
     return __x.base() == __y.base();
 }
 
 template <class _Iter1>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
 bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
-                   "Attempted to compare incomparable iterators");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
+                         "Attempted to compare incomparable iterators");
     return __x.base() < __y.base();
 }
 
 template <class _Iter1, class _Iter2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
 bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
-                   "Attempted to compare incomparable iterators");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
+                         "Attempted to compare incomparable iterators");
     return __x.base() < __y.base();
 }
 
 template <class _Iter1>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
 {
     return !(__x == __y);
 }
 
 template <class _Iter1, class _Iter2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
     return !(__x == __y);
 }
 
 template <class _Iter1>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
 {
     return __y < __x;
 }
 
 template <class _Iter1, class _Iter2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
     return __y < __x;
 }
 
 template <class _Iter1>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
 {
     return !(__x < __y);
 }
 
 template <class _Iter1, class _Iter2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
     return !(__x < __y);
 }
 
 template <class _Iter1>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
 {
     return !(__y < __x);
 }
 
 template <class _Iter1, class _Iter2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
     return !(__y < __x);
 }
 
 template <class _Iter1, class _Iter2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
 #ifndef _LIBCPP_CXX03_LANG
 auto operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
     -> decltype(__x.base() - __y.base())
@@ -266,15 +249,13 @@ typename __wrap_iter<_Iter1>::difference_type
 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 #endif // C++03
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
-                   "Attempted to subtract incompatible iterators");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__less_than_comparable(_VSTD::addressof(__x), _VSTD::addressof(__y)),
+                         "Attempted to subtract incompatible iterators");
     return __x.base() - __y.base();
 }
 
 template <class _Iter1>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
 __wrap_iter<_Iter1> operator+(typename __wrap_iter<_Iter1>::difference_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT
 {
     __x += __n;
@@ -286,15 +267,19 @@ template <class _It>
 struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
 #endif
 
-template <class _Iter>
-_LIBCPP_CONSTEXPR
-decltype(_VSTD::__to_address(declval<_Iter>()))
-__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
-    return _VSTD::__to_address(__w.base());
-}
+template <class _It>
+struct _LIBCPP_TEMPLATE_VIS pointer_traits<__wrap_iter<_It> >
+{
+    typedef __wrap_iter<_It> pointer;
+    typedef typename pointer_traits<_It>::element_type element_type;
+    typedef typename pointer_traits<_It>::difference_type difference_type;
 
-_LIBCPP_END_NAMESPACE_STD
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
+    static element_type *to_address(pointer __w) _NOEXCEPT {
+        return _VSTD::__to_address(__w.base());
+    }
+};
 
-_LIBCPP_POP_MACROS
+_LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___ITERATOR_WRAP_ITER_H
lib/libcxx/include/__memory/addressof.h
@@ -16,13 +16,8 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
-
 template <class _Tp>
 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
 _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
@@ -32,19 +27,6 @@ addressof(_Tp& __x) _NOEXCEPT
     return __builtin_addressof(__x);
 }
 
-#else
-
-template <class _Tp>
-inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
-_Tp*
-addressof(_Tp& __x) _NOEXCEPT
-{
-  return reinterpret_cast<_Tp *>(
-      const_cast<char *>(&reinterpret_cast<const volatile char &>(__x)));
-}
-
-#endif // _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
-
 #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
 // Objective-C++ Automatic Reference Counting uses qualified pointers
 // that require special addressof() signatures. When
@@ -91,6 +73,4 @@ template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_ADDRESSOF_H
lib/libcxx/include/__memory/allocation_guard.h
@@ -19,10 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // Helper class to allocate memory using an Allocator in an exception safe
@@ -84,6 +80,4 @@ private:
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_ALLOCATION_GUARD_H
lib/libcxx/include/__memory/allocator.h
@@ -22,9 +22,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp> class allocator;
@@ -83,6 +80,7 @@ template <class _Tp>
 class _LIBCPP_TEMPLATE_VIS allocator
     : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> >
 {
+    static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
 public:
     typedef size_t      size_type;
     typedef ptrdiff_t   difference_type;
@@ -91,7 +89,7 @@ public:
     typedef true_type   is_always_equal;
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-    allocator() _NOEXCEPT _LIBCPP_DEFAULT
+    allocator() _NOEXCEPT = default;
 
     template <class _Up>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
@@ -100,8 +98,7 @@ public:
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     _Tp* allocate(size_t __n) {
         if (__n > allocator_traits<allocator>::max_size(*this))
-            __throw_length_error("allocator<T>::allocate(size_t n)"
-                                 " 'n' exceeds maximum supported size");
+            __throw_bad_array_new_length();
         if (__libcpp_is_constant_evaluated()) {
             return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
         } else {
@@ -165,6 +162,7 @@ template <class _Tp>
 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
     : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> >
 {
+    static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
 public:
     typedef size_t      size_type;
     typedef ptrdiff_t   difference_type;
@@ -173,7 +171,7 @@ public:
     typedef true_type   is_always_equal;
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-    allocator() _NOEXCEPT _LIBCPP_DEFAULT
+    allocator() _NOEXCEPT = default;
 
     template <class _Up>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
@@ -182,8 +180,7 @@ public:
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     const _Tp* allocate(size_t __n) {
         if (__n > allocator_traits<allocator>::max_size(*this))
-            __throw_length_error("allocator<const T>::allocate(size_t n)"
-                                 " 'n' exceeds maximum supported size");
+            __throw_bad_array_new_length();
         if (__libcpp_is_constant_evaluated()) {
             return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp)));
         } else {
@@ -249,6 +246,4 @@ bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_ALLOCATOR_H
lib/libcxx/include/__memory/allocator_arg_t.h
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP___FUNCTIONAL___ALLOCATOR_ARG_T_H
-#define _LIBCPP___FUNCTIONAL___ALLOCATOR_ARG_T_H
+#ifndef _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
+#define _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
 
 #include <__config>
 #include <__memory/uses_allocator.h>
@@ -26,7 +26,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = defau
 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
 extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
 #else
-/* _LIBCPP_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+/* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
 #endif
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -36,7 +36,7 @@ extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
 template <class _Tp, class _Alloc, class ..._Args>
 struct __uses_alloc_ctor_imp
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename __uncvref<_Alloc>::type _RawAlloc;
+    typedef _LIBCPP_NODEBUG typename __uncvref<_Alloc>::type _RawAlloc;
     static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
     static const bool __ic =
         is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
@@ -75,4 +75,4 @@ void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, con
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // _LIBCPP___FUNCTIONAL___ALLOCATOR_ARG_T_H
+#endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
lib/libcxx/include/__memory/allocator_traits.h
@@ -36,11 +36,11 @@ template <class _Tp, class _Alloc,
           class _RawAlloc = typename remove_reference<_Alloc>::type,
           bool = __has_pointer<_RawAlloc>::value>
 struct __pointer {
-    using type _LIBCPP_NODEBUG_TYPE = typename _RawAlloc::pointer;
+    using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer;
 };
 template <class _Tp, class _Alloc, class _RawAlloc>
 struct __pointer<_Tp, _Alloc, _RawAlloc, false> {
-    using type _LIBCPP_NODEBUG_TYPE = _Tp*;
+    using type _LIBCPP_NODEBUG = _Tp*;
 };
 
 // __const_pointer
@@ -48,14 +48,14 @@ _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer);
 template <class _Tp, class _Ptr, class _Alloc,
           bool = __has_const_pointer<_Alloc>::value>
 struct __const_pointer {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::const_pointer;
+    using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
 };
 template <class _Tp, class _Ptr, class _Alloc>
 struct __const_pointer<_Tp, _Ptr, _Alloc, false> {
 #ifdef _LIBCPP_CXX03_LANG
     using type = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
 #else
-    using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
+    using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
 #endif
 };
 
@@ -64,14 +64,14 @@ _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer);
 template <class _Ptr, class _Alloc,
           bool = __has_void_pointer<_Alloc>::value>
 struct __void_pointer {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::void_pointer;
+    using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
 };
 template <class _Ptr, class _Alloc>
 struct __void_pointer<_Ptr, _Alloc, false> {
 #ifdef _LIBCPP_CXX03_LANG
-    using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<void>::other;
+    using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other;
 #else
-    using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<void>;
+    using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>;
 #endif
 };
 
@@ -80,14 +80,14 @@ _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer);
 template <class _Ptr, class _Alloc,
           bool = __has_const_void_pointer<_Alloc>::value>
 struct __const_void_pointer {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::const_void_pointer;
+    using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
 };
 template <class _Ptr, class _Alloc>
 struct __const_void_pointer<_Ptr, _Alloc, false> {
 #ifdef _LIBCPP_CXX03_LANG
-    using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<const void>::other;
+    using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>::other;
 #else
-    using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind<const void>;
+    using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>;
 #endif
 };
 
@@ -97,18 +97,18 @@ template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
 struct __size_type : make_unsigned<_DiffType> { };
 template <class _Alloc, class _DiffType>
 struct __size_type<_Alloc, _DiffType, true> {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::size_type;
+    using type _LIBCPP_NODEBUG = typename _Alloc::size_type;
 };
 
 // __alloc_traits_difference_type
 _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type);
 template <class _Alloc, class _Ptr, bool = __has_alloc_traits_difference_type<_Alloc>::value>
 struct __alloc_traits_difference_type {
-    using type _LIBCPP_NODEBUG_TYPE = typename pointer_traits<_Ptr>::difference_type;
+    using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type;
 };
 template <class _Alloc, class _Ptr>
 struct __alloc_traits_difference_type<_Alloc, _Ptr, true> {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::difference_type;
+    using type _LIBCPP_NODEBUG = typename _Alloc::difference_type;
 };
 
 // __propagate_on_container_copy_assignment
@@ -117,7 +117,7 @@ template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_All
 struct __propagate_on_container_copy_assignment : false_type { };
 template <class _Alloc>
 struct __propagate_on_container_copy_assignment<_Alloc, true> {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::propagate_on_container_copy_assignment;
+    using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_copy_assignment;
 };
 
 // __propagate_on_container_move_assignment
@@ -126,7 +126,7 @@ template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_All
 struct __propagate_on_container_move_assignment : false_type { };
 template <class _Alloc>
 struct __propagate_on_container_move_assignment<_Alloc, true> {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::propagate_on_container_move_assignment;
+    using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_move_assignment;
 };
 
 // __propagate_on_container_swap
@@ -135,7 +135,7 @@ template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
 struct __propagate_on_container_swap : false_type { };
 template <class _Alloc>
 struct __propagate_on_container_swap<_Alloc, true> {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::propagate_on_container_swap;
+    using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_swap;
 };
 
 // __is_always_equal
@@ -144,7 +144,7 @@ template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
 struct __is_always_equal : is_empty<_Alloc> { };
 template <class _Alloc>
 struct __is_always_equal<_Alloc, true> {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc::is_always_equal;
+    using type _LIBCPP_NODEBUG = typename _Alloc::is_always_equal;
 };
 
 // __allocator_traits_rebind
@@ -158,15 +158,15 @@ struct __has_rebind_other<_Tp, _Up, typename __void_t<
 
 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
 struct __allocator_traits_rebind {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Tp::template rebind<_Up>::other;
+    using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
 };
 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> {
-    using type _LIBCPP_NODEBUG_TYPE = typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other;
+    using type _LIBCPP_NODEBUG = typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other;
 };
 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> {
-    using type _LIBCPP_NODEBUG_TYPE = _Alloc<_Up, _Args...>;
+    using type _LIBCPP_NODEBUG = _Alloc<_Up, _Args...>;
 };
 _LIBCPP_SUPPRESS_DEPRECATED_POP
 
@@ -263,7 +263,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
     }
 
     template <class _Ap = _Alloc, class =
-        _EnableIf<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
+        __enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {
         _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -271,7 +271,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
         _LIBCPP_SUPPRESS_DEPRECATED_POP
     }
     template <class _Ap = _Alloc, class = void, class =
-        _EnableIf<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
+        __enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer) {
         return __a.allocate(__n);
@@ -283,7 +283,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
     }
 
     template <class _Tp, class... _Args, class =
-        _EnableIf<__has_construct<allocator_type, _Tp*, _Args...>::value> >
+        __enable_if_t<__has_construct<allocator_type, _Tp*, _Args...>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) {
         _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -291,7 +291,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
         _LIBCPP_SUPPRESS_DEPRECATED_POP
     }
     template <class _Tp, class... _Args, class = void, class =
-        _EnableIf<!__has_construct<allocator_type, _Tp*, _Args...>::value> >
+        __enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static void construct(allocator_type&, _Tp* __p, _Args&&... __args) {
 #if _LIBCPP_STD_VER > 17
@@ -302,7 +302,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
     }
 
     template <class _Tp, class =
-        _EnableIf<__has_destroy<allocator_type, _Tp*>::value> >
+        __enable_if_t<__has_destroy<allocator_type, _Tp*>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static void destroy(allocator_type& __a, _Tp* __p) {
         _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -310,7 +310,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
         _LIBCPP_SUPPRESS_DEPRECATED_POP
     }
     template <class _Tp, class = void, class =
-        _EnableIf<!__has_destroy<allocator_type, _Tp*>::value> >
+        __enable_if_t<!__has_destroy<allocator_type, _Tp*>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static void destroy(allocator_type&, _Tp* __p) {
 #if _LIBCPP_STD_VER > 17
@@ -321,7 +321,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
     }
 
     template <class _Ap = _Alloc, class =
-        _EnableIf<__has_max_size<const _Ap>::value> >
+        __enable_if_t<__has_max_size<const _Ap>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static size_type max_size(const allocator_type& __a) _NOEXCEPT {
         _LIBCPP_SUPPRESS_DEPRECATED_PUSH
@@ -329,20 +329,20 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
         _LIBCPP_SUPPRESS_DEPRECATED_POP
     }
     template <class _Ap = _Alloc, class = void, class =
-        _EnableIf<!__has_max_size<const _Ap>::value> >
+        __enable_if_t<!__has_max_size<const _Ap>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static size_type max_size(const allocator_type&) _NOEXCEPT {
         return numeric_limits<size_type>::max() / sizeof(value_type);
     }
 
     template <class _Ap = _Alloc, class =
-        _EnableIf<__has_select_on_container_copy_construction<const _Ap>::value> >
+        __enable_if_t<__has_select_on_container_copy_construction<const _Ap>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static allocator_type select_on_container_copy_construction(const allocator_type& __a) {
         return __a.select_on_container_copy_construction();
     }
     template <class _Ap = _Alloc, class = void, class =
-        _EnableIf<!__has_select_on_container_copy_construction<const _Ap>::value> >
+        __enable_if_t<!__has_select_on_container_copy_construction<const _Ap>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static allocator_type select_on_container_copy_construction(const allocator_type& __a) {
         return __a;
@@ -352,7 +352,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
 template <class _Traits, class _Tp>
 struct __rebind_alloc_helper {
 #ifndef _LIBCPP_CXX03_LANG
-    using type _LIBCPP_NODEBUG_TYPE = typename _Traits::template rebind_alloc<_Tp>;
+    using type _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>;
 #else
     using type = typename _Traits::template rebind_alloc<_Tp>::other;
 #endif
@@ -374,7 +374,7 @@ struct __is_cpp17_move_insertable
 { };
 
 template <class _Alloc>
-struct __is_cpp17_move_insertable<_Alloc, _EnableIf<
+struct __is_cpp17_move_insertable<_Alloc, __enable_if_t<
     !__is_default_allocator<_Alloc>::value &&
     __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value
 > > : true_type { };
@@ -389,7 +389,7 @@ struct __is_cpp17_copy_insertable
 { };
 
 template <class _Alloc>
-struct __is_cpp17_copy_insertable<_Alloc, _EnableIf<
+struct __is_cpp17_copy_insertable<_Alloc, __enable_if_t<
     !__is_default_allocator<_Alloc>::value &&
     __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value
 > >
lib/libcxx/include/__memory/auto_ptr.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
@@ -81,6 +78,4 @@ public:
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_AUTO_PTR_H
lib/libcxx/include/__memory/compressed_pair.h
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // Tag used to default initialize one or both of the pair's elements.
@@ -61,10 +58,8 @@ struct __compressed_pair_elem {
       : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
 #endif
 
-
-  _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
-  _LIBCPP_INLINE_VISIBILITY
-  const_reference __get() const _NOEXCEPT { return __value_; }
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return __value_; }
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; }
 
 private:
   _Tp __value_;
@@ -100,9 +95,8 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
       : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
 #endif
 
-  _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
-  _LIBCPP_INLINE_VISIBILITY
-  const_reference __get() const _NOEXCEPT { return *this; }
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return *this; }
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; }
 };
 
 template <class _T1, class _T2>
@@ -118,8 +112,8 @@ public:
     "The current implementation is NOT ABI-compatible with the previous "
     "implementation for this configuration");
 
-    typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1;
-    typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2;
+    typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T1, 0> _Base1;
+    typedef _LIBCPP_NODEBUG __compressed_pair_elem<_T2, 1> _Base2;
 
     template <bool _Dummy = true,
       class = typename enable_if<
@@ -146,23 +140,19 @@ public:
                typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
 #endif
 
-  _LIBCPP_INLINE_VISIBILITY
-  typename _Base1::reference first() _NOEXCEPT {
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base1::reference first() _NOEXCEPT {
     return static_cast<_Base1&>(*this).__get();
   }
 
-  _LIBCPP_INLINE_VISIBILITY
-  typename _Base1::const_reference first() const _NOEXCEPT {
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT {
     return static_cast<_Base1 const&>(*this).__get();
   }
 
-  _LIBCPP_INLINE_VISIBILITY
-  typename _Base2::reference second() _NOEXCEPT {
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base2::reference second() _NOEXCEPT {
     return static_cast<_Base2&>(*this).__get();
   }
 
-  _LIBCPP_INLINE_VISIBILITY
-  typename _Base2::const_reference second() const _NOEXCEPT {
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT {
     return static_cast<_Base2 const&>(*this).__get();
   }
 
@@ -175,11 +165,8 @@ public:
     return static_cast<_Base2*>(__pair);
   }
 
-  _LIBCPP_INLINE_VISIBILITY
-  void swap(__compressed_pair& __x)
-    _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-               __is_nothrow_swappable<_T2>::value)
-  {
+  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 void swap(__compressed_pair& __x)
+      _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
     using _VSTD::swap;
     swap(first(), __x.first());
     swap(second(), __x.second());
@@ -187,15 +174,12 @@ public:
 };
 
 template <class _T1, class _T2>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
-    _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-               __is_nothrow_swappable<_T2>::value) {
+    _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
   __x.swap(__y);
 }
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H
lib/libcxx/include/__memory/concepts.h
@@ -0,0 +1,68 @@
+// -*- 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___MEMORY_CONCEPTS_H
+#define _LIBCPP___MEMORY_CONCEPTS_H
+
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/readable_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <concepts>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+
+// [special.mem.concepts]
+
+// This concept ensures that uninitialized algorithms can construct an object
+// at the address pointed-to by the iterator, which requires an lvalue.
+template <class _Ip>
+concept __nothrow_input_iterator =
+    input_iterator<_Ip> &&
+    is_lvalue_reference_v<iter_reference_t<_Ip>> &&
+    same_as<remove_cvref_t<iter_reference_t<_Ip>>, iter_value_t<_Ip>>;
+
+template <class _Sp, class _Ip>
+concept __nothrow_sentinel_for = sentinel_for<_Sp, _Ip>;
+
+template <class _Rp>
+concept __nothrow_input_range =
+    range<_Rp> &&
+    __nothrow_input_iterator<iterator_t<_Rp>> &&
+    __nothrow_sentinel_for<sentinel_t<_Rp>, iterator_t<_Rp>>;
+
+template <class _Ip>
+concept __nothrow_forward_iterator =
+    __nothrow_input_iterator<_Ip> &&
+    forward_iterator<_Ip> &&
+    __nothrow_sentinel_for<_Ip, _Ip>;
+
+template <class _Rp>
+concept __nothrow_forward_range =
+    __nothrow_input_range<_Rp> &&
+    __nothrow_forward_iterator<iterator_t<_Rp>>;
+
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___MEMORY_CONCEPTS_H
lib/libcxx/include/__memory/construct_at.h
@@ -12,16 +12,17 @@
 
 #include <__config>
 #include <__debug>
+#include <__iterator/access.h>
+#include <__memory/addressof.h>
+#include <__memory/voidify.h>
 #include <__utility/forward.h>
+#include <type_traits>
 #include <utility>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // construct_at
@@ -31,29 +32,79 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template<class _Tp, class ..._Args, class = decltype(
     ::new (declval<void*>()) _Tp(declval<_Args>()...)
 )>
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_HIDE_FROM_ABI
 constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) {
     _LIBCPP_ASSERT(__location, "null pointer given to construct_at");
-    return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...);
+    return ::new (_VSTD::__voidify(*__location)) _Tp(_VSTD::forward<_Args>(__args)...);
 }
 
 #endif
 
 // destroy_at
 
-#if _LIBCPP_STD_VER > 14
+// The internal functions are available regardless of the language version (with the exception of the `__destroy_at`
+// taking an array).
 
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-void destroy_at(_Tp* __loc) {
+template <class _ForwardIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+_ForwardIterator __destroy(_ForwardIterator, _ForwardIterator);
+
+template <class _Tp, typename enable_if<!is_array<_Tp>::value, int>::type = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void __destroy_at(_Tp* __loc) {
     _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
     __loc->~_Tp();
 }
 
+#if _LIBCPP_STD_VER > 17
+template <class _Tp, typename enable_if<is_array<_Tp>::value, int>::type = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void __destroy_at(_Tp* __loc) {
+    _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
+    _VSTD::__destroy(_VSTD::begin(*__loc), _VSTD::end(*__loc));
+}
 #endif
 
-_LIBCPP_END_NAMESPACE_STD
+template <class _ForwardIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+_ForwardIterator __destroy(_ForwardIterator __first, _ForwardIterator __last) {
+    for (; __first != __last; ++__first)
+        _VSTD::__destroy_at(_VSTD::addressof(*__first));
+    return __first;
+}
+
+#if _LIBCPP_STD_VER > 14
 
-_LIBCPP_POP_MACROS
+template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void destroy_at(_Tp* __loc) {
+    _VSTD::__destroy_at(__loc);
+}
+
+#if _LIBCPP_STD_VER > 17
+template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void destroy_at(_Tp* __loc) {
+  _VSTD::__destroy_at(__loc);
+}
+#endif
+
+template <class _ForwardIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void destroy(_ForwardIterator __first, _ForwardIterator __last) {
+  (void)_VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last));
+}
+
+template <class _ForwardIterator, class _Size>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
+    for (; __n > 0; (void)++__first, --__n)
+        _VSTD::__destroy_at(_VSTD::addressof(*__first));
+    return __first;
+}
+
+#endif // _LIBCPP_STD_VER > 14
+
+_LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___MEMORY_CONSTRUCT_AT_H
lib/libcxx/include/__memory/pointer_safety.h
@@ -1,57 +0,0 @@
-// -*- 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___MEMORY_POINTER_SAFETY_H
-#define _LIBCPP___MEMORY_POINTER_SAFETY_H
-
-#include <__config>
-#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
-
-#if !defined(_LIBCPP_CXX03_LANG)
-
-enum class pointer_safety : unsigned char {
-  relaxed,
-  preferred,
-  strict
-};
-
-inline _LIBCPP_INLINE_VISIBILITY
-pointer_safety get_pointer_safety() _NOEXCEPT {
-  return pointer_safety::relaxed;
-}
-
-_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
-_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
-_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
-_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
-
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-_Tp*
-undeclare_reachable(_Tp* __p)
-{
-    return static_cast<_Tp*>(__undeclare_reachable(__p));
-}
-
-#endif // !C++03
-
-_LIBCPP_END_NAMESPACE_STD
-
-_LIBCPP_POP_MACROS
-
-#endif // _LIBCPP___MEMORY_POINTER_SAFETY_H
lib/libcxx/include/__memory/pointer_traits.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp, class = void>
@@ -36,19 +33,19 @@ struct __pointer_traits_element_type;
 template <class _Ptr>
 struct __pointer_traits_element_type<_Ptr, true>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type;
+    typedef _LIBCPP_NODEBUG typename _Ptr::element_type type;
 };
 
 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type;
+    typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::element_type type;
 };
 
 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
 {
-    typedef _LIBCPP_NODEBUG_TYPE _Tp type;
+    typedef _LIBCPP_NODEBUG _Tp type;
 };
 
 template <class _Tp, class = void>
@@ -61,13 +58,13 @@ struct __has_difference_type<_Tp,
 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
 struct __pointer_traits_difference_type
 {
-    typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type;
+    typedef _LIBCPP_NODEBUG ptrdiff_t type;
 };
 
 template <class _Ptr>
 struct __pointer_traits_difference_type<_Ptr, true>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type;
+    typedef _LIBCPP_NODEBUG typename _Ptr::difference_type type;
 };
 
 template <class _Tp, class _Up>
@@ -87,9 +84,9 @@ template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
 struct __pointer_traits_rebind
 {
 #ifndef _LIBCPP_CXX03_LANG
-    typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type;
+    typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up> type;
 #else
-    typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
+    typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up>::other type;
 #endif
 };
 
@@ -97,9 +94,9 @@ template <template <class, class...> class _Sp, class _Tp, class ..._Args, class
 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
 {
 #ifndef _LIBCPP_CXX03_LANG
-    typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
+    typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
 #else
-    typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
+    typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
 #endif
 };
 
@@ -176,7 +173,9 @@ _Tp* __to_address(_Tp* __p) _NOEXCEPT {
 }
 
 // enable_if is needed here to avoid instantiating checks for fancy pointers on raw pointers
-template <class _Pointer, class = _EnableIf<!is_pointer<_Pointer>::value> >
+template <class _Pointer, class = __enable_if_t<
+    !is_pointer<_Pointer>::value && !is_array<_Pointer>::value && !is_function<_Pointer>::value
+> >
 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 typename decay<decltype(__to_address_helper<_Pointer>::__call(declval<const _Pointer&>()))>::type
 __to_address(const _Pointer& __p) _NOEXCEPT {
@@ -187,7 +186,7 @@ template <class _Pointer, class>
 struct __to_address_helper {
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     static decltype(_VSTD::__to_address(declval<const _Pointer&>().operator->()))
-    __call(const _Pointer&__p) _NOEXCEPT {
+    __call(const _Pointer& __p) _NOEXCEPT {
         return _VSTD::__to_address(__p.operator->());
     }
 };
@@ -196,12 +195,18 @@ template <class _Pointer>
 struct __to_address_helper<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))> {
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     static decltype(pointer_traits<_Pointer>::to_address(declval<const _Pointer&>()))
-    __call(const _Pointer&__p) _NOEXCEPT {
+    __call(const _Pointer& __p) _NOEXCEPT {
         return pointer_traits<_Pointer>::to_address(__p);
     }
 };
 
 #if _LIBCPP_STD_VER > 17
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY constexpr
+auto to_address(_Tp *__p) noexcept {
+    return _VSTD::__to_address(__p);
+}
+
 template <class _Pointer>
 inline _LIBCPP_INLINE_VISIBILITY constexpr
 auto to_address(const _Pointer& __p) noexcept {
@@ -211,6 +216,4 @@ auto to_address(const _Pointer& __p) noexcept {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_POINTER_TRAITS_H
lib/libcxx/include/__memory/ranges_construct_at.h
@@ -0,0 +1,124 @@
+// -*- 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___MEMORY_RANGES_CONSTRUCT_AT_H
+#define _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H
+
+#include <__concepts/destructible.h>
+#include <__config>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/readable_traits.h>
+#include <__memory/concepts.h>
+#include <__memory/construct_at.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/declval.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+namespace ranges {
+
+// construct_at
+
+namespace __construct_at {
+
+struct __fn {
+  template<class _Tp, class... _Args, class = decltype(
+    ::new (declval<void*>()) _Tp(declval<_Args>()...)
+  )>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr _Tp* operator()(_Tp* __location, _Args&& ...__args) const {
+    return _VSTD::construct_at(__location, _VSTD::forward<_Args>(__args)...);
+  }
+};
+
+} // namespace __construct_at
+
+inline namespace __cpo {
+  inline constexpr auto construct_at = __construct_at::__fn{};
+} // namespace __cpo
+
+// destroy_at
+
+namespace __destroy_at {
+
+struct __fn {
+  template <destructible _Tp>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr void operator()(_Tp* __location) const noexcept {
+    _VSTD::destroy_at(__location);
+  }
+};
+
+} // namespace __destroy_at
+
+inline namespace __cpo {
+  inline constexpr auto destroy_at = __destroy_at::__fn{};
+} // namespace __cpo
+
+// destroy
+
+namespace __destroy {
+
+struct __fn {
+  template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
+    requires destructible<iter_value_t<_InputIterator>>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept {
+    return _VSTD::__destroy(_VSTD::move(__first), _VSTD::move(__last));
+  }
+
+  template <__nothrow_input_range _InputRange>
+    requires destructible<range_value_t<_InputRange>>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept {
+    return (*this)(ranges::begin(__range), ranges::end(__range));
+  }
+};
+
+} // namespace __destroy
+
+inline namespace __cpo {
+  inline constexpr auto destroy = __destroy::__fn{};
+} // namespace __cpo
+
+// destroy_n
+
+namespace __destroy_n {
+
+struct __fn {
+  template <__nothrow_input_iterator _InputIterator>
+    requires destructible<iter_value_t<_InputIterator>>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr _InputIterator operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept {
+    return _VSTD::destroy_n(_VSTD::move(__first), __n);
+  }
+};
+
+} // namespace __destroy_n
+
+inline namespace __cpo {
+  inline constexpr auto destroy_n = __destroy_n::__fn{};
+} // namespace __cpo
+
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___MEMORY_RANGES_CONSTRUCT_AT_H
lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h
@@ -0,0 +1,318 @@
+// -*- 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___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H
+#define _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H
+
+#include <__algorithm/in_out_result.h>
+#include <__concepts/constructible.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/readable_traits.h>
+#include <__memory/concepts.h>
+#include <__memory/uninitialized_algorithms.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/move.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+
+// uninitialized_default_construct
+
+namespace __uninitialized_default_construct {
+
+struct __fn {
+  template <__nothrow_forward_iterator _ForwardIterator,
+            __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
+    requires default_initializable<iter_value_t<_ForwardIterator>>
+  _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
+    return _VSTD::__uninitialized_default_construct<_ValueType>(
+        _VSTD::move(__first), _VSTD::move(__last));
+  }
+
+  template <__nothrow_forward_range _ForwardRange>
+    requires default_initializable<range_value_t<_ForwardRange>>
+  borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const {
+    return (*this)(ranges::begin(__range), ranges::end(__range));
+  }
+};
+
+} // namespace __uninitialized_default_construct
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn{};
+} // namespace __cpo
+
+// uninitialized_default_construct_n
+
+namespace __uninitialized_default_construct_n {
+
+struct __fn {
+  template <__nothrow_forward_iterator _ForwardIterator>
+    requires default_initializable<iter_value_t<_ForwardIterator>>
+  _ForwardIterator operator()(_ForwardIterator __first,
+                              iter_difference_t<_ForwardIterator> __n) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
+    return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n);
+  }
+};
+
+} // namespace __uninitialized_default_construct_n
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n::__fn{};
+} // namespace __cpo
+
+// uninitialized_value_construct
+
+namespace __uninitialized_value_construct {
+
+struct __fn {
+  template <__nothrow_forward_iterator _ForwardIterator,
+            __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
+    requires default_initializable<iter_value_t<_ForwardIterator>>
+  _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
+    return _VSTD::__uninitialized_value_construct<_ValueType>(
+        _VSTD::move(__first), _VSTD::move(__last));
+  }
+
+  template <__nothrow_forward_range _ForwardRange>
+    requires default_initializable<range_value_t<_ForwardRange>>
+  borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const {
+    return (*this)(ranges::begin(__range), ranges::end(__range));
+  }
+};
+
+} // namespace __uninitialized_value_construct
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct::__fn{};
+} // namespace __cpo
+
+// uninitialized_value_construct_n
+
+namespace __uninitialized_value_construct_n {
+
+struct __fn {
+  template <__nothrow_forward_iterator _ForwardIterator>
+    requires default_initializable<iter_value_t<_ForwardIterator>>
+  _ForwardIterator operator()(_ForwardIterator __first,
+                              iter_difference_t<_ForwardIterator> __n) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
+    return _VSTD::__uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n);
+  }
+};
+
+} // namespace __uninitialized_value_construct_n
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n::__fn{};
+} // namespace __cpo
+
+// uninitialized_fill
+
+namespace __uninitialized_fill {
+
+struct __fn {
+  template <__nothrow_forward_iterator _ForwardIterator,
+            __nothrow_sentinel_for<_ForwardIterator> _Sentinel,
+            class _Tp>
+    requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
+  _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
+    return _VSTD::__uninitialized_fill<_ValueType>(_VSTD::move(__first), _VSTD::move(__last), __x);
+  }
+
+  template <__nothrow_forward_range _ForwardRange, class _Tp>
+    requires constructible_from<range_value_t<_ForwardRange>, const _Tp&>
+  borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range, const _Tp& __x) const {
+    return (*this)(ranges::begin(__range), ranges::end(__range), __x);
+  }
+};
+
+} // namespace __uninitialized_fill
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn{};
+} // namespace __cpo
+
+// uninitialized_fill_n
+
+namespace __uninitialized_fill_n {
+
+struct __fn {
+  template <__nothrow_forward_iterator _ForwardIterator, class _Tp>
+    requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
+  _ForwardIterator operator()(_ForwardIterator __first,
+                              iter_difference_t<_ForwardIterator> __n,
+                              const _Tp& __x) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
+    return _VSTD::__uninitialized_fill_n<_ValueType>(_VSTD::move(__first), __n, __x);
+  }
+};
+
+} // namespace __uninitialized_fill_n
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{};
+} // namespace __cpo
+
+// uninitialized_copy
+
+template <class _InputIterator, class _OutputIterator>
+using uninitialized_copy_result = in_out_result<_InputIterator, _OutputIterator>;
+
+namespace __uninitialized_copy {
+
+struct __fn {
+  template <input_iterator _InputIterator,
+            sentinel_for<_InputIterator> _Sentinel1,
+            __nothrow_forward_iterator _OutputIterator,
+            __nothrow_sentinel_for<_OutputIterator> _Sentinel2>
+    requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
+  uninitialized_copy_result<_InputIterator, _OutputIterator>
+  operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
+
+    auto __result = _VSTD::__uninitialized_copy<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
+                                                            _VSTD::move(__ofirst), _VSTD::move(__olast));
+    return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
+  }
+
+  template <input_range _InputRange, __nothrow_forward_range _OutputRange>
+    requires constructible_from<range_value_t<_OutputRange>, range_reference_t<_InputRange>>
+  uninitialized_copy_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>>
+  operator()( _InputRange&& __in_range, _OutputRange&& __out_range) const {
+    return (*this)(ranges::begin(__in_range), ranges::end(__in_range),
+                   ranges::begin(__out_range), ranges::end(__out_range));
+  }
+};
+
+} // namespace __uninitialized_copy
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{};
+} // namespace __cpo
+
+// uninitialized_copy_n
+
+template <class _InputIterator, class _OutputIterator>
+using uninitialized_copy_n_result = in_out_result<_InputIterator, _OutputIterator>;
+
+namespace __uninitialized_copy_n {
+
+struct __fn {
+  template <input_iterator _InputIterator,
+           __nothrow_forward_iterator _OutputIterator,
+           __nothrow_sentinel_for<_OutputIterator> _Sentinel>
+    requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
+  uninitialized_copy_n_result<_InputIterator, _OutputIterator>
+  operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n,
+             _OutputIterator __ofirst, _Sentinel __olast) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
+    auto __result = _VSTD::__uninitialized_copy_n<_ValueType>(_VSTD::move(__ifirst), __n,
+                                                              _VSTD::move(__ofirst), _VSTD::move(__olast));
+    return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
+  }
+};
+
+} // namespace __uninitialized_copy_n
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{};
+} // namespace __cpo
+
+// uninitialized_move
+
+template <class _InputIterator, class _OutputIterator>
+using uninitialized_move_result = in_out_result<_InputIterator, _OutputIterator>;
+
+namespace __uninitialized_move {
+
+struct __fn {
+  template <input_iterator _InputIterator,
+            sentinel_for<_InputIterator> _Sentinel1,
+            __nothrow_forward_iterator _OutputIterator,
+            __nothrow_sentinel_for<_OutputIterator> _Sentinel2>
+    requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
+  uninitialized_move_result<_InputIterator, _OutputIterator>
+  operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
+    auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
+    auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
+                                                            _VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move);
+    return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
+  }
+
+  template <input_range _InputRange, __nothrow_forward_range _OutputRange>
+    requires constructible_from<range_value_t<_OutputRange>, range_reference_t<_InputRange>>
+  uninitialized_move_result<borrowed_iterator_t<_InputRange>, borrowed_iterator_t<_OutputRange>>
+  operator()(_InputRange&& __in_range, _OutputRange&& __out_range) const {
+    return (*this)(ranges::begin(__in_range), ranges::end(__in_range),
+                   ranges::begin(__out_range), ranges::end(__out_range));
+  }
+};
+
+} // namespace __uninitialized_move
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_move = __uninitialized_move::__fn{};
+} // namespace __cpo
+
+// uninitialized_move_n
+
+template <class _InputIterator, class _OutputIterator>
+using uninitialized_move_n_result = in_out_result<_InputIterator, _OutputIterator>;
+
+namespace __uninitialized_move_n {
+
+struct __fn {
+  template <input_iterator _InputIterator,
+           __nothrow_forward_iterator _OutputIterator,
+           __nothrow_sentinel_for<_OutputIterator> _Sentinel>
+    requires constructible_from<iter_value_t<_OutputIterator>, iter_reference_t<_InputIterator>>
+  uninitialized_move_n_result<_InputIterator, _OutputIterator>
+  operator()(_InputIterator __ifirst, iter_difference_t<_InputIterator> __n,
+             _OutputIterator __ofirst, _Sentinel __olast) const {
+    using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
+    auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
+    auto __result = _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n,
+                                                              _VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move);
+    return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
+  }
+};
+
+} // namespace __uninitialized_move_n
+
+inline namespace __cpo {
+  inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn{};
+} // namespace __cpo
+
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___MEMORY_RANGES_UNINITIALIZED_ALGORITHMS_H
lib/libcxx/include/__memory/raw_storage_iterator.h
@@ -20,9 +20,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR)
@@ -68,6 +65,4 @@ public:
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
lib/libcxx/include/__memory/shared_ptr.h
@@ -12,14 +12,14 @@
 
 #include <__availability>
 #include <__config>
-#include <__functional_base>
 #include <__functional/binary_function.h>
 #include <__functional/operations.h>
 #include <__functional/reference_wrapper.h>
+#include <__functional_base>
 #include <__memory/addressof.h>
 #include <__memory/allocation_guard.h>
-#include <__memory/allocator_traits.h>
 #include <__memory/allocator.h>
+#include <__memory/allocator_traits.h>
 #include <__memory/compressed_pair.h>
 #include <__memory/pointer_traits.h>
 #include <__memory/unique_ptr.h>
@@ -28,8 +28,8 @@
 #include <cstdlib> // abort
 #include <iosfwd>
 #include <stdexcept>
-#include <typeinfo>
 #include <type_traits>
+#include <typeinfo>
 #include <utility>
 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
 #  include <atomic>
@@ -43,18 +43,15 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Alloc>
 class __allocator_destructor
 {
-    typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits;
+    typedef _LIBCPP_NODEBUG allocator_traits<_Alloc> __alloc_traits;
 public:
-    typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer;
-    typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type;
+    typedef _LIBCPP_NODEBUG typename __alloc_traits::pointer pointer;
+    typedef _LIBCPP_NODEBUG typename __alloc_traits::size_type size_type;
 private:
     _Alloc& __alloc_;
     size_type __s_;
@@ -433,14 +430,20 @@ private:
     element_type*      __ptr_;
     __shared_weak_count* __cntrl_;
 
-    struct __nat {int __for_bool_;};
 public:
-    _LIBCPP_INLINE_VISIBILITY
-    _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
-    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
+    _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT
+        : __ptr_(nullptr),
+          __cntrl_(nullptr)
+    { }
+
+    _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT
+        : __ptr_(nullptr),
+          __cntrl_(nullptr)
+    { }
 
-    template<class _Yp, class = _EnableIf<
+    template<class _Yp, class = __enable_if_t<
         _And<
             __compatible_with<_Yp, _Tp>
             // In C++03 we get errors when trying to do SFINAE with the
@@ -460,643 +463,488 @@ public:
         __enable_weak_this(__p, __p);
     }
 
-    template<class _Yp, class _Dp>
-        shared_ptr(_Yp* __p, _Dp __d,
-                   typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat());
-    template<class _Yp, class _Dp, class _Alloc>
-        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
-                   typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type = __nat());
-    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
-    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
-    template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
-    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
-    template<class _Yp>
-        _LIBCPP_INLINE_VISIBILITY
-        shared_ptr(const shared_ptr<_Yp>& __r,
-                   typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat())
-                       _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
-    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
-    template<class _Yp> _LIBCPP_INLINE_VISIBILITY  shared_ptr(shared_ptr<_Yp>&& __r,
-                   typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat())
-                       _NOEXCEPT;
-    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
-                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
-#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
-    template<class _Yp>
-        shared_ptr(auto_ptr<_Yp>&& __r,
-                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
-#endif
-    template <class _Yp, class _Dp>
-        shared_ptr(unique_ptr<_Yp, _Dp>&&,
-                   typename enable_if
-                   <
-                       !is_lvalue_reference<_Dp>::value &&
-                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
-                       __nat
-                   >::type = __nat());
-    template <class _Yp, class _Dp>
-        shared_ptr(unique_ptr<_Yp, _Dp>&&,
-                   typename enable_if
-                   <
-                       is_lvalue_reference<_Dp>::value &&
-                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
-                       __nat
-                   >::type = __nat());
-
-    ~shared_ptr();
+    template<class _Yp, class _Dp, class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(_Yp* __p, _Dp __d)
+        : __ptr_(__p)
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif // _LIBCPP_NO_EXCEPTIONS
+            typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
+            typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
+#ifndef _LIBCPP_CXX03_LANG
+            __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
+#else
+            __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
+#endif // not _LIBCPP_CXX03_LANG
+            __enable_weak_this(__p, __p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __d(__p);
+            throw;
+        }
+#endif // _LIBCPP_NO_EXCEPTIONS
+    }
 
-    _LIBCPP_INLINE_VISIBILITY
-    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
-    template<class _Yp>
-        typename enable_if
-        <
-            __compatible_with<_Yp, element_type>::value,
-            shared_ptr&
-        >::type
-        _LIBCPP_INLINE_VISIBILITY
-        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
-    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
-    template<class _Yp>
-        typename enable_if
-        <
-            __compatible_with<_Yp, element_type>::value,
-            shared_ptr&
-        >::type
-        _LIBCPP_INLINE_VISIBILITY
-        operator=(shared_ptr<_Yp>&& __r);
-#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
-    template<class _Yp>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            !is_array<_Yp>::value &&
-            is_convertible<_Yp*, element_type*>::value,
-            shared_ptr
-        >::type&
-        operator=(auto_ptr<_Yp>&& __r);
-#endif
-    template <class _Yp, class _Dp>
-        typename enable_if
-        <
-            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
-            shared_ptr&
-        >::type
-        _LIBCPP_INLINE_VISIBILITY
-        operator=(unique_ptr<_Yp, _Dp>&& __r);
+    template<class _Yp, class _Dp, class _Alloc, class = __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
+        : __ptr_(__p)
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif // _LIBCPP_NO_EXCEPTIONS
+            typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
+            typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
+            typedef __allocator_destructor<_A2> _D2;
+            _A2 __a2(__a);
+            unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+            ::new ((void*)_VSTD::addressof(*__hold2.get()))
+#ifndef _LIBCPP_CXX03_LANG
+                _CntrlBlk(__p, _VSTD::move(__d), __a);
+#else
+                _CntrlBlk(__p, __d, __a);
+#endif // not _LIBCPP_CXX03_LANG
+            __cntrl_ = _VSTD::addressof(*__hold2.release());
+            __enable_weak_this(__p, __p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __d(__p);
+            throw;
+        }
+#endif // _LIBCPP_NO_EXCEPTIONS
+    }
+
+    template<class _Dp>
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(nullptr_t __p, _Dp __d)
+        : __ptr_(nullptr)
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif // _LIBCPP_NO_EXCEPTIONS
+            typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
+            typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
+#ifndef _LIBCPP_CXX03_LANG
+            __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
+#else
+            __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
+#endif // not _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __d(__p);
+            throw;
+        }
+#endif // _LIBCPP_NO_EXCEPTIONS
+    }
+
+    template<class _Dp, class _Alloc>
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
+        : __ptr_(nullptr)
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif // _LIBCPP_NO_EXCEPTIONS
+            typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
+            typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
+            typedef __allocator_destructor<_A2> _D2;
+            _A2 __a2(__a);
+            unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+            ::new ((void*)_VSTD::addressof(*__hold2.get()))
+#ifndef _LIBCPP_CXX03_LANG
+                _CntrlBlk(__p, _VSTD::move(__d), __a);
+#else
+                _CntrlBlk(__p, __d, __a);
+#endif // not _LIBCPP_CXX03_LANG
+            __cntrl_ = _VSTD::addressof(*__hold2.release());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __d(__p);
+            throw;
+        }
+#endif // _LIBCPP_NO_EXCEPTIONS
+    }
 
-    _LIBCPP_INLINE_VISIBILITY
-    void swap(shared_ptr& __r) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() _NOEXCEPT;
     template<class _Yp>
-        typename enable_if
-        <
-            __compatible_with<_Yp, element_type>::value,
-            void
-        >::type
-        _LIBCPP_INLINE_VISIBILITY
-        reset(_Yp* __p);
-    template<class _Yp, class _Dp>
-        typename enable_if
-        <
-            __compatible_with<_Yp, element_type>::value,
-            void
-        >::type
-        _LIBCPP_INLINE_VISIBILITY
-        reset(_Yp* __p, _Dp __d);
-    template<class _Yp, class _Dp, class _Alloc>
-        typename enable_if
-        <
-            __compatible_with<_Yp, element_type>::value,
-            void
-        >::type
-        _LIBCPP_INLINE_VISIBILITY
-        reset(_Yp* __p, _Dp __d, _Alloc __a);
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
+        : __ptr_(__p),
+          __cntrl_(__r.__cntrl_)
+    {
+        if (__cntrl_)
+            __cntrl_->__add_shared();
+    }
 
-    _LIBCPP_INLINE_VISIBILITY
-    element_type* get() const _NOEXCEPT {return __ptr_;}
-    _LIBCPP_INLINE_VISIBILITY
-    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
-        {return *__ptr_;}
-    _LIBCPP_INLINE_VISIBILITY
-    element_type* operator->() const _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(const shared_ptr& __r) _NOEXCEPT
+        : __ptr_(__r.__ptr_),
+          __cntrl_(__r.__cntrl_)
     {
-        static_assert(!is_array<_Tp>::value,
-                      "std::shared_ptr<T>::operator-> is only valid when T is not an array type.");
-        return __ptr_;
+        if (__cntrl_)
+            __cntrl_->__add_shared();
     }
-    _LIBCPP_INLINE_VISIBILITY
-    long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    bool unique() const _NOEXCEPT {return use_count() == 1;}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit operator bool() const _NOEXCEPT {return get() != nullptr;}
-    template <class _Up>
-        _LIBCPP_INLINE_VISIBILITY
-        bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
-        {return __cntrl_ < __p.__cntrl_;}
-    template <class _Up>
-        _LIBCPP_INLINE_VISIBILITY
-        bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
-        {return __cntrl_ < __p.__cntrl_;}
-    _LIBCPP_INLINE_VISIBILITY
-    bool
-    __owner_equivalent(const shared_ptr& __p) const
-        {return __cntrl_ == __p.__cntrl_;}
 
-#if _LIBCPP_STD_VER > 14
-    typename add_lvalue_reference<element_type>::type
-    _LIBCPP_INLINE_VISIBILITY
-    operator[](ptrdiff_t __i) const
+    template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(const shared_ptr<_Yp>& __r) _NOEXCEPT
+        : __ptr_(__r.__ptr_),
+          __cntrl_(__r.__cntrl_)
     {
-            static_assert(is_array<_Tp>::value,
-                          "std::shared_ptr<T>::operator[] is only valid when T is an array type.");
-            return __ptr_[__i];
+        if (__cntrl_)
+            __cntrl_->__add_shared();
     }
-#endif
 
-#ifndef _LIBCPP_NO_RTTI
-    template <class _Dp>
-        _LIBCPP_INLINE_VISIBILITY
-        _Dp* __get_deleter() const _NOEXCEPT
-            {return static_cast<_Dp*>(__cntrl_
-                    ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
-                      : nullptr);}
-#endif // _LIBCPP_NO_RTTI
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(shared_ptr&& __r) _NOEXCEPT
+        : __ptr_(__r.__ptr_),
+          __cntrl_(__r.__cntrl_)
+    {
+        __r.__ptr_ = nullptr;
+        __r.__cntrl_ = nullptr;
+    }
 
-    template<class _Yp, class _CntrlBlk>
-    static shared_ptr<_Tp>
-    __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT
+    template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(shared_ptr<_Yp>&& __r) _NOEXCEPT
+        : __ptr_(__r.__ptr_),
+          __cntrl_(__r.__cntrl_)
     {
-        shared_ptr<_Tp> __r;
-        __r.__ptr_ = __p;
-        __r.__cntrl_ = __cntrl;
-        __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-        return __r;
+        __r.__ptr_ = nullptr;
+        __r.__cntrl_ = nullptr;
     }
 
-private:
-    template <class _Yp, bool = is_function<_Yp>::value>
-        struct __shared_ptr_default_allocator
-        {
-            typedef allocator<_Yp> type;
-        };
+    template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    explicit shared_ptr(const weak_ptr<_Yp>& __r)
+        : __ptr_(__r.__ptr_),
+          __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
+    {
+        if (__cntrl_ == nullptr)
+            __throw_bad_weak_ptr();
+    }
 
-    template <class _Yp>
-        struct __shared_ptr_default_allocator<_Yp, true>
+#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
+    template<class _Yp, class = __enable_if_t<is_convertible<_Yp*, element_type*>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(auto_ptr<_Yp>&& __r)
+        : __ptr_(__r.get())
+    {
+        typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
+        __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
+        __enable_weak_this(__r.get(), __r.get());
+        __r.release();
+    }
+#endif
+
+    template <class _Yp, class _Dp, class = __enable_if_t<
+        !is_lvalue_reference<_Dp>::value &&
+         is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(unique_ptr<_Yp, _Dp>&& __r)
+        : __ptr_(__r.get())
+    {
+#if _LIBCPP_STD_VER > 11
+        if (__ptr_ == nullptr)
+            __cntrl_ = nullptr;
+        else
+#endif
         {
-            typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
-        };
+            typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
+            typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, _Dp, _AllocT > _CntrlBlk;
+            __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
+            __enable_weak_this(__r.get(), __r.get());
+        }
+        __r.release();
+    }
 
-    template <class _Yp, class _OrigPtr>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if<is_convertible<_OrigPtr*,
-                                          const enable_shared_from_this<_Yp>*
-        >::value,
-            void>::type
-        __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
-                           _OrigPtr* __ptr) _NOEXCEPT
+    template <class _Yp, class _Dp, class = void, class = __enable_if_t<
+        is_lvalue_reference<_Dp>::value &&
+        is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr(unique_ptr<_Yp, _Dp>&& __r)
+        : __ptr_(__r.get())
+    {
+#if _LIBCPP_STD_VER > 11
+        if (__ptr_ == nullptr)
+            __cntrl_ = nullptr;
+        else
+#endif
         {
-            typedef typename remove_cv<_Yp>::type _RawYp;
-            if (__e && __e->__weak_this_.expired())
-            {
-                __e->__weak_this_ = shared_ptr<_RawYp>(*this,
-                    const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
-            }
+            typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
+            typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer,
+                                        reference_wrapper<typename remove_reference<_Dp>::type>,
+                                        _AllocT > _CntrlBlk;
+            __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT());
+            __enable_weak_this(__r.get(), __r.get());
         }
+        __r.release();
+    }
 
-    _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
+    _LIBCPP_HIDE_FROM_ABI
+    ~shared_ptr()
+    {
+        if (__cntrl_)
+            __cntrl_->__release_shared();
+    }
 
-    template <class, class _Yp>
-        struct __shared_ptr_default_delete
-            : default_delete<_Yp> {};
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr<_Tp>& operator=(const shared_ptr& __r) _NOEXCEPT
+    {
+        shared_ptr(__r).swap(*this);
+        return *this;
+    }
 
-    template <class _Yp, class _Un, size_t _Sz>
-        struct __shared_ptr_default_delete<_Yp[_Sz], _Un>
-            : default_delete<_Yp[]> {};
+    template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr<_Tp>& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
+    {
+        shared_ptr(__r).swap(*this);
+        return *this;
+    }
 
-    template <class _Yp, class _Un>
-        struct __shared_ptr_default_delete<_Yp[], _Un>
-            : default_delete<_Yp[]> {};
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr<_Tp>& operator=(shared_ptr&& __r) _NOEXCEPT
+    {
+        shared_ptr(_VSTD::move(__r)).swap(*this);
+        return *this;
+    }
 
-    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
-    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
-};
+    template<class _Yp, class = __enable_if_t<__compatible_with<_Yp, _Tp>::value> >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr<_Tp>& operator=(shared_ptr<_Yp>&& __r)
+    {
+        shared_ptr(_VSTD::move(__r)).swap(*this);
+        return *this;
+    }
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
-template<class _Tp>
-shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
-template<class _Tp, class _Dp>
-shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>;
+#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
+    template<class _Yp, class = __enable_if_t<
+        !is_array<_Yp>::value &&
+        is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr<_Tp>& operator=(auto_ptr<_Yp>&& __r)
+    {
+        shared_ptr(_VSTD::move(__r)).swap(*this);
+        return *this;
+    }
 #endif
 
-template<class _Tp>
-inline
-_LIBCPP_CONSTEXPR
-shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
-    : __ptr_(nullptr),
-      __cntrl_(nullptr)
-{
-}
+    template <class _Yp, class _Dp, class = __enable_if_t<
+        is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    shared_ptr<_Tp>& operator=(unique_ptr<_Yp, _Dp>&& __r)
+    {
+        shared_ptr(_VSTD::move(__r)).swap(*this);
+        return *this;
+    }
 
-template<class _Tp>
-inline
-_LIBCPP_CONSTEXPR
-shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
-    : __ptr_(nullptr),
-      __cntrl_(nullptr)
-{
-}
+    _LIBCPP_HIDE_FROM_ABI
+    void swap(shared_ptr& __r) _NOEXCEPT
+    {
+        _VSTD::swap(__ptr_, __r.__ptr_);
+        _VSTD::swap(__cntrl_, __r.__cntrl_);
+    }
 
-template<class _Tp>
-template<class _Yp, class _Dp>
-shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
-                            typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type)
-    : __ptr_(__p)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
+    _LIBCPP_HIDE_FROM_ABI
+    void reset() _NOEXCEPT
     {
-#endif // _LIBCPP_NO_EXCEPTIONS
-        typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
-        typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
-#ifndef _LIBCPP_CXX03_LANG
-        __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
-#else
-        __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
-#endif // not _LIBCPP_CXX03_LANG
-        __enable_weak_this(__p, __p);
-#ifndef _LIBCPP_NO_EXCEPTIONS
+        shared_ptr().swap(*this);
     }
-    catch (...)
+
+    template<class _Yp, class = __enable_if_t<
+        __compatible_with<_Yp, _Tp>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    void reset(_Yp* __p)
     {
-        __d(__p);
-        throw;
+        shared_ptr(__p).swap(*this);
     }
-#endif // _LIBCPP_NO_EXCEPTIONS
-}
 
-template<class _Tp>
-template<class _Dp>
-shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
-    : __ptr_(nullptr)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
+    template<class _Yp, class _Dp, class = __enable_if_t<
+        __compatible_with<_Yp, _Tp>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    void reset(_Yp* __p, _Dp __d)
     {
-#endif // _LIBCPP_NO_EXCEPTIONS
-        typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
-        typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
-#ifndef _LIBCPP_CXX03_LANG
-        __cntrl_ = new _CntrlBlk(__p, _VSTD::move(__d), _AllocT());
-#else
-        __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
-#endif // not _LIBCPP_CXX03_LANG
-#ifndef _LIBCPP_NO_EXCEPTIONS
+        shared_ptr(__p, __d).swap(*this);
     }
-    catch (...)
+
+    template<class _Yp, class _Dp, class _Alloc, class = __enable_if_t<
+        __compatible_with<_Yp, _Tp>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    void reset(_Yp* __p, _Dp __d, _Alloc __a)
     {
-        __d(__p);
-        throw;
+        shared_ptr(__p, __d, __a).swap(*this);
     }
-#endif // _LIBCPP_NO_EXCEPTIONS
-}
 
-template<class _Tp>
-template<class _Yp, class _Dp, class _Alloc>
-shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
-                            typename enable_if<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, element_type>::value, __nat>::type)
-    : __ptr_(__p)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
+    _LIBCPP_HIDE_FROM_ABI
+    element_type* get() const _NOEXCEPT
     {
-#endif // _LIBCPP_NO_EXCEPTIONS
-        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
-        typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
-        typedef __allocator_destructor<_A2> _D2;
-        _A2 __a2(__a);
-        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
-        ::new ((void*)_VSTD::addressof(*__hold2.get()))
-#ifndef _LIBCPP_CXX03_LANG
-            _CntrlBlk(__p, _VSTD::move(__d), __a);
-#else
-            _CntrlBlk(__p, __d, __a);
-#endif // not _LIBCPP_CXX03_LANG
-        __cntrl_ = _VSTD::addressof(*__hold2.release());
-        __enable_weak_this(__p, __p);
-#ifndef _LIBCPP_NO_EXCEPTIONS
+        return __ptr_;
     }
-    catch (...)
+
+    _LIBCPP_HIDE_FROM_ABI
+    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
     {
-        __d(__p);
-        throw;
+        return *__ptr_;
     }
-#endif // _LIBCPP_NO_EXCEPTIONS
-}
 
-template<class _Tp>
-template<class _Dp, class _Alloc>
-shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
-    : __ptr_(nullptr)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
+    _LIBCPP_HIDE_FROM_ABI
+    element_type* operator->() const _NOEXCEPT
     {
-#endif // _LIBCPP_NO_EXCEPTIONS
-        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
-        typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
-        typedef __allocator_destructor<_A2> _D2;
-        _A2 __a2(__a);
-        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
-        ::new ((void*)_VSTD::addressof(*__hold2.get()))
-#ifndef _LIBCPP_CXX03_LANG
-            _CntrlBlk(__p, _VSTD::move(__d), __a);
-#else
-            _CntrlBlk(__p, __d, __a);
-#endif // not _LIBCPP_CXX03_LANG
-        __cntrl_ = _VSTD::addressof(*__hold2.release());
-#ifndef _LIBCPP_NO_EXCEPTIONS
+        static_assert(!is_array<_Tp>::value,
+                      "std::shared_ptr<T>::operator-> is only valid when T is not an array type.");
+        return __ptr_;
     }
-    catch (...)
+
+    _LIBCPP_HIDE_FROM_ABI
+    long use_count() const _NOEXCEPT
     {
-        __d(__p);
-        throw;
+        return __cntrl_ ? __cntrl_->use_count() : 0;
     }
-#endif // _LIBCPP_NO_EXCEPTIONS
-}
 
-template<class _Tp>
-template<class _Yp>
-inline
-shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
-    : __ptr_(__p),
-      __cntrl_(__r.__cntrl_)
-{
-    if (__cntrl_)
-        __cntrl_->__add_shared();
-}
+    _LIBCPP_HIDE_FROM_ABI
+    bool unique() const _NOEXCEPT
+    {
+        return use_count() == 1;
+    }
 
-template<class _Tp>
-inline
-shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
-    : __ptr_(__r.__ptr_),
-      __cntrl_(__r.__cntrl_)
-{
-    if (__cntrl_)
-        __cntrl_->__add_shared();
-}
+    _LIBCPP_HIDE_FROM_ABI
+    explicit operator bool() const _NOEXCEPT
+    {
+        return get() != nullptr;
+    }
 
-template<class _Tp>
-template<class _Yp>
-inline
-shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
-                            typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
-         _NOEXCEPT
-    : __ptr_(__r.__ptr_),
-      __cntrl_(__r.__cntrl_)
-{
-    if (__cntrl_)
-        __cntrl_->__add_shared();
-}
+    template <class _Up>
+    _LIBCPP_HIDE_FROM_ABI
+    bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
+    {
+        return __cntrl_ < __p.__cntrl_;
+    }
 
-template<class _Tp>
-inline
-shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
-    : __ptr_(__r.__ptr_),
-      __cntrl_(__r.__cntrl_)
-{
-    __r.__ptr_ = nullptr;
-    __r.__cntrl_ = nullptr;
-}
+    template <class _Up>
+    _LIBCPP_HIDE_FROM_ABI
+    bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
+    {
+        return __cntrl_ < __p.__cntrl_;
+    }
 
-template<class _Tp>
-template<class _Yp>
-inline
-shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
-                            typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type)
-         _NOEXCEPT
-    : __ptr_(__r.__ptr_),
-      __cntrl_(__r.__cntrl_)
-{
-    __r.__ptr_ = nullptr;
-    __r.__cntrl_ = nullptr;
-}
+    _LIBCPP_HIDE_FROM_ABI
+    bool __owner_equivalent(const shared_ptr& __p) const
+    {
+        return __cntrl_ == __p.__cntrl_;
+    }
 
-#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
-template<class _Tp>
-template<class _Yp>
-shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
-                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
-    : __ptr_(__r.get())
-{
-    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
-    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
-    __enable_weak_this(__r.get(), __r.get());
-    __r.release();
-}
+#if _LIBCPP_STD_VER > 14
+    _LIBCPP_HIDE_FROM_ABI
+    typename add_lvalue_reference<element_type>::type operator[](ptrdiff_t __i) const
+    {
+            static_assert(is_array<_Tp>::value,
+                          "std::shared_ptr<T>::operator[] is only valid when T is an array type.");
+            return __ptr_[__i];
+    }
 #endif
 
-template<class _Tp>
-template <class _Yp, class _Dp>
-shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
-                            typename enable_if
-                            <
-                                !is_lvalue_reference<_Dp>::value &&
-                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
-                                __nat
-                            >::type)
-    : __ptr_(__r.get())
-{
-#if _LIBCPP_STD_VER > 11
-    if (__ptr_ == nullptr)
-        __cntrl_ = nullptr;
-    else
-#endif
+#ifndef _LIBCPP_NO_RTTI
+    template <class _Dp>
+    _LIBCPP_HIDE_FROM_ABI
+    _Dp* __get_deleter() const _NOEXCEPT
     {
-        typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
-        typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer, _Dp, _AllocT > _CntrlBlk;
-        __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
-        __enable_weak_this(__r.get(), __r.get());
+        return static_cast<_Dp*>(__cntrl_
+                    ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
+                      : nullptr);
     }
-    __r.release();
-}
+#endif // _LIBCPP_NO_RTTI
 
-template<class _Tp>
-template <class _Yp, class _Dp>
-shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
-                            typename enable_if
-                            <
-                                is_lvalue_reference<_Dp>::value &&
-                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
-                                __nat
-                            >::type)
-    : __ptr_(__r.get())
-{
-#if _LIBCPP_STD_VER > 11
-    if (__ptr_ == nullptr)
-        __cntrl_ = nullptr;
-    else
-#endif
+    template<class _Yp, class _CntrlBlk>
+    _LIBCPP_HIDE_FROM_ABI
+    static shared_ptr<_Tp> __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT
     {
-        typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
-        typedef __shared_ptr_pointer<typename unique_ptr<_Yp, _Dp>::pointer,
-                                     reference_wrapper<typename remove_reference<_Dp>::type>,
-                                     _AllocT > _CntrlBlk;
-        __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT());
-        __enable_weak_this(__r.get(), __r.get());
+        shared_ptr<_Tp> __r;
+        __r.__ptr_ = __p;
+        __r.__cntrl_ = __cntrl;
+        __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
+        return __r;
     }
-    __r.release();
-}
-
-template<class _Tp>
-shared_ptr<_Tp>::~shared_ptr()
-{
-    if (__cntrl_)
-        __cntrl_->__release_shared();
-}
-
-template<class _Tp>
-inline
-shared_ptr<_Tp>&
-shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
-{
-    shared_ptr(__r).swap(*this);
-    return *this;
-}
-
-template<class _Tp>
-template<class _Yp>
-inline
-typename enable_if
-<
-    __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
-    shared_ptr<_Tp>&
->::type
-shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
-{
-    shared_ptr(__r).swap(*this);
-    return *this;
-}
 
-template<class _Tp>
-inline
-shared_ptr<_Tp>&
-shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
-{
-    shared_ptr(_VSTD::move(__r)).swap(*this);
-    return *this;
-}
+private:
+    template <class _Yp, bool = is_function<_Yp>::value>
+    struct __shared_ptr_default_allocator
+    {
+        typedef allocator<_Yp> type;
+    };
 
-template<class _Tp>
-template<class _Yp>
-inline
-typename enable_if
-<
-    __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
-    shared_ptr<_Tp>&
->::type
-shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
-{
-    shared_ptr(_VSTD::move(__r)).swap(*this);
-    return *this;
-}
+    template <class _Yp>
+    struct __shared_ptr_default_allocator<_Yp, true>
+    {
+        typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
+    };
 
-#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
-template<class _Tp>
-template<class _Yp>
-inline
-typename enable_if
-<
-    !is_array<_Yp>::value &&
-    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
-    shared_ptr<_Tp>
->::type&
-shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
-{
-    shared_ptr(_VSTD::move(__r)).swap(*this);
-    return *this;
-}
-#endif
+    template <class _Yp, class _OrigPtr, class = __enable_if_t<
+        is_convertible<_OrigPtr*, const enable_shared_from_this<_Yp>*>::value
+    > >
+    _LIBCPP_HIDE_FROM_ABI
+    void __enable_weak_this(const enable_shared_from_this<_Yp>* __e, _OrigPtr* __ptr) _NOEXCEPT
+    {
+        typedef typename remove_cv<_Yp>::type _RawYp;
+        if (__e && __e->__weak_this_.expired())
+        {
+            __e->__weak_this_ = shared_ptr<_RawYp>(*this,
+                const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
+        }
+    }
 
-template<class _Tp>
-template <class _Yp, class _Dp>
-inline
-typename enable_if
-<
-    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
-                   typename shared_ptr<_Tp>::element_type*>::value,
-    shared_ptr<_Tp>&
->::type
-shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
-{
-    shared_ptr(_VSTD::move(__r)).swap(*this);
-    return *this;
-}
+    _LIBCPP_HIDE_FROM_ABI void __enable_weak_this(...) _NOEXCEPT { }
 
-template<class _Tp>
-inline
-void
-shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
-{
-    _VSTD::swap(__ptr_, __r.__ptr_);
-    _VSTD::swap(__cntrl_, __r.__cntrl_);
-}
+    template <class, class _Yp>
+    struct __shared_ptr_default_delete
+        : default_delete<_Yp>
+    { };
 
-template<class _Tp>
-inline
-void
-shared_ptr<_Tp>::reset() _NOEXCEPT
-{
-    shared_ptr().swap(*this);
-}
+    template <class _Yp, class _Un, size_t _Sz>
+    struct __shared_ptr_default_delete<_Yp[_Sz], _Un>
+        : default_delete<_Yp[]>
+    { };
 
-template<class _Tp>
-template<class _Yp>
-inline
-typename enable_if
-<
-    __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
-    void
->::type
-shared_ptr<_Tp>::reset(_Yp* __p)
-{
-    shared_ptr(__p).swap(*this);
-}
+    template <class _Yp, class _Un>
+    struct __shared_ptr_default_delete<_Yp[], _Un>
+        : default_delete<_Yp[]>
+    { };
 
-template<class _Tp>
-template<class _Yp, class _Dp>
-inline
-typename enable_if
-<
-    __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
-    void
->::type
-shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
-{
-    shared_ptr(__p, __d).swap(*this);
-}
+    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
+    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
+};
 
+#if _LIBCPP_STD_VER > 14
 template<class _Tp>
-template<class _Yp, class _Dp, class _Alloc>
-inline
-typename enable_if
-<
-    __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value,
-    void
->::type
-shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
-{
-    shared_ptr(__p, __d, __a).swap(*this);
-}
+shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
+template<class _Tp, class _Dp>
+shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>;
+#endif
 
 //
 // std::allocate_shared and std::make_shared
 //
-template<class _Tp, class _Alloc, class ..._Args, class = _EnableIf<!is_array<_Tp>::value> >
+template<class _Tp, class _Alloc, class ..._Args, class = __enable_if_t<!is_array<_Tp>::value> >
 _LIBCPP_HIDE_FROM_ABI
 shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&& ...__args)
 {
@@ -1108,7 +956,7 @@ shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&& ...__args)
     return shared_ptr<_Tp>::__create_with_control_block((*__control_block).__get_elem(), _VSTD::addressof(*__control_block));
 }
 
-template<class _Tp, class ..._Args, class = _EnableIf<!is_array<_Tp>::value> >
+template<class _Tp, class ..._Args, class = __enable_if_t<!is_array<_Tp>::value> >
 _LIBCPP_HIDE_FROM_ABI
 shared_ptr<_Tp> make_shared(_Args&& ...__args)
 {
@@ -1326,7 +1174,12 @@ template<class _Tp>
 class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr
 {
 public:
+#if _LIBCPP_STD_VER > 14
+    typedef remove_extent_t<_Tp> element_type;
+#else
     typedef _Tp element_type;
+#endif
+
 private:
     element_type*        __ptr_;
     __shared_weak_count* __cntrl_;
@@ -1335,18 +1188,18 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
     template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
-                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
+                   typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
                         _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
     weak_ptr(weak_ptr const& __r) _NOEXCEPT;
     template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
-                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
+                   typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
                          _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     weak_ptr(weak_ptr&& __r) _NOEXCEPT;
     template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
-                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
+                   typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
                          _NOEXCEPT;
     ~weak_ptr();
 
@@ -1355,7 +1208,7 @@ public:
     template<class _Yp>
         typename enable_if
         <
-            is_convertible<_Yp*, element_type*>::value,
+            __compatible_with<_Yp, _Tp>::value,
             weak_ptr&
         >::type
         _LIBCPP_INLINE_VISIBILITY
@@ -1366,7 +1219,7 @@ public:
     template<class _Yp>
         typename enable_if
         <
-            is_convertible<_Yp*, element_type*>::value,
+            __compatible_with<_Yp, _Tp>::value,
             weak_ptr&
         >::type
         _LIBCPP_INLINE_VISIBILITY
@@ -1375,7 +1228,7 @@ public:
     template<class _Yp>
         typename enable_if
         <
-            is_convertible<_Yp*, element_type*>::value,
+            __compatible_with<_Yp, _Tp>::value,
             weak_ptr&
         >::type
         _LIBCPP_INLINE_VISIBILITY
@@ -1406,7 +1259,7 @@ public:
     template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER > 14
 template<class _Tp>
 weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>;
 #endif
@@ -1434,7 +1287,7 @@ template<class _Tp>
 template<class _Yp>
 inline
 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
-                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
+                        typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
                          _NOEXCEPT
     : __ptr_(__r.__ptr_),
       __cntrl_(__r.__cntrl_)
@@ -1447,7 +1300,7 @@ template<class _Tp>
 template<class _Yp>
 inline
 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
-                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
+                        typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
          _NOEXCEPT
     : __ptr_(__r.__ptr_),
       __cntrl_(__r.__cntrl_)
@@ -1470,7 +1323,7 @@ template<class _Tp>
 template<class _Yp>
 inline
 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
-                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
+                        typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
          _NOEXCEPT
     : __ptr_(__r.__ptr_),
       __cntrl_(__r.__cntrl_)
@@ -1500,7 +1353,7 @@ template<class _Yp>
 inline
 typename enable_if
 <
-    is_convertible<_Yp*, _Tp*>::value,
+    __compatible_with<_Yp, _Tp>::value,
     weak_ptr<_Tp>&
 >::type
 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
@@ -1523,7 +1376,7 @@ template<class _Yp>
 inline
 typename enable_if
 <
-    is_convertible<_Yp*, _Tp*>::value,
+    __compatible_with<_Yp, _Tp>::value,
     weak_ptr<_Tp>&
 >::type
 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
@@ -1537,7 +1390,7 @@ template<class _Yp>
 inline
 typename enable_if
 <
-    is_convertible<_Yp*, _Tp*>::value,
+    __compatible_with<_Yp, _Tp>::value,
     weak_ptr<_Tp>&
 >::type
 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
@@ -1571,17 +1424,6 @@ weak_ptr<_Tp>::reset() _NOEXCEPT
     weak_ptr().swap(*this);
 }
 
-template<class _Tp>
-template<class _Yp>
-shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
-                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
-    : __ptr_(__r.__ptr_),
-      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
-{
-    if (__cntrl_ == nullptr)
-        __throw_bad_weak_ptr();
-}
-
 template<class _Tp>
 shared_ptr<_Tp>
 weak_ptr<_Tp>::lock() const _NOEXCEPT
@@ -1730,7 +1572,7 @@ basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
 
 
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+#if !defined(_LIBCPP_HAS_NO_THREADS)
 
 class _LIBCPP_TYPE_VIS __sp_mut
 {
@@ -1870,10 +1712,8 @@ atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v
     return atomic_compare_exchange_weak(__p, __v, __w);
 }
 
-#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+#endif // !defined(_LIBCPP_HAS_NO_THREADS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_SHARED_PTR_H
lib/libcxx/include/__memory/temporary_buffer.h
@@ -19,9 +19,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
@@ -84,6 +81,4 @@ struct __return_temporary_buffer
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H
lib/libcxx/include/__memory/uninitialized_algorithms.h
@@ -13,6 +13,7 @@
 #include <__config>
 #include <__memory/addressof.h>
 #include <__memory/construct_at.h>
+#include <__memory/voidify.h>
 #include <iterator>
 #include <utility>
 
@@ -20,242 +21,330 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+// This is a simplified version of C++20 `unreachable_sentinel` that doesn't use concepts and thus can be used in any
+// language mode.
+struct __unreachable_sentinel {
+  template <class _Iter>
+  _LIBCPP_HIDE_FROM_ABI friend _LIBCPP_CONSTEXPR bool operator!=(const _Iter&, __unreachable_sentinel) _NOEXCEPT {
+    return true;
+  }
+};
+
+// uninitialized_copy
+
+template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2>
+inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
+__uninitialized_copy(_InputIterator __ifirst, _Sentinel1 __ilast,
+                     _ForwardIterator __ofirst, _Sentinel2 __olast) {
+  _ForwardIterator __idx = __ofirst;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+  try {
+#endif
+    for (; __ifirst != __ilast && __idx != __olast; ++__ifirst, (void)++__idx)
+      ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+  } catch (...) {
+    _VSTD::__destroy(__ofirst, __idx);
+    throw;
+  }
+#endif
+
+  return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx));
+}
+
 template <class _InputIterator, class _ForwardIterator>
-_ForwardIterator
-uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
-{
-    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+_ForwardIterator uninitialized_copy(_InputIterator __ifirst, _InputIterator __ilast,
+                                    _ForwardIterator __ofirst) {
+  typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
+  auto __result = _VSTD::__uninitialized_copy<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
+                                                          _VSTD::move(__ofirst), __unreachable_sentinel());
+  return _VSTD::move(__result.second);
+}
+
+// uninitialized_copy_n
+
+template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel>
+inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
+__uninitialized_copy_n(_InputIterator __ifirst, _Size __n,
+                       _ForwardIterator __ofirst, _Sentinel __olast) {
+  _ForwardIterator __idx = __ofirst;
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    _ForwardIterator __s = __r;
-    try
-    {
+  try {
 #endif
-        for (; __f != __l; ++__f, (void) ++__r)
-            ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f);
+    for (; __n > 0 && __idx != __olast; ++__ifirst, (void)++__idx, (void)--__n)
+      ::new (_VSTD::__voidify(*__idx)) _ValueType(*__ifirst);
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        for (; __s != __r; ++__s)
-            __s->~value_type();
-        throw;
-    }
+  } catch (...) {
+    _VSTD::__destroy(__ofirst, __idx);
+    throw;
+  }
 #endif
-    return __r;
+
+  return pair<_InputIterator, _ForwardIterator>(_VSTD::move(__ifirst), _VSTD::move(__idx));
 }
 
 template <class _InputIterator, class _Size, class _ForwardIterator>
-_ForwardIterator
-uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
+inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_copy_n(_InputIterator __ifirst, _Size __n,
+                                                                   _ForwardIterator __ofirst) {
+  typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
+  auto __result = _VSTD::__uninitialized_copy_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst),
+                                                            __unreachable_sentinel());
+  return _VSTD::move(__result.second);
+}
+
+// uninitialized_fill
+
+template <class _ValueType, class _ForwardIterator, class _Sentinel, class _Tp>
+inline _LIBCPP_HIDE_FROM_ABI
+_ForwardIterator __uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    _ForwardIterator __idx = __first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    _ForwardIterator __s = __r;
     try
     {
 #endif
-        for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
-            ::new ((void*)_VSTD::addressof(*__r)) value_type(*__f);
+        for (; __idx != __last; ++__idx)
+            ::new (_VSTD::__voidify(*__idx)) _ValueType(__x);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
-        for (; __s != __r; ++__s)
-            __s->~value_type();
+        _VSTD::__destroy(__first, __idx);
         throw;
     }
 #endif
-    return __r;
+
+    return __idx;
 }
 
 template <class _ForwardIterator, class _Tp>
-void
-uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
+inline _LIBCPP_HIDE_FROM_ABI
+void uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __x)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
+    (void)_VSTD::__uninitialized_fill<_ValueType>(__first, __last, __x);
+}
+
+// uninitialized_fill_n
+
+template <class _ValueType, class _ForwardIterator, class _Size, class _Tp>
+inline _LIBCPP_HIDE_FROM_ABI
+_ForwardIterator __uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
+{
+    _ForwardIterator __idx = __first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    _ForwardIterator __s = __f;
     try
     {
 #endif
-        for (; __f != __l; ++__f)
-            ::new ((void*)_VSTD::addressof(*__f)) value_type(__x);
+        for (; __n > 0; ++__idx, (void) --__n)
+            ::new (_VSTD::__voidify(*__idx)) _ValueType(__x);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
-        for (; __s != __f; ++__s)
-            __s->~value_type();
+        _VSTD::__destroy(__first, __idx);
         throw;
     }
 #endif
+
+    return __idx;
 }
 
 template <class _ForwardIterator, class _Size, class _Tp>
-_ForwardIterator
-uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
+inline _LIBCPP_HIDE_FROM_ABI
+_ForwardIterator uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
+    return _VSTD::__uninitialized_fill_n<_ValueType>(__first, __n, __x);
+}
+
+#if _LIBCPP_STD_VER > 14
+
+// uninitialized_default_construct
+
+template <class _ValueType, class _ForwardIterator, class _Sentinel>
+inline _LIBCPP_HIDE_FROM_ABI
+_ForwardIterator __uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) {
+    auto __idx = __first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    _ForwardIterator __s = __f;
-    try
-    {
+    try {
 #endif
-        for (; __n > 0; ++__f, (void) --__n)
-            ::new ((void*)_VSTD::addressof(*__f)) value_type(__x);
+    for (; __idx != __last; ++__idx)
+        ::new (_VSTD::__voidify(*__idx)) _ValueType;
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        for (; __s != __f; ++__s)
-            __s->~value_type();
+    } catch (...) {
+        _VSTD::__destroy(__first, __idx);
         throw;
     }
 #endif
-    return __f;
-}
 
-#if _LIBCPP_STD_VER > 14
+    return __idx;
+}
 
 template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-void destroy(_ForwardIterator __first, _ForwardIterator __last) {
-    for (; __first != __last; ++__first)
-        _VSTD::destroy_at(_VSTD::addressof(*__first));
+inline _LIBCPP_HIDE_FROM_ABI
+void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
+    using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
+    (void)_VSTD::__uninitialized_default_construct<_ValueType>(
+        _VSTD::move(__first), _VSTD::move(__last));
 }
 
-template <class _ForwardIterator, class _Size>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
-    for (; __n > 0; (void)++__first, --__n)
-        _VSTD::destroy_at(_VSTD::addressof(*__first));
-    return __first;
-}
+// uninitialized_default_construct_n
 
-template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY
-void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
-    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
+template <class _ValueType, class _ForwardIterator, class _Size>
+inline _LIBCPP_HIDE_FROM_ABI
+_ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
     auto __idx = __first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
     try {
 #endif
-    for (; __idx != __last; ++__idx)
-        ::new ((void*)_VSTD::addressof(*__idx)) _Vt;
+    for (; __n > 0; ++__idx, (void) --__n)
+        ::new (_VSTD::__voidify(*__idx)) _ValueType;
 #ifndef _LIBCPP_NO_EXCEPTIONS
     } catch (...) {
-        _VSTD::destroy(__first, __idx);
+        _VSTD::__destroy(__first, __idx);
         throw;
     }
 #endif
+
+    return __idx;
 }
 
 template <class _ForwardIterator, class _Size>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI
 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
-    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
+    using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
+    return _VSTD::__uninitialized_default_construct_n<_ValueType>(_VSTD::move(__first), __n);
+}
+
+// uninitialized_value_construct
+
+template <class _ValueType, class _ForwardIterator, class _Sentinel>
+inline _LIBCPP_HIDE_FROM_ABI
+_ForwardIterator __uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) {
     auto __idx = __first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
     try {
 #endif
-    for (; __n > 0; (void)++__idx, --__n)
-        ::new ((void*)_VSTD::addressof(*__idx)) _Vt;
-    return __idx;
+    for (; __idx != __last; ++__idx)
+        ::new (_VSTD::__voidify(*__idx)) _ValueType();
 #ifndef _LIBCPP_NO_EXCEPTIONS
     } catch (...) {
-        _VSTD::destroy(__first, __idx);
+        _VSTD::__destroy(__first, __idx);
         throw;
     }
 #endif
-}
 
+    return __idx;
+}
 
 template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI
 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
-    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
+    using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
+    (void)_VSTD::__uninitialized_value_construct<_ValueType>(
+        _VSTD::move(__first), _VSTD::move(__last));
+}
+
+// uninitialized_value_construct_n
+
+template <class _ValueType, class _ForwardIterator, class _Size>
+inline _LIBCPP_HIDE_FROM_ABI
+_ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
     auto __idx = __first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
     try {
 #endif
-    for (; __idx != __last; ++__idx)
-        ::new ((void*)_VSTD::addressof(*__idx)) _Vt();
+    for (; __n > 0; ++__idx, (void) --__n)
+        ::new (_VSTD::__voidify(*__idx)) _ValueType();
 #ifndef _LIBCPP_NO_EXCEPTIONS
     } catch (...) {
-        _VSTD::destroy(__first, __idx);
+        _VSTD::__destroy(__first, __idx);
         throw;
     }
 #endif
+
+    return __idx;
 }
 
 template <class _ForwardIterator, class _Size>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI
 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
-    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
-    auto __idx = __first;
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try {
-#endif
-    for (; __n > 0; (void)++__idx, --__n)
-        ::new ((void*)_VSTD::addressof(*__idx)) _Vt();
-    return __idx;
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    } catch (...) {
-        _VSTD::destroy(__first, __idx);
-        throw;
-    }
-#endif
+    using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
+    return __uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n);
 }
 
+// uninitialized_move
 
-template <class _InputIt, class _ForwardIt>
-inline _LIBCPP_INLINE_VISIBILITY
-_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
-    using _Vt = typename iterator_traits<_ForwardIt>::value_type;
-    auto __idx = __first_res;
+template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2,
+          class _IterMove>
+inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
+__uninitialized_move(_InputIterator __ifirst, _Sentinel1 __ilast,
+                     _ForwardIterator __ofirst, _Sentinel2 __olast, _IterMove __iter_move) {
+  auto __idx = __ofirst;
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    try {
+  try {
 #endif
-    for (; __first != __last; (void)++__idx, ++__first)
-        ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first));
-    return __idx;
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    } catch (...) {
-        _VSTD::destroy(__first_res, __idx);
-        throw;
+    for (; __ifirst != __ilast && __idx != __olast; ++__idx, (void)++__ifirst) {
+      ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
     }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+  } catch (...) {
+    _VSTD::__destroy(__ofirst, __idx);
+    throw;
+  }
 #endif
+
+  return {_VSTD::move(__ifirst), _VSTD::move(__idx)};
+}
+
+template <class _InputIterator, class _ForwardIterator>
+inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator uninitialized_move(_InputIterator __ifirst, _InputIterator __ilast,
+                                                                 _ForwardIterator __ofirst) {
+  using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
+  auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); };
+
+  auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
+                                                          _VSTD::move(__ofirst), __unreachable_sentinel(), __iter_move);
+  return _VSTD::move(__result.second);
 }
 
-template <class _InputIt, class _Size, class _ForwardIt>
-inline _LIBCPP_INLINE_VISIBILITY
-pair<_InputIt, _ForwardIt>
-uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
-    using _Vt = typename iterator_traits<_ForwardIt>::value_type;
-    auto __idx = __first_res;
+// uninitialized_move_n
+
+template <class _ValueType, class _InputIterator, class _Size, class _ForwardIterator, class _Sentinel, class _IterMove>
+inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
+__uninitialized_move_n(_InputIterator __ifirst, _Size __n,
+                       _ForwardIterator __ofirst, _Sentinel __olast, _IterMove __iter_move) {
+  auto __idx = __ofirst;
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    try {
+  try {
 #endif
-    for (; __n > 0; ++__idx, (void)++__first, --__n)
-        ::new ((void*)_VSTD::addressof(*__idx)) _Vt(_VSTD::move(*__first));
-    return {__first, __idx};
+    for (; __n > 0 && __idx != __olast; ++__idx, (void)++__ifirst, --__n)
+      ::new (_VSTD::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    } catch (...) {
-        _VSTD::destroy(__first_res, __idx);
-        throw;
-    }
+  } catch (...) {
+    _VSTD::__destroy(__ofirst, __idx);
+    throw;
+  }
 #endif
+
+  return {_VSTD::move(__ifirst), _VSTD::move(__idx)};
+}
+
+template <class _InputIterator, class _Size, class _ForwardIterator>
+inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
+uninitialized_move_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst) {
+  using _ValueType = typename iterator_traits<_ForwardIterator>::value_type;
+  auto __iter_move = [](auto&& __iter) -> decltype(auto) { return _VSTD::move(*__iter); };
+
+  return _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst),
+                                                   __unreachable_sentinel(), __iter_move);
 }
 
 #endif // _LIBCPP_STD_VER > 14
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H
lib/libcxx/include/__memory/unique_ptr.h
@@ -11,9 +11,9 @@
 #define _LIBCPP___MEMORY_UNIQUE_PTR_H
 
 #include <__config>
-#include <__functional_base>
 #include <__functional/hash.h>
 #include <__functional/operations.h>
+#include <__functional_base>
 #include <__memory/allocator_traits.h> // __pointer
 #include <__memory/compressed_pair.h>
 #include <__utility/forward.h>
@@ -29,9 +29,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
@@ -122,7 +119,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
 public:
   typedef _Tp element_type;
   typedef _Dp deleter_type;
-  typedef _LIBCPP_NODEBUG_TYPE typename __pointer<_Tp, deleter_type>::type pointer;
+  typedef _LIBCPP_NODEBUG typename __pointer<_Tp, deleter_type>::type pointer;
 
   static_assert(!is_rvalue_reference<deleter_type>::value,
                 "the specified deleter type cannot be an rvalue reference");
@@ -132,38 +129,38 @@ private:
 
   struct __nat { int __for_bool_; };
 
-  typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
+  typedef _LIBCPP_NODEBUG __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
 
   template <bool _Dummy>
-  using _LValRefType _LIBCPP_NODEBUG_TYPE =
+  using _LValRefType _LIBCPP_NODEBUG =
       typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
 
   template <bool _Dummy>
-  using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
+  using _GoodRValRefType _LIBCPP_NODEBUG =
       typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
 
   template <bool _Dummy>
-  using _BadRValRefType _LIBCPP_NODEBUG_TYPE  =
+  using _BadRValRefType _LIBCPP_NODEBUG =
       typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
 
   template <bool _Dummy, class _Deleter = typename __dependent_type<
                              __identity<deleter_type>, _Dummy>::type>
-  using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
+  using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
       typename enable_if<is_default_constructible<_Deleter>::value &&
                          !is_pointer<_Deleter>::value>::type;
 
   template <class _ArgType>
-  using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE  =
+  using _EnableIfDeleterConstructible _LIBCPP_NODEBUG =
       typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
 
   template <class _UPtr, class _Up>
-  using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE  = typename enable_if<
+  using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if<
       is_convertible<typename _UPtr::pointer, pointer>::value &&
       !is_array<_Up>::value
   >::type;
 
   template <class _UDel>
-  using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE  = typename enable_if<
+  using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = typename enable_if<
       (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
       (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
     >::type;
@@ -177,17 +174,17 @@ public:
   template <bool _Dummy = true,
             class = _EnableIfDeleterDefaultConstructible<_Dummy> >
   _LIBCPP_INLINE_VISIBILITY
-  _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
+  _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
 
   template <bool _Dummy = true,
             class = _EnableIfDeleterDefaultConstructible<_Dummy> >
   _LIBCPP_INLINE_VISIBILITY
-  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
+  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
 
   template <bool _Dummy = true,
             class = _EnableIfDeleterDefaultConstructible<_Dummy> >
   _LIBCPP_INLINE_VISIBILITY
-  explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {}
+  explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {}
 
   template <bool _Dummy = true,
             class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
@@ -229,7 +226,7 @@ public:
              typename enable_if<is_convertible<_Up*, _Tp*>::value &&
                                     is_same<_Dp, default_delete<_Tp> >::value,
                                 __nat>::type = __nat()) _NOEXCEPT
-      : __ptr_(__p.release(), __default_init_tag()) {}
+      : __ptr_(__p.release(), __value_init_tag()) {}
 #endif
 
   _LIBCPP_INLINE_VISIBILITY
@@ -350,35 +347,35 @@ private:
   typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
 
   template <bool _Dummy>
-  using _LValRefType _LIBCPP_NODEBUG_TYPE =
+  using _LValRefType _LIBCPP_NODEBUG =
       typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
 
   template <bool _Dummy>
-  using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
+  using _GoodRValRefType _LIBCPP_NODEBUG =
       typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
 
   template <bool _Dummy>
-  using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
+  using _BadRValRefType _LIBCPP_NODEBUG =
       typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
 
   template <bool _Dummy, class _Deleter = typename __dependent_type<
                              __identity<deleter_type>, _Dummy>::type>
-  using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE  =
+  using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
       typename enable_if<is_default_constructible<_Deleter>::value &&
                          !is_pointer<_Deleter>::value>::type;
 
   template <class _ArgType>
-  using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE  =
+  using _EnableIfDeleterConstructible _LIBCPP_NODEBUG =
       typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
 
   template <class _Pp>
-  using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE  = typename enable_if<
+  using _EnableIfPointerConvertible _LIBCPP_NODEBUG = typename enable_if<
       _CheckArrayPointerConversion<_Pp>::value
   >::type;
 
   template <class _UPtr, class _Up,
         class _ElemT = typename _UPtr::element_type>
-  using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE  = typename enable_if<
+  using _EnableIfMoveConvertible _LIBCPP_NODEBUG = typename enable_if<
       is_array<_Up>::value &&
       is_same<pointer, element_type*>::value &&
       is_same<typename _UPtr::pointer, _ElemT*>::value &&
@@ -386,13 +383,13 @@ private:
     >::type;
 
   template <class _UDel>
-  using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE  = typename enable_if<
+  using _EnableIfDeleterConvertible _LIBCPP_NODEBUG = typename enable_if<
       (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
       (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
     >::type;
 
   template <class _UDel>
-  using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE  = typename enable_if<
+  using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = typename enable_if<
       is_assignable<_Dp&, _UDel&&>::value
     >::type;
 
@@ -400,19 +397,19 @@ public:
   template <bool _Dummy = true,
             class = _EnableIfDeleterDefaultConstructible<_Dummy> >
   _LIBCPP_INLINE_VISIBILITY
-  _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
+  _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
 
   template <bool _Dummy = true,
             class = _EnableIfDeleterDefaultConstructible<_Dummy> >
   _LIBCPP_INLINE_VISIBILITY
-  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
+  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
 
   template <class _Pp, bool _Dummy = true,
             class = _EnableIfDeleterDefaultConstructible<_Dummy>,
             class = _EnableIfPointerConvertible<_Pp> >
   _LIBCPP_INLINE_VISIBILITY
   explicit unique_ptr(_Pp __p) _NOEXCEPT
-      : __ptr_(__p, __default_init_tag()) {}
+      : __ptr_(__p, __value_init_tag()) {}
 
   template <class _Pp, bool _Dummy = true,
             class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
@@ -768,6 +765,4 @@ struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___MEMORY_UNIQUE_PTR_H
lib/libcxx/include/__memory/uses_allocator.h
@@ -52,7 +52,7 @@ struct _LIBCPP_TEMPLATE_VIS uses_allocator
 
 #if _LIBCPP_STD_VER > 14
 template <class _Tp, class _Alloc>
-_LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
+inline constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
 #endif
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__memory/voidify.h
@@ -0,0 +1,30 @@
+// -*- 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___MEMORY_VOIDIFY_H
+#define _LIBCPP___MEMORY_VOIDIFY_H
+
+#include <__config>
+#include <__memory/addressof.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <typename _Tp>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void* __voidify(_Tp& __from) {
+  // Cast away cv-qualifiers to allow modifying elements of a range through const iterators.
+  return const_cast<void*>(static_cast<const volatile void*>(_VSTD::addressof(__from)));
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___MEMORY_VOIDIFY_H
lib/libcxx/include/__numeric/accumulate.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___NUMERIC_ACCUMULATE_H
+#define _LIBCPP___NUMERIC_ACCUMULATE_H
+
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _InputIterator, class _Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_Tp
+accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
+{
+    for (; __first != __last; ++__first)
+#if _LIBCPP_STD_VER > 17
+        __init = _VSTD::move(__init) + *__first;
+#else
+        __init = __init + *__first;
+#endif
+    return __init;
+}
+
+template <class _InputIterator, class _Tp, class _BinaryOperation>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_Tp
+accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
+{
+    for (; __first != __last; ++__first)
+#if _LIBCPP_STD_VER > 17
+        __init = __binary_op(_VSTD::move(__init), *__first);
+#else
+        __init = __binary_op(__init, *__first);
+#endif
+    return __init;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_ACCUMULATE_H
lib/libcxx/include/__numeric/adjacent_difference.h
@@ -0,0 +1,72 @@
+// -*- 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___NUMERIC_ADJACENT_DIFFERENCE_H
+#define _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H
+
+#include <__config>
+#include <__iterator/iterator_traits.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _InputIterator, class _OutputIterator>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_OutputIterator
+adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __acc(*__first);
+        *__result = __acc;
+        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
+        {
+            typename iterator_traits<_InputIterator>::value_type __val(*__first);
+#if _LIBCPP_STD_VER > 17
+            *__result = __val - _VSTD::move(__acc);
+#else
+            *__result = __val - __acc;
+#endif
+            __acc = _VSTD::move(__val);
+        }
+    }
+    return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_OutputIterator
+adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
+                      _BinaryOperation __binary_op)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __acc(*__first);
+        *__result = __acc;
+        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
+        {
+            typename iterator_traits<_InputIterator>::value_type __val(*__first);
+#if _LIBCPP_STD_VER > 17
+            *__result = __binary_op(__val, _VSTD::move(__acc));
+#else
+            *__result = __binary_op(__val, __acc);
+#endif
+            __acc = _VSTD::move(__val);
+        }
+    }
+    return __result;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H
lib/libcxx/include/__numeric/exclusive_scan.h
@@ -0,0 +1,53 @@
+// -*- 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___NUMERIC_EXCLUSIVE_SCAN_H
+#define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
+
+#include <__config>
+#include <__functional/operations.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 14
+
+template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
+exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) {
+  if (__first != __last) {
+    _Tp __tmp(__b(__init, *__first));
+    while (true) {
+      *__result = _VSTD::move(__init);
+      ++__result;
+      ++__first;
+      if (__first == __last)
+        break;
+      __init = _VSTD::move(__tmp);
+      __tmp = __b(__init, *__first);
+    }
+  }
+  return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
+exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) {
+  return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
+}
+
+#endif // _LIBCPP_STD_VER > 14
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/gcd_lcm.h
@@ -0,0 +1,96 @@
+// -*- 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___NUMERIC_GCD_LCM_H
+#define _LIBCPP___NUMERIC_GCD_LCM_H
+
+#include <__config>
+#include <__debug>
+#include <limits>
+#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
+
+#if _LIBCPP_STD_VER > 14
+
+template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __ct_abs;
+
+template <typename _Result, typename _Source>
+struct __ct_abs<_Result, _Source, true> {
+    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+    _Result operator()(_Source __t) const noexcept
+    {
+        if (__t >= 0) return __t;
+        if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t);
+        return -__t;
+    }
+};
+
+template <typename _Result, typename _Source>
+struct __ct_abs<_Result, _Source, false> {
+    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+    _Result operator()(_Source __t) const noexcept { return __t; }
+};
+
+
+template<class _Tp>
+_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
+_Tp __gcd(_Tp __m, _Tp __n)
+{
+    static_assert((!is_signed<_Tp>::value), "");
+    return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n);
+}
+
+template<class _Tp, class _Up>
+_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+common_type_t<_Tp,_Up>
+gcd(_Tp __m, _Up __n)
+{
+    static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types");
+    static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" );
+    static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
+    using _Rp = common_type_t<_Tp,_Up>;
+    using _Wp = make_unsigned_t<_Rp>;
+    return static_cast<_Rp>(_VSTD::__gcd(
+        static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)),
+        static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n))));
+}
+
+template<class _Tp, class _Up>
+_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+common_type_t<_Tp,_Up>
+lcm(_Tp __m, _Up __n)
+{
+    static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types");
+    static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" );
+    static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" );
+    if (__m == 0 || __n == 0)
+        return 0;
+
+    using _Rp = common_type_t<_Tp,_Up>;
+    _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n);
+    _Rp __val2 = __ct_abs<_Rp, _Up>()(__n);
+    _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm");
+    return __val1 * __val2;
+}
+
+#endif // _LIBCPP_STD_VER
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___NUMERIC_GCD_LCM_H
lib/libcxx/include/__numeric/inclusive_scan.h
@@ -0,0 +1,60 @@
+// -*- 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___NUMERIC_INCLUSIVE_SCAN_H
+#define _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H
+
+#include <__config>
+#include <__functional/operations.h>
+#include <__iterator/iterator_traits.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 14
+
+template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
+inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) {
+  for (; __first != __last; ++__first, (void)++__result) {
+    __init = __b(__init, *__first);
+    *__result = __init;
+  }
+  return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
+inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) {
+  if (__first != __last) {
+    typename iterator_traits<_InputIterator>::value_type __init = *__first;
+    *__result++ = __init;
+    if (++__first != __last)
+      return _VSTD::inclusive_scan(__first, __last, __result, __b, __init);
+  }
+
+  return __result;
+}
+
+template <class _InputIterator, class _OutputIterator>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator inclusive_scan(_InputIterator __first,
+                                                                                       _InputIterator __last,
+                                                                                       _OutputIterator __result) {
+  return _VSTD::inclusive_scan(__first, __last, __result, _VSTD::plus<>());
+}
+
+#endif // _LIBCPP_STD_VER > 14
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/inner_product.h
@@ -0,0 +1,53 @@
+// -*- 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___NUMERIC_INNER_PRODUCT_H
+#define _LIBCPP___NUMERIC_INNER_PRODUCT_H
+
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _InputIterator1, class _InputIterator2, class _Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_Tp
+inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
+{
+    for (; __first1 != __last1; ++__first1, (void) ++__first2)
+#if _LIBCPP_STD_VER > 17
+        __init = _VSTD::move(__init) + *__first1 * *__first2;
+#else
+        __init = __init + *__first1 * *__first2;
+#endif
+    return __init;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_Tp
+inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
+              _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
+{
+    for (; __first1 != __last1; ++__first1, (void) ++__first2)
+#if _LIBCPP_STD_VER > 17
+        __init = __binary_op1(_VSTD::move(__init), __binary_op2(*__first1, *__first2));
+#else
+        __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
+#endif
+    return __init;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_INNER_PRODUCT_H
lib/libcxx/include/__numeric/iota.h
@@ -0,0 +1,32 @@
+// -*- 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___NUMERIC_IOTA_H
+#define _LIBCPP___NUMERIC_IOTA_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _ForwardIterator, class _Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+void
+iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
+{
+    for (; __first != __last; ++__first, (void) ++__value_)
+        *__first = __value_;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_IOTA_H
lib/libcxx/include/__numeric/midpoint.h
@@ -0,0 +1,85 @@
+// -*- 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___NUMERIC_MIDPOINT_H
+#define _LIBCPP___NUMERIC_MIDPOINT_H
+
+#include <__config>
+#include <limits>
+#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
+
+#if _LIBCPP_STD_VER > 17
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY constexpr
+enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp>
+midpoint(_Tp __a, _Tp __b) noexcept
+_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
+{
+    using _Up = make_unsigned_t<_Tp>;
+    constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1;
+
+    _Up __diff = _Up(__b) - _Up(__a);
+    _Up __sign_bit = __b < __a;
+
+    _Up __half_diff = (__diff / 2) + (__sign_bit << __bitshift) + (__sign_bit & __diff);
+
+    return __a + __half_diff;
+}
+
+
+template <class _TPtr>
+_LIBCPP_INLINE_VISIBILITY constexpr
+enable_if_t<is_pointer_v<_TPtr>
+             && is_object_v<remove_pointer_t<_TPtr>>
+             && ! is_void_v<remove_pointer_t<_TPtr>>
+             && (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr>
+midpoint(_TPtr __a, _TPtr __b) noexcept
+{
+    return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a);
+}
+
+
+template <typename _Tp>
+constexpr int __sign(_Tp __val) {
+    return (_Tp(0) < __val) - (__val < _Tp(0));
+}
+
+template <typename _Fp>
+constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; }
+
+template <class _Fp>
+_LIBCPP_INLINE_VISIBILITY constexpr
+enable_if_t<is_floating_point_v<_Fp>, _Fp>
+midpoint(_Fp __a, _Fp __b) noexcept
+{
+    constexpr _Fp __lo = numeric_limits<_Fp>::min()*2;
+    constexpr _Fp __hi = numeric_limits<_Fp>::max()/2;
+    return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ?  // typical case: overflow is impossible
+      (__a + __b)/2 :                                        // always correctly rounded
+      __fp_abs(__a) < __lo ? __a + __b/2 :                   // not safe to halve a
+      __fp_abs(__b) < __lo ? __a/2 + __b :                   // not safe to halve b
+      __a/2 + __b/2;                                         // otherwise correctly rounded
+}
+
+#endif // _LIBCPP_STD_VER > 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___NUMERIC_MIDPOINT_H
lib/libcxx/include/__numeric/partial_sum.h
@@ -0,0 +1,70 @@
+// -*- 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___NUMERIC_PARTIAL_SUM_H
+#define _LIBCPP___NUMERIC_PARTIAL_SUM_H
+
+#include <__config>
+#include <__iterator/iterator_traits.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _InputIterator, class _OutputIterator>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_OutputIterator
+partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __t(*__first);
+        *__result = __t;
+        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
+        {
+#if _LIBCPP_STD_VER > 17
+            __t = _VSTD::move(__t) + *__first;
+#else
+            __t = __t + *__first;
+#endif
+            *__result = __t;
+        }
+    }
+    return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_OutputIterator
+partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
+              _BinaryOperation __binary_op)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __t(*__first);
+        *__result = __t;
+        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
+        {
+#if _LIBCPP_STD_VER > 17
+            __t = __binary_op(_VSTD::move(__t), *__first);
+#else
+            __t = __binary_op(__t, *__first);
+#endif
+            *__result = __t;
+        }
+    }
+    return __result;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_PARTIAL_SUM_H
lib/libcxx/include/__numeric/reduce.h
@@ -0,0 +1,47 @@
+// -*- 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___NUMERIC_REDUCE_H
+#define _LIBCPP___NUMERIC_REDUCE_H
+
+#include <__config>
+#include <__functional/operations.h>
+#include <__iterator/iterator_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 14
+template <class _InputIterator, class _Tp, class _BinaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last,
+                                                                   _Tp __init, _BinaryOp __b) {
+  for (; __first != __last; ++__first)
+    __init = __b(__init, *__first);
+  return __init;
+}
+
+template <class _InputIterator, class _Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last,
+                                                                   _Tp __init) {
+  return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
+}
+
+template <class _InputIterator>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename iterator_traits<_InputIterator>::value_type
+reduce(_InputIterator __first, _InputIterator __last) {
+  return _VSTD::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{});
+}
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_REDUCE_H
lib/libcxx/include/__numeric/transform_exclusive_scan.h
@@ -0,0 +1,49 @@
+// -*- 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___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H
+#define _LIBCPP___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 14
+
+template <class _InputIterator, class _OutputIterator, class _Tp,
+          class _BinaryOp, class _UnaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_OutputIterator
+transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
+                           _OutputIterator __result, _Tp __init,
+                           _BinaryOp __b, _UnaryOp __u)
+{
+    if (__first != __last)
+    {
+        _Tp __saved = __init;
+        do
+        {
+            __init = __b(__init, __u(*__first));
+            *__result = __saved;
+            __saved = __init;
+            ++__result;
+        } while (++__first != __last);
+    }
+    return __result;
+}
+
+#endif // _LIBCPP_STD_VER > 14
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/transform_inclusive_scan.h
@@ -0,0 +1,58 @@
+// -*- 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___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H
+#define _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H
+
+#include <__config>
+#include <__iterator/iterator_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 14
+
+template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_OutputIterator
+transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
+                           _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init)
+{
+    for (; __first != __last; ++__first, (void) ++__result) {
+        __init = __b(__init, __u(*__first));
+        *__result = __init;
+        }
+
+    return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_OutputIterator
+transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
+                               _OutputIterator __result, _BinaryOp __b, _UnaryOp __u)
+{
+    if (__first != __last) {
+        typename iterator_traits<_InputIterator>::value_type __init = __u(*__first);
+        *__result++ = __init;
+        if (++__first != __last)
+            return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init);
+    }
+
+    return __result;
+}
+
+#endif // _LIBCPP_STD_VER > 14
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H
lib/libcxx/include/__numeric/transform_reduce.h
@@ -0,0 +1,54 @@
+// -*- 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___NUMERIC_TRANSFORM_REDUCE_H
+#define _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H
+
+#include <__config>
+#include <__functional/operations.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 14
+template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator __first,
+                                                                             _InputIterator __last, _Tp __init,
+                                                                             _BinaryOp __b, _UnaryOp __u) {
+  for (; __first != __last; ++__first)
+    __init = __b(__init, __u(*__first));
+  return __init;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOp1, class _BinaryOp2>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1,
+                                                                             _InputIterator1 __last1,
+                                                                             _InputIterator2 __first2, _Tp __init,
+                                                                             _BinaryOp1 __b1, _BinaryOp2 __b2) {
+  for (; __first1 != __last1; ++__first1, (void)++__first2)
+    __init = __b1(__init, __b2(*__first1, *__first2));
+  return __init;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1,
+                                                                             _InputIterator1 __last1,
+                                                                             _InputIterator2 __first2, _Tp __init) {
+  return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init), _VSTD::plus<>(),
+                                 _VSTD::multiplies<>());
+}
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H
lib/libcxx/include/__random/bernoulli_distribution.h
@@ -0,0 +1,143 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_BERNOULLI_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <iosfwd>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class _LIBCPP_TEMPLATE_VIS bernoulli_distribution
+{
+public:
+    // types
+    typedef bool result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        double __p_;
+    public:
+        typedef bernoulli_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(double __p = 0.5) : __p_(__p) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        double p() const {return __p_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__p_ == __y.__p_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    bernoulli_distribution() : bernoulli_distribution(0.5) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit bernoulli_distribution(double __p) : __p_(param_type(__p)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit bernoulli_distribution(double __p = 0.5) : __p_(param_type(__p)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    double p() const {return __p_.p();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return false;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return true;}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const bernoulli_distribution& __x,
+                        const bernoulli_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const bernoulli_distribution& __x,
+                        const bernoulli_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template<class _URNG>
+inline
+bernoulli_distribution::result_type
+bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
+{
+    uniform_real_distribution<double> __gen;
+    return __gen(__g) < __p.p();
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.p();
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x)
+{
+    typedef bernoulli_distribution _Eng;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    double __p;
+    __is >> __p;
+    if (!__is.fail())
+        __x.param(param_type(__p));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H
lib/libcxx/include/__random/binomial_distribution.h
@@ -0,0 +1,225 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_BINOMIAL_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <cmath>
+#include <iosfwd>
+
+#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 _IntType = int>
+class _LIBCPP_TEMPLATE_VIS binomial_distribution
+{
+public:
+    // types
+    typedef _IntType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __t_;
+        double __p_;
+        double __pr_;
+        double __odds_ratio_;
+        result_type __r0_;
+    public:
+        typedef binomial_distribution distribution_type;
+
+        explicit param_type(result_type __t = 1, double __p = 0.5);
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type t() const {return __t_;}
+        _LIBCPP_INLINE_VISIBILITY
+        double p() const {return __p_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+
+        friend class binomial_distribution;
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    binomial_distribution() : binomial_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit binomial_distribution(result_type __t, double __p = 0.5)
+        : __p_(param_type(__t, __p)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit binomial_distribution(result_type __t = 1, double __p = 0.5)
+        : __p_(param_type(__t, __p)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit binomial_distribution(const param_type& __p) : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type t() const {return __p_.t();}
+    _LIBCPP_INLINE_VISIBILITY
+    double p() const {return __p_.p();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return t();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const binomial_distribution& __x,
+                        const binomial_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const binomial_distribution& __x,
+                        const binomial_distribution& __y)
+        {return !(__x == __y);}
+};
+
+#ifndef _LIBCPP_MSVCRT_LIKE
+extern "C" double lgamma_r(double, int *);
+#endif
+
+inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) {
+#if defined(_LIBCPP_MSVCRT_LIKE)
+  return lgamma(__d);
+#else
+  int __sign;
+  return lgamma_r(__d, &__sign);
+#endif
+}
+
+template<class _IntType>
+binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p)
+    : __t_(__t), __p_(__p)
+{
+    if (0 < __p_ && __p_ < 1)
+    {
+        __r0_ = static_cast<result_type>((__t_ + 1) * __p_);
+        __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) -
+                           __libcpp_lgamma(__r0_ + 1.) -
+                           __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) +
+                           (__t_ - __r0_) * _VSTD::log(1 - __p_));
+        __odds_ratio_ = __p_ / (1 - __p_);
+    }
+}
+
+// Reference: Kemp, C.D. (1986). `A modal method for generating binomial
+//           variables', Commun. Statist. - Theor. Meth. 15(3), 805-813.
+template<class _IntType>
+template<class _URNG>
+_IntType
+binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
+{
+    if (__pr.__t_ == 0 || __pr.__p_ == 0)
+        return 0;
+    if (__pr.__p_ == 1)
+        return __pr.__t_;
+    uniform_real_distribution<double> __gen;
+    double __u = __gen(__g) - __pr.__pr_;
+    if (__u < 0)
+        return __pr.__r0_;
+    double __pu = __pr.__pr_;
+    double __pd = __pu;
+    result_type __ru = __pr.__r0_;
+    result_type __rd = __ru;
+    while (true)
+    {
+        bool __break = true;
+        if (__rd >= 1)
+        {
+            __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
+            __u -= __pd;
+            __break = false;
+            if (__u < 0)
+                return __rd - 1;
+        }
+        if ( __rd != 0 )
+            --__rd;
+        ++__ru;
+        if (__ru <= __pr.__t_)
+        {
+            __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
+            __u -= __pu;
+            __break = false;
+            if (__u < 0)
+                return __ru;
+        }
+        if (__break)
+            return 0;
+    }
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const binomial_distribution<_IntType>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.t() << __sp << __x.p();
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           binomial_distribution<_IntType>& __x)
+{
+    typedef binomial_distribution<_IntType> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __t;
+    double __p;
+    __is >> __t >> __p;
+    if (!__is.fail())
+        __x.param(param_type(__t, __p));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H
lib/libcxx/include/__random/cauchy_distribution.h
@@ -0,0 +1,162 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_CAUCHY_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS cauchy_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __a_;
+        result_type __b_;
+    public:
+        typedef cauchy_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __a = 0, result_type __b = 1)
+            : __a_(__a), __b_(__b) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type a() const {return __a_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type b() const {return __b_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    cauchy_distribution() : cauchy_distribution(0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit cauchy_distribution(result_type __a, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit cauchy_distribution(result_type __a = 0, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit cauchy_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type a() const {return __p_.a();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type b() const {return __p_.b();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return -numeric_limits<result_type>::infinity();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const cauchy_distribution& __x,
+                        const cauchy_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const cauchy_distribution& __x,
+                        const cauchy_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _RealType>
+template<class _URNG>
+inline
+_RealType
+cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    uniform_real_distribution<result_type> __gen;
+    // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
+    return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const cauchy_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.a() << __sp << __x.b();
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           cauchy_distribution<_RT>& __x)
+{
+    typedef cauchy_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __a;
+    result_type __b;
+    __is >> __a >> __b;
+    if (!__is.fail())
+        __x.param(param_type(__a, __b));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H
lib/libcxx/include/__random/chi_squared_distribution.h
@@ -0,0 +1,144 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_CHI_SQUARED_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_CHI_SQUARED_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/gamma_distribution.h>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS chi_squared_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __n_;
+    public:
+        typedef chi_squared_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __n = 1) : __n_(__n) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type n() const {return __n_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__n_ == __y.__n_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    chi_squared_distribution() : chi_squared_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit chi_squared_distribution(result_type __n)
+        : __p_(param_type(__n)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit chi_squared_distribution(result_type __n = 1)
+        : __p_(param_type(__n)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit chi_squared_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g, const param_type& __p)
+        {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);}
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type n() const {return __p_.n();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const chi_squared_distribution& __x,
+                        const chi_squared_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const chi_squared_distribution& __x,
+                        const chi_squared_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const chi_squared_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    __os << __x.n();
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           chi_squared_distribution<_RT>& __x)
+{
+    typedef chi_squared_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __n;
+    __is >> __n;
+    if (!__is.fail())
+        __x.param(param_type(__n));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_CHI_SQUARED_DISTRIBUTION_H
lib/libcxx/include/__random/clamp_to_integral.h
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_CLAMP_TO_INTEGRAL_H
+#define _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H
+
+#include <__config>
+#include <cmath>
+#include <limits>
+#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 _IntT, class _FloatT,
+    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
+    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
+_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT {
+  static_assert(is_floating_point<_FloatT>::value, "must be a floating point type");
+  static_assert(is_integral<_IntT>::value, "must be an integral type");
+  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
+  static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value
+                 || _IsSame<_FloatT,long double>::value), "unsupported floating point type");
+  return _FloatBigger ? numeric_limits<_IntT>::max() :  (numeric_limits<_IntT>::max() >> _Bits << _Bits);
+}
+
+// Convert a floating point number to the specified integral type after
+// clamping to the integral type's representable range.
+//
+// The behavior is undefined if `__r` is NaN.
+template <class _IntT, class _RealT>
+_LIBCPP_INLINE_VISIBILITY
+_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
+  using _Lim = numeric_limits<_IntT>;
+  const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>();
+  if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {
+    return _Lim::max();
+  } else if (__r <= _Lim::lowest()) {
+    return _Lim::min();
+  }
+  return static_cast<_IntT>(__r);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H
lib/libcxx/include/__random/default_random_engine.h
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_DEFAULT_RANDOM_ENGINE_H
+#define _LIBCPP___RANDOM_DEFAULT_RANDOM_ENGINE_H
+
+#include <__config>
+#include <__random/linear_congruential_engine.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+typedef minstd_rand default_random_engine;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANDOM_DEFAULT_RANDOM_ENGINE_H
lib/libcxx/include/__random/discard_block_engine.h
@@ -0,0 +1,203 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_DISCARD_BLOCK_ENGINE_H
+#define _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H
+
+#include <__config>
+#include <__random/is_seed_sequence.h>
+#include <__utility/move.h>
+#include <climits>
+#include <iosfwd>
+#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 _Engine, size_t __p, size_t __r>
+class _LIBCPP_TEMPLATE_VIS discard_block_engine
+{
+    _Engine __e_;
+    int     __n_;
+
+    static_assert(  0 <  __r, "discard_block_engine invalid parameters");
+    static_assert(__r <= __p, "discard_block_engine invalid parameters");
+    static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters");
+public:
+    // types
+    typedef typename _Engine::result_type result_type;
+
+    // engine characteristics
+    static _LIBCPP_CONSTEXPR const size_t block_size = __p;
+    static _LIBCPP_CONSTEXPR const size_t used_block = __r;
+
+#ifdef _LIBCPP_CXX03_LANG
+    static const result_type _Min = _Engine::_Min;
+    static const result_type _Max = _Engine::_Max;
+#else
+    static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
+    static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); }
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); }
+
+    // constructors and seeding functions
+    _LIBCPP_INLINE_VISIBILITY
+    discard_block_engine() : __n_(0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit discard_block_engine(const _Engine& __e)
+        : __e_(__e), __n_(0) {}
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    explicit discard_block_engine(_Engine&& __e)
+        : __e_(_VSTD::move(__e)), __n_(0) {}
+#endif // _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit discard_block_engine(_Sseq& __q,
+        typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
+                           !is_convertible<_Sseq, _Engine>::value>::type* = 0)
+        : __e_(__q), __n_(0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed() {__e_.seed(); __n_ = 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            __is_seed_sequence<_Sseq, discard_block_engine>::value,
+            void
+        >::type
+        seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
+
+    // generating functions
+    result_type operator()();
+    _LIBCPP_INLINE_VISIBILITY
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    const _Engine& base() const _NOEXCEPT {return __e_;}
+
+    template<class _Eng, size_t _Pp, size_t _Rp>
+    friend
+    bool
+    operator==(
+        const discard_block_engine<_Eng, _Pp, _Rp>& __x,
+        const discard_block_engine<_Eng, _Pp, _Rp>& __y);
+
+    template<class _Eng, size_t _Pp, size_t _Rp>
+    friend
+    bool
+    operator!=(
+        const discard_block_engine<_Eng, _Pp, _Rp>& __x,
+        const discard_block_engine<_Eng, _Pp, _Rp>& __y);
+
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _Pp, size_t _Rp>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const discard_block_engine<_Eng, _Pp, _Rp>& __x);
+
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _Pp, size_t _Rp>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               discard_block_engine<_Eng, _Pp, _Rp>& __x);
+};
+
+template<class _Engine, size_t __p, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
+
+template<class _Engine, size_t __p, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
+
+template<class _Engine, size_t __p, size_t __r>
+typename discard_block_engine<_Engine, __p, __r>::result_type
+discard_block_engine<_Engine, __p, __r>::operator()()
+{
+    if (__n_ >= static_cast<int>(__r))
+    {
+        __e_.discard(__p - __r);
+        __n_ = 0;
+    }
+    ++__n_;
+    return __e_();
+}
+
+template<class _Eng, size_t _Pp, size_t _Rp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
+           const discard_block_engine<_Eng, _Pp, _Rp>& __y)
+{
+    return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_;
+}
+
+template<class _Eng, size_t _Pp, size_t _Rp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
+           const discard_block_engine<_Eng, _Pp, _Rp>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _Pp, size_t _Rp>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const discard_block_engine<_Eng, _Pp, _Rp>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _Ostream;
+    __os.flags(_Ostream::dec | _Ostream::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.__e_ << __sp << __x.__n_;
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _Pp, size_t _Rp>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           discard_block_engine<_Eng, _Pp, _Rp>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    _Eng __e;
+    int __n;
+    __is >> __e >> __n;
+    if (!__is.fail())
+    {
+        __x.__e_ = __e;
+        __x.__n_ = __n;
+    }
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H
lib/libcxx/include/__random/discrete_distribution.h
@@ -0,0 +1,260 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_DISCRETE_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_DISCRETE_DISTRIBUTION_H
+
+#include <__algorithm/upper_bound.h>
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <cstddef>
+#include <iosfwd>
+#include <numeric>
+#include <vector>
+
+#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 _IntType = int>
+class _LIBCPP_TEMPLATE_VIS discrete_distribution
+{
+public:
+    // types
+    typedef _IntType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        vector<double> __p_;
+    public:
+        typedef discrete_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        param_type() {}
+        template<class _InputIterator>
+            _LIBCPP_INLINE_VISIBILITY
+            param_type(_InputIterator __f, _InputIterator __l)
+            : __p_(__f, __l) {__init();}
+#ifndef _LIBCPP_CXX03_LANG
+        _LIBCPP_INLINE_VISIBILITY
+        param_type(initializer_list<double> __wl)
+            : __p_(__wl.begin(), __wl.end()) {__init();}
+#endif // _LIBCPP_CXX03_LANG
+        template<class _UnaryOperation>
+            param_type(size_t __nw, double __xmin, double __xmax,
+                       _UnaryOperation __fw);
+
+        vector<double> probabilities() const;
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__p_ == __y.__p_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+
+    private:
+        void __init();
+
+        friend class discrete_distribution;
+
+        template <class _CharT, class _Traits, class _IT>
+        friend
+        basic_ostream<_CharT, _Traits>&
+        operator<<(basic_ostream<_CharT, _Traits>& __os,
+                   const discrete_distribution<_IT>& __x);
+
+        template <class _CharT, class _Traits, class _IT>
+        friend
+        basic_istream<_CharT, _Traits>&
+        operator>>(basic_istream<_CharT, _Traits>& __is,
+                   discrete_distribution<_IT>& __x);
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+    _LIBCPP_INLINE_VISIBILITY
+    discrete_distribution() {}
+    template<class _InputIterator>
+        _LIBCPP_INLINE_VISIBILITY
+        discrete_distribution(_InputIterator __f, _InputIterator __l)
+            : __p_(__f, __l) {}
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    discrete_distribution(initializer_list<double> __wl)
+        : __p_(__wl) {}
+#endif // _LIBCPP_CXX03_LANG
+    template<class _UnaryOperation>
+        _LIBCPP_INLINE_VISIBILITY
+        discrete_distribution(size_t __nw, double __xmin, double __xmax,
+                              _UnaryOperation __fw)
+        : __p_(__nw, __xmin, __xmax, __fw) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit discrete_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    vector<double> probabilities() const {return __p_.probabilities();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return __p_.__p_.size();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const discrete_distribution& __x,
+                        const discrete_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const discrete_distribution& __x,
+                        const discrete_distribution& __y)
+        {return !(__x == __y);}
+
+    template <class _CharT, class _Traits, class _IT>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const discrete_distribution<_IT>& __x);
+
+    template <class _CharT, class _Traits, class _IT>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               discrete_distribution<_IT>& __x);
+};
+
+template<class _IntType>
+template<class _UnaryOperation>
+discrete_distribution<_IntType>::param_type::param_type(size_t __nw,
+                                                        double __xmin,
+                                                        double __xmax,
+                                                        _UnaryOperation __fw)
+{
+    if (__nw > 1)
+    {
+        __p_.reserve(__nw - 1);
+        double __d = (__xmax - __xmin) / __nw;
+        double __d2 = __d / 2;
+        for (size_t __k = 0; __k < __nw; ++__k)
+            __p_.push_back(__fw(__xmin + __k * __d + __d2));
+        __init();
+    }
+}
+
+template<class _IntType>
+void
+discrete_distribution<_IntType>::param_type::__init()
+{
+    if (!__p_.empty())
+    {
+        if (__p_.size() > 1)
+        {
+            double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0);
+            for (vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); __i < __e; ++__i)
+                *__i /= __s;
+            vector<double> __t(__p_.size() - 1);
+            _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin());
+            swap(__p_, __t);
+        }
+        else
+        {
+            __p_.clear();
+            __p_.shrink_to_fit();
+        }
+    }
+}
+
+template<class _IntType>
+vector<double>
+discrete_distribution<_IntType>::param_type::probabilities() const
+{
+    size_t __n = __p_.size();
+    vector<double> __p(__n+1);
+    _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin());
+    if (__n > 0)
+        __p[__n] = 1 - __p_[__n-1];
+    else
+        __p[0] = 1;
+    return __p;
+}
+
+template<class _IntType>
+template<class _URNG>
+_IntType
+discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
+{
+    uniform_real_distribution<double> __gen;
+    return static_cast<_IntType>(
+           _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
+                                                              __p.__p_.begin());
+}
+
+template <class _CharT, class _Traits, class _IT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const discrete_distribution<_IT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    size_t __n = __x.__p_.__p_.size();
+    __os << __n;
+    for (size_t __i = 0; __i < __n; ++__i)
+        __os << __sp << __x.__p_.__p_[__i];
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _IT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           discrete_distribution<_IT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    size_t __n;
+    __is >> __n;
+    vector<double> __p(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __is >> __p[__i];
+    if (!__is.fail())
+        swap(__x.__p_.__p_, __p);
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_DISCRETE_DISTRIBUTION_H
lib/libcxx/include/__random/exponential_distribution.h
@@ -0,0 +1,155 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_EXPONENTIAL_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/generate_canonical.h>
+#include <__random/uniform_real_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS exponential_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __lambda_;
+    public:
+        typedef exponential_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type lambda() const {return __lambda_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__lambda_ == __y.__lambda_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    exponential_distribution() : exponential_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit exponential_distribution(result_type __lambda)
+        : __p_(param_type(__lambda)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit exponential_distribution(result_type __lambda = 1)
+        : __p_(param_type(__lambda)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit exponential_distribution(const param_type& __p) : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type lambda() const {return __p_.lambda();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const exponential_distribution& __x,
+                        const exponential_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const exponential_distribution& __x,
+                        const exponential_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _RealType>
+template<class _URNG>
+_RealType
+exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    return -_VSTD::log
+                  (
+                      result_type(1) -
+                      _VSTD::generate_canonical<result_type,
+                                       numeric_limits<result_type>::digits>(__g)
+                  )
+                  / __p.lambda();
+}
+
+template <class _CharT, class _Traits, class _RealType>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const exponential_distribution<_RealType>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    return __os << __x.lambda();
+}
+
+template <class _CharT, class _Traits, class _RealType>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           exponential_distribution<_RealType>& __x)
+{
+    typedef exponential_distribution<_RealType> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __lambda;
+    __is >> __lambda;
+    if (!__is.fail())
+        __x.param(param_type(__lambda));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H
lib/libcxx/include/__random/extreme_value_distribution.h
@@ -0,0 +1,161 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS extreme_value_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __a_;
+        result_type __b_;
+    public:
+        typedef extreme_value_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __a = 0, result_type __b = 1)
+            : __a_(__a), __b_(__b) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type a() const {return __a_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type b() const {return __b_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    extreme_value_distribution() : extreme_value_distribution(0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit extreme_value_distribution(result_type __a, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit extreme_value_distribution(result_type __a = 0,
+                                        result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit extreme_value_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type a() const {return __p_.a();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type b() const {return __p_.b();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return -numeric_limits<result_type>::infinity();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const extreme_value_distribution& __x,
+                        const extreme_value_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const extreme_value_distribution& __x,
+                        const extreme_value_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template<class _RealType>
+template<class _URNG>
+_RealType
+extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    return __p.a() - __p.b() *
+         _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const extreme_value_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.a() << __sp << __x.b();
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           extreme_value_distribution<_RT>& __x)
+{
+    typedef extreme_value_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __a;
+    result_type __b;
+    __is >> __a >> __b;
+    if (!__is.fail())
+        __x.param(param_type(__a, __b));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
lib/libcxx/include/__random/fisher_f_distribution.h
@@ -0,0 +1,160 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_FISHER_F_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_FISHER_F_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/gamma_distribution.h>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS fisher_f_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __m_;
+        result_type __n_;
+    public:
+        typedef fisher_f_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __m = 1, result_type __n = 1)
+            : __m_(__m), __n_(__n) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type m() const {return __m_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type n() const {return __n_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    fisher_f_distribution() : fisher_f_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit fisher_f_distribution(result_type __m, result_type __n = 1)
+        : __p_(param_type(__m, __n)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
+        : __p_(param_type(__m, __n)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit fisher_f_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type m() const {return __p_.m();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type n() const {return __p_.n();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const fisher_f_distribution& __x,
+                        const fisher_f_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const fisher_f_distribution& __x,
+                        const fisher_f_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _RealType>
+template<class _URNG>
+_RealType
+fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
+    gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
+    return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const fisher_f_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.m() << __sp << __x.n();
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           fisher_f_distribution<_RT>& __x)
+{
+    typedef fisher_f_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __m;
+    result_type __n;
+    __is >> __m >> __n;
+    if (!__is.fail())
+        __x.param(param_type(__m, __n));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_FISHER_F_DISTRIBUTION_H
lib/libcxx/include/__random/gamma_distribution.h
@@ -0,0 +1,213 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_GAMMA_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/exponential_distribution.h>
+#include <__random/uniform_real_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS gamma_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __alpha_;
+        result_type __beta_;
+    public:
+        typedef gamma_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __alpha = 1, result_type __beta = 1)
+            : __alpha_(__alpha), __beta_(__beta) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type alpha() const {return __alpha_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type beta() const {return __beta_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    gamma_distribution() : gamma_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit gamma_distribution(result_type __alpha, result_type __beta = 1)
+        : __p_(param_type(__alpha, __beta)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit gamma_distribution(result_type __alpha = 1,
+                                result_type __beta = 1)
+        : __p_(param_type(__alpha, __beta)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit gamma_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type alpha() const {return __p_.alpha();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type beta() const {return __p_.beta();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const gamma_distribution& __x,
+                        const gamma_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const gamma_distribution& __x,
+                        const gamma_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _RealType>
+template<class _URNG>
+_RealType
+gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    result_type __a = __p.alpha();
+    uniform_real_distribution<result_type> __gen(0, 1);
+    exponential_distribution<result_type> __egen;
+    result_type __x;
+    if (__a == 1)
+        __x = __egen(__g);
+    else if (__a > 1)
+    {
+        const result_type __b = __a - 1;
+        const result_type __c = 3 * __a - result_type(0.75);
+        while (true)
+        {
+            const result_type __u = __gen(__g);
+            const result_type __v = __gen(__g);
+            const result_type __w = __u * (1 - __u);
+            if (__w != 0)
+            {
+                const result_type __y = _VSTD::sqrt(__c / __w) *
+                                        (__u - result_type(0.5));
+                __x = __b + __y;
+                if (__x >= 0)
+                {
+                    const result_type __z = 64 * __w * __w * __w * __v * __v;
+                    if (__z <= 1 - 2 * __y * __y / __x)
+                        break;
+                    if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y))
+                        break;
+                }
+            }
+        }
+    }
+    else  // __a < 1
+    {
+        while (true)
+        {
+            const result_type __u = __gen(__g);
+            const result_type __es = __egen(__g);
+            if (__u <= 1 - __a)
+            {
+                __x = _VSTD::pow(__u, 1 / __a);
+                if (__x <= __es)
+                    break;
+            }
+            else
+            {
+                const result_type __e = -_VSTD::log((1-__u)/__a);
+                __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a);
+                if (__x <= __e + __es)
+                    break;
+            }
+        }
+    }
+    return __x * __p.beta();
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const gamma_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.alpha() << __sp << __x.beta();
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           gamma_distribution<_RT>& __x)
+{
+    typedef gamma_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __alpha;
+    result_type __beta;
+    __is >> __alpha >> __beta;
+    if (!__is.fail())
+        __x.param(param_type(__alpha, __beta));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H
lib/libcxx/include/__random/generate_canonical.h
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_GENERATE_CANONICAL_H
+#define _LIBCPP___RANDOM_GENERATE_CANONICAL_H
+
+#include <__config>
+#include <__random/log2.h>
+#include <cstdint>
+#include <initializer_list>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// generate_canonical
+
+template<class _RealType, size_t __bits, class _URNG>
+_RealType
+generate_canonical(_URNG& __g)
+{
+    const size_t _Dt = numeric_limits<_RealType>::digits;
+    const size_t __b = _Dt < __bits ? _Dt : __bits;
+#ifdef _LIBCPP_CXX03_LANG
+    const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
+#else
+    const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
+#endif
+    const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
+    const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1);
+    _RealType __base = _Rp;
+    _RealType _Sp = __g() - _URNG::min();
+    for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp)
+        _Sp += (__g() - _URNG::min()) * __base;
+    return _Sp / __base;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_GENERATE_CANONICAL_H
lib/libcxx/include/__random/geometric_distribution.h
@@ -0,0 +1,141 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_GEOMETRIC_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/negative_binomial_distribution.h>
+#include <iosfwd>
+#include <limits>
+
+#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 _IntType = int>
+class _LIBCPP_TEMPLATE_VIS geometric_distribution
+{
+public:
+    // types
+    typedef _IntType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        double __p_;
+    public:
+        typedef geometric_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(double __p = 0.5) : __p_(__p) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        double p() const {return __p_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__p_ == __y.__p_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    geometric_distribution() : geometric_distribution(0.5) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit geometric_distribution(double __p)
+        : __p_(__p) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit geometric_distribution(double __p = 0.5)
+        : __p_(__p) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit geometric_distribution(const param_type& __p) : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g, const param_type& __p)
+        {return negative_binomial_distribution<result_type>(1, __p.p())(__g);}
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    double p() const {return __p_.p();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::max();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const geometric_distribution& __x,
+                        const geometric_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const geometric_distribution& __x,
+                        const geometric_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _CharT, class _Traits, class _IntType>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const geometric_distribution<_IntType>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    return __os << __x.p();
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           geometric_distribution<_IntType>& __x)
+{
+    typedef geometric_distribution<_IntType> _Eng;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    double __p;
+    __is >> __p;
+    if (!__is.fail())
+        __x.param(param_type(__p));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H
lib/libcxx/include/__random/independent_bits_engine.h
@@ -0,0 +1,271 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_INDEPENDENT_BITS_ENGINE_H
+#define _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H
+
+#include <__config>
+#include <__random/is_seed_sequence.h>
+#include <__random/log2.h>
+#include <__utility/move.h>
+#include <iosfwd>
+#include <limits>
+#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 _Engine, size_t __w, class _UIntType>
+class _LIBCPP_TEMPLATE_VIS independent_bits_engine
+{
+    template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp>
+    class __get_n
+    {
+        static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits;
+        static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0);
+        static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np;
+        static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0;
+    public:
+        static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np;
+    };
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    _Engine __e_;
+
+    static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
+    static_assert(  0 <  __w, "independent_bits_engine invalid parameters");
+    static_assert(__w <= _Dt, "independent_bits_engine invalid parameters");
+
+    typedef typename _Engine::result_type _Engine_result_type;
+    typedef typename conditional
+        <
+            sizeof(_Engine_result_type) <= sizeof(result_type),
+                result_type,
+                _Engine_result_type
+        >::type _Working_result_type;
+#ifdef _LIBCPP_CXX03_LANG
+    static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min
+                                          + _Working_result_type(1);
+#else
+    static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min()
+                                                            + _Working_result_type(1);
+#endif
+    static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value;
+    static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value;
+    static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n;
+    static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n;
+    static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits;
+    static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
+    static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 :
+                                                               (_Rp >> __w0) << __w0;
+    static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 :
+                                                               (_Rp >> (__w0+1)) << (__w0+1);
+    static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ?
+                                _Engine_result_type(~0) >> (_EDt - __w0) :
+                                _Engine_result_type(0);
+    static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ?
+                                _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) :
+                                _Engine_result_type(~0);
+public:
+    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
+    static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
+                                                      (result_type(1) << __w) - result_type(1);
+    static_assert(_Min < _Max, "independent_bits_engine invalid parameters");
+
+    // engine characteristics
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
+
+    // constructors and seeding functions
+    _LIBCPP_INLINE_VISIBILITY
+    independent_bits_engine() {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit independent_bits_engine(const _Engine& __e)
+        : __e_(__e) {}
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    explicit independent_bits_engine(_Engine&& __e)
+        : __e_(_VSTD::move(__e)) {}
+#endif // _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit independent_bits_engine(_Sseq& __q,
+        typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
+                           !is_convertible<_Sseq, _Engine>::value>::type* = 0)
+         : __e_(__q) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed() {__e_.seed();}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(result_type __sd) {__e_.seed(__sd);}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            __is_seed_sequence<_Sseq, independent_bits_engine>::value,
+            void
+        >::type
+        seed(_Sseq& __q) {__e_.seed(__q);}
+
+    // generating functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
+    _LIBCPP_INLINE_VISIBILITY
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    const _Engine& base() const _NOEXCEPT {return __e_;}
+
+    template<class _Eng, size_t _Wp, class _UInt>
+    friend
+    bool
+    operator==(
+        const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
+        const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
+
+    template<class _Eng, size_t _Wp, class _UInt>
+    friend
+    bool
+    operator!=(
+        const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
+        const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
+
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _Wp, class _UInt>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const independent_bits_engine<_Eng, _Wp, _UInt>& __x);
+
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _Wp, class _UInt>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               independent_bits_engine<_Eng, _Wp, _UInt>& __x);
+
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    result_type __eval(false_type);
+    result_type __eval(true_type);
+
+    template <size_t __count>
+        _LIBCPP_INLINE_VISIBILITY
+        static
+        typename enable_if
+        <
+            __count < _Dt,
+            result_type
+        >::type
+        __lshift(result_type __x) {return __x << __count;}
+
+    template <size_t __count>
+        _LIBCPP_INLINE_VISIBILITY
+        static
+        typename enable_if
+        <
+            (__count >= _Dt),
+            result_type
+        >::type
+        __lshift(result_type) {return result_type(0);}
+};
+
+template<class _Engine, size_t __w, class _UIntType>
+inline
+_UIntType
+independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
+{
+    return static_cast<result_type>(__e_() & __mask0);
+}
+
+template<class _Engine, size_t __w, class _UIntType>
+_UIntType
+independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
+{
+    result_type _Sp = 0;
+    for (size_t __k = 0; __k < __n0; ++__k)
+    {
+        _Engine_result_type __u;
+        do
+        {
+            __u = __e_() - _Engine::min();
+        } while (__u >= __y0);
+        _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0));
+    }
+    for (size_t __k = __n0; __k < __n; ++__k)
+    {
+        _Engine_result_type __u;
+        do
+        {
+            __u = __e_() - _Engine::min();
+        } while (__u >= __y1);
+        _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1));
+    }
+    return _Sp;
+}
+
+template<class _Eng, size_t _Wp, class _UInt>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(
+    const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
+    const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
+{
+    return __x.base() == __y.base();
+}
+
+template<class _Eng, size_t _Wp, class _UInt>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(
+    const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
+    const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _Wp, class _UInt>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const independent_bits_engine<_Eng, _Wp, _UInt>& __x)
+{
+    return __os << __x.base();
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _Wp, class _UInt>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           independent_bits_engine<_Eng, _Wp, _UInt>& __x)
+{
+    _Eng __e;
+    __is >> __e;
+    if (!__is.fail())
+        __x.__e_ = __e;
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H
lib/libcxx/include/__random/is_seed_sequence.h
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_IS_SEED_SEQUENCE_H
+#define _LIBCPP___RANDOM_IS_SEED_SEQUENCE_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Sseq, class _Engine>
+struct __is_seed_sequence
+{
+    static _LIBCPP_CONSTEXPR const bool value =
+              !is_convertible<_Sseq, typename _Engine::result_type>::value &&
+              !is_same<typename remove_cv<_Sseq>::type, _Engine>::value;
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANDOM_IS_SEED_SEQUENCE_H
lib/libcxx/include/__random/knuth_b.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_KNUTH_B_H
+#define _LIBCPP___RANDOM_KNUTH_B_H
+
+#include <__config>
+#include <__random/linear_congruential_engine.h>
+#include <__random/shuffle_order_engine.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANDOM_KNUTH_B_H
lib/libcxx/include/__random/linear_congruential_engine.h
@@ -0,0 +1,398 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H
+#define _LIBCPP___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H
+
+#include <__config>
+#include <__random/is_seed_sequence.h>
+#include <cstdint>
+#include <iosfwd>
+#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 <unsigned long long __a, unsigned long long __c,
+          unsigned long long __m, unsigned long long _Mp,
+          bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a),
+          bool _OverflowOK = ((__m | (__m-1)) > __m), // m = 2^n
+          bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q
+struct __lce_alg_picker
+{
+    static_assert(__a != 0 || __m != 0 || !_MightOverflow || _OverflowOK || _SchrageOK,
+                  "The current values of a, c, and m cannot generate a number "
+                  "within bounds of linear_congruential_engine.");
+
+    static _LIBCPP_CONSTEXPR const bool __use_schrage = _MightOverflow &&
+                                                        !_OverflowOK &&
+                                                        _SchrageOK;
+};
+
+template <unsigned long long __a, unsigned long long __c,
+          unsigned long long __m, unsigned long long _Mp,
+          bool _UseSchrage = __lce_alg_picker<__a, __c, __m, _Mp>::__use_schrage>
+struct __lce_ta;
+
+// 64
+
+template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
+struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true>
+{
+    typedef unsigned long long result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        __x += __c - (__x >= __m - __c) * __m;
+        return __x;
+    }
+};
+
+template <unsigned long long __a, unsigned long long __m>
+struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true>
+{
+    typedef unsigned long long result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        return __x;
+    }
+};
+
+template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
+struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false>
+{
+    typedef unsigned long long result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        return (__a * __x + __c) % __m;
+    }
+};
+
+template <unsigned long long __a, unsigned long long __c>
+struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false>
+{
+    typedef unsigned long long result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        return __a * __x + __c;
+    }
+};
+
+// 32
+
+template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
+struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true>
+{
+    typedef unsigned result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_Ap);
+        const result_type __c = static_cast<result_type>(_Cp);
+        const result_type __m = static_cast<result_type>(_Mp);
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        __x += __c - (__x >= __m - __c) * __m;
+        return __x;
+    }
+};
+
+template <unsigned long long _Ap, unsigned long long _Mp>
+struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true>
+{
+    typedef unsigned result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_Ap);
+        const result_type __m = static_cast<result_type>(_Mp);
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        return __x;
+    }
+};
+
+template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
+struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false>
+{
+    typedef unsigned result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_Ap);
+        const result_type __c = static_cast<result_type>(_Cp);
+        const result_type __m = static_cast<result_type>(_Mp);
+        return (__a * __x + __c) % __m;
+    }
+};
+
+template <unsigned long long _Ap, unsigned long long _Cp>
+struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false>
+{
+    typedef unsigned result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_Ap);
+        const result_type __c = static_cast<result_type>(_Cp);
+        return __a * __x + __c;
+    }
+};
+
+// 16
+
+template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b>
+struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b>
+{
+    typedef unsigned short result_type;
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type next(result_type __x)
+    {
+        return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x));
+    }
+};
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+class _LIBCPP_TEMPLATE_VIS linear_congruential_engine;
+
+template <class _CharT, class _Traits,
+          class _Up, _Up _Ap, _Up _Cp, _Up _Np>
+_LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
+
+template <class _CharT, class _Traits,
+          class _Up, _Up _Ap, _Up _Cp, _Up _Np>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+class _LIBCPP_TEMPLATE_VIS linear_congruential_engine
+{
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    result_type __x_;
+
+    static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
+
+    static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters");
+    static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
+    static_assert(is_unsigned<_UIntType>::value, "_UIntType must be unsigned type");
+public:
+    static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u;
+    static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u;
+    static_assert(_Min < _Max,           "linear_congruential_engine invalid parameters");
+
+    // engine characteristics
+    static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
+    static _LIBCPP_CONSTEXPR const result_type increment = __c;
+    static _LIBCPP_CONSTEXPR const result_type modulus = __m;
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type min() {return _Min;}
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type max() {return _Max;}
+    static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
+
+    // constructors and seeding functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    linear_congruential_engine() : linear_congruential_engine(default_seed) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit linear_congruential_engine(result_type __s) { seed(__s); }
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit linear_congruential_engine(result_type __s = default_seed) {
+      seed(__s);
+    }
+#endif
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit linear_congruential_engine(_Sseq& __q,
+        typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
+        {seed(__q);}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(result_type __s = default_seed)
+        {seed(integral_constant<bool, __m == 0>(),
+              integral_constant<bool, __c == 0>(), __s);}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            __is_seed_sequence<_Sseq, linear_congruential_engine>::value,
+            void
+        >::type
+        seed(_Sseq& __q)
+            {__seed(__q, integral_constant<unsigned,
+                1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
+                             :  (__m > 0x100000000ull))>());}
+
+    // generating functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type operator()()
+        {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));}
+    _LIBCPP_INLINE_VISIBILITY
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator==(const linear_congruential_engine& __x,
+                    const linear_congruential_engine& __y)
+        {return __x.__x_ == __y.__x_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(const linear_congruential_engine& __x,
+                    const linear_congruential_engine& __y)
+        {return !(__x == __y);}
+
+private:
+
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(true_type, false_type, result_type __s) {__x_ = __s;}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ?
+                                                                 1 : __s % __m;}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;}
+
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
+
+    template <class _CharT, class _Traits,
+              class _Up, _Up _Ap, _Up _Cp, _Up _Np>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
+
+    template <class _CharT, class _Traits,
+              class _Up, _Up _Ap, _Up _Cp, _Up _Np>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
+};
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+template<class _Sseq>
+void
+linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
+                                                 integral_constant<unsigned, 1>)
+{
+    const unsigned __k = 1;
+    uint32_t __ar[__k+3];
+    __q.generate(__ar, __ar + __k + 3);
+    result_type __s = static_cast<result_type>(__ar[3] % __m);
+    __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
+}
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+template<class _Sseq>
+void
+linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
+                                                 integral_constant<unsigned, 2>)
+{
+    const unsigned __k = 2;
+    uint32_t __ar[__k+3];
+    __q.generate(__ar, __ar + __k + 3);
+    result_type __s = static_cast<result_type>((__ar[3] +
+                                              ((uint64_t)__ar[4] << 32)) % __m);
+    __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
+}
+
+template <class _CharT, class _Traits,
+          class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _Ostream;
+    __os.flags(_Ostream::dec | _Ostream::left);
+    __os.fill(__os.widen(' '));
+    return __os << __x.__x_;
+}
+
+template <class _CharT, class _Traits,
+          class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    _UIntType __t;
+    __is >> __t;
+    if (!__is.fail())
+        __x.__x_ = __t;
+    return __is;
+}
+
+typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
+                                                                   minstd_rand0;
+typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
+                                                                    minstd_rand;
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H
lib/libcxx/include/__random/log2.h
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_LOG2_H
+#define _LIBCPP___RANDOM_LOG2_H
+
+#include <__config>
+#include <cstddef>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _UIntType, _UIntType _Xp, size_t _Rp>
+struct __log2_imp;
+
+template <unsigned long long _Xp, size_t _Rp>
+struct __log2_imp<unsigned long long, _Xp, _Rp>
+{
+    static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp
+                                           : __log2_imp<unsigned long long, _Xp, _Rp - 1>::value;
+};
+
+template <unsigned long long _Xp>
+struct __log2_imp<unsigned long long, _Xp, 0>
+{
+    static const size_t value = 0;
+};
+
+template <size_t _Rp>
+struct __log2_imp<unsigned long long, 0, _Rp>
+{
+    static const size_t value = _Rp + 1;
+};
+
+#ifndef _LIBCPP_HAS_NO_INT128
+
+template <__uint128_t _Xp, size_t _Rp>
+struct __log2_imp<__uint128_t, _Xp, _Rp>
+{
+    static const size_t value = (_Xp >> 64)
+        ? (64 + __log2_imp<unsigned long long, (_Xp >> 64), 63>::value)
+        : __log2_imp<unsigned long long, _Xp, 63>::value;
+};
+
+#endif // _LIBCPP_HAS_NO_INT128
+
+template <class _UIntType, _UIntType _Xp>
+struct __log2
+{
+    static const size_t value = __log2_imp<
+#ifndef _LIBCPP_HAS_NO_INT128
+        typename conditional<
+                sizeof(_UIntType) <= sizeof(unsigned long long),
+                    unsigned long long,
+                    __uint128_t
+            >::type,
+#else
+        unsigned long long,
+#endif // _LIBCPP_HAS_NO_INT128
+        _Xp, sizeof(_UIntType) * __CHAR_BIT__ - 1>::value;
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANDOM_LOG2_H
lib/libcxx/include/__random/lognormal_distribution.h
@@ -0,0 +1,299 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_LOGNORMAL_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/normal_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifdef _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION
+
+template<class _RealType = double>
+class _LIBCPP_TEMPLATE_VIS lognormal_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        normal_distribution<result_type> __nd_;
+    public:
+        typedef lognormal_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __m = 0, result_type __s = 1)
+            : __nd_(__m, __s) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type m() const {return __nd_.mean();}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type s() const {return __nd_.stddev();}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__nd_ == __y.__nd_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+        friend class lognormal_distribution;
+
+        template <class _CharT, class _Traits, class _RT>
+        friend
+        basic_ostream<_CharT, _Traits>&
+        operator<<(basic_ostream<_CharT, _Traits>& __os,
+                   const lognormal_distribution<_RT>& __x);
+
+        template <class _CharT, class _Traits, class _RT>
+        friend
+        basic_istream<_CharT, _Traits>&
+        operator>>(basic_istream<_CharT, _Traits>& __is,
+                   lognormal_distribution<_RT>& __x);
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    lognormal_distribution() : lognormal_distribution(0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit lognormal_distribution(result_type __m, result_type __s = 1)
+        : __p_(param_type(__m, __s)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit lognormal_distribution(result_type __m = 0,
+                                    result_type __s = 1)
+        : __p_(param_type(__m, __s)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit lognormal_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {__p_.__nd_.reset();}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g, const param_type& __p)
+        {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));}
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type m() const {return __p_.m();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type s() const {return __p_.s();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const lognormal_distribution& __x,
+                        const lognormal_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const lognormal_distribution& __x,
+                        const lognormal_distribution& __y)
+        {return !(__x == __y);}
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const lognormal_distribution<_RT>& __x);
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               lognormal_distribution<_RT>& __x);
+};
+
+template <class _CharT, class _Traits, class _RT>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const lognormal_distribution<_RT>& __x)
+{
+    return __os << __x.__p_.__nd_;
+}
+
+template <class _CharT, class _Traits, class _RT>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           lognormal_distribution<_RT>& __x)
+{
+    return __is >> __x.__p_.__nd_;
+}
+
+#else // _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION
+
+template<class _RealType = double>
+class _LIBCPP_TEMPLATE_VIS lognormal_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __m_;
+        result_type __s_;
+    public:
+        typedef lognormal_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __m = 0, result_type __s = 1)
+            : __m_(__m), __s_(__s) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type m() const {return __m_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type s() const {return __s_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__m_ == __y.__m_ && __x.__s_ == __y.__s_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    normal_distribution<result_type> __nd_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    lognormal_distribution() : lognormal_distribution(0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit lognormal_distribution(result_type __m, result_type __s = 1)
+        : __nd_(__m, __s) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit lognormal_distribution(result_type __m = 0,
+                                    result_type __s = 1)
+        : __nd_(__m, __s) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit lognormal_distribution(const param_type& __p)
+        : __nd_(__p.m(), __p.s()) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {__nd_.reset();}
+
+    // generating functions
+    template<class _URNG>
+    _LIBCPP_INLINE_VISIBILITY
+    result_type operator()(_URNG& __g)
+    {
+        return _VSTD::exp(__nd_(__g));
+    }
+
+    template<class _URNG>
+    _LIBCPP_INLINE_VISIBILITY
+    result_type operator()(_URNG& __g, const param_type& __p)
+    {
+        typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());
+        return _VSTD::exp(__nd_(__g, __pn));
+    }
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type m() const {return __nd_.mean();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type s() const {return __nd_.stddev();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return param_type(__nd_.mean(), __nd_.stddev());}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p)
+    {
+        typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());
+        __nd_.param(__pn);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const lognormal_distribution& __x,
+                        const lognormal_distribution& __y)
+        {return __x.__nd_ == __y.__nd_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const lognormal_distribution& __x,
+                        const lognormal_distribution& __y)
+        {return !(__x == __y);}
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const lognormal_distribution<_RT>& __x);
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               lognormal_distribution<_RT>& __x);
+};
+
+template <class _CharT, class _Traits, class _RT>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const lognormal_distribution<_RT>& __x)
+{
+    return __os << __x.__nd_;
+}
+
+template <class _CharT, class _Traits, class _RT>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           lognormal_distribution<_RT>& __x)
+{
+    return __is >> __x.__nd_;
+}
+
+#endif // _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H
lib/libcxx/include/__random/mersenne_twister_engine.h
@@ -0,0 +1,534 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_MERSENNE_TWISTER_ENGINE_H
+#define _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H
+
+#include <__algorithm/equal.h>
+#include <__algorithm/min.h>
+#include <__config>
+#include <__random/is_seed_sequence.h>
+#include <cstddef>
+#include <cstdint>
+#include <iosfwd>
+#include <limits>
+#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 _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;
+
+template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+bool
+operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
+           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
+
+template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+_LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
+           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                   _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine
+{
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    result_type __x_[__n];
+    size_t      __i_;
+
+    static_assert(  0 <  __m, "mersenne_twister_engine invalid parameters");
+    static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
+    static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
+    static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
+    static_assert(  2 <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
+public:
+    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
+    static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
+                                                      (result_type(1) << __w) - result_type(1);
+    static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
+
+    // engine characteristics
+    static _LIBCPP_CONSTEXPR const size_t word_size = __w;
+    static _LIBCPP_CONSTEXPR const size_t state_size = __n;
+    static _LIBCPP_CONSTEXPR const size_t shift_size = __m;
+    static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
+    static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
+    static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
+    static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
+    static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
+    static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
+    static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
+    static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
+    static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
+    static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
+    static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
+
+    // constructors and seeding functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit mersenne_twister_engine(result_type __sd) { seed(__sd); }
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit mersenne_twister_engine(result_type __sd = default_seed) {
+      seed(__sd);
+    }
+#endif
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit mersenne_twister_engine(_Sseq& __q,
+        typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
+        {seed(__q);}
+    void seed(result_type __sd = default_seed);
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            __is_seed_sequence<_Sseq, mersenne_twister_engine>::value,
+            void
+        >::type
+        seed(_Sseq& __q)
+            {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
+
+    // generating functions
+    result_type operator()();
+    _LIBCPP_INLINE_VISIBILITY
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+    friend
+    bool
+    operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
+               const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
+
+    template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+    friend
+    bool
+    operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
+               const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
+
+    template <class _CharT, class _Traits,
+              class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
+
+    template <class _CharT, class _Traits,
+              class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                       _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
+private:
+
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
+
+    template <size_t __count>
+        _LIBCPP_INLINE_VISIBILITY
+        static
+        typename enable_if
+        <
+            __count < __w,
+            result_type
+        >::type
+        __lshift(result_type __x) {return (__x << __count) & _Max;}
+
+    template <size_t __count>
+        _LIBCPP_INLINE_VISIBILITY
+        static
+        typename enable_if
+        <
+            (__count >= __w),
+            result_type
+        >::type
+        __lshift(result_type) {return result_type(0);}
+
+    template <size_t __count>
+        _LIBCPP_INLINE_VISIBILITY
+        static
+        typename enable_if
+        <
+            __count < _Dt,
+            result_type
+        >::type
+        __rshift(result_type __x) {return __x >> __count;}
+
+    template <size_t __count>
+        _LIBCPP_INLINE_VISIBILITY
+        static
+        typename enable_if
+        <
+            (__count >= _Dt),
+            result_type
+        >::type
+        __rshift(result_type) {return result_type(0);}
+};
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+void
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::seed(result_type __sd)
+    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
+{   // __w >= 2
+    __x_[0] = __sd & _Max;
+    for (size_t __i = 1; __i < __n; ++__i)
+        __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max;
+    __i_ = 0;
+}
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+template<class _Sseq>
+void
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>)
+{
+    const unsigned __k = 1;
+    uint32_t __ar[__n * __k];
+    __q.generate(__ar, __ar + __n * __k);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
+    const result_type __mask = __r == _Dt ? result_type(~0) :
+                                       (result_type(1) << __r) - result_type(1);
+    __i_ = 0;
+    if ((__x_[0] & ~__mask) == 0)
+    {
+        for (size_t __i = 1; __i < __n; ++__i)
+            if (__x_[__i] != 0)
+                return;
+        __x_[0] = result_type(1) << (__w - 1);
+    }
+}
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+template<class _Sseq>
+void
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>)
+{
+    const unsigned __k = 2;
+    uint32_t __ar[__n * __k];
+    __q.generate(__ar, __ar + __n * __k);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __x_[__i] = static_cast<result_type>(
+            (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
+    const result_type __mask = __r == _Dt ? result_type(~0) :
+                                       (result_type(1) << __r) - result_type(1);
+    __i_ = 0;
+    if ((__x_[0] & ~__mask) == 0)
+    {
+        for (size_t __i = 1; __i < __n; ++__i)
+            if (__x_[__i] != 0)
+                return;
+        __x_[0] = result_type(1) << (__w - 1);
+    }
+}
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+_UIntType
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::operator()()
+{
+    const size_t __j = (__i_ + 1) % __n;
+    const result_type __mask = __r == _Dt ? result_type(~0) :
+                                       (result_type(1) << __r) - result_type(1);
+    const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
+    const size_t __k = (__i_ + __m) % __n;
+    __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1));
+    result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
+    __i_ = __j;
+    __z ^= __lshift<__s>(__z) & __b;
+    __z ^= __lshift<__t>(__z) & __c;
+    return __z ^ __rshift<__l>(__z);
+}
+
+template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+bool
+operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
+           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
+{
+    if (__x.__i_ == __y.__i_)
+        return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);
+    if (__x.__i_ == 0 || __y.__i_ == 0)
+    {
+        size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_);
+        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (__x.__i_ == 0)
+            return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);
+        return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);
+    }
+    if (__x.__i_ < __y.__i_)
+    {
+        size_t __j = _Np - __y.__i_;
+        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np,
+                         __y.__x_))
+            return false;
+        return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
+                           __y.__x_ + (_Np - (__x.__i_ + __j)));
+    }
+    size_t __j = _Np - __x.__i_;
+    if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
+                     __x.__x_ + __x.__i_))
+        return false;
+    if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np,
+                     __x.__x_))
+        return false;
+    return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
+                       __x.__x_ + (_Np - (__y.__i_ + __j)));
+}
+
+template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
+           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _Ostream;
+    __os.flags(_Ostream::dec | _Ostream::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.__x_[__x.__i_];
+    for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)
+        __os << __sp << __x.__x_[__j];
+    for (size_t __j = 0; __j < __x.__i_; ++__j)
+        __os << __sp << __x.__x_[__j];
+    return __os;
+}
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
+          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
+          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
+                                   _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    _UInt __t[_Np];
+    for (size_t __i = 0; __i < _Np; ++__i)
+        __is >> __t[__i];
+    if (!__is.fail())
+    {
+        for (size_t __i = 0; __i < _Np; ++__i)
+            __x.__x_[__i] = __t[__i];
+        __x.__i_ = 0;
+    }
+    return __is;
+}
+
+typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
+                                0x9908b0df, 11, 0xffffffff,
+                                7,  0x9d2c5680,
+                                15, 0xefc60000,
+                                18, 1812433253>                         mt19937;
+typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
+                                0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL,
+                                17, 0x71d67fffeda60000ULL,
+                                37, 0xfff7eee000000000ULL,
+                                43, 6364136223846793005ULL>          mt19937_64;
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H
lib/libcxx/include/__random/negative_binomial_distribution.h
@@ -0,0 +1,176 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/bernoulli_distribution.h>
+#include <__random/gamma_distribution.h>
+#include <__random/poisson_distribution.h>
+#include <iosfwd>
+#include <limits>
+
+#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 _IntType = int>
+class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution
+{
+public:
+    // types
+    typedef _IntType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __k_;
+        double __p_;
+    public:
+        typedef negative_binomial_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __k = 1, double __p = 0.5)
+            : __k_(__k), __p_(__p) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type k() const {return __k_;}
+        _LIBCPP_INLINE_VISIBILITY
+        double p() const {return __p_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    negative_binomial_distribution() : negative_binomial_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit negative_binomial_distribution(result_type __k, double __p = 0.5)
+        : __p_(__k, __p) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit negative_binomial_distribution(result_type __k = 1,
+                                            double __p = 0.5)
+        : __p_(__k, __p) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type k() const {return __p_.k();}
+    _LIBCPP_INLINE_VISIBILITY
+    double p() const {return __p_.p();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::max();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const negative_binomial_distribution& __x,
+                        const negative_binomial_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const negative_binomial_distribution& __x,
+                        const negative_binomial_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _IntType>
+template<class _URNG>
+_IntType
+negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
+{
+    result_type __k = __pr.k();
+    double __p = __pr.p();
+    if (__k <= 21 * __p)
+    {
+        bernoulli_distribution __gen(__p);
+        result_type __f = 0;
+        result_type __s = 0;
+        while (__s < __k)
+        {
+            if (__gen(__urng))
+                ++__s;
+            else
+                ++__f;
+        }
+        return __f;
+    }
+    return poisson_distribution<result_type>(gamma_distribution<double>
+                                            (__k, (1-__p)/__p)(__urng))(__urng);
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const negative_binomial_distribution<_IntType>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.k() << __sp << __x.p();
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           negative_binomial_distribution<_IntType>& __x)
+{
+    typedef negative_binomial_distribution<_IntType> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __k;
+    double __p;
+    __is >> __k >> __p;
+    if (!__is.fail())
+        __x.param(param_type(__k, __p));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H
lib/libcxx/include/__random/normal_distribution.h
@@ -0,0 +1,208 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_NORMAL_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS normal_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __mean_;
+        result_type __stddev_;
+    public:
+        typedef normal_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __mean = 0, result_type __stddev = 1)
+            : __mean_(__mean), __stddev_(__stddev) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type mean() const {return __mean_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type stddev() const {return __stddev_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+    result_type _V_;
+    bool _V_hot_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    normal_distribution() : normal_distribution(0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit normal_distribution(result_type __mean, result_type __stddev = 1)
+        : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit normal_distribution(result_type __mean = 0,
+                                 result_type __stddev = 1)
+        : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit normal_distribution(const param_type& __p)
+        : __p_(__p), _V_hot_(false) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {_V_hot_ = false;}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type mean() const {return __p_.mean();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type stddev() const {return __p_.stddev();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return -numeric_limits<result_type>::infinity();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const normal_distribution& __x,
+                        const normal_distribution& __y)
+        {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ &&
+                (!__x._V_hot_ || __x._V_ == __y._V_);}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const normal_distribution& __x,
+                        const normal_distribution& __y)
+        {return !(__x == __y);}
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const normal_distribution<_RT>& __x);
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               normal_distribution<_RT>& __x);
+};
+
+template <class _RealType>
+template<class _URNG>
+_RealType
+normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    result_type _Up;
+    if (_V_hot_)
+    {
+        _V_hot_ = false;
+        _Up = _V_;
+    }
+    else
+    {
+        uniform_real_distribution<result_type> _Uni(-1, 1);
+        result_type __u;
+        result_type __v;
+        result_type __s;
+        do
+        {
+            __u = _Uni(__g);
+            __v = _Uni(__g);
+            __s = __u * __u + __v * __v;
+        } while (__s > 1 || __s == 0);
+        result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
+        _V_ = __v * _Fp;
+        _V_hot_ = true;
+        _Up = __u * _Fp;
+    }
+    return _Up * __p.stddev() + __p.mean();
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const normal_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_;
+    if (__x._V_hot_)
+        __os << __sp << __x._V_;
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           normal_distribution<_RT>& __x)
+{
+    typedef normal_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __mean;
+    result_type __stddev;
+    result_type _Vp = 0;
+    bool _V_hot = false;
+    __is >> __mean >> __stddev >> _V_hot;
+    if (_V_hot)
+        __is >> _Vp;
+    if (!__is.fail())
+    {
+        __x.param(param_type(__mean, __stddev));
+        __x._V_hot_ = _V_hot;
+        __x._V_ = _Vp;
+    }
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H
lib/libcxx/include/__random/piecewise_constant_distribution.h
@@ -0,0 +1,356 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H
+
+#include <__algorithm/upper_bound.h>
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <iosfwd>
+#include <numeric>
+#include <vector>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        vector<result_type> __b_;
+        vector<result_type> __densities_;
+        vector<result_type> __areas_;
+    public:
+        typedef piecewise_constant_distribution distribution_type;
+
+        param_type();
+        template<class _InputIteratorB, class _InputIteratorW>
+            param_type(_InputIteratorB __fB, _InputIteratorB __lB,
+                       _InputIteratorW __fW);
+#ifndef _LIBCPP_CXX03_LANG
+        template<class _UnaryOperation>
+            param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
+#endif // _LIBCPP_CXX03_LANG
+        template<class _UnaryOperation>
+            param_type(size_t __nw, result_type __xmin, result_type __xmax,
+                       _UnaryOperation __fw);
+        param_type(param_type const&) = default;
+        param_type & operator=(const param_type& __rhs);
+
+        _LIBCPP_INLINE_VISIBILITY
+        vector<result_type> intervals() const {return __b_;}
+        _LIBCPP_INLINE_VISIBILITY
+        vector<result_type> densities() const {return __densities_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+
+    private:
+        void __init();
+
+        friend class piecewise_constant_distribution;
+
+        template <class _CharT, class _Traits, class _RT>
+        friend
+        basic_ostream<_CharT, _Traits>&
+        operator<<(basic_ostream<_CharT, _Traits>& __os,
+                   const piecewise_constant_distribution<_RT>& __x);
+
+        template <class _CharT, class _Traits, class _RT>
+        friend
+        basic_istream<_CharT, _Traits>&
+        operator>>(basic_istream<_CharT, _Traits>& __is,
+                   piecewise_constant_distribution<_RT>& __x);
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+    _LIBCPP_INLINE_VISIBILITY
+    piecewise_constant_distribution() {}
+    template<class _InputIteratorB, class _InputIteratorW>
+        _LIBCPP_INLINE_VISIBILITY
+        piecewise_constant_distribution(_InputIteratorB __fB,
+                                        _InputIteratorB __lB,
+                                        _InputIteratorW __fW)
+        : __p_(__fB, __lB, __fW) {}
+
+#ifndef _LIBCPP_CXX03_LANG
+    template<class _UnaryOperation>
+        _LIBCPP_INLINE_VISIBILITY
+        piecewise_constant_distribution(initializer_list<result_type> __bl,
+                                        _UnaryOperation __fw)
+        : __p_(__bl, __fw) {}
+#endif // _LIBCPP_CXX03_LANG
+
+    template<class _UnaryOperation>
+        _LIBCPP_INLINE_VISIBILITY
+        piecewise_constant_distribution(size_t __nw, result_type __xmin,
+                                        result_type __xmax, _UnaryOperation __fw)
+        : __p_(__nw, __xmin, __xmax, __fw) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit piecewise_constant_distribution(const param_type& __p)
+        : __p_(__p) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    vector<result_type> intervals() const {return __p_.intervals();}
+    _LIBCPP_INLINE_VISIBILITY
+    vector<result_type> densities() const {return __p_.densities();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return __p_.__b_.front();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return __p_.__b_.back();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const piecewise_constant_distribution& __x,
+                        const piecewise_constant_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const piecewise_constant_distribution& __x,
+                           const piecewise_constant_distribution& __y)
+        {return !(__x == __y);}
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const piecewise_constant_distribution<_RT>& __x);
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               piecewise_constant_distribution<_RT>& __x);
+};
+
+template<class _RealType>
+typename piecewise_constant_distribution<_RealType>::param_type &
+piecewise_constant_distribution<_RealType>::param_type::operator=
+                                                       (const param_type& __rhs)
+{
+//  These can throw
+    __b_.reserve        (__rhs.__b_.size ());
+    __densities_.reserve(__rhs.__densities_.size());
+    __areas_.reserve    (__rhs.__areas_.size());
+
+//  These can not throw
+    __b_         = __rhs.__b_;
+    __densities_ = __rhs.__densities_;
+    __areas_     =  __rhs.__areas_;
+    return *this;
+}
+
+template<class _RealType>
+void
+piecewise_constant_distribution<_RealType>::param_type::__init()
+{
+    // __densities_ contains non-normalized areas
+    result_type __total_area = _VSTD::accumulate(__densities_.begin(),
+                                                __densities_.end(),
+                                                result_type());
+    for (size_t __i = 0; __i < __densities_.size(); ++__i)
+        __densities_[__i] /= __total_area;
+    // __densities_ contains normalized areas
+    __areas_.assign(__densities_.size(), result_type());
+    _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1,
+                                                          __areas_.begin() + 1);
+    // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
+    __densities_.back() = 1 - __areas_.back();  // correct round off error
+    for (size_t __i = 0; __i < __densities_.size(); ++__i)
+        __densities_[__i] /= (__b_[__i+1] - __b_[__i]);
+    // __densities_ now contains __densities_
+}
+
+template<class _RealType>
+piecewise_constant_distribution<_RealType>::param_type::param_type()
+    : __b_(2),
+      __densities_(1, 1.0),
+      __areas_(1, 0.0)
+{
+    __b_[1] = 1;
+}
+
+template<class _RealType>
+template<class _InputIteratorB, class _InputIteratorW>
+piecewise_constant_distribution<_RealType>::param_type::param_type(
+        _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
+    : __b_(__fB, __lB)
+{
+    if (__b_.size() < 2)
+    {
+        __b_.resize(2);
+        __b_[0] = 0;
+        __b_[1] = 1;
+        __densities_.assign(1, 1.0);
+        __areas_.assign(1, 0.0);
+    }
+    else
+    {
+        __densities_.reserve(__b_.size() - 1);
+        for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW)
+            __densities_.push_back(*__fW);
+        __init();
+    }
+}
+
+#ifndef _LIBCPP_CXX03_LANG
+
+template<class _RealType>
+template<class _UnaryOperation>
+piecewise_constant_distribution<_RealType>::param_type::param_type(
+        initializer_list<result_type> __bl, _UnaryOperation __fw)
+    : __b_(__bl.begin(), __bl.end())
+{
+    if (__b_.size() < 2)
+    {
+        __b_.resize(2);
+        __b_[0] = 0;
+        __b_[1] = 1;
+        __densities_.assign(1, 1.0);
+        __areas_.assign(1, 0.0);
+    }
+    else
+    {
+        __densities_.reserve(__b_.size() - 1);
+        for (size_t __i = 0; __i < __b_.size() - 1; ++__i)
+            __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5));
+        __init();
+    }
+}
+
+#endif // _LIBCPP_CXX03_LANG
+
+template<class _RealType>
+template<class _UnaryOperation>
+piecewise_constant_distribution<_RealType>::param_type::param_type(
+        size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
+    : __b_(__nw == 0 ? 2 : __nw + 1)
+{
+    size_t __n = __b_.size() - 1;
+    result_type __d = (__xmax - __xmin) / __n;
+    __densities_.reserve(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+    {
+        __b_[__i] = __xmin + __i * __d;
+        __densities_.push_back(__fw(__b_[__i] + __d*.5));
+    }
+    __b_[__n] = __xmax;
+    __init();
+}
+
+template<class _RealType>
+template<class _URNG>
+_RealType
+piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    typedef uniform_real_distribution<result_type> _Gen;
+    result_type __u = _Gen()(__g);
+    ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
+                                      __u) - __p.__areas_.begin() - 1;
+    return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k];
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const piecewise_constant_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    size_t __n = __x.__p_.__b_.size();
+    __os << __n;
+    for (size_t __i = 0; __i < __n; ++__i)
+        __os << __sp << __x.__p_.__b_[__i];
+    __n = __x.__p_.__densities_.size();
+    __os << __sp << __n;
+    for (size_t __i = 0; __i < __n; ++__i)
+        __os << __sp << __x.__p_.__densities_[__i];
+    __n = __x.__p_.__areas_.size();
+    __os << __sp << __n;
+    for (size_t __i = 0; __i < __n; ++__i)
+        __os << __sp << __x.__p_.__areas_[__i];
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           piecewise_constant_distribution<_RT>& __x)
+{
+    typedef piecewise_constant_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    size_t __n;
+    __is >> __n;
+    vector<result_type> __b(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __is >> __b[__i];
+    __is >> __n;
+    vector<result_type> __densities(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __is >> __densities[__i];
+    __is >> __n;
+    vector<result_type> __areas(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __is >> __areas[__i];
+    if (!__is.fail())
+    {
+        swap(__x.__p_.__b_, __b);
+        swap(__x.__p_.__densities_, __densities);
+        swap(__x.__p_.__areas_, __areas);
+    }
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H
lib/libcxx/include/__random/piecewise_linear_distribution.h
@@ -0,0 +1,372 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H
+
+#include <__algorithm/upper_bound.h>
+#include <__config>
+#include <__random/uniform_real_distribution.h>
+#include <iosfwd>
+#include <numeric>
+#include <vector>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        vector<result_type> __b_;
+        vector<result_type> __densities_;
+        vector<result_type> __areas_;
+    public:
+        typedef piecewise_linear_distribution distribution_type;
+
+        param_type();
+        template<class _InputIteratorB, class _InputIteratorW>
+            param_type(_InputIteratorB __fB, _InputIteratorB __lB,
+                       _InputIteratorW __fW);
+#ifndef _LIBCPP_CXX03_LANG
+        template<class _UnaryOperation>
+            param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
+#endif // _LIBCPP_CXX03_LANG
+        template<class _UnaryOperation>
+            param_type(size_t __nw, result_type __xmin, result_type __xmax,
+                       _UnaryOperation __fw);
+        param_type(param_type const&) = default;
+        param_type & operator=(const param_type& __rhs);
+
+        _LIBCPP_INLINE_VISIBILITY
+        vector<result_type> intervals() const {return __b_;}
+        _LIBCPP_INLINE_VISIBILITY
+        vector<result_type> densities() const {return __densities_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+
+    private:
+        void __init();
+
+        friend class piecewise_linear_distribution;
+
+        template <class _CharT, class _Traits, class _RT>
+        friend
+        basic_ostream<_CharT, _Traits>&
+        operator<<(basic_ostream<_CharT, _Traits>& __os,
+                   const piecewise_linear_distribution<_RT>& __x);
+
+        template <class _CharT, class _Traits, class _RT>
+        friend
+        basic_istream<_CharT, _Traits>&
+        operator>>(basic_istream<_CharT, _Traits>& __is,
+                   piecewise_linear_distribution<_RT>& __x);
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+    _LIBCPP_INLINE_VISIBILITY
+    piecewise_linear_distribution() {}
+    template<class _InputIteratorB, class _InputIteratorW>
+        _LIBCPP_INLINE_VISIBILITY
+        piecewise_linear_distribution(_InputIteratorB __fB,
+                                      _InputIteratorB __lB,
+                                      _InputIteratorW __fW)
+        : __p_(__fB, __lB, __fW) {}
+
+#ifndef _LIBCPP_CXX03_LANG
+    template<class _UnaryOperation>
+        _LIBCPP_INLINE_VISIBILITY
+        piecewise_linear_distribution(initializer_list<result_type> __bl,
+                                      _UnaryOperation __fw)
+        : __p_(__bl, __fw) {}
+#endif // _LIBCPP_CXX03_LANG
+
+    template<class _UnaryOperation>
+        _LIBCPP_INLINE_VISIBILITY
+        piecewise_linear_distribution(size_t __nw, result_type __xmin,
+                                      result_type __xmax, _UnaryOperation __fw)
+        : __p_(__nw, __xmin, __xmax, __fw) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit piecewise_linear_distribution(const param_type& __p)
+        : __p_(__p) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    vector<result_type> intervals() const {return __p_.intervals();}
+    _LIBCPP_INLINE_VISIBILITY
+    vector<result_type> densities() const {return __p_.densities();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return __p_.__b_.front();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return __p_.__b_.back();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const piecewise_linear_distribution& __x,
+                        const piecewise_linear_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const piecewise_linear_distribution& __x,
+                        const piecewise_linear_distribution& __y)
+        {return !(__x == __y);}
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const piecewise_linear_distribution<_RT>& __x);
+
+    template <class _CharT, class _Traits, class _RT>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               piecewise_linear_distribution<_RT>& __x);
+};
+
+template<class _RealType>
+typename piecewise_linear_distribution<_RealType>::param_type &
+piecewise_linear_distribution<_RealType>::param_type::operator=
+                                                       (const param_type& __rhs)
+{
+//  These can throw
+    __b_.reserve        (__rhs.__b_.size ());
+    __densities_.reserve(__rhs.__densities_.size());
+    __areas_.reserve    (__rhs.__areas_.size());
+
+//  These can not throw
+    __b_         = __rhs.__b_;
+    __densities_ = __rhs.__densities_;
+    __areas_     =  __rhs.__areas_;
+    return *this;
+}
+
+
+template<class _RealType>
+void
+piecewise_linear_distribution<_RealType>::param_type::__init()
+{
+    __areas_.assign(__densities_.size() - 1, result_type());
+    result_type _Sp = 0;
+    for (size_t __i = 0; __i < __areas_.size(); ++__i)
+    {
+        __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
+                        (__b_[__i+1] - __b_[__i]) * .5;
+        _Sp += __areas_[__i];
+    }
+    for (size_t __i = __areas_.size(); __i > 1;)
+    {
+        --__i;
+        __areas_[__i] = __areas_[__i-1] / _Sp;
+    }
+    __areas_[0] = 0;
+    for (size_t __i = 1; __i < __areas_.size(); ++__i)
+        __areas_[__i] += __areas_[__i-1];
+    for (size_t __i = 0; __i < __densities_.size(); ++__i)
+        __densities_[__i] /= _Sp;
+}
+
+template<class _RealType>
+piecewise_linear_distribution<_RealType>::param_type::param_type()
+    : __b_(2),
+      __densities_(2, 1.0),
+      __areas_(1, 0.0)
+{
+    __b_[1] = 1;
+}
+
+template<class _RealType>
+template<class _InputIteratorB, class _InputIteratorW>
+piecewise_linear_distribution<_RealType>::param_type::param_type(
+        _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
+    : __b_(__fB, __lB)
+{
+    if (__b_.size() < 2)
+    {
+        __b_.resize(2);
+        __b_[0] = 0;
+        __b_[1] = 1;
+        __densities_.assign(2, 1.0);
+        __areas_.assign(1, 0.0);
+    }
+    else
+    {
+        __densities_.reserve(__b_.size());
+        for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW)
+            __densities_.push_back(*__fW);
+        __init();
+    }
+}
+
+#ifndef _LIBCPP_CXX03_LANG
+
+template<class _RealType>
+template<class _UnaryOperation>
+piecewise_linear_distribution<_RealType>::param_type::param_type(
+        initializer_list<result_type> __bl, _UnaryOperation __fw)
+    : __b_(__bl.begin(), __bl.end())
+{
+    if (__b_.size() < 2)
+    {
+        __b_.resize(2);
+        __b_[0] = 0;
+        __b_[1] = 1;
+        __densities_.assign(2, 1.0);
+        __areas_.assign(1, 0.0);
+    }
+    else
+    {
+        __densities_.reserve(__b_.size());
+        for (size_t __i = 0; __i < __b_.size(); ++__i)
+            __densities_.push_back(__fw(__b_[__i]));
+        __init();
+    }
+}
+
+#endif // _LIBCPP_CXX03_LANG
+
+template<class _RealType>
+template<class _UnaryOperation>
+piecewise_linear_distribution<_RealType>::param_type::param_type(
+        size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
+    : __b_(__nw == 0 ? 2 : __nw + 1)
+{
+    size_t __n = __b_.size() - 1;
+    result_type __d = (__xmax - __xmin) / __n;
+    __densities_.reserve(__b_.size());
+    for (size_t __i = 0; __i < __n; ++__i)
+    {
+        __b_[__i] = __xmin + __i * __d;
+        __densities_.push_back(__fw(__b_[__i]));
+    }
+    __b_[__n] = __xmax;
+    __densities_.push_back(__fw(__b_[__n]));
+    __init();
+}
+
+template<class _RealType>
+template<class _URNG>
+_RealType
+piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    typedef uniform_real_distribution<result_type> _Gen;
+    result_type __u = _Gen()(__g);
+    ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
+                                      __u) - __p.__areas_.begin() - 1;
+    __u -= __p.__areas_[__k];
+    const result_type __dk = __p.__densities_[__k];
+    const result_type __dk1 = __p.__densities_[__k+1];
+    const result_type __deltad = __dk1 - __dk;
+    const result_type __bk = __p.__b_[__k];
+    if (__deltad == 0)
+        return __u / __dk + __bk;
+    const result_type __bk1 = __p.__b_[__k+1];
+    const result_type __deltab = __bk1 - __bk;
+    return (__bk * __dk1 - __bk1 * __dk +
+        _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
+        __deltad;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const piecewise_linear_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    size_t __n = __x.__p_.__b_.size();
+    __os << __n;
+    for (size_t __i = 0; __i < __n; ++__i)
+        __os << __sp << __x.__p_.__b_[__i];
+    __n = __x.__p_.__densities_.size();
+    __os << __sp << __n;
+    for (size_t __i = 0; __i < __n; ++__i)
+        __os << __sp << __x.__p_.__densities_[__i];
+    __n = __x.__p_.__areas_.size();
+    __os << __sp << __n;
+    for (size_t __i = 0; __i < __n; ++__i)
+        __os << __sp << __x.__p_.__areas_[__i];
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           piecewise_linear_distribution<_RT>& __x)
+{
+    typedef piecewise_linear_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    size_t __n;
+    __is >> __n;
+    vector<result_type> __b(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __is >> __b[__i];
+    __is >> __n;
+    vector<result_type> __densities(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __is >> __densities[__i];
+    __is >> __n;
+    vector<result_type> __areas(__n);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __is >> __areas[__i];
+    if (!__is.fail())
+    {
+        swap(__x.__p_.__b_, __b);
+        swap(__x.__p_.__densities_, __densities);
+        swap(__x.__p_.__areas_, __areas);
+    }
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H
lib/libcxx/include/__random/poisson_distribution.h
@@ -0,0 +1,277 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_POISSON_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_POISSON_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/clamp_to_integral.h>
+#include <__random/exponential_distribution.h>
+#include <__random/normal_distribution.h>
+#include <__random/uniform_real_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _IntType = int>
+class _LIBCPP_TEMPLATE_VIS poisson_distribution
+{
+public:
+    // types
+    typedef _IntType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        double __mean_;
+        double __s_;
+        double __d_;
+        double __l_;
+        double __omega_;
+        double __c0_;
+        double __c1_;
+        double __c2_;
+        double __c3_;
+        double __c_;
+
+    public:
+        typedef poisson_distribution distribution_type;
+
+        explicit param_type(double __mean = 1.0);
+
+        _LIBCPP_INLINE_VISIBILITY
+        double mean() const {return __mean_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__mean_ == __y.__mean_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+
+        friend class poisson_distribution;
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    poisson_distribution() : poisson_distribution(1.0) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit poisson_distribution(double __mean)
+        : __p_(__mean) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit poisson_distribution(double __mean = 1.0)
+        : __p_(__mean) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit poisson_distribution(const param_type& __p) : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    double mean() const {return __p_.mean();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::max();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const poisson_distribution& __x,
+                        const poisson_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const poisson_distribution& __x,
+                        const poisson_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template<class _IntType>
+poisson_distribution<_IntType>::param_type::param_type(double __mean)
+    // According to the standard `inf` is a valid input, but it causes the
+    // distribution to hang, so we replace it with the maximum representable
+    // mean.
+    : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean)
+{
+    if (__mean_ < 10)
+    {
+        __s_ = 0;
+        __d_ = 0;
+        __l_ = _VSTD::exp(-__mean_);
+        __omega_ = 0;
+        __c3_ = 0;
+        __c2_ = 0;
+        __c1_ = 0;
+        __c0_ = 0;
+        __c_ = 0;
+    }
+    else
+    {
+        __s_ = _VSTD::sqrt(__mean_);
+        __d_ = 6 * __mean_ * __mean_;
+        __l_ = _VSTD::trunc(__mean_ - 1.1484);
+        __omega_ = .3989423 / __s_;
+        double __b1_ = .4166667E-1 / __mean_;
+        double __b2_ = .3 * __b1_ * __b1_;
+        __c3_ = .1428571 * __b1_ * __b2_;
+        __c2_ = __b2_ - 15. * __c3_;
+        __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_;
+        __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_;
+        __c_ = .1069 / __mean_;
+    }
+}
+
+template <class _IntType>
+template<class _URNG>
+_IntType
+poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
+{
+    double __tx;
+    uniform_real_distribution<double> __urd;
+    if (__pr.__mean_ < 10)
+    {
+         __tx = 0;
+        for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx)
+            __p *= __urd(__urng);
+    }
+    else
+    {
+        double __difmuk;
+        double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng);
+        double __u;
+        if (__g > 0)
+        {
+            __tx = _VSTD::trunc(__g);
+            if (__tx >= __pr.__l_)
+                return _VSTD::__clamp_to_integral<result_type>(__tx);
+            __difmuk = __pr.__mean_ - __tx;
+            __u = __urd(__urng);
+            if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk)
+                return _VSTD::__clamp_to_integral<result_type>(__tx);
+        }
+        exponential_distribution<double> __edist;
+        for (bool __using_exp_dist = false; true; __using_exp_dist = true)
+        {
+            double __e;
+            if (__using_exp_dist || __g <= 0)
+            {
+                double __t;
+                do
+                {
+                    __e = __edist(__urng);
+                    __u = __urd(__urng);
+                    __u += __u - 1;
+                    __t = 1.8 + (__u < 0 ? -__e : __e);
+                } while (__t <= -.6744);
+                __tx = _VSTD::trunc(__pr.__mean_ + __pr.__s_ * __t);
+                __difmuk = __pr.__mean_ - __tx;
+                __using_exp_dist = true;
+            }
+            double __px;
+            double __py;
+            if (__tx < 10 && __tx >= 0)
+            {
+                const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
+                                             40320, 362880};
+                __px = -__pr.__mean_;
+                __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)];
+            }
+            else
+            {
+                double __del = .8333333E-1 / __tx;
+                __del -= 4.8 * __del * __del * __del;
+                double __v = __difmuk / __tx;
+                if (_VSTD::abs(__v) > 0.25)
+                    __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del;
+                else
+                    __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) *
+                           __v + .1421878) * __v + -.1661269) * __v + .2000118) *
+                           __v + -.2500068) * __v + .3333333) * __v + -.5) - __del;
+                __py = .3989423 / _VSTD::sqrt(__tx);
+            }
+            double __r = (0.5 - __difmuk) / __pr.__s_;
+            double __r2 = __r * __r;
+            double __fx = -0.5 * __r2;
+            double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) *
+                                        __r2 + __pr.__c1_) * __r2 + __pr.__c0_);
+            if (__using_exp_dist)
+            {
+                if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) -
+                                                   __fy * _VSTD::exp(__fx + __e))
+                    break;
+            }
+            else
+            {
+                if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx))
+                    break;
+            }
+        }
+    }
+    return _VSTD::__clamp_to_integral<result_type>(__tx);
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const poisson_distribution<_IntType>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    return __os << __x.mean();
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           poisson_distribution<_IntType>& __x)
+{
+    typedef poisson_distribution<_IntType> _Eng;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    double __mean;
+    __is >> __mean;
+    if (!__is.fail())
+        __x.param(param_type(__mean));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_POISSON_DISTRIBUTION_H
lib/libcxx/include/__random/random_device.h
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_RANDOM_DEVICE_H
+#define _LIBCPP___RANDOM_RANDOM_DEVICE_H
+
+#include <__config>
+#include <string>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)
+
+class _LIBCPP_TYPE_VIS random_device
+{
+#ifdef _LIBCPP_USING_DEV_RANDOM
+    int __f_;
+#elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT)
+#   if defined(__clang__)
+#       pragma clang diagnostic push
+#       pragma clang diagnostic ignored "-Wunused-private-field"
+#   endif
+
+    // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now
+    // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we
+    // retain the same layout as before.
+#   if defined(__APPLE__)
+    int __padding_; // padding to fake the `__f_` field above
+#   endif
+
+    // ... vendors can add workarounds here if they switch to a different representation ...
+
+#   if defined(__clang__)
+#       pragma clang diagnostic pop
+#   endif
+#endif
+
+public:
+    // types
+    typedef unsigned result_type;
+
+    // generator characteristics
+    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
+    static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
+
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
+
+    // constructors
+#ifndef _LIBCPP_CXX03_LANG
+    random_device() : random_device("/dev/urandom") {}
+    explicit random_device(const string& __token);
+#else
+    explicit random_device(const string& __token = "/dev/urandom");
+#endif
+    ~random_device();
+
+    // generating functions
+    result_type operator()();
+
+    // property functions
+    double entropy() const _NOEXCEPT;
+
+    random_device(const random_device&) = delete;
+    void operator=(const random_device&) = delete;
+};
+
+#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H
lib/libcxx/include/__random/ranlux.h
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_RANLUX_H
+#define _LIBCPP___RANDOM_RANLUX_H
+
+#include <__config>
+#include <__random/discard_block_engine.h>
+#include <__random/subtract_with_carry_engine.h>
+#include <cstdint>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base;
+typedef subtract_with_carry_engine<uint_fast64_t, 48,  5, 12> ranlux48_base;
+
+typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
+typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANDOM_RANLUX_H
lib/libcxx/include/__random/seed_seq.h
@@ -0,0 +1,153 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_SEED_SEQ_H
+#define _LIBCPP___RANDOM_SEED_SEQ_H
+
+#include <__algorithm/copy.h>
+#include <__algorithm/fill.h>
+#include <__algorithm/max.h>
+#include <__config>
+#include <initializer_list>
+#include <vector>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class _LIBCPP_TEMPLATE_VIS seed_seq
+{
+public:
+    // types
+    typedef uint32_t result_type;
+
+    // constructors
+    _LIBCPP_INLINE_VISIBILITY
+    seed_seq() _NOEXCEPT {}
+#ifndef _LIBCPP_CXX03_LANG
+    template<class _Tp, __enable_if_t<is_integral<_Tp>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    seed_seq(initializer_list<_Tp> __il) {
+        __init(__il.begin(), __il.end());
+    }
+#endif // _LIBCPP_CXX03_LANG
+
+    template<class _InputIterator>
+    _LIBCPP_INLINE_VISIBILITY
+    seed_seq(_InputIterator __first, _InputIterator __last) {
+        static_assert(is_integral<typename iterator_traits<_InputIterator>::value_type>::value,
+            "Mandates: iterator_traits<InputIterator>::value_type is an integer type");
+        __init(__first, __last);
+    }
+
+    // generating functions
+    template<class _RandomAccessIterator>
+        void generate(_RandomAccessIterator __first, _RandomAccessIterator __last);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    size_t size() const _NOEXCEPT {return __v_.size();}
+    template<class _OutputIterator>
+        _LIBCPP_INLINE_VISIBILITY
+        void param(_OutputIterator __dest) const
+            {_VSTD::copy(__v_.begin(), __v_.end(), __dest);}
+
+    seed_seq(const seed_seq&) = delete;
+    void operator=(const seed_seq&) = delete;
+
+    _LIBCPP_INLINE_VISIBILITY
+    static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);}
+
+private:
+    template<class _InputIterator>
+    void __init(_InputIterator __first, _InputIterator __last);
+
+    vector<result_type> __v_;
+};
+
+template<class _InputIterator>
+void
+seed_seq::__init(_InputIterator __first, _InputIterator __last)
+{
+    for (_InputIterator __s = __first; __s != __last; ++__s)
+        __v_.push_back(*__s & 0xFFFFFFFF);
+}
+
+template<class _RandomAccessIterator>
+void
+seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    if (__first != __last)
+    {
+        _VSTD::fill(__first, __last, 0x8b8b8b8b);
+        const size_t __n = static_cast<size_t>(__last - __first);
+        const size_t __s = __v_.size();
+        const size_t __t = (__n >= 623) ? 11
+                         : (__n >= 68) ? 7
+                         : (__n >= 39) ? 5
+                         : (__n >= 7)  ? 3
+                         : (__n - 1) / 2;
+        const size_t __p = (__n - __t) / 2;
+        const size_t __q = __p + __t;
+        const size_t __m = _VSTD::max(__s + 1, __n);
+        // __k = 0;
+        {
+            result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p]
+                                                      ^  __first[__n - 1]);
+            __first[__p] += __r;
+            __r += __s;
+            __first[__q] += __r;
+            __first[0] = __r;
+        }
+        for (size_t __k = 1; __k <= __s; ++__k)
+        {
+            const size_t __kmodn = __k % __n;
+            const size_t __kpmodn = (__k + __p) % __n;
+            result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
+                                           ^ __first[(__k - 1) % __n]);
+            __first[__kpmodn] += __r;
+            __r +=  __kmodn + __v_[__k-1];
+            __first[(__k + __q) % __n] += __r;
+            __first[__kmodn] = __r;
+        }
+        for (size_t __k = __s + 1; __k < __m; ++__k)
+        {
+            const size_t __kmodn = __k % __n;
+            const size_t __kpmodn = (__k + __p) % __n;
+            result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
+                                           ^ __first[(__k - 1) % __n]);
+            __first[__kpmodn] += __r;
+            __r +=  __kmodn;
+            __first[(__k + __q) % __n] += __r;
+            __first[__kmodn] = __r;
+        }
+        for (size_t __k = __m; __k < __m + __n; ++__k)
+        {
+            const size_t __kmodn = __k % __n;
+            const size_t __kpmodn = (__k + __p) % __n;
+            result_type __r = 1566083941 * _Tp(__first[__kmodn] +
+                                              __first[__kpmodn] +
+                                              __first[(__k - 1) % __n]);
+            __first[__kpmodn] ^= __r;
+            __r -= __kmodn;
+            __first[(__k + __q) % __n] ^= __r;
+            __first[__kmodn] = __r;
+        }
+    }
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_SEED_SEQ_H
lib/libcxx/include/__random/shuffle_order_engine.h
@@ -0,0 +1,283 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_SHUFFLE_ORDER_ENGINE_H
+#define _LIBCPP___RANDOM_SHUFFLE_ORDER_ENGINE_H
+
+#include <__algorithm/equal.h>
+#include <__config>
+#include <__random/is_seed_sequence.h>
+#include <__utility/move.h>
+#include <cstdint>
+#include <iosfwd>
+#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 <uint64_t _Xp, uint64_t _Yp>
+struct __ugcd
+{
+    static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value;
+};
+
+template <uint64_t _Xp>
+struct __ugcd<_Xp, 0>
+{
+    static _LIBCPP_CONSTEXPR const uint64_t value = _Xp;
+};
+
+template <uint64_t _Np, uint64_t _Dp>
+class __uratio
+{
+    static_assert(_Dp != 0, "__uratio divide by 0");
+    static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value;
+public:
+    static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd;
+    static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd;
+
+    typedef __uratio<num, den> type;
+};
+
+template<class _Engine, size_t __k>
+class _LIBCPP_TEMPLATE_VIS shuffle_order_engine
+{
+    static_assert(0 < __k, "shuffle_order_engine invalid parameters");
+public:
+    // types
+    typedef typename _Engine::result_type result_type;
+
+private:
+    _Engine __e_;
+    result_type _V_[__k];
+    result_type _Y_;
+
+public:
+    // engine characteristics
+    static _LIBCPP_CONSTEXPR const size_t table_size = __k;
+
+#ifdef _LIBCPP_CXX03_LANG
+    static const result_type _Min = _Engine::_Min;
+    static const result_type _Max = _Engine::_Max;
+#else
+    static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
+    static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
+#endif
+    static_assert(_Min < _Max, "shuffle_order_engine invalid parameters");
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
+
+    static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull;
+
+    // constructors and seeding functions
+    _LIBCPP_INLINE_VISIBILITY
+    shuffle_order_engine() {__init();}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit shuffle_order_engine(const _Engine& __e)
+        : __e_(__e) {__init();}
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    explicit shuffle_order_engine(_Engine&& __e)
+        : __e_(_VSTD::move(__e)) {__init();}
+#endif // _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit shuffle_order_engine(_Sseq& __q,
+        typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
+                           !is_convertible<_Sseq, _Engine>::value>::type* = 0)
+         : __e_(__q) {__init();}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed() {__e_.seed(); __init();}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(result_type __sd) {__e_.seed(__sd); __init();}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            __is_seed_sequence<_Sseq, shuffle_order_engine>::value,
+            void
+        >::type
+        seed(_Sseq& __q) {__e_.seed(__q); __init();}
+
+    // generating functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
+    _LIBCPP_INLINE_VISIBILITY
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    const _Engine& base() const _NOEXCEPT {return __e_;}
+
+private:
+    template<class _Eng, size_t _Kp>
+    friend
+    bool
+    operator==(
+        const shuffle_order_engine<_Eng, _Kp>& __x,
+        const shuffle_order_engine<_Eng, _Kp>& __y);
+
+    template<class _Eng, size_t _Kp>
+    friend
+    bool
+    operator!=(
+        const shuffle_order_engine<_Eng, _Kp>& __x,
+        const shuffle_order_engine<_Eng, _Kp>& __y);
+
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _Kp>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const shuffle_order_engine<_Eng, _Kp>& __x);
+
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _Kp>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               shuffle_order_engine<_Eng, _Kp>& __x);
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __init()
+    {
+        for (size_t __i = 0; __i < __k; ++__i)
+            _V_[__i] = __e_();
+        _Y_ = __e_();
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type __eval2(true_type) {return __evalf<__k, 0>();}
+
+    template <uint64_t _Np, uint64_t _Dp>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)),
+            result_type
+        >::type
+        __eval(__uratio<_Np, _Dp>)
+            {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();}
+
+    template <uint64_t _Np, uint64_t _Dp>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min),
+            result_type
+        >::type
+        __eval(__uratio<_Np, _Dp>)
+        {
+            const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min)
+                                                   / __uratio<_Np, _Dp>::den);
+            _Y_ = _V_[__j];
+            _V_[__j] = __e_();
+            return _Y_;
+        }
+
+    template <uint64_t __n, uint64_t __d>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type __evalf()
+        {
+            const double _Fp = __d == 0 ?
+                __n / (2. * 0x8000000000000000ull) :
+                __n / (double)__d;
+            const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min));
+            _Y_ = _V_[__j];
+            _V_[__j] = __e_();
+            return _Y_;
+        }
+};
+
+template<class _Engine, size_t __k>
+    _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size;
+
+template<class _Eng, size_t _Kp>
+bool
+operator==(
+    const shuffle_order_engine<_Eng, _Kp>& __x,
+    const shuffle_order_engine<_Eng, _Kp>& __y)
+{
+    return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) &&
+           __x.__e_ == __y.__e_;
+}
+
+template<class _Eng, size_t _Kp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(
+    const shuffle_order_engine<_Eng, _Kp>& __x,
+    const shuffle_order_engine<_Eng, _Kp>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _Kp>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const shuffle_order_engine<_Eng, _Kp>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _Ostream;
+    __os.flags(_Ostream::dec | _Ostream::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.__e_ << __sp << __x._V_[0];
+    for (size_t __i = 1; __i < _Kp; ++__i)
+        __os << __sp << __x._V_[__i];
+    return __os << __sp << __x._Y_;
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _Kp>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           shuffle_order_engine<_Eng, _Kp>& __x)
+{
+    typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    _Eng __e;
+    result_type _Vp[_Kp+1];
+    __is >> __e;
+    for (size_t __i = 0; __i < _Kp+1; ++__i)
+        __is >> _Vp[__i];
+    if (!__is.fail())
+    {
+        __x.__e_ = __e;
+        for (size_t __i = 0; __i < _Kp; ++__i)
+            __x._V_[__i] = _Vp[__i];
+        __x._Y_ = _Vp[_Kp];
+    }
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_SHUFFLE_ORDER_ENGINE_H
lib/libcxx/include/__random/student_t_distribution.h
@@ -0,0 +1,153 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_STUDENT_T_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_STUDENT_T_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/gamma_distribution.h>
+#include <__random/normal_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS student_t_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __n_;
+    public:
+        typedef student_t_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __n = 1) : __n_(__n) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type n() const {return __n_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__n_ == __y.__n_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+    normal_distribution<result_type> __nd_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    student_t_distribution() : student_t_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit student_t_distribution(result_type __n)
+        : __p_(param_type(__n)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit student_t_distribution(result_type __n = 1)
+        : __p_(param_type(__n)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit student_t_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {__nd_.reset();}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type n() const {return __p_.n();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return -numeric_limits<result_type>::infinity();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const student_t_distribution& __x,
+                        const student_t_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const student_t_distribution& __x,
+                        const student_t_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _RealType>
+template<class _URNG>
+_RealType
+student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    gamma_distribution<result_type> __gd(__p.n() * .5, 2);
+    return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const student_t_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    __os << __x.n();
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           student_t_distribution<_RT>& __x)
+{
+    typedef student_t_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __n;
+    __is >> __n;
+    if (!__is.fail())
+        __x.param(param_type(__n));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_STUDENT_T_DISTRIBUTION_H
lib/libcxx/include/__random/subtract_with_carry_engine.h
@@ -0,0 +1,352 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H
+#define _LIBCPP___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H
+
+#include <__algorithm/equal.h>
+#include <__algorithm/min.h>
+#include <__config>
+#include <__random/is_seed_sequence.h>
+#include <__random/linear_congruential_engine.h>
+#include <cstddef>
+#include <cstdint>
+#include <iosfwd>
+#include <limits>
+#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 _UIntType, size_t __w, size_t __s, size_t __r>
+class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine;
+
+template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+bool
+operator==(
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
+
+template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+_LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine
+{
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    result_type __x_[__r];
+    result_type  __c_;
+    size_t      __i_;
+
+    static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
+    static_assert(  0 <  __w, "subtract_with_carry_engine invalid parameters");
+    static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters");
+    static_assert(  0 <  __s, "subtract_with_carry_engine invalid parameters");
+    static_assert(__s <  __r, "subtract_with_carry_engine invalid parameters");
+public:
+    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
+    static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
+                                                      (result_type(1) << __w) - result_type(1);
+    static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
+
+    // engine characteristics
+    static _LIBCPP_CONSTEXPR const size_t word_size = __w;
+    static _LIBCPP_CONSTEXPR const size_t short_lag = __s;
+    static _LIBCPP_CONSTEXPR const size_t long_lag = __r;
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
+    static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
+
+    // constructors and seeding functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit subtract_with_carry_engine(result_type __sd) { seed(__sd); }
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit subtract_with_carry_engine(result_type __sd = default_seed) {
+      seed(__sd);
+    }
+#endif
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit subtract_with_carry_engine(_Sseq& __q,
+        typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
+        {seed(__q);}
+    _LIBCPP_INLINE_VISIBILITY
+    void seed(result_type __sd = default_seed)
+        {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
+    template<class _Sseq>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value,
+            void
+        >::type
+        seed(_Sseq& __q)
+            {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
+
+    // generating functions
+    result_type operator()();
+    _LIBCPP_INLINE_VISIBILITY
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+    friend
+    bool
+    operator==(
+        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
+        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
+
+    template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+    friend
+    bool
+    operator!=(
+        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
+        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
+
+    template <class _CharT, class _Traits,
+              class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
+
+    template <class _CharT, class _Traits,
+              class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
+
+private:
+
+    void seed(result_type __sd, integral_constant<unsigned, 1>);
+    void seed(result_type __sd, integral_constant<unsigned, 2>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
+};
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type
+    subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
+        integral_constant<unsigned, 1>)
+{
+    linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
+        __e(__sd == 0u ? default_seed : __sd);
+    for (size_t __i = 0; __i < __r; ++__i)
+        __x_[__i] = static_cast<result_type>(__e() & _Max);
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
+        integral_constant<unsigned, 2>)
+{
+    linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
+        __e(__sd == 0u ? default_seed : __sd);
+    for (size_t __i = 0; __i < __r; ++__i)
+    {
+        result_type __e0 = __e();
+        __x_[__i] = static_cast<result_type>(
+                                    (__e0 + ((uint64_t)__e() << 32)) & _Max);
+    }
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+template<class _Sseq>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
+        integral_constant<unsigned, 1>)
+{
+    const unsigned __k = 1;
+    uint32_t __ar[__r * __k];
+    __q.generate(__ar, __ar + __r * __k);
+    for (size_t __i = 0; __i < __r; ++__i)
+        __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+template<class _Sseq>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
+        integral_constant<unsigned, 2>)
+{
+    const unsigned __k = 2;
+    uint32_t __ar[__r * __k];
+    __q.generate(__ar, __ar + __r * __k);
+    for (size_t __i = 0; __i < __r; ++__i)
+        __x_[__i] = static_cast<result_type>(
+                  (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+_UIntType
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()()
+{
+    const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r];
+    result_type& __xr = __x_[__i_];
+    result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1;
+    __xr = (__xs - __xr - __c_) & _Max;
+    __c_ = __new_c;
+    __i_ = (__i_ + 1) % __r;
+    return __xr;
+}
+
+template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+bool
+operator==(
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
+{
+    if (__x.__c_ != __y.__c_)
+        return false;
+    if (__x.__i_ == __y.__i_)
+        return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_);
+    if (__x.__i_ == 0 || __y.__i_ == 0)
+    {
+        size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_);
+        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (__x.__i_ == 0)
+            return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_);
+        return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j);
+    }
+    if (__x.__i_ < __y.__i_)
+    {
+        size_t __j = _Rp - __y.__i_;
+        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp,
+                         __y.__x_))
+            return false;
+        return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
+                           __y.__x_ + (_Rp - (__x.__i_ + __j)));
+    }
+    size_t __j = _Rp - __x.__i_;
+    if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
+                     __x.__x_ + __x.__i_))
+        return false;
+    if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp,
+                     __x.__x_))
+        return false;
+    return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
+                       __x.__x_ + (_Rp - (__y.__i_ + __j)));
+}
+
+template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
+    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _Ostream;
+    __os.flags(_Ostream::dec | _Ostream::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.__x_[__x.__i_];
+    for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j)
+        __os << __sp << __x.__x_[__j];
+    for (size_t __j = 0; __j < __x.__i_; ++__j)
+        __os << __sp << __x.__x_[__j];
+    __os << __sp << __x.__c_;
+    return __os;
+}
+
+template <class _CharT, class _Traits,
+          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    _UInt __t[_Rp+1];
+    for (size_t __i = 0; __i < _Rp+1; ++__i)
+        __is >> __t[__i];
+    if (!__is.fail())
+    {
+        for (size_t __i = 0; __i < _Rp; ++__i)
+            __x.__x_[__i] = __t[__i];
+        __x.__c_ = __t[_Rp];
+        __x.__i_ = 0;
+    }
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H
lib/libcxx/include/__random/uniform_int_distribution.h
@@ -11,6 +11,8 @@
 
 #include <__bits>
 #include <__config>
+#include <__random/log2.h>
+#include <bit>
 #include <cstddef>
 #include <cstdint>
 #include <iosfwd>
@@ -26,34 +28,6 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-// __independent_bits_engine
-
-template <unsigned long long _Xp, size_t _Rp>
-struct __log2_imp
-{
-    static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp
-                                           : __log2_imp<_Xp, _Rp - 1>::value;
-};
-
-template <unsigned long long _Xp>
-struct __log2_imp<_Xp, 0>
-{
-    static const size_t value = 0;
-};
-
-template <size_t _Rp>
-struct __log2_imp<0, _Rp>
-{
-    static const size_t value = _Rp + 1;
-};
-
-template <class _UIntType, _UIntType _Xp>
-struct __log2
-{
-    static const size_t value = __log2_imp<_Xp,
-                                         sizeof(_UIntType) * __CHAR_BIT__ - 1>::value;
-};
-
 template<class _Engine, class _UIntType>
 class __independent_bits_engine
 {
@@ -181,7 +155,7 @@ __independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
     return _Sp;
 }
 
-template<class _IntType = int>
+template<class _IntType = int> // __int128_t is also supported as an extension here
 class uniform_int_distribution
 {
 public:
@@ -256,8 +230,8 @@ typename uniform_int_distribution<_IntType>::result_type
 uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
 {
-    typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t),
-                                            uint32_t, uint64_t>::type _UIntType;
+    typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t), uint32_t,
+                                 typename make_unsigned<result_type>::type>::type _UIntType;
     const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1);
     if (_Rp == 1)
         return __p.a();
@@ -265,7 +239,7 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
     typedef __independent_bits_engine<_URNG, _UIntType> _Eng;
     if (_Rp == 0)
         return static_cast<result_type>(_Eng(__g, _Dt)());
-    size_t __w = _Dt - __libcpp_clz(_Rp) - 1;
+    size_t __w = _Dt - __countl_zero(_Rp) - 1;
     if ((_Rp & (numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0)
         ++__w;
     _Eng __e(__g, __w);
lib/libcxx/include/__random/uniform_random_bit_generator.h
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H
+#define _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H
+
+#include <__concepts/arithmetic.h>
+#include <__concepts/invocable.h>
+#include <__concepts/same_as.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
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [rand.req.urng]
+template<class _Gen>
+concept uniform_random_bit_generator =
+  invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> &&
+  requires {
+    { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>;
+    { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>;
+    requires bool_constant<(_Gen::min() < _Gen::max())>::value;
+  };
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H
lib/libcxx/include/__random/uniform_real_distribution.h
@@ -0,0 +1,160 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_UNIFORM_REAL_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_UNIFORM_REAL_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/generate_canonical.h>
+#include <iosfwd>
+#include <limits>
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS uniform_real_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __a_;
+        result_type __b_;
+    public:
+        typedef uniform_real_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __a = 0,
+                            result_type __b = 1)
+            : __a_(__a), __b_(__b) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type a() const {return __a_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type b() const {return __b_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    uniform_real_distribution() : uniform_real_distribution(0) {}
+    explicit uniform_real_distribution(result_type __a, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type a() const {return __p_.a();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type b() const {return __p_.b();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return a();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return b();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const uniform_real_distribution& __x,
+                        const uniform_real_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const uniform_real_distribution& __x,
+                        const uniform_real_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template<class _RealType>
+template<class _URNG>
+inline
+typename uniform_real_distribution<_RealType>::result_type
+uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    return (__p.b() - __p.a())
+        * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
+        + __p.a();
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const uniform_real_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.a() << __sp << __x.b();
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           uniform_real_distribution<_RT>& __x)
+{
+    typedef uniform_real_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __a;
+    result_type __b;
+    __is >> __a >> __b;
+    if (!__is.fail())
+        __x.param(param_type(__a, __b));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_UNIFORM_REAL_DISTRIBUTION_H
lib/libcxx/include/__random/weibull_distribution.h
@@ -0,0 +1,155 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___RANDOM_WEIBULL_DISTRIBUTION_H
+#define _LIBCPP___RANDOM_WEIBULL_DISTRIBUTION_H
+
+#include <__config>
+#include <__random/exponential_distribution.h>
+#include <cmath>
+#include <iosfwd>
+#include <limits>
+
+#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 _RealType = double>
+class _LIBCPP_TEMPLATE_VIS weibull_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class _LIBCPP_TEMPLATE_VIS param_type
+    {
+        result_type __a_;
+        result_type __b_;
+    public:
+        typedef weibull_distribution distribution_type;
+
+        _LIBCPP_INLINE_VISIBILITY
+        explicit param_type(result_type __a = 1, result_type __b = 1)
+            : __a_(__a), __b_(__b) {}
+
+        _LIBCPP_INLINE_VISIBILITY
+        result_type a() const {return __a_;}
+        _LIBCPP_INLINE_VISIBILITY
+        result_type b() const {return __b_;}
+
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
+        friend _LIBCPP_INLINE_VISIBILITY
+            bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructor and reset functions
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    weibull_distribution() : weibull_distribution(1) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit weibull_distribution(result_type __a, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    explicit weibull_distribution(const param_type& __p)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY
+    void reset() {}
+
+    // generating functions
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG>
+        _LIBCPP_INLINE_VISIBILITY
+        result_type operator()(_URNG& __g, const param_type& __p)
+        {return __p.b() *
+            _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());}
+
+    // property functions
+    _LIBCPP_INLINE_VISIBILITY
+    result_type a() const {return __p_.a();}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type b() const {return __p_.b();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    param_type param() const {return __p_;}
+    _LIBCPP_INLINE_VISIBILITY
+    void param(const param_type& __p) {__p_ = __p;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    result_type min() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY
+    result_type max() const {return numeric_limits<result_type>::infinity();}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const weibull_distribution& __x,
+                        const weibull_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const weibull_distribution& __x,
+                        const weibull_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const weibull_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> __lx(__os);
+    typedef basic_ostream<_CharT, _Traits> _OStream;
+    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+               _OStream::scientific);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.a() << __sp << __x.b();
+    return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           weibull_distribution<_RT>& __x)
+{
+    typedef weibull_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> __lx(__is);
+    typedef basic_istream<_CharT, _Traits> _Istream;
+    __is.flags(_Istream::dec | _Istream::skipws);
+    result_type __a;
+    result_type __b;
+    __is >> __a >> __b;
+    if (!__is.fail())
+        __x.param(param_type(__a, __b));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANDOM_WEIBULL_DISTRIBUTION_H
lib/libcxx/include/__ranges/access.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ __ranges/access.h ---------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,12 +9,13 @@
 #ifndef _LIBCPP___RANGES_ACCESS_H
 #define _LIBCPP___RANGES_ACCESS_H
 
+#include <__concepts/class_or_enum.h>
 #include <__config>
 #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 <__utility/as_const.h>
+#include <__utility/auto_cast.h>
 #include <concepts>
 #include <type_traits>
 
@@ -22,31 +23,26 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
-
-// clang-format off
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 namespace ranges {
   template <class _Tp>
   concept __can_borrow =
-      is_lvalue_reference_v<_Tp> || enable_borrowed_range<remove_cvref_t<_Tp> >;
-
-  template<class _Tp>
-  concept __is_complete = requires { sizeof(_Tp); };
+    is_lvalue_reference_v<_Tp> || enable_borrowed_range<remove_cvref_t<_Tp>>;
 } // namespace ranges
 
 // [range.access.begin]
-namespace ranges::__begin {
+
+namespace ranges {
+namespace __begin {
   template <class _Tp>
   concept __member_begin =
     __can_borrow<_Tp> &&
+    __workaround_52970<_Tp> &&
     requires(_Tp&& __t) {
-      { _VSTD::__decay_copy(__t.begin()) } -> input_or_output_iterator;
+      { _LIBCPP_AUTO_CAST(__t.begin()) } -> input_or_output_iterator;
     };
 
   void begin(auto&) = delete;
@@ -56,61 +52,69 @@ namespace ranges::__begin {
   concept __unqualified_begin =
     !__member_begin<_Tp> &&
     __can_borrow<_Tp> &&
-    __class_or_enum<remove_cvref_t<_Tp> > &&
+    __class_or_enum<remove_cvref_t<_Tp>> &&
     requires(_Tp && __t) {
-      { _VSTD::__decay_copy(begin(__t)) } -> input_or_output_iterator;
+      { _LIBCPP_AUTO_CAST(begin(__t)) } -> input_or_output_iterator;
     };
 
   struct __fn {
     template <class _Tp>
-    requires is_array_v<remove_cv_t<_Tp>>
-    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp& __t) const noexcept {
-      constexpr bool __complete = __is_complete<iter_value_t<_Tp> >;
-      if constexpr (__complete) { // used to disable cryptic diagnostic
-        return __t + 0;
-      }
-      else {
-        static_assert(__complete, "`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type.");
-      }
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[]) const noexcept
+      requires (sizeof(_Tp) != 0)  // Disallow incomplete element types.
+    {
+      return __t + 0;
+    }
+
+    template <class _Tp, size_t _Np>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
+      requires (sizeof(_Tp) != 0)  // Disallow incomplete element types.
+    {
+      return __t + 0;
     }
 
     template <class _Tp>
-    requires __member_begin<_Tp>
+      requires __member_begin<_Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-    noexcept(noexcept(_VSTD::__decay_copy(__t.begin())))
+      noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.begin())))
     {
-      return __t.begin();
+      return _LIBCPP_AUTO_CAST(__t.begin());
     }
 
     template <class _Tp>
-    requires __unqualified_begin<_Tp>
+      requires __unqualified_begin<_Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-    noexcept(noexcept(_VSTD::__decay_copy(begin(__t))))
+      noexcept(noexcept(_LIBCPP_AUTO_CAST(begin(__t))))
     {
-      return begin(__t);
+      return _LIBCPP_AUTO_CAST(begin(__t));
     }
 
     void operator()(auto&&) const = delete;
   };
-} // namespace ranges::__begin
+} // namespace __begin
 
-namespace ranges {
-  inline namespace __cpo {
-    inline constexpr auto begin = __begin::__fn{};
-  } // namespace __cpo
+inline namespace __cpo {
+  inline constexpr auto begin = __begin::__fn{};
+} // namespace __cpo
+} // namespace ranges
 
+// [range.range]
+
+namespace ranges {
   template <class _Tp>
   using iterator_t = decltype(ranges::begin(declval<_Tp&>()));
 } // namespace ranges
 
 // [range.access.end]
-namespace ranges::__end {
+
+namespace ranges {
+namespace __end {
   template <class _Tp>
   concept __member_end =
     __can_borrow<_Tp> &&
+    __workaround_52970<_Tp> &&
     requires(_Tp&& __t) {
       typename iterator_t<_Tp>;
-      { _VSTD::__decay_copy(_VSTD::forward<_Tp>(__t).end()) } -> sentinel_for<iterator_t<_Tp> >;
+      { _LIBCPP_AUTO_CAST(__t.end()) } -> sentinel_for<iterator_t<_Tp>>;
     };
 
   void end(auto&) = delete;
@@ -120,103 +124,104 @@ namespace ranges::__end {
   concept __unqualified_end =
     !__member_end<_Tp> &&
     __can_borrow<_Tp> &&
-    __class_or_enum<remove_cvref_t<_Tp> > &&
+    __class_or_enum<remove_cvref_t<_Tp>> &&
     requires(_Tp && __t) {
       typename iterator_t<_Tp>;
-      { _VSTD::__decay_copy(end(_VSTD::forward<_Tp>(__t))) } -> sentinel_for<iterator_t<_Tp> >;
+      { _LIBCPP_AUTO_CAST(end(__t)) } -> sentinel_for<iterator_t<_Tp>>;
     };
 
   class __fn {
   public:
     template <class _Tp, size_t _Np>
-    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept {
-      constexpr bool __complete = __is_complete<remove_cv_t<_Tp> >;
-      if constexpr (__complete) { // used to disable cryptic diagnostic
-        return __t + _Np;
-      }
-      else {
-        static_assert(__complete, "`std::ranges::end` is SFINAE-unfriendly on arrays of an incomplete type.");
-      }
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
+      requires (sizeof(_Tp) != 0)  // Disallow incomplete element types.
+    {
+      return __t + _Np;
     }
 
     template <class _Tp>
-    requires __member_end<_Tp>
+      requires __member_end<_Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-    noexcept(noexcept(_VSTD::__decay_copy(__t.end())))
+      noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.end())))
     {
-      return _VSTD::forward<_Tp>(__t).end();
+      return _LIBCPP_AUTO_CAST(__t.end());
     }
 
     template <class _Tp>
-    requires __unqualified_end<_Tp>
+      requires __unqualified_end<_Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-    noexcept(noexcept(_VSTD::__decay_copy(end(__t))))
+      noexcept(noexcept(_LIBCPP_AUTO_CAST(end(__t))))
     {
-      return end(__t);
+      return _LIBCPP_AUTO_CAST(end(__t));
     }
 
     void operator()(auto&&) const = delete;
   };
-} // namespace ranges::__end
+} // namespace __end
 
-namespace ranges::inline __cpo {
+inline namespace __cpo {
   inline constexpr auto end = __end::__fn{};
-} // namespace ranges::__cpo
+} // namespace __cpo
+} // namespace ranges
 
-namespace ranges::__cbegin {
+// [range.access.cbegin]
+
+namespace ranges {
+namespace __cbegin {
   struct __fn {
     template <class _Tp>
-    requires invocable<decltype(ranges::begin), _Tp const&>
-    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp& __t) const
-    noexcept(noexcept(ranges::begin(_VSTD::as_const(__t))))
-    {
-      return ranges::begin(_VSTD::as_const(__t));
-    }
+      requires is_lvalue_reference_v<_Tp&&>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))))
+      -> decltype(      ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t)))
+      { return          ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t)); }
 
     template <class _Tp>
-    requires is_rvalue_reference_v<_Tp> && invocable<decltype(ranges::begin), _Tp const&&>
-    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-    noexcept(noexcept(ranges::begin(static_cast<_Tp const&&>(__t))))
-    {
-      return ranges::begin(static_cast<_Tp const&&>(__t));
-    }
+      requires is_rvalue_reference_v<_Tp&&>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::begin(static_cast<const _Tp&&>(__t))))
+      -> decltype(      ranges::begin(static_cast<const _Tp&&>(__t)))
+      { return          ranges::begin(static_cast<const _Tp&&>(__t)); }
   };
-} // namespace ranges::__cbegin
+} // namespace __cbegin
 
-namespace ranges::inline __cpo {
+inline namespace __cpo {
   inline constexpr auto cbegin = __cbegin::__fn{};
-} // namespace ranges::__cpo
+} // namespace __cpo
+} // namespace ranges
+
+// [range.access.cend]
 
-namespace ranges::__cend {
+namespace ranges {
+namespace __cend {
   struct __fn {
     template <class _Tp>
-    requires invocable<decltype(ranges::end), _Tp const&>
-    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp& __t) const
-    noexcept(noexcept(ranges::end(_VSTD::as_const(__t))))
-    {
-      return ranges::end(_VSTD::as_const(__t));
-    }
+      requires is_lvalue_reference_v<_Tp&&>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))))
+      -> decltype(      ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t)))
+      { return          ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t)); }
 
     template <class _Tp>
-    requires is_rvalue_reference_v<_Tp> && invocable<decltype(ranges::end), _Tp const&&>
-    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
-    noexcept(noexcept(ranges::end(static_cast<_Tp const&&>(__t))))
-    {
-      return ranges::end(static_cast<_Tp const&&>(__t));
-    }
+      requires is_rvalue_reference_v<_Tp&&>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::end(static_cast<const _Tp&&>(__t))))
+      -> decltype(      ranges::end(static_cast<const _Tp&&>(__t)))
+      { return          ranges::end(static_cast<const _Tp&&>(__t)); }
   };
-} // namespace ranges::__cend
+} // namespace __cend
 
-namespace ranges::inline __cpo {
+inline namespace __cpo {
   inline constexpr auto cend = __cend::__fn{};
-} // namespace ranges::__cpo
-
-// clang-format off
+} // namespace __cpo
+} // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_ACCESS_H
lib/libcxx/include/__ranges/all.h
@@ -14,9 +14,10 @@
 #include <__iterator/iterator_traits.h>
 #include <__ranges/access.h>
 #include <__ranges/concepts.h>
+#include <__ranges/owning_view.h>
+#include <__ranges/range_adaptor.h>
 #include <__ranges/ref_view.h>
-#include <__ranges/subrange.h>
-#include <__utility/__decay_copy.h>
+#include <__utility/auto_cast.h>
 #include <__utility/declval.h>
 #include <__utility/forward.h>
 #include <type_traits>
@@ -25,30 +26,27 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
-namespace views {
+namespace ranges::views {
 
 namespace __all {
-  struct __fn {
+  struct __fn : __range_adaptor_closure<__fn> {
     template<class _Tp>
       requires ranges::view<decay_t<_Tp>>
-    _LIBCPP_HIDE_FROM_ABI
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
     constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(_VSTD::__decay_copy(_VSTD::forward<_Tp>(__t))))
+      noexcept(noexcept(_LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t))))
     {
-      return _VSTD::forward<_Tp>(__t);
+      return _LIBCPP_AUTO_CAST(_VSTD::forward<_Tp>(__t));
     }
 
     template<class _Tp>
       requires (!ranges::view<decay_t<_Tp>>) &&
                requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; }
-    _LIBCPP_HIDE_FROM_ABI
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
     constexpr auto operator()(_Tp&& __t) const
       noexcept(noexcept(ranges::ref_view{_VSTD::forward<_Tp>(__t)}))
     {
@@ -58,15 +56,15 @@ namespace __all {
     template<class _Tp>
       requires (!ranges::view<decay_t<_Tp>> &&
                 !requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; } &&
-                 requires (_Tp&& __t) { ranges::subrange{_VSTD::forward<_Tp>(__t)}; })
-    _LIBCPP_HIDE_FROM_ABI
+                 requires (_Tp&& __t) { ranges::owning_view{_VSTD::forward<_Tp>(__t)}; })
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
     constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::subrange{_VSTD::forward<_Tp>(__t)}))
+      noexcept(noexcept(ranges::owning_view{_VSTD::forward<_Tp>(__t)}))
     {
-      return ranges::subrange{_VSTD::forward<_Tp>(__t)};
+      return ranges::owning_view{_VSTD::forward<_Tp>(__t)};
     }
   };
-}
+} // namespace __all
 
 inline namespace __cpo {
   inline constexpr auto all = __all::__fn{};
@@ -75,12 +73,10 @@ inline namespace __cpo {
 template<ranges::viewable_range _Range>
 using all_t = decltype(views::all(declval<_Range>()));
 
-} // namespace views
+} // namespace ranges::views
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_ALL_H
lib/libcxx/include/__ranges/common_view.h
@@ -16,8 +16,11 @@
 #include <__ranges/all.h>
 #include <__ranges/concepts.h>
 #include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
 #include <__ranges/size.h>
 #include <__ranges/view_interface.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
 #include <concepts>
 #include <type_traits>
 
@@ -25,12 +28,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 namespace ranges {
 
@@ -102,12 +102,34 @@ common_view(_Range&&)
 template<class _View>
 inline constexpr bool enable_borrowed_range<common_view<_View>> = enable_borrowed_range<_View>;
 
+namespace views {
+namespace __common {
+  struct __fn : __range_adaptor_closure<__fn> {
+    template<class _Range>
+      requires common_range<_Range>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Range&& __range) const
+      noexcept(noexcept(views::all(_VSTD::forward<_Range>(__range))))
+      -> decltype(      views::all(_VSTD::forward<_Range>(__range)))
+      { return          views::all(_VSTD::forward<_Range>(__range)); }
+
+    template<class _Range>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Range&& __range) const
+      noexcept(noexcept(common_view{_VSTD::forward<_Range>(__range)}))
+      -> decltype(      common_view{_VSTD::forward<_Range>(__range)})
+      { return          common_view{_VSTD::forward<_Range>(__range)}; }
+  };
+} // namespace __common
+
+inline namespace __cpo {
+  inline constexpr auto common = __common::__fn{};
+} // namespace __cpo
+} // namespace views
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_COMMON_VIEW_H
lib/libcxx/include/__ranges/concepts.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------- __ranges/concepts.h ----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,6 +9,9 @@
 #ifndef _LIBCPP___RANGES_CONCEPTS_H
 #define _LIBCPP___RANGES_CONCEPTS_H
 
+#include <__concepts/constructible.h>
+#include <__concepts/movable.h>
+#include <__concepts/same_as.h>
 #include <__config>
 #include <__iterator/concepts.h>
 #include <__iterator/incrementable_traits.h>
@@ -16,34 +19,34 @@
 #include <__iterator/iterator_traits.h>
 #include <__iterator/readable_traits.h>
 #include <__ranges/access.h>
-#include <__ranges/enable_borrowed_range.h>
 #include <__ranges/data.h>
+#include <__ranges/enable_borrowed_range.h>
 #include <__ranges/enable_view.h>
 #include <__ranges/size.h>
-#include <concepts>
+#include <initializer_list>
 #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
 
-// clang-format off
-
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 namespace ranges {
+
   // [range.range]
+
   template <class _Tp>
   concept range = requires(_Tp& __t) {
     ranges::begin(__t); // sometimes equality-preserving
     ranges::end(__t);
   };
 
+  template <class _Tp>
+  concept input_range = range<_Tp> && input_iterator<iterator_t<_Tp>>;
+
   template<class _Range>
   concept borrowed_range = range<_Range> &&
     (is_lvalue_reference_v<_Range> || enable_borrowed_range<remove_cvref_t<_Range>>);
@@ -85,19 +88,16 @@ namespace ranges {
     movable<_Tp> &&
     enable_view<_Tp>;
 
-  template<class _Range>
+  template <class _Range>
   concept __simple_view =
     view<_Range> && range<const _Range> &&
     same_as<iterator_t<_Range>, iterator_t<const _Range>> &&
-    same_as<sentinel_t<_Range>, iterator_t<const _Range>>;
+    same_as<sentinel_t<_Range>, sentinel_t<const _Range>>;
 
   // [range.refinements], other range refinements
   template <class _Rp, class _Tp>
   concept output_range = range<_Rp> && output_iterator<iterator_t<_Rp>, _Tp>;
 
-  template <class _Tp>
-  concept input_range = range<_Tp> && input_iterator<iterator_t<_Tp>>;
-
   template <class _Tp>
   concept forward_range = input_range<_Tp> && forward_iterator<iterator_t<_Tp>>;
 
@@ -119,20 +119,24 @@ namespace ranges {
   template <class _Tp>
   concept common_range = range<_Tp> && same_as<iterator_t<_Tp>, sentinel_t<_Tp>>;
 
-  template<class _Tp>
+  template <class _Tp>
+  inline constexpr bool __is_std_initializer_list = false;
+
+  template <class _Ep>
+  inline constexpr bool __is_std_initializer_list<initializer_list<_Ep>> = true;
+
+  template <class _Tp>
   concept viewable_range =
-    range<_Tp> && (
-      (view<remove_cvref_t<_Tp>> && constructible_from<remove_cvref_t<_Tp>, _Tp>) ||
-      (!view<remove_cvref_t<_Tp>> && borrowed_range<_Tp>)
-    );
-} // namespace ranges
+    range<_Tp> &&
+    ((view<remove_cvref_t<_Tp>> && constructible_from<remove_cvref_t<_Tp>, _Tp>) ||
+     (!view<remove_cvref_t<_Tp>> &&
+      (is_lvalue_reference_v<_Tp> ||
+       (movable<remove_reference_t<_Tp>> && !__is_std_initializer_list<remove_cvref_t<_Tp>>))));
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+} // namespace ranges
 
-// clang-format on
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_CONCEPTS_H
lib/libcxx/include/__ranges/copyable_box.h
@@ -22,12 +22,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 // __copyable_box allows turning a type that is copy-constructible (but maybe not copy-assignable) into
 // a type that is both copy-constructible and copy-assignable. It does that by introducing an empty state
@@ -91,6 +88,10 @@ namespace ranges {
 
     _LIBCPP_HIDE_FROM_ABI constexpr _Tp const& operator*() const noexcept { return *__val_; }
     _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() noexcept { return *__val_; }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr const _Tp *operator->() const noexcept { return __val_.operator->(); }
+    _LIBCPP_HIDE_FROM_ABI constexpr _Tp *operator->() noexcept { return __val_.operator->(); }
+
     _LIBCPP_HIDE_FROM_ABI constexpr bool __has_value() const noexcept { return __val_.has_value(); }
   };
 
@@ -162,14 +163,16 @@ namespace ranges {
 
     _LIBCPP_HIDE_FROM_ABI constexpr _Tp const& operator*() const noexcept { return __val_; }
     _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() noexcept { return __val_; }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr const _Tp *operator->() const noexcept { return _VSTD::addressof(__val_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr _Tp *operator->() noexcept { return _VSTD::addressof(__val_); }
+
     _LIBCPP_HIDE_FROM_ABI constexpr bool __has_value() const noexcept { return true; }
   };
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_COPYABLE_BOX_H
lib/libcxx/include/__ranges/counted.h
@@ -0,0 +1,81 @@
+// -*- 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___RANGES_COUNTED_H
+#define _LIBCPP___RANGES_COUNTED_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/counted_iterator.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iterator_traits.h>
+#include <__memory/pointer_traits.h>
+#include <__ranges/subrange.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include <span>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges::views {
+
+namespace __counted {
+
+  struct __fn {
+    template<contiguous_iterator _It>
+    _LIBCPP_HIDE_FROM_ABI
+    static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
+      noexcept(noexcept(span(_VSTD::to_address(__it), static_cast<size_t>(__count))))
+      // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
+      { return          span(_VSTD::to_address(__it), static_cast<size_t>(__count)); }
+
+    template<random_access_iterator _It>
+    _LIBCPP_HIDE_FROM_ABI
+    static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
+      noexcept(noexcept(subrange(__it, __it + __count)))
+      -> decltype(      subrange(__it, __it + __count))
+      { return          subrange(__it, __it + __count); }
+
+    template<class _It>
+    _LIBCPP_HIDE_FROM_ABI
+    static constexpr auto __go(_It __it, iter_difference_t<_It> __count)
+      noexcept(noexcept(subrange(counted_iterator(_VSTD::move(__it), __count), default_sentinel)))
+      -> decltype(      subrange(counted_iterator(_VSTD::move(__it), __count), default_sentinel))
+      { return          subrange(counted_iterator(_VSTD::move(__it), __count), default_sentinel); }
+
+    template<class _It, convertible_to<iter_difference_t<_It>> _Diff>
+      requires input_or_output_iterator<decay_t<_It>>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_It&& __it, _Diff&& __count) const
+      noexcept(noexcept(__go(_VSTD::forward<_It>(__it), _VSTD::forward<_Diff>(__count))))
+      -> decltype(      __go(_VSTD::forward<_It>(__it), _VSTD::forward<_Diff>(__count)))
+      { return          __go(_VSTD::forward<_It>(__it), _VSTD::forward<_Diff>(__count)); }
+  };
+
+} // namespace __counted
+
+inline namespace __cpo {
+  inline constexpr auto counted = __counted::__fn{};
+} // namespace __cpo
+
+} // namespace ranges::views
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_COUNTED_H
lib/libcxx/include/__ranges/dangling.h
@@ -19,12 +19,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 namespace ranges {
 struct dangling {
@@ -38,10 +35,8 @@ using borrowed_iterator_t = _If<borrowed_range<_Rp>, iterator_t<_Rp>, dangling>;
 // borrowed_subrange_t defined in <__ranges/subrange.h>
 } // namespace ranges
 
-#endif // !_LIBCPP_HAS_NO_RANGES
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_DANGLING_H
lib/libcxx/include/__ranges/data.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ __ranges/data.h ------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,78 +9,98 @@
 #ifndef _LIBCPP___RANGES_DATA_H
 #define _LIBCPP___RANGES_DATA_H
 
+#include <__concepts/class_or_enum.h>
 #include <__config>
 #include <__iterator/concepts.h>
 #include <__iterator/iterator_traits.h>
 #include <__memory/pointer_traits.h>
 #include <__ranges/access.h>
-#include <__utility/forward.h>
-#include <concepts>
+#include <__utility/auto_cast.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
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
-// clang-format off
-namespace ranges {
 // [range.prim.data]
+
+namespace ranges {
 namespace __data {
   template <class _Tp>
   concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>;
 
   template <class _Tp>
   concept __member_data =
+    __can_borrow<_Tp> &&
+    __workaround_52970<_Tp> &&
     requires(_Tp&& __t) {
-      { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
-      { __t.data() } -> __ptr_to_object;
+      { _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object;
     };
 
   template <class _Tp>
   concept __ranges_begin_invocable =
     !__member_data<_Tp> &&
+    __can_borrow<_Tp> &&
     requires(_Tp&& __t) {
-      { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
-      { ranges::begin(_VSTD::forward<_Tp>(__t)) } -> contiguous_iterator;
+      { ranges::begin(__t) } -> contiguous_iterator;
     };
 
   struct __fn {
     template <__member_data _Tp>
-      requires __can_borrow<_Tp>
     _LIBCPP_HIDE_FROM_ABI
-    constexpr __ptr_to_object auto operator()(_Tp&& __t) const
+    constexpr auto operator()(_Tp&& __t) const
         noexcept(noexcept(__t.data())) {
       return __t.data();
     }
 
     template<__ranges_begin_invocable _Tp>
-      requires __can_borrow<_Tp>
     _LIBCPP_HIDE_FROM_ABI
-    constexpr __ptr_to_object auto operator()(_Tp&& __t) const
-        noexcept(noexcept(_VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))))) {
-      return _VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t)));
+    constexpr auto operator()(_Tp&& __t) const
+        noexcept(noexcept(_VSTD::to_address(ranges::begin(__t)))) {
+      return _VSTD::to_address(ranges::begin(__t));
     }
   };
-} // end namespace __data
+} // namespace __data
 
 inline namespace __cpo {
-  inline constexpr const auto data = __data::__fn{};
+  inline constexpr auto data = __data::__fn{};
 } // namespace __cpo
 } // namespace ranges
 
-// clang-format off
+// [range.prim.cdata]
+
+namespace ranges {
+namespace __cdata {
+  struct __fn {
+    template <class _Tp>
+      requires is_lvalue_reference_v<_Tp&&>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))))
+      -> decltype(      ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)))
+      { return          ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)); }
+
+    template <class _Tp>
+      requires is_rvalue_reference_v<_Tp&&>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Tp&& __t) const
+      noexcept(noexcept(ranges::data(static_cast<const _Tp&&>(__t))))
+      -> decltype(      ranges::data(static_cast<const _Tp&&>(__t)))
+      { return          ranges::data(static_cast<const _Tp&&>(__t)); }
+  };
+} // namespace __cdata
+
+inline namespace __cpo {
+  inline constexpr auto cdata = __cdata::__fn{};
+} // namespace __cpo
+} // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_DATA_H
lib/libcxx/include/__ranges/drop_view.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___RANGES_DROP_VIEW_H
 
 #include <__config>
+#include <__debug>
 #include <__iterator/concepts.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/next.h>
@@ -28,12 +29,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 namespace ranges {
   template<view _View>
@@ -76,7 +74,7 @@ public:
 
       auto __tmp = ranges::next(ranges::begin(__base_), __count_, ranges::end(__base_));
       if constexpr (_UseCache)
-        __cached_begin_.__set(__tmp);
+        __cached_begin_.__emplace(__tmp);
       return __tmp;
     }
 
@@ -122,10 +120,8 @@ public:
   inline constexpr bool enable_borrowed_range<drop_view<_Tp>> = enable_borrowed_range<_Tp>;
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_DROP_VIEW_H
lib/libcxx/include/__ranges/empty.h
@@ -9,37 +9,36 @@
 #ifndef _LIBCPP___RANGES_EMPTY_H
 #define _LIBCPP___RANGES_EMPTY_H
 
+#include <__concepts/class_or_enum.h>
 #include <__config>
 #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)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
-// clang-format off
-namespace ranges {
 // [range.prim.empty]
+
+namespace ranges {
 namespace __empty {
   template <class _Tp>
-  concept __member_empty = requires(_Tp&& __t) {
-    bool(_VSTD::forward<_Tp>(__t).empty());
-  };
+  concept __member_empty =
+    __workaround_52970<_Tp> &&
+    requires(_Tp&& __t) {
+      bool(__t.empty());
+    };
 
   template<class _Tp>
   concept __can_invoke_size =
     !__member_empty<_Tp> &&
-    requires(_Tp&& __t) { ranges::size(_VSTD::forward<_Tp>(__t)); };
+    requires(_Tp&& __t) { ranges::size(__t); };
 
   template <class _Tp>
   concept __can_compare_begin_end =
@@ -54,13 +53,13 @@ namespace __empty {
     template <__member_empty _Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
         noexcept(noexcept(bool(__t.empty()))) {
-      return __t.empty();
+      return bool(__t.empty());
     }
 
     template <__can_invoke_size _Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
-        noexcept(noexcept(ranges::size(_VSTD::forward<_Tp>(__t)))) {
-      return ranges::size(_VSTD::forward<_Tp>(__t)) == 0;
+        noexcept(noexcept(ranges::size(__t))) {
+      return ranges::size(__t) == 0;
     }
 
     template<__can_compare_begin_end _Tp>
@@ -69,18 +68,15 @@ namespace __empty {
       return ranges::begin(__t) == ranges::end(__t);
     }
   };
-}
+} // namespace __empty
 
 inline namespace __cpo {
   inline constexpr auto empty = __empty::__fn{};
 } // namespace __cpo
 } // namespace ranges
-// clang-format off
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_EMPTY_H
lib/libcxx/include/__ranges/empty_view.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___RANGES_EMPTY_VIEW_H
 
 #include <__config>
+#include <__ranges/enable_borrowed_range.h>
 #include <__ranges/view_interface.h>
 #include <type_traits>
 
@@ -17,12 +18,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 namespace ranges {
   template<class _Tp>
@@ -35,12 +33,13 @@ namespace ranges {
     _LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 0; }
     _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return true; }
   };
+
+  template<class _Tp>
+  inline constexpr bool enable_borrowed_range<empty_view<_Tp>> = true;
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_EMPTY_VIEW_H
lib/libcxx/include/__ranges/enable_borrowed_range.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------ __ranges/enable_borrowed_range.h ------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -20,15 +20,11 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
-namespace ranges
-{
+namespace ranges {
 
 // [range.range], ranges
 
@@ -37,10 +33,8 @@ inline constexpr bool enable_borrowed_range = false;
 
 } // namespace ranges
 
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_ENABLE_BORROWED_RANGE_H
lib/libcxx/include/__ranges/enable_view.h
@@ -12,31 +12,36 @@
 
 #include <__config>
 #include <concepts>
+#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
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 namespace ranges {
 
 struct view_base { };
 
+template<class _Derived>
+  requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>>
+class view_interface;
+
+template<class _Op, class _Yp>
+  requires is_convertible_v<_Op*, view_interface<_Yp>*>
+void __is_derived_from_view_interface(const _Op*, const view_interface<_Yp>*);
+
 template <class _Tp>
-inline constexpr bool enable_view = derived_from<_Tp, view_base>;
+inline constexpr bool enable_view = derived_from<_Tp, view_base> ||
+  requires { ranges::__is_derived_from_view_interface((_Tp*)nullptr, (_Tp*)nullptr); };
 
-} // end namespace ranges
+} // namespace ranges
 
-#endif // !_LIBCPP_HAS_NO_RANGES
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_ENABLE_VIEW_H
lib/libcxx/include/__ranges/iota_view.h
@@ -0,0 +1,408 @@
+// -*- 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___RANGES_IOTA_VIEW_H
+#define _LIBCPP___RANGES_IOTA_VIEW_H
+
+#include <__compare/three_way_comparable.h>
+#include <__concepts/arithmetic.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/invocable.h>
+#include <__concepts/same_as.h>
+#include <__concepts/semiregular.h>
+#include <__concepts/totally_ordered.h>
+#include <__config>
+#include <__debug>
+#include <__functional/ranges_operations.h>
+#include <__iterator/concepts.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/unreachable_sentinel.h>
+#include <__ranges/copyable_box.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/view_interface.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+  template<class _Int>
+  struct __get_wider_signed {
+    static auto __call() {
+           if constexpr (sizeof(_Int) < sizeof(short)) return type_identity<short>{};
+      else if constexpr (sizeof(_Int) < sizeof(int))   return type_identity<int>{};
+      else if constexpr (sizeof(_Int) < sizeof(long))  return type_identity<long>{};
+      else                                             return type_identity<long long>{};
+
+      static_assert(sizeof(_Int) <= sizeof(long long),
+        "Found integer-like type that is bigger than largest integer like type.");
+    }
+
+    using type = typename decltype(__call())::type;
+  };
+
+  template<class _Start>
+  using _IotaDiffT = typename _If<
+      (!integral<_Start> || sizeof(iter_difference_t<_Start>) > sizeof(_Start)),
+      type_identity<iter_difference_t<_Start>>,
+      __get_wider_signed<_Start>
+    >::type;
+
+  template<class _Iter>
+  concept __decrementable = incrementable<_Iter> && requires(_Iter __i) {
+    { --__i } -> same_as<_Iter&>;
+    { __i-- } -> same_as<_Iter>;
+  };
+
+  template<class _Iter>
+  concept __advanceable =
+    __decrementable<_Iter> && totally_ordered<_Iter> &&
+    requires(_Iter __i, const _Iter __j, const _IotaDiffT<_Iter> __n) {
+      { __i += __n } -> same_as<_Iter&>;
+      { __i -= __n } -> same_as<_Iter&>;
+      _Iter(__j + __n);
+      _Iter(__n + __j);
+      _Iter(__j - __n);
+      { __j - __j } -> convertible_to<_IotaDiffT<_Iter>>;
+    };
+
+  template<class>
+  struct __iota_iterator_category {};
+
+  template<incrementable _Tp>
+  struct __iota_iterator_category<_Tp> {
+    using iterator_category = input_iterator_tag;
+  };
+
+  template<weakly_incrementable _Start, semiregular _Bound = unreachable_sentinel_t>
+    requires __weakly_equality_comparable_with<_Start, _Bound> && copyable<_Start>
+  class iota_view : public view_interface<iota_view<_Start, _Bound>> {
+    struct __iterator : public __iota_iterator_category<_Start> {
+      friend class iota_view;
+
+      using iterator_concept =
+        _If<__advanceable<_Start>,   random_access_iterator_tag,
+        _If<__decrementable<_Start>, bidirectional_iterator_tag,
+        _If<incrementable<_Start>,   forward_iterator_tag,
+        /*Else*/                     input_iterator_tag>>>;
+
+      using value_type = _Start;
+      using difference_type = _IotaDiffT<_Start>;
+
+      _Start __value_ = _Start();
+
+      _LIBCPP_HIDE_FROM_ABI
+      __iterator() requires default_initializable<_Start> = default;
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr explicit __iterator(_Start __value) : __value_(_VSTD::move(__value)) {}
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr _Start operator*() const noexcept(is_nothrow_copy_constructible_v<_Start>) {
+        return __value_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr __iterator& operator++() {
+        ++__value_;
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr void operator++(int) { ++*this; }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr __iterator operator++(int) requires incrementable<_Start> {
+        auto __tmp = *this;
+        ++*this;
+        return __tmp;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr __iterator& operator--() requires __decrementable<_Start> {
+        --__value_;
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr __iterator  operator--(int) requires __decrementable<_Start> {
+        auto __tmp = *this;
+        --*this;
+        return __tmp;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr __iterator& operator+=(difference_type __n)
+        requires __advanceable<_Start>
+      {
+        if constexpr (__integer_like<_Start> && !__signed_integer_like<_Start>) {
+          if (__n >= difference_type(0)) {
+            __value_ += static_cast<_Start>(__n);
+          } else {
+            __value_ -= static_cast<_Start>(-__n);
+          }
+        } else {
+          __value_ += __n;
+        }
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr __iterator& operator-=(difference_type __n)
+        requires __advanceable<_Start>
+      {
+        if constexpr (__integer_like<_Start> && !__signed_integer_like<_Start>) {
+          if (__n >= difference_type(0)) {
+            __value_ -= static_cast<_Start>(__n);
+          } else {
+            __value_ += static_cast<_Start>(-__n);
+          }
+        } else {
+          __value_ -= __n;
+        }
+        return *this;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      constexpr _Start operator[](difference_type __n) const
+        requires __advanceable<_Start>
+      {
+        return _Start(__value_ + __n);
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
+        requires equality_comparable<_Start>
+      {
+        return __x.__value_ == __y.__value_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr bool operator<(const __iterator& __x, const __iterator& __y)
+        requires totally_ordered<_Start>
+      {
+        return __x.__value_ < __y.__value_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr bool operator>(const __iterator& __x, const __iterator& __y)
+        requires totally_ordered<_Start>
+      {
+        return __y < __x;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y)
+        requires totally_ordered<_Start>
+      {
+        return !(__y < __x);
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y)
+        requires totally_ordered<_Start>
+      {
+        return !(__x < __y);
+      }
+
+      friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
+        requires totally_ordered<_Start> && three_way_comparable<_Start>
+      {
+        return __x.__value_ <=> __y.__value_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr __iterator operator+(__iterator __i, difference_type __n)
+        requires __advanceable<_Start>
+      {
+        __i += __n;
+        return __i;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr __iterator operator+(difference_type __n, __iterator __i)
+        requires __advanceable<_Start>
+      {
+        return __i + __n;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr __iterator operator-(__iterator __i, difference_type __n)
+        requires __advanceable<_Start>
+      {
+        __i -= __n;
+        return __i;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y)
+        requires __advanceable<_Start>
+      {
+        if constexpr (__integer_like<_Start>) {
+          if constexpr (__signed_integer_like<_Start>) {
+            return difference_type(difference_type(__x.__value_) - difference_type(__y.__value_));
+          }
+          if (__y.__value_ > __x.__value_) {
+            return difference_type(-difference_type(__y.__value_ - __x.__value_));
+          }
+          return difference_type(__x.__value_ - __y.__value_);
+        }
+        return __x.__value_ - __y.__value_;
+      }
+    };
+
+    struct __sentinel {
+      friend class iota_view;
+
+    private:
+      _Bound __bound_ = _Bound();
+
+    public:
+      _LIBCPP_HIDE_FROM_ABI
+      __sentinel() = default;
+      constexpr explicit __sentinel(_Bound __bound) : __bound_(_VSTD::move(__bound)) {}
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr bool operator==(const __iterator& __x, const __sentinel& __y) {
+        return __x.__value_ == __y.__bound_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr iter_difference_t<_Start> operator-(const __iterator& __x, const __sentinel& __y)
+        requires sized_sentinel_for<_Bound, _Start>
+      {
+        return __x.__value_ - __y.__bound_;
+      }
+
+      _LIBCPP_HIDE_FROM_ABI
+      friend constexpr iter_difference_t<_Start> operator-(const __sentinel& __x, const __iterator& __y)
+        requires sized_sentinel_for<_Bound, _Start>
+      {
+        return -(__y - __x);
+      }
+    };
+
+    _Start __value_ = _Start();
+    _Bound __bound_ = _Bound();
+
+  public:
+    _LIBCPP_HIDE_FROM_ABI
+    iota_view() requires default_initializable<_Start> = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit iota_view(_Start __value) : __value_(_VSTD::move(__value)) { }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr iota_view(type_identity_t<_Start> __value, type_identity_t<_Bound> __bound)
+      : __value_(_VSTD::move(__value)), __bound_(_VSTD::move(__bound)) {
+      // Validate the precondition if possible.
+      if constexpr (totally_ordered_with<_Start, _Bound>) {
+        _LIBCPP_ASSERT(ranges::less_equal()(__value_, __bound_),
+                       "Precondition violated: value is greater than bound.");
+      }
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr iota_view(__iterator __first, __iterator __last)
+      requires same_as<_Start, _Bound>
+      : iota_view(_VSTD::move(__first.__value_), _VSTD::move(__last.__value_)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr iota_view(__iterator __first, _Bound __last)
+      requires same_as<_Bound, unreachable_sentinel_t>
+      : iota_view(_VSTD::move(__first.__value_), _VSTD::move(__last)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr iota_view(__iterator __first, __sentinel __last)
+      requires (!same_as<_Start, _Bound> && !same_as<_Start, unreachable_sentinel_t>)
+      : iota_view(_VSTD::move(__first.__value_), _VSTD::move(__last.__bound_)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator begin() const { return __iterator{__value_}; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto end() const {
+      if constexpr (same_as<_Bound, unreachable_sentinel_t>)
+        return unreachable_sentinel;
+      else
+        return __sentinel{__bound_};
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator end() const requires same_as<_Start, _Bound> {
+      return __iterator{__bound_};
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto size() const
+      requires (same_as<_Start, _Bound> && __advanceable<_Start>) ||
+               (integral<_Start> && integral<_Bound>) ||
+               sized_sentinel_for<_Bound, _Start>
+    {
+      if constexpr (__integer_like<_Start> && __integer_like<_Bound>) {
+        if (__value_ < 0) {
+          if (__bound_ < 0) {
+            return _VSTD::__to_unsigned_like(-__value_) - _VSTD::__to_unsigned_like(-__bound_);
+          }
+          return _VSTD::__to_unsigned_like(__bound_) + _VSTD::__to_unsigned_like(-__value_);
+        }
+        return _VSTD::__to_unsigned_like(__bound_) - _VSTD::__to_unsigned_like(__value_);
+      }
+      return _VSTD::__to_unsigned_like(__bound_ - __value_);
+    }
+  };
+
+  template<class _Start, class _Bound>
+    requires (!__integer_like<_Start> || !__integer_like<_Bound> ||
+              (__signed_integer_like<_Start> == __signed_integer_like<_Bound>))
+  iota_view(_Start, _Bound) -> iota_view<_Start, _Bound>;
+
+  template<class _Start, class _Bound>
+  inline constexpr bool enable_borrowed_range<iota_view<_Start, _Bound>> = true;
+
+namespace views {
+namespace __iota {
+  struct __fn {
+    template<class _Start>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Start&& __start) const
+      noexcept(noexcept(ranges::iota_view(_VSTD::forward<_Start>(__start))))
+      -> decltype(      ranges::iota_view(_VSTD::forward<_Start>(__start)))
+      { return          ranges::iota_view(_VSTD::forward<_Start>(__start)); }
+
+    template<class _Start, class _Bound>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Start&& __start, _Bound&& __bound) const
+      noexcept(noexcept(ranges::iota_view(_VSTD::forward<_Start>(__start), _VSTD::forward<_Bound>(__bound))))
+      -> decltype(      ranges::iota_view(_VSTD::forward<_Start>(__start), _VSTD::forward<_Bound>(__bound)))
+      { return          ranges::iota_view(_VSTD::forward<_Start>(__start), _VSTD::forward<_Bound>(__bound)); }
+  };
+} // namespace __iota
+
+inline namespace __cpo {
+  inline constexpr auto iota = __iota::__fn{};
+} // namespace __cpo
+} // namespace views
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_IOTA_VIEW_H
lib/libcxx/include/__ranges/join_view.h
@@ -0,0 +1,350 @@
+// -*- 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___RANGES_JOIN_VIEW_H
+#define _LIBCPP___RANGES_JOIN_VIEW_H
+
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/ref_view.h>
+#include <__ranges/subrange.h>
+#include <__ranges/view_interface.h>
+#include <__utility/declval.h>
+#include <__utility/forward.h>
+#include <optional>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+  template<class>
+  struct __join_view_iterator_category {};
+
+  template<class _View>
+    requires is_reference_v<range_reference_t<_View>> &&
+             forward_range<_View> &&
+             forward_range<range_reference_t<_View>>
+  struct __join_view_iterator_category<_View> {
+    using _OuterC = typename iterator_traits<iterator_t<_View>>::iterator_category;
+    using _InnerC = typename iterator_traits<iterator_t<range_reference_t<_View>>>::iterator_category;
+
+    using iterator_category = _If<
+      derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag>,
+      bidirectional_iterator_tag,
+      _If<
+        derived_from<_OuterC, forward_iterator_tag> && derived_from<_InnerC, forward_iterator_tag>,
+        forward_iterator_tag,
+        input_iterator_tag
+      >
+    >;
+  };
+
+  template<input_range _View>
+    requires view<_View> && input_range<range_reference_t<_View>>
+  class join_view
+    : public view_interface<join_view<_View>> {
+  private:
+    using _InnerRange = range_reference_t<_View>;
+
+    template<bool> struct __iterator;
+    template<bool> struct __sentinel;
+
+    static constexpr bool _UseCache = !is_reference_v<_InnerRange>;
+    using _Cache = _If<_UseCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
+    [[no_unique_address]] _Cache __cache_;
+    _View __base_ = _View(); // TODO: [[no_unique_address]] makes clang crash! File a bug :)
+
+  public:
+    _LIBCPP_HIDE_FROM_ABI
+    join_view() requires default_initializable<_View> = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit join_view(_View __base)
+      : __base_(_VSTD::move(__base)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _View base() && { return _VSTD::move(__base_); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto begin() {
+      constexpr bool __use_const = __simple_view<_View> &&
+                                   is_reference_v<range_reference_t<_View>>;
+      return __iterator<__use_const>{*this, ranges::begin(__base_)};
+    }
+
+    template<class _V2 = _View>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto begin() const
+      requires input_range<const _V2> &&
+               is_reference_v<range_reference_t<const _V2>>
+    {
+      return __iterator<true>{*this, ranges::begin(__base_)};
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto end() {
+      if constexpr (forward_range<_View> &&
+                    is_reference_v<_InnerRange> &&
+                    forward_range<_InnerRange> &&
+                    common_range<_View> &&
+                    common_range<_InnerRange>)
+        return __iterator<__simple_view<_View>>{*this, ranges::end(__base_)};
+      else
+        return __sentinel<__simple_view<_View>>{*this};
+    }
+
+    template<class _V2 = _View>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto end() const
+      requires input_range<const _V2> &&
+               is_reference_v<range_reference_t<const _V2>>
+    {
+      using _ConstInnerRange = range_reference_t<const _View>;
+      if constexpr (forward_range<const _View> &&
+                    is_reference_v<_ConstInnerRange> &&
+                    forward_range<_ConstInnerRange> &&
+                    common_range<const _View> &&
+                    common_range<_ConstInnerRange>) {
+        return __iterator<true>{*this, ranges::end(__base_)};
+      } else {
+        return __sentinel<true>{*this};
+      }
+    }
+  };
+
+  template<input_range _View>
+    requires view<_View> && input_range<range_reference_t<_View>>
+  template<bool _Const> struct join_view<_View>::__sentinel {
+    template<bool> friend struct __sentinel;
+
+  private:
+    using _Parent = __maybe_const<_Const, join_view>;
+    using _Base = __maybe_const<_Const, _View>;
+    sentinel_t<_Base> __end_ = sentinel_t<_Base>();
+
+  public:
+    _LIBCPP_HIDE_FROM_ABI
+    __sentinel() = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit __sentinel(_Parent& __parent)
+      : __end_(ranges::end(__parent.__base_)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __sentinel(__sentinel<!_Const> __s)
+      requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
+      : __end_(_VSTD::move(__s.__end_)) {}
+
+    template<bool _OtherConst>
+      requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
+    _LIBCPP_HIDE_FROM_ABI
+    friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
+      return __x.__outer_ == __y.__end_;
+    }
+  };
+
+  template<input_range _View>
+    requires view<_View> && input_range<range_reference_t<_View>>
+  template<bool _Const> struct join_view<_View>::__iterator
+    : public __join_view_iterator_category<__maybe_const<_Const, _View>> {
+
+    template<bool> friend struct __iterator;
+
+  private:
+    using _Parent = __maybe_const<_Const, join_view>;
+    using _Base = __maybe_const<_Const, _View>;
+    using _Outer = iterator_t<_Base>;
+    using _Inner = iterator_t<range_reference_t<_Base>>;
+
+    static constexpr bool __ref_is_glvalue = is_reference_v<range_reference_t<_Base>>;
+
+  public:
+    _Outer __outer_ = _Outer();
+
+  private:
+    optional<_Inner> __inner_;
+    _Parent *__parent_ = nullptr;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void __satisfy() {
+      for (; __outer_ != ranges::end(__parent_->__base_); ++__outer_) {
+        auto&& __inner = [&]() -> auto&& {
+          if constexpr (__ref_is_glvalue)
+            return *__outer_;
+          else
+            return __parent_->__cache_.__emplace_from([&]() -> decltype(auto) { return *__outer_; });
+        }();
+        __inner_ = ranges::begin(__inner);
+        if (*__inner_ != ranges::end(__inner))
+          return;
+      }
+
+      if constexpr (__ref_is_glvalue)
+        __inner_.reset();
+    }
+
+  public:
+    using iterator_concept = _If<
+      __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range<range_reference_t<_Base>>,
+      bidirectional_iterator_tag,
+      _If<
+        __ref_is_glvalue && forward_range<_Base> && forward_range<range_reference_t<_Base>>,
+        forward_iterator_tag,
+        input_iterator_tag
+      >
+    >;
+
+    using value_type = range_value_t<range_reference_t<_Base>>;
+
+    using difference_type = common_type_t<
+      range_difference_t<_Base>, range_difference_t<range_reference_t<_Base>>>;
+
+    _LIBCPP_HIDE_FROM_ABI
+    __iterator() requires default_initializable<_Outer> = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator(_Parent& __parent, _Outer __outer)
+      : __outer_(_VSTD::move(__outer))
+      , __parent_(_VSTD::addressof(__parent)) {
+      __satisfy();
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator(__iterator<!_Const> __i)
+      requires _Const &&
+               convertible_to<iterator_t<_View>, _Outer> &&
+               convertible_to<iterator_t<_InnerRange>, _Inner>
+      : __outer_(_VSTD::move(__i.__outer_))
+      , __inner_(_VSTD::move(__i.__inner_))
+      , __parent_(__i.__parent_) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr decltype(auto) operator*() const {
+      return **__inner_;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _Inner operator->() const
+      requires __has_arrow<_Inner> && copyable<_Inner>
+    {
+      return *__inner_;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator& operator++() {
+      auto&& __inner = [&]() -> auto&& {
+        if constexpr (__ref_is_glvalue)
+          return *__outer_;
+        else
+          return *__parent_->__cache_;
+      }();
+      if (++*__inner_ == ranges::end(__inner)) {
+        ++__outer_;
+        __satisfy();
+      }
+      return *this;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr void operator++(int) {
+      ++*this;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator operator++(int)
+      requires __ref_is_glvalue &&
+               forward_range<_Base> &&
+               forward_range<range_reference_t<_Base>>
+    {
+      auto __tmp = *this;
+      ++*this;
+      return __tmp;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator& operator--()
+      requires __ref_is_glvalue &&
+               bidirectional_range<_Base> &&
+               bidirectional_range<range_reference_t<_Base>> &&
+               common_range<range_reference_t<_Base>>
+    {
+      if (__outer_ == ranges::end(__parent_->__base_))
+        __inner_ = ranges::end(*--__outer_);
+
+      // Skip empty inner ranges when going backwards.
+      while (*__inner_ == ranges::begin(*__outer_)) {
+        __inner_ = ranges::end(*--__outer_);
+      }
+
+      --*__inner_;
+      return *this;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __iterator operator--(int)
+      requires __ref_is_glvalue &&
+               bidirectional_range<_Base> &&
+               bidirectional_range<range_reference_t<_Base>> &&
+               common_range<range_reference_t<_Base>>
+    {
+      auto __tmp = *this;
+      --*this;
+      return __tmp;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
+      requires __ref_is_glvalue &&
+               equality_comparable<iterator_t<_Base>> &&
+               equality_comparable<iterator_t<range_reference_t<_Base>>>
+    {
+      return __x.__outer_ == __y.__outer_ && __x.__inner_ == __y.__inner_;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    friend constexpr decltype(auto) iter_move(const __iterator& __i)
+      noexcept(noexcept(ranges::iter_move(*__i.__inner_)))
+    {
+      return ranges::iter_move(*__i.__inner_);
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    friend constexpr void iter_swap(const __iterator& __x, const __iterator& __y)
+      noexcept(noexcept(ranges::iter_swap(*__x.__inner_, *__y.__inner_)))
+      requires indirectly_swappable<_Inner>
+    {
+      return ranges::iter_swap(*__x.__inner_, *__y.__inner_);
+    }
+  };
+
+  template<class _Range>
+  explicit join_view(_Range&&) -> join_view<views::all_t<_Range>>;
+
+} // namespace ranges
+
+#undef _CONSTEXPR_TERNARY
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_JOIN_VIEW_H
lib/libcxx/include/__ranges/non_propagating_cache.h
@@ -13,6 +13,7 @@
 #include <__iterator/concepts.h>        // indirectly_readable
 #include <__iterator/iterator_traits.h> // iter_reference_t
 #include <__memory/addressof.h>
+#include <__utility/forward.h>
 #include <concepts>                     // constructible_from
 #include <optional>
 #include <type_traits>
@@ -21,14 +22,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-// clang-format off
-
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 namespace ranges {
   // __non_propagating_cache is a helper type that allows storing an optional value in it,
@@ -42,7 +38,20 @@ namespace ranges {
   template<class _Tp>
     requires is_object_v<_Tp>
   class _LIBCPP_TEMPLATE_VIS __non_propagating_cache {
-    optional<_Tp> __value_ = nullopt;
+    struct __from_tag { };
+    struct __forward_tag { };
+
+    // This helper class is needed to perform copy and move elision when
+    // constructing the contained type from an iterator.
+    struct __wrapper {
+      template<class ..._Args>
+      constexpr explicit __wrapper(__forward_tag, _Args&& ...__args) : __t_(_VSTD::forward<_Args>(__args)...) { }
+      template<class _Fn>
+      constexpr explicit __wrapper(__from_tag, _Fn const& __f) : __t_(__f()) { }
+      _Tp __t_;
+    };
+
+    optional<__wrapper> __value_ = nullopt;
 
   public:
     _LIBCPP_HIDE_FROM_ABI __non_propagating_cache() = default;
@@ -75,25 +84,31 @@ namespace ranges {
     }
 
     _LIBCPP_HIDE_FROM_ABI
-    constexpr _Tp& operator*() { return *__value_; }
+    constexpr _Tp& operator*() { return __value_->__t_; }
     _LIBCPP_HIDE_FROM_ABI
-    constexpr _Tp const& operator*() const { return *__value_; }
+    constexpr _Tp const& operator*() const { return __value_->__t_; }
 
     _LIBCPP_HIDE_FROM_ABI
     constexpr bool __has_value() const { return __value_.has_value(); }
+
+    template<class _Fn>
     _LIBCPP_HIDE_FROM_ABI
-    constexpr void __set(_Tp const& __value) { __value_.emplace(__value); }
+    constexpr _Tp& __emplace_from(_Fn const& __f) {
+      return __value_.emplace(__from_tag{}, __f).__t_;
+    }
+
+    template<class ..._Args>
     _LIBCPP_HIDE_FROM_ABI
-    constexpr void __set(_Tp&& __value) { __value_.emplace(_VSTD::move(__value)); }
+    constexpr _Tp& __emplace(_Args&& ...__args) {
+      return __value_.emplace(__forward_tag{}, _VSTD::forward<_Args>(__args)...).__t_;
+    }
   };
 
   struct __empty_cache { };
 } // namespace ranges
 
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_NON_PROPAGATING_CACHE_H
lib/libcxx/include/__ranges/owning_view.h
@@ -0,0 +1,81 @@
+// -*- 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___RANGES_OWNING_VIEW_H
+#define _LIBCPP___RANGES_OWNING_VIEW_H
+
+#include <__concepts/constructible.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/data.h>
+#include <__ranges/empty.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__utility/move.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+  template<range _Rp>
+    requires movable<_Rp> && (!__is_std_initializer_list<remove_cvref_t<_Rp>>)
+  class owning_view : public view_interface<owning_view<_Rp>> {
+    _Rp __r_ = _Rp();
+
+public:
+    owning_view() requires default_initializable<_Rp> = default;
+    _LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(_VSTD::move(__r)) {}
+
+    owning_view(owning_view&&) = default;
+    owning_view& operator=(owning_view&&) = default;
+
+    _LIBCPP_HIDE_FROM_ABI constexpr _Rp& base() & noexcept { return __r_; }
+    _LIBCPP_HIDE_FROM_ABI constexpr const _Rp& base() const& noexcept { return __r_; }
+    _LIBCPP_HIDE_FROM_ABI constexpr _Rp&& base() && noexcept { return _VSTD::move(__r_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr const _Rp&& base() const&& noexcept { return _VSTD::move(__r_); }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Rp> begin() { return ranges::begin(__r_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Rp> end() { return ranges::end(__r_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range<const _Rp> { return ranges::begin(__r_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range<const _Rp> { return ranges::end(__r_); }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr bool empty() requires requires { ranges::empty(__r_); }
+      { return ranges::empty(__r_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const requires requires { ranges::empty(__r_); }
+      { return ranges::empty(__r_); }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_Rp>
+      { return ranges::size(__r_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range<const _Rp>
+      { return ranges::size(__r_); }
+
+    _LIBCPP_HIDE_FROM_ABI constexpr auto data() requires contiguous_range<_Rp>
+      { return ranges::data(__r_); }
+    _LIBCPP_HIDE_FROM_ABI constexpr auto data() const requires contiguous_range<const _Rp>
+      { return ranges::data(__r_); }
+  };
+
+  template<class _Tp>
+  inline constexpr bool enable_borrowed_range<owning_view<_Tp>> = enable_borrowed_range<_Tp>;
+
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_OWNING_VIEW_H
lib/libcxx/include/__ranges/range_adaptor.h
@@ -0,0 +1,73 @@
+// -*- 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___RANGES_RANGE_ADAPTOR_H
+#define _LIBCPP___RANGES_RANGE_ADAPTOR_H
+
+#include <__config>
+#include <__functional/compose.h>
+#include <__functional/invoke.h>
+#include <__ranges/concepts.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include <concepts>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+// CRTP base that one can derive from in order to be considered a range adaptor closure
+// by the library. When deriving from this class, a pipe operator will be provided to
+// make the following hold:
+// - `x | f` is equivalent to `f(x)`
+// - `f1 | f2` is an adaptor closure `g` such that `g(x)` is equivalent to `f2(f1(x))`
+template <class _Tp>
+struct __range_adaptor_closure;
+
+// Type that wraps an arbitrary function object and makes it into a range adaptor closure,
+// i.e. something that can be called via the `x | f` notation.
+template <class _Fn>
+struct __range_adaptor_closure_t : _Fn, __range_adaptor_closure<__range_adaptor_closure_t<_Fn>> {
+    constexpr explicit __range_adaptor_closure_t(_Fn&& __f) : _Fn(_VSTD::move(__f)) { }
+};
+
+template <class _Tp>
+concept _RangeAdaptorClosure = derived_from<remove_cvref_t<_Tp>, __range_adaptor_closure<remove_cvref_t<_Tp>>>;
+
+template <class _Tp>
+struct __range_adaptor_closure {
+    template <ranges::viewable_range _View, _RangeAdaptorClosure _Closure>
+        requires same_as<_Tp, remove_cvref_t<_Closure>> &&
+                 invocable<_Closure, _View>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    friend constexpr decltype(auto) operator|(_View&& __view, _Closure&& __closure)
+        noexcept(is_nothrow_invocable_v<_Closure, _View>)
+    { return _VSTD::invoke(_VSTD::forward<_Closure>(__closure), _VSTD::forward<_View>(__view)); }
+
+    template <_RangeAdaptorClosure _Closure, _RangeAdaptorClosure _OtherClosure>
+        requires same_as<_Tp, remove_cvref_t<_Closure>> &&
+                 constructible_from<decay_t<_Closure>, _Closure> &&
+                 constructible_from<decay_t<_OtherClosure>, _OtherClosure>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    friend constexpr auto operator|(_Closure&& __c1, _OtherClosure&& __c2)
+        noexcept(is_nothrow_constructible_v<decay_t<_Closure>, _Closure> &&
+                 is_nothrow_constructible_v<decay_t<_OtherClosure>, _OtherClosure>)
+    { return __range_adaptor_closure_t(_VSTD::__compose(_VSTD::forward<_OtherClosure>(__c2), _VSTD::forward<_Closure>(__c1))); }
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_RANGE_ADAPTOR_H
lib/libcxx/include/__ranges/ref_view.h
@@ -18,8 +18,10 @@
 #include <__ranges/concepts.h>
 #include <__ranges/data.h>
 #include <__ranges/empty.h>
+#include <__ranges/enable_borrowed_range.h>
 #include <__ranges/size.h>
 #include <__ranges/view_interface.h>
+#include <__utility/forward.h>
 #include <concepts>
 #include <type_traits>
 
@@ -27,12 +29,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 namespace ranges {
   template<range _Range>
@@ -76,12 +75,12 @@ public:
   template<class _Range>
   ref_view(_Range&) -> ref_view<_Range>;
 
+  template<class _Tp>
+  inline constexpr bool enable_borrowed_range<ref_view<_Tp>> = true;
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_REF_VIEW_H
lib/libcxx/include/__ranges/reverse_view.h
@@ -0,0 +1,190 @@
+// -*- 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___RANGES_REVERSE_VIEW_H
+#define _LIBCPP___RANGES_REVERSE_VIEW_H
+
+#include <__concepts/constructible.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/next.h>
+#include <__iterator/reverse_iterator.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/subrange.h>
+#include <__ranges/view_interface.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+  template<view _View>
+    requires bidirectional_range<_View>
+  class reverse_view : public view_interface<reverse_view<_View>> {
+    // We cache begin() whenever ranges::next is not guaranteed O(1) to provide an
+    // amortized O(1) begin() method.
+    static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>;
+    using _Cache = _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>;
+    [[no_unique_address]] _Cache __cached_begin_ = _Cache();
+    [[no_unique_address]] _View __base_ = _View();
+
+  public:
+    _LIBCPP_HIDE_FROM_ABI
+    reverse_view() requires default_initializable<_View> = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit reverse_view(_View __view) : __base_(_VSTD::move(__view)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _View base() && { return _VSTD::move(__base_); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr reverse_iterator<iterator_t<_View>> begin() {
+      if constexpr (_UseCache)
+        if (__cached_begin_.__has_value())
+          return *__cached_begin_;
+
+      auto __tmp = _VSTD::make_reverse_iterator(ranges::next(ranges::begin(__base_), ranges::end(__base_)));
+      if constexpr (_UseCache)
+        __cached_begin_.__emplace(__tmp);
+      return __tmp;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr reverse_iterator<iterator_t<_View>> begin() requires common_range<_View> {
+      return _VSTD::make_reverse_iterator(ranges::end(__base_));
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto begin() const requires common_range<const _View> {
+      return _VSTD::make_reverse_iterator(ranges::end(__base_));
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr reverse_iterator<iterator_t<_View>> end() {
+      return _VSTD::make_reverse_iterator(ranges::begin(__base_));
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto end() const requires common_range<const _View> {
+      return _VSTD::make_reverse_iterator(ranges::begin(__base_));
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto size() requires sized_range<_View> {
+      return ranges::size(__base_);
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto size() const requires sized_range<const _View> {
+      return ranges::size(__base_);
+    }
+  };
+
+  template<class _Range>
+  reverse_view(_Range&&) -> reverse_view<views::all_t<_Range>>;
+
+  template<class _Tp>
+  inline constexpr bool enable_borrowed_range<reverse_view<_Tp>> = enable_borrowed_range<_Tp>;
+
+  namespace views {
+  namespace __reverse {
+    template<class _Tp>
+    constexpr bool __is_reverse_view = false;
+
+    template<class _Tp>
+    constexpr bool __is_reverse_view<reverse_view<_Tp>> = true;
+
+    template<class _Tp>
+    constexpr bool __is_sized_reverse_subrange = false;
+
+    template<class _Iter>
+    constexpr bool __is_sized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, subrange_kind::sized>> = true;
+
+    template<class _Tp>
+    constexpr bool __is_unsized_reverse_subrange = false;
+
+    template<class _Iter, subrange_kind _Kind>
+    constexpr bool __is_unsized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> = _Kind == subrange_kind::unsized;
+
+    template<class _Tp>
+    struct __unwrapped_reverse_subrange {
+      using type = void; // avoid SFINAE-ing out the overload below -- let the concept requirements do it for better diagnostics
+    };
+
+    template<class _Iter, subrange_kind _Kind>
+    struct __unwrapped_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> {
+      using type = subrange<_Iter, _Iter, _Kind>;
+    };
+
+    struct __fn : __range_adaptor_closure<__fn> {
+      template<class _Range>
+        requires __is_reverse_view<remove_cvref_t<_Range>>
+      [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+      constexpr auto operator()(_Range&& __range) const
+        noexcept(noexcept(_VSTD::forward<_Range>(__range).base()))
+        -> decltype(      _VSTD::forward<_Range>(__range).base())
+        { return          _VSTD::forward<_Range>(__range).base(); }
+
+      template<class _Range,
+               class _UnwrappedSubrange = typename __unwrapped_reverse_subrange<remove_cvref_t<_Range>>::type>
+        requires __is_sized_reverse_subrange<remove_cvref_t<_Range>>
+      [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+      constexpr auto operator()(_Range&& __range) const
+        noexcept(noexcept(_UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size())))
+        -> decltype(      _UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size()))
+        { return          _UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size()); }
+
+      template<class _Range,
+               class _UnwrappedSubrange = typename __unwrapped_reverse_subrange<remove_cvref_t<_Range>>::type>
+        requires __is_unsized_reverse_subrange<remove_cvref_t<_Range>>
+      [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+      constexpr auto operator()(_Range&& __range) const
+        noexcept(noexcept(_UnwrappedSubrange(__range.end().base(), __range.begin().base())))
+        -> decltype(      _UnwrappedSubrange(__range.end().base(), __range.begin().base()))
+        { return          _UnwrappedSubrange(__range.end().base(), __range.begin().base()); }
+
+      template<class _Range>
+        requires (!__is_reverse_view<remove_cvref_t<_Range>> &&
+                  !__is_sized_reverse_subrange<remove_cvref_t<_Range>> &&
+                  !__is_unsized_reverse_subrange<remove_cvref_t<_Range>>)
+      [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+      constexpr auto operator()(_Range&& __range) const
+        noexcept(noexcept(reverse_view{_VSTD::forward<_Range>(__range)}))
+        -> decltype(      reverse_view{_VSTD::forward<_Range>(__range)})
+        { return          reverse_view{_VSTD::forward<_Range>(__range)}; }
+    };
+  } // namespace __reverse
+
+  inline namespace __cpo {
+    inline constexpr auto reverse = __reverse::__fn{};
+  } // namespace __cpo
+  } // namespace views
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_REVERSE_VIEW_H
lib/libcxx/include/__ranges/single_view.h
@@ -0,0 +1,81 @@
+// -*- 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___RANGES_SINGLE_VIEW_H
+#define _LIBCPP___RANGES_SINGLE_VIEW_H
+
+#include <__config>
+#include <__ranges/copyable_box.h>
+#include <__ranges/view_interface.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include <concepts>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+  template<copy_constructible _Tp>
+    requires is_object_v<_Tp>
+  class single_view : public view_interface<single_view<_Tp>> {
+    __copyable_box<_Tp> __value_;
+
+  public:
+    _LIBCPP_HIDE_FROM_ABI
+    single_view() requires default_initializable<_Tp> = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit single_view(const _Tp& __t) : __value_(in_place, __t) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit single_view(_Tp&& __t) : __value_(in_place, _VSTD::move(__t)) {}
+
+    template<class... _Args>
+      requires constructible_from<_Tp, _Args...>
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit single_view(in_place_t, _Args&&... __args)
+      : __value_{in_place, _VSTD::forward<_Args>(__args)...} {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _Tp* begin() noexcept { return data(); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr const _Tp* begin() const noexcept { return data(); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _Tp* end() noexcept { return data() + 1; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr const _Tp* end() const noexcept { return data() + 1; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    static constexpr size_t size() noexcept { return 1; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _Tp* data() noexcept { return __value_.operator->(); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr const _Tp* data() const noexcept { return __value_.operator->(); }
+  };
+
+  template<class _Tp>
+  single_view(_Tp) -> single_view<_Tp>;
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_SINGLE_VIEW_H
lib/libcxx/include/__ranges/size.h
@@ -9,12 +9,12 @@
 #ifndef _LIBCPP___RANGES_SIZE_H
 #define _LIBCPP___RANGES_SIZE_H
 
+#include <__concepts/class_or_enum.h>
 #include <__config>
 #include <__iterator/concepts.h>
 #include <__iterator/iterator_traits.h>
 #include <__ranges/access.h>
-#include <__utility/__decay_copy.h>
-#include <__utility/forward.h>
+#include <__utility/auto_cast.h>
 #include <concepts>
 #include <type_traits>
 
@@ -22,19 +22,18 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
-// clang-format off
 namespace ranges {
-template<class>
-inline constexpr bool disable_sized_range = false;
+  template<class>
+  inline constexpr bool disable_sized_range = false;
+} // namespace ranges
 
 // [range.prim.size]
+
+namespace ranges {
 namespace __size {
   void size(auto&) = delete;
   void size(const auto&) = delete;
@@ -43,9 +42,12 @@ namespace __size {
   concept __size_enabled = !disable_sized_range<remove_cvref_t<_Tp>>;
 
   template <class _Tp>
-  concept __member_size = __size_enabled<_Tp> && requires(_Tp&& __t) {
-    { _VSTD::__decay_copy(_VSTD::forward<_Tp>(__t).size()) } -> __integer_like;
-  };
+  concept __member_size =
+    __size_enabled<_Tp> &&
+    __workaround_52970<_Tp> &&
+    requires(_Tp&& __t) {
+      { _LIBCPP_AUTO_CAST(__t.size()) } -> __integer_like;
+    };
 
   template <class _Tp>
   concept __unqualified_size =
@@ -53,7 +55,7 @@ namespace __size {
     !__member_size<_Tp> &&
     __class_or_enum<remove_cvref_t<_Tp>> &&
     requires(_Tp&& __t) {
-      { _VSTD::__decay_copy(size(_VSTD::forward<_Tp>(__t))) } -> __integer_like;
+      { _LIBCPP_AUTO_CAST(size(__t)) } -> __integer_like;
     };
 
   template <class _Tp>
@@ -79,14 +81,14 @@ namespace __size {
 
     template <__member_size _Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
-        noexcept(noexcept(_VSTD::forward<_Tp>(__t).size())) {
-      return _VSTD::forward<_Tp>(__t).size();
+        noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.size()))) {
+      return _LIBCPP_AUTO_CAST(__t.size());
     }
 
     template <__unqualified_size _Tp>
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr __integer_like auto operator()(_Tp&& __t) const
-        noexcept(noexcept(size(_VSTD::forward<_Tp>(__t)))) {
-      return size(_VSTD::forward<_Tp>(__t));
+        noexcept(noexcept(_LIBCPP_AUTO_CAST(size(__t)))) {
+      return _LIBCPP_AUTO_CAST(size(__t));
     }
 
     template<__difference _Tp>
@@ -95,18 +97,23 @@ namespace __size {
       return _VSTD::__to_unsigned_like(ranges::end(__t) - ranges::begin(__t));
     }
   };
-} // end namespace __size
+} // namespace __size
 
 inline namespace __cpo {
   inline constexpr auto size = __size::__fn{};
 } // namespace __cpo
+} // namespace ranges
+
+// [range.prim.ssize]
 
+namespace ranges {
 namespace __ssize {
   struct __fn {
     template<class _Tp>
       requires requires (_Tp&& __t) { ranges::size(__t); }
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr integral auto operator()(_Tp&& __t) const
-        noexcept(noexcept(ranges::size(__t))) {
+      noexcept(noexcept(ranges::size(__t)))
+    {
       using _Signed = make_signed_t<decltype(ranges::size(__t))>;
       if constexpr (sizeof(ptrdiff_t) > sizeof(_Signed))
         return static_cast<ptrdiff_t>(ranges::size(__t));
@@ -114,19 +121,15 @@ namespace __ssize {
         return static_cast<_Signed>(ranges::size(__t));
     }
   };
-}
+} // namespace __ssize
 
 inline namespace __cpo {
-  inline constexpr const auto ssize = __ssize::__fn{};
+  inline constexpr auto ssize = __ssize::__fn{};
 } // namespace __cpo
 } // namespace ranges
 
-// clang-format off
-
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_SIZE_H
lib/libcxx/include/__ranges/subrange.h
@@ -9,40 +9,45 @@
 #ifndef _LIBCPP___RANGES_SUBRANGE_H
 #define _LIBCPP___RANGES_SUBRANGE_H
 
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/different_from.h>
 #include <__config>
+#include <__debug>
+#include <__iterator/advance.h>
 #include <__iterator/concepts.h>
 #include <__iterator/incrementable_traits.h>
 #include <__iterator/iterator_traits.h>
-#include <__iterator/advance.h>
 #include <__ranges/access.h>
 #include <__ranges/concepts.h>
 #include <__ranges/dangling.h>
 #include <__ranges/enable_borrowed_range.h>
 #include <__ranges/size.h>
 #include <__ranges/view_interface.h>
-#include <concepts>
+#include <__tuple>
+#include <__utility/move.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
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
-// clang-format off
 namespace ranges {
+  template<class _From, class _To>
+  concept __uses_nonqualification_pointer_conversion =
+    is_pointer_v<_From> && is_pointer_v<_To> &&
+    !convertible_to<remove_pointer_t<_From>(*)[], remove_pointer_t<_To>(*)[]>;
+
   template<class _From, class _To>
   concept __convertible_to_non_slicing =
     convertible_to<_From, _To> &&
-    // If they're both pointers, they must have the same element type.
-    !(is_pointer_v<decay_t<_From>> &&
-      is_pointer_v<decay_t<_To>> &&
-      __different_from<remove_pointer_t<decay_t<_From>>, remove_pointer_t<decay_t<_To>>>);
+    !__uses_nonqualification_pointer_conversion<decay_t<_From>, decay_t<_To>>;
 
   template<class _Tp>
   concept __pair_like =
@@ -64,59 +69,43 @@ namespace ranges {
 
   enum class _LIBCPP_ENUM_VIS subrange_kind : bool { unsized, sized };
 
-  template<class _Iter, class _Sent, bool>
-  struct __subrange_base {
-    static constexpr bool __store_size = false;
-    _Iter __begin_ = _Iter();
-    _Sent __end_ = _Sent();
-
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr __subrange_base() = default;
-
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr __subrange_base(_Iter __iter, _Sent __sent, make_unsigned_t<iter_difference_t<_Iter>> = 0)
-      : __begin_(_VSTD::move(__iter)), __end_(__sent) { }
-  };
-
-  template<class _Iter, class _Sent>
-  struct __subrange_base<_Iter, _Sent, true> {
-    static constexpr bool __store_size = true;
-    _Iter __begin_ = _Iter();
-    _Sent __end_ = _Sent();
-    make_unsigned_t<iter_difference_t<_Iter>> __size_ = 0;
-
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr __subrange_base() = default;
-
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr __subrange_base(_Iter __iter, _Sent __sent, decltype(__size_) __size)
-      : __begin_(_VSTD::move(__iter)), __end_(__sent), __size_(__size) { }
-  };
-
   template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent = _Iter,
            subrange_kind _Kind = sized_sentinel_for<_Sent, _Iter>
              ? subrange_kind::sized
              : subrange_kind::unsized>
     requires (_Kind == subrange_kind::sized || !sized_sentinel_for<_Sent, _Iter>)
-  struct _LIBCPP_TEMPLATE_VIS subrange
-    : public view_interface<subrange<_Iter, _Sent, _Kind>>,
-      private __subrange_base<_Iter, _Sent, _Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>> {
-
-    using _Base = __subrange_base<_Iter, _Sent, _Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>>;
-
+  class _LIBCPP_TEMPLATE_VIS subrange
+    : public view_interface<subrange<_Iter, _Sent, _Kind>>
+  {
+  private:
+    static constexpr bool _StoreSize = (_Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>);
+    static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics
+    struct _Empty { constexpr _Empty(auto) noexcept { } };
+    using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>;
+    [[no_unique_address]] _Iter __begin_ = _Iter();
+    [[no_unique_address]] _Sent __end_ = _Sent();
+    [[no_unique_address]] _Size __size_ = 0;
+
+  public:
     _LIBCPP_HIDE_FROM_ABI
     subrange() requires default_initializable<_Iter> = default;
 
     _LIBCPP_HIDE_FROM_ABI
     constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent)
-      requires (!_Base::__store_size)
-      : _Base(_VSTD::move(__iter), __sent) {}
+      requires _MustProvideSizeAtConstruction
+      : __begin_(_VSTD::move(__iter)), __end_(_VSTD::move(__sent))
+    { }
 
     _LIBCPP_HIDE_FROM_ABI
     constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent,
                        make_unsigned_t<iter_difference_t<_Iter>> __n)
       requires (_Kind == subrange_kind::sized)
-      : _Base(_VSTD::move(__iter), __sent, __n) { }
+      : __begin_(_VSTD::move(__iter)), __end_(_VSTD::move(__sent)), __size_(__n)
+    {
+      if constexpr (sized_sentinel_for<_Sent, _Iter>)
+        _LIBCPP_ASSERT((__end_ - __begin_) == static_cast<iter_difference_t<_Iter>>(__n),
+          "std::ranges::subrange was passed an invalid size hint");
+    }
 
     template<__different_from<subrange> _Range>
       requires borrowed_range<_Range> &&
@@ -124,8 +113,9 @@ namespace ranges {
                convertible_to<sentinel_t<_Range>, _Sent>
     _LIBCPP_HIDE_FROM_ABI
     constexpr subrange(_Range&& __range)
-      requires (!_Base::__store_size)
-      : subrange(ranges::begin(__range), ranges::end(__range)) { }
+      requires (!_StoreSize)
+      : subrange(ranges::begin(__range), ranges::end(__range))
+    { }
 
     template<__different_from<subrange> _Range>
       requires borrowed_range<_Range> &&
@@ -133,9 +123,9 @@ namespace ranges {
                convertible_to<sentinel_t<_Range>, _Sent>
     _LIBCPP_HIDE_FROM_ABI
     constexpr subrange(_Range&& __range)
-      requires _Base::__store_size && sized_range<_Range>
-      : subrange(__range, ranges::size(__range)) { }
-
+      requires _StoreSize && sized_range<_Range>
+      : subrange(__range, ranges::size(__range))
+    { }
 
     template<borrowed_range _Range>
       requires __convertible_to_non_slicing<iterator_t<_Range>, _Iter> &&
@@ -143,39 +133,47 @@ namespace ranges {
     _LIBCPP_HIDE_FROM_ABI
     constexpr subrange(_Range&& __range, make_unsigned_t<iter_difference_t<_Iter>> __n)
       requires (_Kind == subrange_kind::sized)
-      : subrange(ranges::begin(__range), ranges::end(__range), __n) { }
+      : subrange(ranges::begin(__range), ranges::end(__range), __n)
+    { }
 
     template<__different_from<subrange> _Pair>
       requires __pair_like_convertible_from<_Pair, const _Iter&, const _Sent&>
     _LIBCPP_HIDE_FROM_ABI
-    constexpr operator _Pair() const { return _Pair(this->__begin_, this->__end_); }
+    constexpr operator _Pair() const {
+      return _Pair(__begin_, __end_);
+    }
 
     _LIBCPP_HIDE_FROM_ABI
     constexpr _Iter begin() const requires copyable<_Iter> {
-      return this->__begin_;
+      return __begin_;
     }
 
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter begin() requires (!copyable<_Iter>) {
-      return _VSTD::move(this->__begin_);
+      return _VSTD::move(__begin_);
     }
 
     _LIBCPP_HIDE_FROM_ABI
-    constexpr _Sent end() const { return this->__end_; }
+    constexpr _Sent end() const {
+      return __end_;
+    }
 
-    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const { return this->__begin_ == this->__end_; }
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const {
+      return __begin_ == __end_;
+    }
 
     _LIBCPP_HIDE_FROM_ABI
     constexpr make_unsigned_t<iter_difference_t<_Iter>> size() const
       requires (_Kind == subrange_kind::sized)
     {
-      if constexpr (_Base::__store_size)
-        return this->__size_;
+      if constexpr (_StoreSize)
+        return __size_;
       else
-        return __to_unsigned_like(this->__end_ - this->__begin_);
+        return _VSTD::__to_unsigned_like(__end_ - __begin_);
     }
 
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange next(iter_difference_t<_Iter> __n = 1) const&
-      requires forward_iterator<_Iter> {
+      requires forward_iterator<_Iter>
+    {
       auto __tmp = *this;
       __tmp.advance(__n);
       return __tmp;
@@ -187,7 +185,8 @@ namespace ranges {
     }
 
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange prev(iter_difference_t<_Iter> __n = 1) const
-      requires bidirectional_iterator<_Iter> {
+      requires bidirectional_iterator<_Iter>
+    {
       auto __tmp = *this;
       __tmp.advance(-__n);
       return __tmp;
@@ -197,16 +196,16 @@ namespace ranges {
     constexpr subrange& advance(iter_difference_t<_Iter> __n) {
       if constexpr (bidirectional_iterator<_Iter>) {
         if (__n < 0) {
-          ranges::advance(this->__begin_, __n);
-          if constexpr (_Base::__store_size)
-            this->__size_ += _VSTD::__to_unsigned_like(-__n);
+          ranges::advance(__begin_, __n);
+          if constexpr (_StoreSize)
+            __size_ += _VSTD::__to_unsigned_like(-__n);
           return *this;
         }
       }
 
-      auto __d = __n - ranges::advance(this->__begin_, __n, this->__end_);
-      if constexpr (_Base::__store_size)
-        this->__size_ -= _VSTD::__to_unsigned_like(__d);
+      auto __d = __n - ranges::advance(__begin_, __n, __end_);
+      if constexpr (_StoreSize)
+        __size_ -= _VSTD::__to_unsigned_like(__d);
       return *this;
     }
   };
@@ -228,7 +227,7 @@ namespace ranges {
     -> subrange<iterator_t<_Range>, sentinel_t<_Range>, subrange_kind::sized>;
 
   template<size_t _Index, class _Iter, class _Sent, subrange_kind _Kind>
-    requires (_Index < 2)
+    requires ((_Index == 0 && copyable<_Iter>) || _Index == 1)
   _LIBCPP_HIDE_FROM_ABI
   constexpr auto get(const subrange<_Iter, _Sent, _Kind>& __subrange) {
     if constexpr (_Index == 0)
@@ -251,17 +250,40 @@ namespace ranges {
   inline constexpr bool enable_borrowed_range<subrange<_Ip, _Sp, _Kp>> = true;
 
   template<range _Rp>
-  using borrowed_subrange_t = _If<borrowed_range<_Rp>, subrange<iterator_t<_Rp> >, dangling>;
+  using borrowed_subrange_t = _If<borrowed_range<_Rp>, subrange<iterator_t<_Rp>>, dangling>;
 } // namespace ranges
 
+// [range.subrange.general]
+
 using ranges::get;
 
-// clang-format off
+// [ranges.syn]
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
+struct tuple_size<ranges::subrange<_Ip, _Sp, _Kp>> : integral_constant<size_t, 2> {};
 
-_LIBCPP_END_NAMESPACE_STD
+template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
+struct tuple_element<0, ranges::subrange<_Ip, _Sp, _Kp>> {
+  using type = _Ip;
+};
+
+template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
+struct tuple_element<1, ranges::subrange<_Ip, _Sp, _Kp>> {
+  using type = _Sp;
+};
 
-_LIBCPP_POP_MACROS
+template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
+struct tuple_element<0, const ranges::subrange<_Ip, _Sp, _Kp>> {
+  using type = _Ip;
+};
+
+template<class _Ip, class _Sp, ranges::subrange_kind _Kp>
+struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> {
+  using type = _Sp;
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___RANGES_SUBRANGE_H
lib/libcxx/include/__ranges/take_view.h
@@ -0,0 +1,185 @@
+// -*- 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___RANGES_TAKE_VIEW_H
+#define _LIBCPP___RANGES_TAKE_VIEW_H
+
+#include <__algorithm/min.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/counted_iterator.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__utility/move.h>
+#include <concepts>
+#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
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+  template<view _View>
+  class take_view : public view_interface<take_view<_View>> {
+    [[no_unique_address]] _View __base_ = _View();
+    range_difference_t<_View> __count_ = 0;
+
+    template<bool> class __sentinel;
+
+  public:
+    _LIBCPP_HIDE_FROM_ABI
+    take_view() requires default_initializable<_View> = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr take_view(_View __base, range_difference_t<_View> __count)
+      : __base_(_VSTD::move(__base)), __count_(__count) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _View base() const& requires copy_constructible<_View> { return __base_; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr _View base() && { return _VSTD::move(__base_); }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto begin() requires (!__simple_view<_View>) {
+      if constexpr (sized_range<_View>) {
+        if constexpr (random_access_range<_View>) {
+          return ranges::begin(__base_);
+        } else {
+          using _DifferenceT = range_difference_t<_View>;
+          auto __size = size();
+          return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
+        }
+      } else {
+        return counted_iterator(ranges::begin(__base_), __count_);
+      }
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto begin() const requires range<const _View> {
+      if constexpr (sized_range<const _View>) {
+        if constexpr (random_access_range<const _View>) {
+          return ranges::begin(__base_);
+        } else {
+          using _DifferenceT = range_difference_t<const _View>;
+          auto __size = size();
+          return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size));
+        }
+      } else {
+        return counted_iterator(ranges::begin(__base_), __count_);
+      }
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto end() requires (!__simple_view<_View>) {
+      if constexpr (sized_range<_View>) {
+        if constexpr (random_access_range<_View>) {
+          return ranges::begin(__base_) + size();
+        } else {
+          return default_sentinel;
+        }
+      } else {
+        return __sentinel<false>{ranges::end(__base_)};
+      }
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto end() const requires range<const _View> {
+      if constexpr (sized_range<const _View>) {
+        if constexpr (random_access_range<const _View>) {
+          return ranges::begin(__base_) + size();
+        } else {
+          return default_sentinel;
+        }
+      } else {
+        return __sentinel<true>{ranges::end(__base_)};
+      }
+    }
+
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto size() requires sized_range<_View> {
+      auto __n = ranges::size(__base_);
+      // TODO: use ranges::min here.
+      return _VSTD::min(__n, static_cast<decltype(__n)>(__count_));
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr auto size() const requires sized_range<const _View> {
+      auto __n = ranges::size(__base_);
+      // TODO: use ranges::min here.
+      return _VSTD::min(__n, static_cast<decltype(__n)>(__count_));
+    }
+  };
+
+  template<view _View>
+  template<bool _Const>
+  class take_view<_View>::__sentinel {
+    using _Base = __maybe_const<_Const, _View>;
+    template<bool _OtherConst>
+    using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>;
+    [[no_unique_address]] sentinel_t<_Base> __end_ = sentinel_t<_Base>();
+
+    template<bool>
+    friend class take_view<_View>::__sentinel;
+
+public:
+    _LIBCPP_HIDE_FROM_ABI
+    __sentinel() = default;
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(_VSTD::move(__end)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr __sentinel(__sentinel<!_Const> __s)
+      requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
+      : __end_(_VSTD::move(__s.__end_)) {}
+
+    _LIBCPP_HIDE_FROM_ABI
+    constexpr sentinel_t<_Base> base() const { return __end_; }
+
+    _LIBCPP_HIDE_FROM_ABI
+    friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) {
+      return __lhs.count() == 0 || __lhs.base() == __rhs.__end_;
+    }
+
+    template<bool _OtherConst = !_Const>
+      requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
+    _LIBCPP_HIDE_FROM_ABI
+    friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) {
+      return __lhs.count() == 0 || __lhs.base() == __rhs.__end_;
+    }
+  };
+
+  template<class _Range>
+  take_view(_Range&&, range_difference_t<_Range>) -> take_view<views::all_t<_Range>>;
+
+  template<class _Tp>
+  inline constexpr bool enable_borrowed_range<take_view<_Tp>> = enable_borrowed_range<_Tp>;
+} // namespace ranges
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___RANGES_TAKE_VIEW_H
lib/libcxx/include/__ranges/transform_view.h
@@ -9,38 +9,51 @@
 #ifndef _LIBCPP___RANGES_TRANSFORM_VIEW_H
 #define _LIBCPP___RANGES_TRANSFORM_VIEW_H
 
+#include <__compare/three_way_comparable.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/invocable.h>
 #include <__config>
+#include <__functional/bind_back.h>
+#include <__functional/invoke.h>
 #include <__iterator/concepts.h>
-#include <__iterator/iter_swap.h>
 #include <__iterator/iterator_traits.h>
+#include <__memory/addressof.h>
 #include <__ranges/access.h>
 #include <__ranges/all.h>
 #include <__ranges/concepts.h>
 #include <__ranges/copyable_box.h>
 #include <__ranges/empty.h>
+#include <__ranges/range_adaptor.h>
 #include <__ranges/size.h>
 #include <__ranges/view_interface.h>
-#include <concepts>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.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
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 namespace ranges {
 
+template<class _Fn, class _View>
+concept __regular_invocable_with_range_ref =
+  regular_invocable<_Fn, range_reference_t<_View>>;
+
 template<class _View, class _Fn>
 concept __transform_view_constraints =
-           view<_View> && is_object_v<_Fn> &&
-           regular_invocable<_Fn&, range_reference_t<_View>> &&
-           __referenceable<invoke_result_t<_Fn&, range_reference_t<_View>>>;
+  view<_View> && is_object_v<_Fn> &&
+  regular_invocable<_Fn&, range_reference_t<_View>> &&
+  __referenceable<invoke_result_t<_Fn&, range_reference_t<_View>>>;
 
 template<input_range _View, copy_constructible _Fn>
   requires __transform_view_constraints<_View, _Fn>
@@ -72,7 +85,7 @@ public:
   _LIBCPP_HIDE_FROM_ABI
   constexpr __iterator<true> begin() const
     requires range<const _View> &&
-             regular_invocable<const _Fn&, range_reference_t<const _View>>
+             __regular_invocable_with_range_ref<const _Fn&, const _View>
   {
     return __iterator<true>(*this, ranges::begin(__base_));
   }
@@ -90,14 +103,14 @@ public:
   _LIBCPP_HIDE_FROM_ABI
   constexpr __sentinel<true> end() const
     requires range<const _View> &&
-             regular_invocable<const _Fn&, range_reference_t<const _View>>
+             __regular_invocable_with_range_ref<const _Fn&, const _View>
   {
     return __sentinel<true>(ranges::end(__base_));
   }
   _LIBCPP_HIDE_FROM_ABI
   constexpr __iterator<true> end() const
     requires common_range<const _View> &&
-             regular_invocable<const _Fn&, range_reference_t<const _View>>
+             __regular_invocable_with_range_ref<const _Fn&, const _View>
   {
     return __iterator<true>(*this, ranges::end(__base_));
   }
@@ -181,9 +194,7 @@ public:
     : __parent_(__i.__parent_), __current_(_VSTD::move(__i.__current_)) {}
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr iterator_t<_Base> base() const&
-    requires copyable<iterator_t<_Base>>
-  {
+  constexpr const iterator_t<_Base>& base() const& noexcept {
     return __current_;
   }
 
@@ -293,13 +304,12 @@ public:
     return __x.__current_ >= __y.__current_;
   }
 
-// TODO: Fix this as soon as soon as three_way_comparable is implemented.
-//   _LIBCPP_HIDE_FROM_ABI
-//   friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
-//     requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>>
-//   {
-//     return __x.__current_ <=> __y.__current_;
-//   }
+  _LIBCPP_HIDE_FROM_ABI
+  friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
+    requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>>
+  {
+    return __x.__current_ <=> __y.__current_;
+  }
 
   _LIBCPP_HIDE_FROM_ABI
   friend constexpr __iterator operator+(__iterator __i, difference_type __n)
@@ -397,12 +407,34 @@ public:
   }
 };
 
+namespace views {
+namespace __transform {
+  struct __fn {
+    template<class _Range, class _Fn>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Range&& __range, _Fn&& __f) const
+      noexcept(noexcept(transform_view(_VSTD::forward<_Range>(__range), _VSTD::forward<_Fn>(__f))))
+      -> decltype(      transform_view(_VSTD::forward<_Range>(__range), _VSTD::forward<_Fn>(__f)))
+      { return          transform_view(_VSTD::forward<_Range>(__range), _VSTD::forward<_Fn>(__f)); }
+
+    template<class _Fn>
+      requires constructible_from<decay_t<_Fn>, _Fn>
+    [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+    constexpr auto operator()(_Fn&& __f) const
+      noexcept(is_nothrow_constructible_v<decay_t<_Fn>, _Fn>)
+    { return __range_adaptor_closure_t(_VSTD::__bind_back(*this, _VSTD::forward<_Fn>(__f))); }
+  };
+} // namespace __transform
+
+inline namespace __cpo {
+  inline constexpr auto transform = __transform::__fn{};
+} // namespace __cpo
+} // namespace views
+
 } // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_TRANSFORM_VIEW_H
lib/libcxx/include/__ranges/view_interface.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___RANGES_VIEW_INTERFACE_H
 
 #include <__config>
+#include <__debug>
 #include <__iterator/concepts.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/prev.h>
@@ -17,7 +18,6 @@
 #include <__ranges/access.h>
 #include <__ranges/concepts.h>
 #include <__ranges/empty.h>
-#include <__ranges/enable_view.h>
 #include <concepts>
 #include <type_traits>
 
@@ -25,12 +25,9 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 namespace ranges {
 
@@ -42,14 +39,16 @@ void __implicitly_convert_to(type_identity_t<_Tp>) noexcept;
 
 template<class _Derived>
   requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>>
-class view_interface : public view_base {
+class view_interface {
   _LIBCPP_HIDE_FROM_ABI
   constexpr _Derived& __derived() noexcept {
+    static_assert(sizeof(_Derived) && derived_from<_Derived, view_interface> && view<_Derived>);
     return static_cast<_Derived&>(*this);
   }
 
   _LIBCPP_HIDE_FROM_ABI
   constexpr _Derived const& __derived() const noexcept {
+    static_assert(sizeof(_Derived) && derived_from<_Derived, view_interface> && view<_Derived>);
     return static_cast<_Derived const&>(*this);
   }
 
@@ -187,12 +186,10 @@ public:
   }
 };
 
-}
+} // namespace ranges
 
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___RANGES_VIEW_INTERFACE_H
lib/libcxx/include/__ranges/views.h
@@ -0,0 +1,35 @@
+// -*- 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___RANGES_VIEWS
+#define _LIBCPP___RANGES_VIEWS
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+
+namespace views { }
+
+} // namespace ranges
+
+namespace views = ranges::views;
+
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_VIEWS
lib/libcxx/include/__support/ibm/locale_mgmt_aix.h
@@ -1,84 +0,0 @@
-// -*- 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_SUPPORT_IBM_LOCALE_MGMT_AIX_H
-#define _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
-
-#if defined(_AIX)
-#include "cstdlib"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if !defined(_AIX71)
-// AIX 7.1 and higher has these definitions.  Definitions and stubs
-// are provied here as a temporary workaround on AIX 6.1.
-
-#define LC_COLLATE_MASK         1
-#define LC_CTYPE_MASK           2
-#define LC_MESSAGES_MASK        4
-#define LC_MONETARY_MASK        8
-#define LC_NUMERIC_MASK         16
-#define LC_TIME_MASK            32
-#define LC_ALL_MASK             (LC_COLLATE_MASK | LC_CTYPE_MASK | \
-                                 LC_MESSAGES_MASK | LC_MONETARY_MASK |\
-                                 LC_NUMERIC_MASK | LC_TIME_MASK)
-
-typedef void* locale_t;
-
-// The following are stubs.  They are not supported on AIX 6.1.
-static inline
-locale_t newlocale(int category_mask, const char *locale, locale_t base)
-{
-  _LC_locale_t *newloc, *loc;
-  if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL)
-  {
-    errno = EINVAL;
-    return (locale_t)0;
-  }
-  if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL)
-  {
-    errno = ENOMEM;
-    return (locale_t)0;
-  }
-  if (!base)
-    base = (_LC_locale_t *)__xopen_locale("C");
-  memcpy(newloc, base, sizeof (_LC_locale_t));
-  if (category_mask & LC_COLLATE_MASK)
-    newloc->lc_collate = loc->lc_collate;
-  if (category_mask & LC_CTYPE_MASK)
-    newloc->lc_ctype = loc->lc_ctype;
-  //if (category_mask & LC_MESSAGES_MASK)
-  //  newloc->lc_messages = loc->lc_messages;
-  if (category_mask & LC_MONETARY_MASK)
-    newloc->lc_monetary = loc->lc_monetary;
-  if (category_mask & LC_TIME_MASK)
-    newloc->lc_time = loc->lc_time;
-  if (category_mask & LC_NUMERIC_MASK)
-    newloc->lc_numeric = loc->lc_numeric;
-  return (locale_t)newloc;
-}
-static inline
-void freelocale(locale_t locobj)
-{
-  free(locobj);
-}
-static inline
-locale_t uselocale(locale_t newloc)
-{
-  return (locale_t)0;
-}
-#endif // !defined(_AIX71)
-
-#ifdef __cplusplus
-}
-#endif
-#endif // defined(_AIX)
-#endif // _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
lib/libcxx/include/__support/ibm/nanosleep.h
@@ -21,14 +21,13 @@ inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
     errno = EINVAL;
     return -1;
   }
-  useconds_t __micro_sec =
-      static_cast<useconds_t>((__req->tv_nsec + 999) / 1000);
+  long __micro_sec = (__req->tv_nsec + 999) / 1000;
   time_t __sec = __req->tv_sec;
   if (__micro_sec > 999999) {
     ++__sec;
     __micro_sec -= 1000000;
   }
-  __sec = sleep(static_cast<unsigned int>(__sec));
+  __sec = static_cast<time_t>(sleep(static_cast<unsigned int>(__sec)));
   if (__sec) {
     if (__rem) {
       // Updating the remaining time to sleep in case of unsuccessful call to sleep().
@@ -39,7 +38,7 @@ inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
     return -1;
   }
   if (__micro_sec) {
-    int __rt = usleep(__micro_sec);
+    int __rt = usleep(static_cast<unsigned int>(__micro_sec));
     if (__rt != 0 && __rem) {
       // The usleep() does not provide the amount of remaining time upon its failure,
       // so the time slept will be ignored.
lib/libcxx/include/__support/ibm/xlocale.h
@@ -10,7 +10,6 @@
 #ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H
 #define _LIBCPP_SUPPORT_IBM_XLOCALE_H
 
-#include <__support/ibm/locale_mgmt_aix.h>
 #include <__support/ibm/locale_mgmt_zos.h>
 #include <stdarg.h>
 
@@ -20,207 +19,7 @@
 extern "C" {
 #endif
 
-#if defined(_AIX)
-#if !defined(_AIX71)
-// AIX 7.1 and higher has these definitions.  Definitions and stubs
-// are provied here as a temporary workaround on AIX 6.1.
-static inline
-int isalnum_l(int c, locale_t locale)
-{
-  return __xisalnum(locale, c);
-}
-static inline
-int isalpha_l(int c, locale_t locale)
-{
-  return __xisalpha(locale, c);
-}
-static inline
-int isblank_l(int c, locale_t locale)
-{
-  return __xisblank(locale, c);
-}
-static inline
-int iscntrl_l(int c, locale_t locale)
-{
-  return __xiscntrl(locale, c);
-}
-static inline
-int isdigit_l(int c, locale_t locale)
-{
-  return __xisdigit(locale, c);
-}
-static inline
-int isgraph_l(int c, locale_t locale)
-{
-  return __xisgraph(locale, c);
-}
-static inline
-int islower_l(int c, locale_t locale)
-{
-  return __xislower(locale, c);
-}
-static inline
-int isprint_l(int c, locale_t locale)
-{
-  return __xisprint(locale, c);
-}
-
-static inline
-int ispunct_l(int c, locale_t locale)
-{
-  return __xispunct(locale, c);
-}
-static inline
-int isspace_l(int c, locale_t locale)
-{
-  return __xisspace(locale, c);
-}
-static inline
-int isupper_l(int c, locale_t locale)
-{
-  return __xisupper(locale, c);
-}
-
-static inline
-int isxdigit_l(int c, locale_t locale)
-{
-  return __xisxdigit(locale, c);
-}
-
-static inline
-int iswalnum_l(wchar_t wc, locale_t locale)
-{
-  return __xiswalnum(locale, wc);
-}
-
-static inline
-int iswalpha_l(wchar_t wc, locale_t locale)
-{
-  return __xiswalpha(locale, wc);
-}
-
-static inline
-int iswblank_l(wchar_t wc, locale_t locale)
-{
-  return __xiswblank(locale, wc);
-}
-
-static inline
-int iswcntrl_l(wchar_t wc, locale_t locale)
-{
-  return __xiswcntrl(locale, wc);
-}
-
-static inline
-int iswdigit_l(wchar_t wc, locale_t locale)
-{
-  return __xiswdigit(locale, wc);
-}
-
-static inline
-int iswgraph_l(wchar_t wc, locale_t locale)
-{
-  return __xiswgraph(locale, wc);
-}
-
-static inline
-int iswlower_l(wchar_t wc, locale_t locale)
-{
-  return __xiswlower(locale, wc);
-}
-
-static inline
-int iswprint_l(wchar_t wc, locale_t locale)
-{
-  return __xiswprint(locale, wc);
-}
-
-static inline
-int iswpunct_l(wchar_t wc, locale_t locale)
-{
-  return __xiswpunct(locale, wc);
-}
-
-static inline
-int iswspace_l(wchar_t wc, locale_t locale)
-{
-  return __xiswspace(locale, wc);
-}
-
-static inline
-int iswupper_l(wchar_t wc, locale_t locale)
-{
-  return __xiswupper(locale, wc);
-}
-
-static inline
-int iswxdigit_l(wchar_t wc, locale_t locale)
-{
-  return __xiswxdigit(locale, wc);
-}
-
-static inline
-int iswctype_l(wint_t wc, wctype_t desc, locale_t locale)
-{
-  return __xiswctype(locale, wc, desc);
-}
-
-static inline
-int toupper_l(int c, locale_t locale)
-{
-  return __xtoupper(locale, c);
-}
-static inline
-int tolower_l(int c, locale_t locale)
-{
-  return __xtolower(locale, c);
-}
-static inline
-wint_t towupper_l(wint_t wc, locale_t locale)
-{
-  return __xtowupper(locale, wc);
-}
-static inline
-wint_t towlower_l(wint_t wc, locale_t locale)
-{
-  return __xtowlower(locale, wc);
-}
-
-static inline
-int strcoll_l(const char *__s1, const char *__s2, locale_t locale)
-{
-  return __xstrcoll(locale, __s1, __s2);
-}
-static inline
-int wcscoll_l(const wchar_t *__s1, const wchar_t *__s2, locale_t locale)
-{
-  return __xwcscoll(locale, __s1, __s2);
-}
-static inline
-size_t strxfrm_l(char *__s1, const char *__s2, size_t __n, locale_t locale)
-{
-  return __xstrxfrm(locale, __s1, __s2, __n);
-}
-
-static inline
-size_t wcsxfrm_l(wchar_t *__ws1, const wchar_t *__ws2, size_t __n,
-    locale_t locale)
-{
-  return __xwcsxfrm(locale, __ws1, __ws2, __n);
-}
-#endif // !defined(_AIX71)
-
-// strftime_l() is defined by POSIX. However, AIX 7.1 and z/OS do not have it
-// implemented yet. z/OS retrieves it from the POSIX fallbacks.
-#if !defined(_AIX72)
-static inline
-size_t strftime_l(char *__s, size_t __size, const char *__fmt,
-                  const struct tm *__tm, locale_t locale) {
-  return __xstrftime(locale, __s, __size, __fmt, __tm);
-}
-#endif
-
-#elif defined(__MVS__)
+#if defined(__MVS__)
 #include <wctype.h>
 // POSIX routines
 #include <__support/xlocale/__posix_l_fallback.h>
lib/libcxx/include/__support/openbsd/xlocale.h
@@ -16,4 +16,24 @@
 #include <ctype.h>
 #include <cwctype>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+inline _LIBCPP_HIDE_FROM_ABI long
+strtol_l(const char *nptr, char **endptr, int base, locale_t) {
+  return ::strtol(nptr, endptr, base);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI unsigned long
+strtoul_l(const char *nptr, char **endptr, int base, locale_t) {
+  return ::strtoul(nptr, endptr, base);
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
lib/libcxx/include/__support/win32/limits_msvc_win32.h
@@ -14,7 +14,7 @@
 #error "This header complements the Microsoft C Runtime library, and should not be included otherwise."
 #endif
 #if defined(__clang__)
-#error "This header should only be included when using Microsofts C1XX frontend"
+#error "This header should only be included when using Microsoft's C1XX frontend"
 #endif
 
 #include <float.h> // limit constants
lib/libcxx/include/__thread/poll_with_backoff.h
@@ -0,0 +1,69 @@
+// -*- 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___THREAD_POLL_WITH_BACKOFF_H
+#define _LIBCPP___THREAD_POLL_WITH_BACKOFF_H
+
+#include <__availability>
+#include <__config>
+#include <chrono>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
+
+// Polls a thread for a condition given by a predicate, and backs off based on a backoff policy
+// before polling again.
+//
+// - __f is the "test function" that should return true if polling succeeded, and false if it failed.
+//
+// - __bf is the "backoff policy", which is called with the duration since we started polling. It should
+//   return false in order to resume polling, and true if polling should stop entirely for some reason.
+//   In general, backoff policies sleep for some time before returning control to the polling loop.
+//
+// - __max_elapsed is the maximum duration to try polling for. If the maximum duration is exceeded,
+//   the polling loop will return false to report a timeout.
+template<class _Fn, class _BFn>
+_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
+bool __libcpp_thread_poll_with_backoff(_Fn&& __f, _BFn&& __bf, chrono::nanoseconds __max_elapsed = chrono::nanoseconds::zero()) {
+    auto const __start = chrono::high_resolution_clock::now();
+    for (int __count = 0;;) {
+      if (__f())
+        return true; // _Fn completion means success
+      if (__count < __libcpp_polling_count) {
+        __count += 1;
+        continue;
+      }
+      chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
+      if (__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
+          return false; // timeout failure
+      if (__bf(__elapsed))
+        return false; // _BFn completion means failure
+    }
+}
+
+// A trivial backoff policy that always immediately returns the control to
+// the polling loop.
+//
+// This is not very well-behaved since it will cause the polling loop to spin,
+// so this should most likely only be used on single-threaded systems where there
+// are no other threads to compete with.
+struct __spinning_backoff_policy {
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
+  bool operator()(chrono::nanoseconds const&) const {
+      return false;
+  }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___THREAD_POLL_WITH_BACKOFF_H
lib/libcxx/include/__thread/timed_backoff_policy.h
@@ -0,0 +1,45 @@
+// -*- 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___THREAD_TIMED_BACKOFF_POLICY_H
+#define _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
+
+#include <__config>
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
+#include <__threading_support>
+#include <chrono>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct __libcpp_timed_backoff_policy {
+  _LIBCPP_INLINE_VISIBILITY
+  bool operator()(chrono::nanoseconds __elapsed) const
+  {
+      if(__elapsed > chrono::milliseconds(128))
+          __libcpp_thread_sleep_for(chrono::milliseconds(8));
+      else if(__elapsed > chrono::microseconds(64))
+          __libcpp_thread_sleep_for(__elapsed / 2);
+      else if(__elapsed > chrono::microseconds(4))
+        __libcpp_thread_yield();
+      else
+        {} // poll
+      return false;
+  }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_HAS_NO_THREADS
+
+#endif // _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
lib/libcxx/include/__utility/as_const.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -33,6 +30,4 @@ void as_const(const _Tp&&) = delete;
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_AS_CONST_H
lib/libcxx/include/__support/nuttx/xlocale.h โ†’ lib/libcxx/include/__utility/auto_cast.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,12 +7,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP_SUPPORT_NUTTX_XLOCALE_H
-#define _LIBCPP_SUPPORT_NUTTX_XLOCALE_H
+#ifndef _LIBCPP___UTILITY_AUTO_CAST_H
+#define _LIBCPP___UTILITY_AUTO_CAST_H
 
-#if defined(__NuttX__)
-#include <__support/xlocale/__posix_l_fallback.h>
-#include <__support/xlocale/__strtonum_fallback.h>
-#endif // __NuttX__
+#include <__config>
+#include <type_traits>
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
 #endif
+
+#define _LIBCPP_AUTO_CAST(expr) static_cast<typename decay<decltype((expr))>::type>(expr)
+
+#endif // _LIBCPP___UTILITY_AUTO_CAST_H
lib/libcxx/include/__utility/cmp.h
@@ -24,20 +24,23 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 template<class _Tp, class... _Up>
 struct _IsSameAsAny : _Or<_IsSame<_Tp, _Up>...> {};
 
 template<class _Tp>
 concept __is_safe_integral_cmp = is_integral_v<_Tp> &&
-                      !_IsSameAsAny<_Tp, bool, char,
+                      !_IsSameAsAny<_Tp, bool, char
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
-                                    char8_t,
+                                    , char8_t
 #endif
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
-                                    char16_t, char32_t,
+                                    , char16_t, char32_t
 #endif
-                                    wchar_t>::value;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+                                    , wchar_t
+#endif
+                                    >::value;
 
 template<__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
lib/libcxx/include/__utility/declval.h
@@ -15,9 +15,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // Suppress deprecation notice for volatile-qualified return type resulting
@@ -34,6 +31,4 @@ decltype(__declval<_Tp>(0)) declval() _NOEXCEPT;
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_DECLVAL_H
lib/libcxx/include/__utility/exchange.h
@@ -12,20 +12,19 @@
 #include <__config>
 #include <__utility/forward.h>
 #include <__utility/move.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
 
 #if _LIBCPP_STD_VER > 11
 template<class _T1, class _T2 = _T1>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_T1 exchange(_T1& __obj, _T2 && __new_value)
+_T1 exchange(_T1& __obj, _T2&& __new_value)
+    noexcept(is_nothrow_move_constructible<_T1>::value && is_nothrow_assignable<_T1&, _T2>::value)
 {
     _T1 __old_value = _VSTD::move(__obj);
     __obj = _VSTD::forward<_T2>(__new_value);
@@ -35,6 +34,4 @@ _T1 exchange(_T1& __obj, _T2 && __new_value)
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_EXCHANGE_H
lib/libcxx/include/__utility/forward.h
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
@@ -37,6 +34,4 @@ forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_FORWARD_H
lib/libcxx/include/__utility/in_place.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -26,21 +23,21 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 struct _LIBCPP_TYPE_VIS in_place_t {
     explicit in_place_t() = default;
 };
-_LIBCPP_INLINE_VAR constexpr in_place_t in_place{};
+inline constexpr in_place_t in_place{};
 
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
     explicit in_place_type_t() = default;
 };
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
+inline constexpr in_place_type_t<_Tp> in_place_type{};
 
 template <size_t _Idx>
 struct _LIBCPP_TEMPLATE_VIS in_place_index_t {
     explicit in_place_index_t() = default;
 };
 template <size_t _Idx>
-_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
+inline constexpr in_place_index_t<_Idx> in_place_index{};
 
 template <class _Tp> struct __is_inplace_type_imp : false_type {};
 template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
@@ -58,6 +55,4 @@ using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>;
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_IN_PLACE_H
lib/libcxx/include/__utility/integer_sequence.h
@@ -16,9 +16,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 11
@@ -42,11 +39,11 @@ template<size_t... _Ip>
 #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
 
 template <class _Tp, _Tp _Ep>
-using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>;
+using __make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>;
 
 #else
 
-template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG_TYPE  =
+template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG =
   typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
 
 template <class _Tp, _Tp _Ep>
@@ -57,11 +54,11 @@ struct __make_integer_sequence_checked
     static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
     // Workaround GCC bug by preventing bad installations when 0 <= _Ep
     // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
-    typedef _LIBCPP_NODEBUG_TYPE  __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
+    typedef _LIBCPP_NODEBUG __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
 };
 
 template <class _Tp, _Tp _Ep>
-using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
+using __make_integer_sequence _LIBCPP_NODEBUG = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
 
 #endif
 
@@ -78,6 +75,4 @@ template<class... _Tp>
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
lib/libcxx/include/__utility/move.h
@@ -17,15 +17,12 @@
 #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;
+  typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
   return static_cast<_Up&&>(__t);
 }
 
@@ -47,6 +44,4 @@ move_if_noexcept(_Tp& __x) _NOEXCEPT {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_MOVE_H
lib/libcxx/include/__utility/pair.h
@@ -9,6 +9,8 @@
 #ifndef _LIBCPP___UTILITY_PAIR_H
 #define _LIBCPP___UTILITY_PAIR_H
 
+#include <__compare/common_comparison_category.h>
+#include <__compare/synth_three_way.h>
 #include <__config>
 #include <__functional/unwrap_ref.h>
 #include <__tuple>
@@ -22,12 +24,8 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-
 #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
 template <class, class>
 struct __non_trivially_copyable_base {
@@ -75,9 +73,6 @@ struct _LIBCPP_TEMPLATE_VIS pair
         return *this;
     }
 #else
-    template <bool _Val>
-    using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type;
-
     struct _CheckArgs {
       template <int&...>
       static constexpr bool __enable_explicit_default() {
@@ -110,7 +105,7 @@ struct _LIBCPP_TEMPLATE_VIS pair
     };
 
     template <bool _MaybeEnable>
-    using _CheckArgsDep _LIBCPP_NODEBUG_TYPE = typename conditional<
+    using _CheckArgsDep _LIBCPP_NODEBUG = typename conditional<
       _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
 
     struct _CheckTupleLikeConstructor {
@@ -132,112 +127,122 @@ struct _LIBCPP_TEMPLATE_VIS pair
     };
 
     template <class _Tuple>
-    using _CheckTLC _LIBCPP_NODEBUG_TYPE = typename conditional<
+    using _CheckTLC _LIBCPP_NODEBUG = typename conditional<
         __tuple_like_with_size<_Tuple, 2>::value
             && !is_same<typename decay<_Tuple>::type, pair>::value,
         _CheckTupleLikeConstructor,
         __check_tuple_constructor_fail
     >::type;
 
-    template<bool _Dummy = true, _EnableB<
+    template<bool _Dummy = true, typename enable_if<
             _CheckArgsDep<_Dummy>::__enable_explicit_default()
-    > = false>
+    >::type* = nullptr>
     explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
                       is_nothrow_default_constructible<second_type>::value)
         : first(), second() {}
 
-    template<bool _Dummy = true, _EnableB<
+    template<bool _Dummy = true, typename enable_if<
             _CheckArgsDep<_Dummy>::__enable_implicit_default()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
                       is_nothrow_default_constructible<second_type>::value)
         : first(), second() {}
 
-    template <bool _Dummy = true, _EnableB<
+    template <bool _Dummy = true, typename enable_if<
              _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     explicit pair(_T1 const& __t1, _T2 const& __t2)
         _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
                    is_nothrow_copy_constructible<second_type>::value)
         : first(__t1), second(__t2) {}
 
-    template<bool _Dummy = true, _EnableB<
+    template<bool _Dummy = true, typename enable_if<
             _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     pair(_T1 const& __t1, _T2 const& __t2)
         _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
                    is_nothrow_copy_constructible<second_type>::value)
         : first(__t1), second(__t2) {}
 
-    template<class _U1, class _U2, _EnableB<
-             _CheckArgs::template __enable_explicit<_U1, _U2>()
-    > = false>
+    template <
+#if _LIBCPP_STD_VER > 20 // http://wg21.link/P1951
+        class _U1 = _T1, class _U2 = _T2,
+#else
+        class _U1, class _U2,
+#endif
+        typename enable_if<_CheckArgs::template __enable_explicit<_U1, _U2>()>::type* = nullptr
+    >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     explicit pair(_U1&& __u1, _U2&& __u2)
         _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
                     is_nothrow_constructible<second_type, _U2>::value))
         : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
 
-    template<class _U1, class _U2, _EnableB<
-            _CheckArgs::template __enable_implicit<_U1, _U2>()
-    > = false>
+    template <
+#if _LIBCPP_STD_VER > 20 // http://wg21.link/P1951
+        class _U1 = _T1, class _U2 = _T2,
+#else
+        class _U1, class _U2,
+#endif
+        typename enable_if<_CheckArgs::template __enable_implicit<_U1, _U2>()>::type* = nullptr
+    >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     pair(_U1&& __u1, _U2&& __u2)
         _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
                     is_nothrow_constructible<second_type, _U2>::value))
         : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
 
-    template<class _U1, class _U2, _EnableB<
+    template<class _U1, class _U2, typename enable_if<
             _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     explicit pair(pair<_U1, _U2> const& __p)
         _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
                     is_nothrow_constructible<second_type, _U2 const&>::value))
         : first(__p.first), second(__p.second) {}
 
-    template<class _U1, class _U2, _EnableB<
+    template<class _U1, class _U2, typename enable_if<
             _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     pair(pair<_U1, _U2> const& __p)
         _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
                     is_nothrow_constructible<second_type, _U2 const&>::value))
         : first(__p.first), second(__p.second) {}
 
-    template<class _U1, class _U2, _EnableB<
+    template<class _U1, class _U2, typename enable_if<
             _CheckArgs::template __enable_explicit<_U1, _U2>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     explicit pair(pair<_U1, _U2>&&__p)
         _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
                     is_nothrow_constructible<second_type, _U2&&>::value))
         : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
 
-    template<class _U1, class _U2, _EnableB<
+    template<class _U1, class _U2, typename enable_if<
             _CheckArgs::template __enable_implicit<_U1, _U2>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     pair(pair<_U1, _U2>&& __p)
         _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
                     is_nothrow_constructible<second_type, _U2&&>::value))
         : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
 
-    template<class _Tuple, _EnableB<
+    template<class _Tuple, typename enable_if<
             _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     explicit pair(_Tuple&& __p)
         : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
           second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
 
-    template<class _Tuple, _EnableB<
+    template<class _Tuple, typename enable_if<
             _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
-    > = false>
+    >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     pair(_Tuple&& __p)
         : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
@@ -279,9 +284,9 @@ struct _LIBCPP_TEMPLATE_VIS pair
         return *this;
     }
 
-    template <class _Tuple, _EnableB<
+    template <class _Tuple, typename enable_if<
             _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
-     > = false>
+     >::type* = nullptr>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     pair& operator=(_Tuple&& __p) {
         first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
@@ -310,10 +315,12 @@ private:
 #endif
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _T1, class _T2>
 pair(_T1, _T2) -> pair<_T1, _T2>;
-#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#endif
+
+// [pairs.spec], specialized algorithms
 
 template <class _T1, class _T2>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
@@ -323,6 +330,23 @@ operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
     return __x.first == __y.first && __x.second == __y.second;
 }
 
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+template <class _T1, class _T2>
+_LIBCPP_HIDE_FROM_ABI constexpr
+common_comparison_category_t<
+        __synth_three_way_result<_T1>,
+        __synth_three_way_result<_T2> >
+operator<=>(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
+{
+    if (auto __c = _VSTD::__synth_three_way(__x.first, __y.first); __c != 0) {
+      return __c;
+    }
+    return _VSTD::__synth_three_way(__x.second, __y.second);
+}
+
+#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
 template <class _T1, class _T2>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 bool
@@ -363,6 +387,8 @@ operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
     return !(__y < __x);
 }
 
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
 template <class _T1, class _T2>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 typename enable_if
@@ -414,13 +440,13 @@ struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
 template <class _T1, class _T2>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
 {
-    typedef _LIBCPP_NODEBUG_TYPE _T1 type;
+    typedef _LIBCPP_NODEBUG _T1 type;
 };
 
 template <class _T1, class _T2>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> >
 {
-    typedef _LIBCPP_NODEBUG_TYPE _T2 type;
+    typedef _LIBCPP_NODEBUG _T2 type;
 };
 
 template <size_t _Ip> struct __get_pair;
@@ -580,6 +606,4 @@ constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_PAIR_H
lib/libcxx/include/__utility/piecewise_construct.h
@@ -15,20 +15,15 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; };
 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
 extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
 #else
-/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
+/* inline */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
 #endif
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_PIECEWISE_CONSTRUCT_H
lib/libcxx/include/__utility/priority_tag.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_PRIORITY_TAG_H
+#define _LIBCPP___UTILITY_PRIORITY_TAG_H
+
+#include <__config>
+#include <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template<size_t _Ip> struct __priority_tag : __priority_tag<_Ip - 1> {};
+template<> struct __priority_tag<0> {};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___UTILITY_PRIORITY_TAG_H
lib/libcxx/include/__utility/rel_ops.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace rel_ops
@@ -58,10 +55,8 @@ operator>=(const _Tp& __x, const _Tp& __y)
     return !(__x < __y);
 }
 
-}  // rel_ops
+} // namespace rel_ops
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_REL_OPS_H
lib/libcxx/include/__utility/swap.h
@@ -12,16 +12,13 @@
 #include <__config>
 #include <__utility/declval.h>
 #include <__utility/move.h>
-#include <type_traits>
 #include <cstddef>
+#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
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -50,6 +47,4 @@ swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::v
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_SWAP_H
lib/libcxx/include/__utility/to_underlying.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------- __utility/to_underlying.h --------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -17,9 +17,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -40,6 +37,4 @@ to_underlying(_Tp __val) noexcept {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___UTILITY_TO_UNDERLYING_H
lib/libcxx/include/__utility/transaction.h
@@ -0,0 +1,91 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_TRANSACTION_H
+#define _LIBCPP___UTILITY_TRANSACTION_H
+
+#include <__config>
+#include <__utility/exchange.h>
+#include <__utility/move.h>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// __transaction is a helper class for writing code with the strong exception guarantee.
+//
+// When writing code that can throw an exception, one can store rollback instructions in a
+// transaction so that if an exception is thrown at any point during the lifetime of the
+// transaction, it will be rolled back automatically. When the transaction is done, one
+// must mark it as being complete so it isn't rolled back when the transaction is destroyed.
+//
+// Transactions are not default constructible, they can't be copied or assigned to, but
+// they can be moved around for convenience.
+//
+// __transaction can help greatly simplify code that would normally be cluttered by
+// `#if _LIBCPP_NO_EXCEPTIONS`. For example:
+//
+//    template <class Iterator, class Size, class OutputIterator>
+//    Iterator uninitialized_copy_n(Iterator iter, Size n, OutputIterator out) {
+//        typedef typename iterator_traits<Iterator>::value_type value_type;
+//        __transaction transaction([start=out, &out] {
+//            std::destroy(start, out);
+//        });
+//
+//        for (; n > 0; ++iter, ++out, --n) {
+//            ::new ((void*)std::addressof(*out)) value_type(*iter);
+//        }
+//        transaction.__complete();
+//        return out;
+//    }
+//
+template <class _Rollback>
+struct __transaction {
+    __transaction() = delete;
+
+    _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit __transaction(_Rollback __rollback)
+        : __rollback_(_VSTD::move(__rollback))
+        , __completed_(false)
+    { }
+
+    _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_CONSTEXPR_AFTER_CXX17 __transaction(__transaction&& __other)
+        _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value)
+        : __rollback_(_VSTD::move(__other.__rollback_))
+        , __completed_(__other.__completed_)
+    {
+        __other.__completed_ = true;
+    }
+
+    __transaction(__transaction const&) = delete;
+    __transaction& operator=(__transaction const&) = delete;
+    __transaction& operator=(__transaction&&) = delete;
+
+    _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __complete() _NOEXCEPT {
+        __completed_ = true;
+    }
+
+    _LIBCPP_HIDE_FROM_ABI
+    _LIBCPP_CONSTEXPR_AFTER_CXX17 ~__transaction() {
+        if (!__completed_)
+            __rollback_();
+    }
+
+private:
+    _Rollback __rollback_;
+    bool __completed_;
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___UTILITY_TRANSACTION_H
lib/libcxx/include/__variant/monostate.h
@@ -18,9 +18,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -60,6 +57,4 @@ struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP___VARIANT_MONOSTATE_H
lib/libcxx/include/experimental/__config
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- __config ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -45,6 +45,10 @@
 #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM \
     } } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
 
+#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
+#define _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
+#endif
+
 #define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES \
   _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace coroutines_v1 {
 
lib/libcxx/include/experimental/__memory
@@ -10,13 +10,17 @@
 #ifndef _LIBCPP_EXPERIMENTAL___MEMORY
 #define _LIBCPP_EXPERIMENTAL___MEMORY
 
+#include <__functional_base>
 #include <__memory/allocator_arg_t.h>
 #include <__memory/uses_allocator.h>
 #include <experimental/__config>
 #include <experimental/utility> // for erased_type
-#include <__functional_base>
 #include <type_traits>
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_LFTS
 
 template <
lib/libcxx/include/experimental/algorithm
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- algorithm ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -31,20 +31,15 @@ ForwardIterator search(ForwardIterator first, ForwardIterator last,
 
 */
 
-#include <experimental/__config>
+#include <__debug>
 #include <algorithm>
+#include <experimental/__config>
 #include <type_traits>
 
-#include <__debug>
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-
 _LIBCPP_BEGIN_NAMESPACE_LFTS
 
 template <class _ForwardIterator, class _Searcher>
@@ -54,6 +49,4 @@ _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searc
 
 _LIBCPP_END_NAMESPACE_LFTS
 
-_LIBCPP_POP_MACROS
-
 #endif /* _LIBCPP_EXPERIMENTAL_ALGORITHM */
lib/libcxx/include/experimental/coroutine
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------------- coroutine -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -45,19 +45,19 @@ template <class P> struct hash<coroutine_handle<P>>;
 
  */
 
+#include <__debug>
+#include <cstddef>
 #include <experimental/__config>
-#include <new>
-#include <type_traits>
 #include <functional>
 #include <memory> // for hash<T*>
-#include <cstddef>
-#include <__debug>
+#include <new>
+#include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-#ifdef _LIBCPP_HAS_NO_COROUTINES
+#ifdef _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
 # if defined(_LIBCPP_WARNING)
     _LIBCPP_WARNING("<experimental/coroutine> cannot be used with this compiler")
 # else
@@ -65,7 +65,7 @@ template <class P> struct hash<coroutine_handle<P>>;
 # endif
 #endif
 
-#ifndef _LIBCPP_HAS_NO_COROUTINES
+#ifndef _LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES
 
 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES
 
@@ -329,6 +329,6 @@ struct hash<_VSTD_CORO::coroutine_handle<_Tp> > {
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !defined(_LIBCPP_HAS_NO_COROUTINES)
+#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES)
 
 #endif /* _LIBCPP_EXPERIMENTAL_COROUTINE */
lib/libcxx/include/experimental/deque
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- deque ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -28,8 +28,8 @@ namespace pmr {
 
  */
 
-#include <experimental/__config>
 #include <deque>
+#include <experimental/__config>
 #include <experimental/memory_resource>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/experimental/filesystem
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- filesystem -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/experimental/forward_list
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- forward_list -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -29,8 +29,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <forward_list>
 #include <experimental/memory_resource>
+#include <forward_list>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/experimental/functional
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- functional --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -86,16 +86,15 @@ inline namespace fundamentals_v1 {
 
 */
 
+#include <__debug>
 #include <__memory/uses_allocator.h>
+#include <algorithm>
+#include <array>
 #include <experimental/__config>
 #include <functional>
-#include <algorithm>
 #include <type_traits>
-#include <vector>
-#include <array>
 #include <unordered_map>
-
-#include <__debug>
+#include <vector>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -104,7 +103,6 @@ inline namespace fundamentals_v1 {
 _LIBCPP_PUSH_MACROS
 #include <__undef_macros>
 
-
 _LIBCPP_BEGIN_NAMESPACE_LFTS
 
 #if _LIBCPP_STD_VER > 11
lib/libcxx/include/experimental/iterator
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------------- iterator -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -52,15 +52,18 @@ namespace std {
 
 */
 
-#include <experimental/__config>
-
-#if _LIBCPP_STD_VER > 11
-
 #include <__memory/addressof.h>
-#include <__utility/move.h>
 #include <__utility/forward.h>
+#include <__utility/move.h>
+#include <experimental/__config>
 #include <iterator>
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 11
+
 _LIBCPP_BEGIN_NAMESPACE_LFTS
 
 template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
@@ -111,6 +114,6 @@ make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
 
 _LIBCPP_END_NAMESPACE_LFTS
 
-#endif /* _LIBCPP_STD_VER > 11 */
+#endif // _LIBCPP_STD_VER > 11
 
 #endif // _LIBCPP_EXPERIMENTAL_ITERATOR
lib/libcxx/include/experimental/list
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- list ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -29,8 +29,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <list>
 #include <experimental/memory_resource>
+#include <list>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/experimental/map
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------------- map ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -34,8 +34,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <map>
 #include <experimental/memory_resource>
+#include <map>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/experimental/memory_resource
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ memory_resource -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -64,18 +64,18 @@ namespace pmr {
 
  */
 
+#include <__debug>
+#include <__tuple>
+#include <cstddef>
+#include <cstdlib>
 #include <experimental/__config>
 #include <experimental/__memory>
 #include <limits>
 #include <memory>
 #include <new>
 #include <stdexcept>
-#include <__tuple>
 #include <type_traits>
 #include <utility>
-#include <cstddef>
-#include <cstdlib>
-#include <__debug>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -183,11 +183,8 @@ public:
     // 8.6.3, memory.polymorphic.allocator.mem
     _LIBCPP_INLINE_VISIBILITY
     _ValueType* allocate(size_t __n) {
-        if (__n > __max_size()) {
-            __throw_length_error(
-                "std::experimental::pmr::polymorphic_allocator<T>::allocate(size_t n)"
-                " 'n' exceeds maximum supported size");
-        }
+        if (__n > __max_size())
+            __throw_bad_array_new_length();
         return static_cast<_ValueType*>(
             __res_->allocate(__n * sizeof(_ValueType), _LIBCPP_ALIGNOF(_ValueType))
         );
@@ -384,11 +381,8 @@ public:
 private:
     virtual void * do_allocate(size_t __bytes, size_t)
     {
-        if (__bytes > __max_size()) {
-            __throw_length_error(
-                "std::experimental::pmr::resource_adaptor<T>::do_allocate(size_t bytes, size_t align)"
-                " 'bytes' exceeds maximum supported size");
-        }
+        if (__bytes > __max_size())
+            __throw_bad_array_new_length();
         size_t __s = __aligned_allocation_size(__bytes, _MaxAlign) / _MaxAlign;
         return __alloc_.allocate(__s);
     }
lib/libcxx/include/experimental/propagate_const
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ propagate_const -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -107,19 +107,18 @@
 */
 
 #include <experimental/__config>
+#include <functional>
+#include <type_traits>
+#include <utility>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
 #if _LIBCPP_STD_VER > 11
 
-#include <type_traits>
-#include <utility>
-#include <functional>
-
 _LIBCPP_BEGIN_NAMESPACE_LFTS_V2
 
-
 template <class _Tp>
 class propagate_const;
 
lib/libcxx/include/experimental/regex
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------------- regex ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -36,9 +36,9 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <regex>
-#include <experimental/string>
 #include <experimental/memory_resource>
+#include <experimental/string>
+#include <regex>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -52,9 +52,11 @@ using match_results =
         polymorphic_allocator<_VSTD::sub_match<_BiDirIter>>>;
 
 typedef match_results<const char*> cmatch;
-typedef match_results<const wchar_t*> wcmatch;
 typedef match_results<_VSTD_LFTS_PMR::string::const_iterator> smatch;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+typedef match_results<const wchar_t*> wcmatch;
 typedef match_results<_VSTD_LFTS_PMR::wstring::const_iterator> wsmatch;
+#endif
 
 _LIBCPP_END_NAMESPACE_LFTS_PMR
 
lib/libcxx/include/experimental/set
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- list ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -34,8 +34,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <set>
 #include <experimental/memory_resource>
+#include <set>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/experimental/simd
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------------- simd ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -649,10 +649,10 @@ public:
 
 */
 
-#include <experimental/__config>
 #include <algorithm>
 #include <array>
 #include <cstddef>
+#include <experimental/__config>
 #include <functional>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -689,7 +689,7 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> {
   friend struct simd_mask;
 
 public:
-  _Tp __get(size_t __index) const noexcept { return __storage_[__index]; };
+  _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }
   void __set(size_t __index, _Tp __val) noexcept {
     __storage_[__index] = __val;
   }
@@ -706,7 +706,7 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> {
   friend struct simd_mask;
 
 public:
-  _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; };
+  _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; }
   void __set(size_t __index, _Tp __val) noexcept {
     (&__storage_)[__index] = __val;
   }
@@ -770,7 +770,7 @@ struct __vec_ext_traits {
   _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 29);                                       \
   _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 30);                                       \
   _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 31);                                       \
-  _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32);
+  _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32)
 
 _LIBCPP_SPECIALIZE_VEC_EXT_32(char);
 _LIBCPP_SPECIALIZE_VEC_EXT_32(char16_t);
@@ -808,7 +808,7 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> {
   friend struct simd_mask;
 
 public:
-  _Tp __get(size_t __index) const noexcept { return __storage_[__index]; };
+  _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }
   void __set(size_t __index, _Tp __val) noexcept {
     __storage_[__index] = __val;
   }
@@ -963,7 +963,7 @@ template <int _Np>
 using fixed_size = __simd_abi<_StorageKind::_Array, _Np>;
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr size_t max_fixed_size = 32;
+inline constexpr size_t max_fixed_size = 32;
 
 template <class _Tp>
 using compatible = fixed_size<16 / sizeof(_Tp)>;
@@ -990,10 +990,10 @@ struct element_aligned_tag {};
 struct vector_aligned_tag {};
 template <size_t>
 struct overaligned_tag {};
-_LIBCPP_INLINE_VAR constexpr element_aligned_tag element_aligned{};
-_LIBCPP_INLINE_VAR constexpr vector_aligned_tag vector_aligned{};
+inline constexpr element_aligned_tag element_aligned{};
+inline constexpr vector_aligned_tag vector_aligned{};
 template <size_t _Np>
-_LIBCPP_INLINE_VAR constexpr overaligned_tag<_Np> overaligned{};
+inline constexpr overaligned_tag<_Np> overaligned{};
 
 // traits [simd.traits]
 template <class _Tp>
@@ -1032,14 +1032,13 @@ struct is_simd_flag_type<overaligned_tag<_Align>>
     : std::integral_constant<bool, true> {};
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
+inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool is_simd_v = is_simd<_Tp>::value;
+inline constexpr bool is_simd_v = is_simd<_Tp>::value;
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
+inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool is_simd_flag_type_v =
-    is_simd_flag_type<_Tp>::value;
+inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value;
 template <class _Tp, size_t _Np>
 struct abi_for_size {
   using type = simd_abi::fixed_size<_Np>;
@@ -1064,11 +1063,10 @@ template <class _Tp, class _Up = typename _Tp::value_type>
 struct memory_alignment;
 
 template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
-_LIBCPP_INLINE_VAR constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
+inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
 
 template <class _Tp, class _Up = typename _Tp::value_type>
-_LIBCPP_INLINE_VAR constexpr size_t memory_alignment_v =
-    memory_alignment<_Tp, _Up>::value;
+inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
 
 // class template simd [simd.class]
 template <class _Tp>
lib/libcxx/include/experimental/string
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- string ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -38,8 +38,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <string>
 #include <experimental/memory_resource>
+#include <string>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -54,7 +54,9 @@ using basic_string =
 typedef basic_string<char> string;
 typedef basic_string<char16_t> u16string;
 typedef basic_string<char32_t> u32string;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 typedef basic_string<wchar_t> wstring;
+#endif
 
 _LIBCPP_END_NAMESPACE_LFTS_PMR
 
lib/libcxx/include/experimental/type_traits
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- type_traits -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/experimental/unordered_map
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------- unordered_map ------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -40,8 +40,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <unordered_map>
 #include <experimental/memory_resource>
+#include <unordered_map>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/experimental/unordered_set
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------- unordered_set ------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -34,8 +34,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <unordered_set>
 #include <experimental/memory_resource>
+#include <unordered_set>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/experimental/utility
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- utility ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/experimental/vector
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- vector ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -29,8 +29,8 @@ namespace pmr {
  */
 
 #include <experimental/__config>
-#include <vector>
 #include <experimental/memory_resource>
+#include <vector>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/ext/__hash
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------- hash_set ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -13,8 +13,8 @@
 #pragma GCC system_header
 
 #include <__string>
-#include <string>
 #include <cstring>
+#include <string>
 
 namespace __gnu_cxx {
 
@@ -129,6 +129,6 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
         return __c;
     }
 };
-}
+} // namespace __gnu_cxx
 
 #endif // _LIBCPP_EXT_HASH
lib/libcxx/include/ext/hash_map
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- hash_map ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -203,10 +203,10 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
 
 #include <__config>
 #include <__hash_table>
+#include <ext/__hash>
 #include <functional>
 #include <stdexcept>
 #include <type_traits>
-#include <ext/__hash>
 
 #if defined(__DEPRECATED) && __DEPRECATED
 #if defined(_LIBCPP_WARNING)
@@ -979,6 +979,6 @@ operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
     return !(__x == __y);
 }
 
-} // __gnu_cxx
+} // namespace __gnu_cxx
 
 #endif // _LIBCPP_HASH_MAP
lib/libcxx/include/ext/hash_set
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------- hash_set ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -194,8 +194,8 @@ template <class Value, class Hash, class Pred, class Alloc>
 
 #include <__config>
 #include <__hash_table>
-#include <functional>
 #include <ext/__hash>
+#include <functional>
 
 #if defined(__DEPRECATED) && __DEPRECATED
 #if defined(_LIBCPP_WARNING)
@@ -205,6 +205,10 @@ template <class Value, class Hash, class Pred, class Alloc>
 #endif
 #endif
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
 namespace __gnu_cxx {
 
 
@@ -654,6 +658,6 @@ operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
     return !(__x == __y);
 }
 
-} // __gnu_cxx
+} // namespace __gnu_cxx
 
 #endif // _LIBCPP_HASH_SET
lib/libcxx/include/__availability
@@ -129,6 +129,10 @@
     // This controls the availability of std::to_chars.
 #   define _LIBCPP_AVAILABILITY_TO_CHARS
 
+    // This controls the availability of floating-point std::to_chars functions.
+    // These overloads were added later than the integer overloads.
+#   define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+
     // This controls the availability of the C++20 synchronization library,
     // which requires shared library support for various operations
     // (see libcxx/src/atomic.cpp).
@@ -139,9 +143,9 @@
 // #   define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore
 
     // This controls the availability of the C++20 format library.
-    // The library is in development and not ABI stable yet. Currently
-    // P2216 is aiming to be retroactively accepted in C++20. This paper
-    // contains ABI breaking changes.
+    // The library is in development and not ABI stable yet. P2216 is
+    // retroactively accepted in C++20. This paper contains ABI breaking
+    // changes.
 #   define _LIBCPP_AVAILABILITY_FORMAT
 // #   define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format
 
@@ -222,6 +226,9 @@
 #   define _LIBCPP_AVAILABILITY_TO_CHARS                                        \
         _LIBCPP_AVAILABILITY_FILESYSTEM
 
+#   define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT                         \
+        __attribute__((unavailable))
+
 #   define _LIBCPP_AVAILABILITY_SYNC                                            \
         __attribute__((availability(macosx,strict,introduced=11.0)))            \
         __attribute__((availability(ios,strict,introduced=14.0)))               \
@@ -238,9 +245,9 @@
 #   endif
 
     // This controls the availability of the C++20 format library.
-    // The library is in development and not ABI stable yet. Currently
-    // P2216 is aiming to be retroactively accepted in C++20. This paper
-    // contains ABI breaking changes.
+    // The library is in development and not ABI stable yet. P2216 is
+    // retroactively accepted in C++20. This paper contains ABI breaking
+    // changes.
 #   define _LIBCPP_AVAILABILITY_FORMAT                                          \
         __attribute__((unavailable))
 #   define _LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format
lib/libcxx/include/__bit_reference
@@ -10,8 +10,8 @@
 #ifndef _LIBCPP___BIT_REFERENCE
 #define _LIBCPP___BIT_REFERENCE
 
-#include <__config>
 #include <__bits>
+#include <__config>
 #include <algorithm>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__bsd_locale_defaults.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------- __bsd_locale_defaults.h -----------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/__bsd_locale_fallbacks.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------- __bsd_locale_fallbacks.h ----------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -30,6 +30,7 @@ decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
     return MB_CUR_MAX;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 inline _LIBCPP_INLINE_VISIBILITY
 wint_t __libcpp_btowc_l(int __c, locale_t __l)
 {
@@ -88,6 +89,7 @@ size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t
     __libcpp_locale_guard __current(__l);
     return mbrlen(__s, __n, __ps);
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 inline _LIBCPP_INLINE_VISIBILITY
 lconv *__libcpp_localeconv_l(locale_t __l)
@@ -96,6 +98,7 @@ lconv *__libcpp_localeconv_l(locale_t __l)
     return localeconv();
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
                      mbstate_t *__ps, locale_t __l)
@@ -103,8 +106,9 @@ size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
     __libcpp_locale_guard __current(__l);
     return mbsrtowcs(__dest, __src, __len, __ps);
 }
+#endif
 
-inline
+inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5)
 int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
     va_list __va;
     va_start(__va, __format);
@@ -114,7 +118,7 @@ int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__forma
     return __res;
 }
 
-inline
+inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
 int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
     va_list __va;
     va_start(__va, __format);
@@ -124,7 +128,7 @@ int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
     return __res;
 }
 
-inline
+inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4)
 int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
     va_list __va;
     va_start(__va, __format);
lib/libcxx/include/__config
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- __config ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,6 +10,8 @@
 #ifndef _LIBCPP_CONFIG
 #define _LIBCPP_CONFIG
 
+#include <__config_site>
+
 #if defined(_MSC_VER) && !defined(__clang__)
 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #    define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
@@ -22,17 +24,7 @@
 
 #ifdef __cplusplus
 
-#ifdef __GNUC__
-#  define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
-// The _GNUC_VER_NEW macro better represents the new GCC versioning scheme
-// introduced in GCC 5.0.
-#  define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__)
-#else
-#  define _GNUC_VER 0
-#  define _GNUC_VER_NEW 0
-#endif
-
-#define _LIBCPP_VERSION 13000
+#define _LIBCPP_VERSION 14000
 
 #ifndef _LIBCPP_ABI_VERSION
 #  define _LIBCPP_ABI_VERSION 1
@@ -82,14 +74,15 @@
 #  define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
 #  define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
 #  define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
-// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr
-// provided under the alternate keyword __nullptr, which changes the mangling
-// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode.
-#  define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
 // Define a key function for `bad_function_call` in the library, to centralize
 // its vtable and typeinfo to libc++ rather than having all other libraries
 // using that class define their own copies.
 #  define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
+// Override the default return value of exception::what() for
+// bad_function_call::what() with a string that is specific to
+// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
+// because it changes the vtable layout of bad_function_call.
+#  define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
 // Enable optimized version of __do_get_(un)signed which avoids redundant copies.
 #  define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
 // In C++20 and later, don't derive std::plus from std::binary_function,
@@ -114,6 +107,17 @@
 #  define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
 // Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
 #  define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
+// std::random_device holds some state when it uses an implementation that gets
+// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
+// implementation to another one on a platform that has already shipped
+// std::random_device, one needs to retain the same object layout to remain ABI
+// compatible. This switch removes these workarounds for platforms that don't care
+// about ABI compatibility.
+#  define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
+// Remove basic_string common base
+#  define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
+// Remove vector base class
+#  define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
 #elif _LIBCPP_ABI_VERSION == 1
 #  if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
 // Enable compiling copies of now inline methods into the dylib to support
@@ -125,16 +129,38 @@
 #  endif
 // Feature macros for disabling pre ABI v1 features. All of these options
 // are deprecated.
-#  if defined(__FreeBSD__) || defined(__DragonFly__)
+#  if defined(__FreeBSD__)
 #    define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
 #  endif
 #endif
 
+// By default, don't use a nullptr_t emulation type in C++03.
+//
+// This is technically an ABI break from previous releases, however it is
+// very unlikely to impact anyone. If a user is impacted by this break,
+// they can return to using the C++03 nullptr emulation by defining
+// _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION.
+//
+// This switch will be removed entirely in favour of never providing a
+// C++03 emulation after one release.
+//
+// IMPORTANT: IF YOU ARE READING THIS AND YOU TURN THIS MACRO ON, PLEASE LEAVE
+//            A COMMENT ON https://reviews.llvm.org/D109459 OR YOU WILL BE BROKEN
+//            IN THE FUTURE WHEN WE REMOVE THE ABILITY TO USE THE C++03 EMULATION.
+#ifndef _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION
+# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
+#endif
+
 #if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
 // Enable additional explicit instantiations of iostreams components. This
 // reduces the number of weak definitions generated in programs that use
 // iostreams by providing a single strong definition in the shared library.
 # define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
+
+// Define a key function for `bad_function_call` in the library, to centralize
+// its vtable and typeinfo to libc++ rather than having all other libraries
+// using that class define their own copies.
+#  define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
 #endif
 
 #define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
@@ -235,6 +261,10 @@
 #  endif // defined(__GLIBC_PREREQ)
 #endif // defined(__linux__)
 
+#if defined(__MVS__)
+#  include <features.h> // for __NATIVE_ASCII_F
+#endif
+
 #ifdef __LITTLE_ENDIAN__
 #  if __LITTLE_ENDIAN__
 #    define _LIBCPP_LITTLE_ENDIAN
@@ -263,9 +293,6 @@
 #  else  // _BYTE_ORDER == _LITTLE_ENDIAN
 #    define _LIBCPP_BIG_ENDIAN
 #  endif  // _BYTE_ORDER == _LITTLE_ENDIAN
-#  ifndef __LONG_LONG_SUPPORTED
-#    define _LIBCPP_HAS_NO_LONG_LONG
-#  endif  // __LONG_LONG_SUPPORTED
 #endif // __FreeBSD__
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
@@ -316,18 +343,56 @@
 #  endif
 #endif // __sun__
 
-#if defined(__OpenBSD__) || defined(__CloudABI__)
-   // Certain architectures provide arc4random(). Prefer using
-   // arc4random() over /dev/{u,}random to make it possible to obtain
-   // random data even when using sandboxing mechanisms such as chroots,
-   // Capsicum, etc.
+#if defined(_AIX) && !defined(__64BIT__)
+   // The size of wchar is 2 byte on 32-bit mode on AIX.
+#  define _LIBCPP_SHORT_WCHAR   1
+#endif
+
+// Libc++ supports various implementations of std::random_device.
+//
+// _LIBCPP_USING_DEV_RANDOM
+//      Read entropy from the given file, by default `/dev/urandom`.
+//      If a token is provided, it is assumed to be the path to a file
+//      to read entropy from. This is the default behavior if nothing
+//      else is specified. This implementation requires storing state
+//      inside `std::random_device`.
+//
+// _LIBCPP_USING_ARC4_RANDOM
+//      Use arc4random(). This allows obtaining random data even when
+//      using sandboxing mechanisms. On some platforms like Apple, this
+//      is the recommended source of entropy for user-space programs.
+//      When this option is used, the token passed to `std::random_device`'s
+//      constructor *must* be "/dev/urandom" -- anything else is an error.
+//
+// _LIBCPP_USING_GETENTROPY
+//      Use getentropy().
+//      When this option is used, the token passed to `std::random_device`'s
+//      constructor *must* be "/dev/urandom" -- anything else is an error.
+//
+// _LIBCPP_USING_FUCHSIA_CPRNG
+//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
+//      deliver high-quality entropy and cannot fail.
+//      When this option is used, the token passed to `std::random_device`'s
+//      constructor *must* be "/dev/urandom" -- anything else is an error.
+//
+// _LIBCPP_USING_NACL_RANDOM
+//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
+//      including accesses to the special files under `/dev`. This implementation
+//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
+//      When this option is used, the token passed to `std::random_device`'s
+//      constructor *must* be "/dev/urandom" -- anything else is an error.
+//
+// _LIBCPP_USING_WIN32_RANDOM
+//      Use rand_s(), for use on Windows.
+//      When this option is used, the token passed to `std::random_device`'s
+//      constructor *must* be "/dev/urandom" -- anything else is an error.
+#if defined(__OpenBSD__) || defined(__APPLE__)
 #  define _LIBCPP_USING_ARC4_RANDOM
-#elif defined(__Fuchsia__) || defined(__wasi__)
+#elif defined(__wasi__)
 #  define _LIBCPP_USING_GETENTROPY
+#elif defined(__Fuchsia__)
+#  define _LIBCPP_USING_FUCHSIA_CPRNG
 #elif defined(__native_client__)
-   // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
-   // including accesses to the special files under /dev. C++11's
-   // std::random_device is instead exposed through a NaCl syscall.
 #  define _LIBCPP_USING_NACL_RANDOM
 #elif defined(_LIBCPP_WIN32API)
 #  define _LIBCPP_USING_WIN32_RANDOM
@@ -380,7 +445,7 @@
 #    if __ANDROID_API__ >= 29
 #      define _LIBCPP_HAS_TIMESPEC_GET
 #    endif
-#  elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__) || defined(__DragonFly__)
+#  elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
 #    define _LIBCPP_HAS_ALIGNED_ALLOC
 #    define _LIBCPP_HAS_QUICK_EXIT
 #    define _LIBCPP_HAS_TIMESPEC_GET
@@ -490,14 +555,6 @@ typedef __char32_t char32_t;
 #  define _LIBCPP_HAS_BLOCKS_RUNTIME
 #endif
 
-#if !(__has_feature(cxx_relaxed_constexpr))
-#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
-#endif
-
-#if !(__has_feature(cxx_variable_templates))
-#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
-#endif
-
 #if !(__has_feature(cxx_noexcept))
 #define _LIBCPP_HAS_NO_NOEXCEPT
 #endif
@@ -511,26 +568,8 @@ typedef __char32_t char32_t;
 #define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
 #endif
 
-#if __has_builtin(__builtin_launder)
-#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
-#endif
-
-#if __has_builtin(__builtin_constant_p)
-#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
-#endif
-
-#if !__is_identifier(__has_unique_object_representations)
-#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
-#endif
-
 #define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
 
-// Literal operators ""d and ""y are supported starting with LLVM Clang 8 and AppleClang 10.0.1
-#if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) ||                 \
-    (defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1001)
-#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS
-#endif
-
 #define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
 
 #elif defined(_LIBCPP_COMPILER_GCC)
@@ -544,26 +583,10 @@ typedef __char32_t char32_t;
 #  define _LIBCPP_NO_EXCEPTIONS
 #endif
 
-// Determine if GCC supports relaxed constexpr
-#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L
-#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
-#endif
-
-// GCC 5 supports variable templates
-#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L
-#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
-#endif
-
 #if !defined(__SANITIZE_ADDRESS__)
 #define _LIBCPP_HAS_NO_ASAN
 #endif
 
-#if _GNUC_VER >= 700
-#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
-#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
-#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
-#endif
-
 #define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
 
 #define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
@@ -578,8 +601,6 @@ typedef __char32_t char32_t;
 #error "MSVC versions prior to Visual Studio 2015 are not supported"
 #endif
 
-#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
-#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
 #define __alignof__ __alignof
 #define _LIBCPP_NORETURN __declspec(noreturn)
 #define _ALIGNAS(x) __declspec(align(x))
@@ -603,7 +624,6 @@ typedef __char32_t char32_t;
 #define _LIBCPP_NORETURN __attribute__((noreturn))
 
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
-#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
 
 #if defined(_AIX)
 #define __MULTILOCALE_API
@@ -803,10 +823,10 @@ typedef __char32_t char32_t;
 // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
 #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
 #define _LIBCPP_END_NAMESPACE_STD  } }
-#define _VSTD std::_LIBCPP_ABI_NAMESPACE
+#define _VSTD std
 _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER >= 17
+#if _LIBCPP_STD_VER > 14
 #define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
   _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
 #else
@@ -834,7 +854,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
 #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
 typedef unsigned short char16_t;
 typedef unsigned int   char32_t;
-#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
+#endif
 
 #ifndef __SIZEOF_INT128__
 #define _LIBCPP_HAS_NO_INT128
@@ -857,26 +877,10 @@ typedef unsigned int   char32_t;
 #  define _LIBCPP_CONSTEVAL consteval
 #endif
 
-#if !defined(__cpp_concepts) || __cpp_concepts < 201907L
+#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_concepts) || __cpp_concepts < 201907L
 #define _LIBCPP_HAS_NO_CONCEPTS
 #endif
 
-#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_HAS_NO_CONCEPTS)
-#define _LIBCPP_HAS_NO_RANGES
-#endif
-
-#ifdef _LIBCPP_CXX03_LANG
-#  define _LIBCPP_DEFAULT {}
-#else
-#  define _LIBCPP_DEFAULT = default;
-#endif
-
-#ifdef _LIBCPP_CXX03_LANG
-#  define _LIBCPP_EQUAL_DELETE
-#else
-#  define _LIBCPP_EQUAL_DELETE = delete
-#endif
-
 #ifdef __GNUC__
 #  define _LIBCPP_NOALIAS __attribute__((__malloc__))
 #else
@@ -905,16 +909,35 @@ typedef unsigned int   char32_t;
 // _LIBCPP_DEBUG potential values:
 //  - undefined: No assertions. This is the default.
 //  - 0:         Basic assertions
-//  - 1:         Basic assertions + iterator validity checks.
-#if !defined(_LIBCPP_DEBUG)
-# define _LIBCPP_DEBUG_LEVEL 0
-#elif _LIBCPP_DEBUG == 0
-# define _LIBCPP_DEBUG_LEVEL 1
-#elif _LIBCPP_DEBUG == 1
-# define _LIBCPP_DEBUG_LEVEL 2
-#else
-# error Supported values for _LIBCPP_DEBUG are 0 and 1
-#endif
+//  - 1:         Basic assertions + iterator validity checks + unspecified behavior randomization.
+#  if !defined(_LIBCPP_DEBUG)
+#    define _LIBCPP_DEBUG_LEVEL 0
+#  elif _LIBCPP_DEBUG == 0
+#    define _LIBCPP_DEBUG_LEVEL 1
+#  elif _LIBCPP_DEBUG == 1
+#    define _LIBCPP_DEBUG_LEVEL 2
+#  else
+#    error Supported values for _LIBCPP_DEBUG are 0 and 1
+#  endif
+
+#  if _LIBCPP_DEBUG_LEVEL >= 2 && !defined(_LIBCPP_CXX03_LANG)
+#    define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
+#  endif
+
+#  if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
+#    if defined(_LIBCPP_CXX03_LANG)
+#      error Support for unspecified stability is only for C++11 and higher
+#    endif
+#    define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last)                                                             \
+      do {                                                                                                             \
+        if (!__builtin_is_constant_evaluated())                                                                        \
+          _VSTD::shuffle(__first, __last, __libcpp_debug_randomizer());                                                \
+      } while (false)
+#  else
+#    define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last)                                                             \
+      do {                                                                                                             \
+      } while (false)
+#  endif
 
 // Libc++ allows disabling extern template instantiation declarations by
 // means of users defining _LIBCPP_DISABLE_EXTERN_TEMPLATE.
@@ -938,11 +961,11 @@ typedef unsigned int   char32_t;
 #endif
 
 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
-    defined(__sun__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CloudABI__)
+    defined(__sun__) || defined(__NetBSD__)
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#ifdef __FreeBSD__
 #define _DECLARE_C99_LDBL_MATH 1
 #endif
 
@@ -958,23 +981,16 @@ typedef unsigned int   char32_t;
 #  define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
 #endif
 
-#if defined(__APPLE__)
-#  if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
-      defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
-#    define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
-#  endif
-#endif // defined(__APPLE__)
-
 #if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
     (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
 #  define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
 #endif
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #define _LIBCPP_HAS_DEFAULTRUNELOCALE
 #endif
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__sun__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
 #define _LIBCPP_WCTYPE_IS_MASK
 #endif
 
@@ -1047,64 +1063,50 @@ typedef unsigned int   char32_t;
 #  define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
 #endif
 
-#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
+#if _LIBCPP_STD_VER > 11
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
 #else
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX11
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
+#if _LIBCPP_STD_VER > 14
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
 #else
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX14
 #endif
 
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
+#if _LIBCPP_STD_VER > 17
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
 #else
 #  define _LIBCPP_CONSTEXPR_AFTER_CXX17
 #endif
 
-// The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other
-// NODISCARD macros to the correct attribute.
 #if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
-#  define _LIBCPP_NODISCARD_ATTRIBUTE [[nodiscard]]
+#  define _LIBCPP_NODISCARD [[nodiscard]]
 #elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
-#  define _LIBCPP_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]]
+#  define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
 #else
 // We can't use GCC's [[gnu::warn_unused_result]] and
 // __attribute__((warn_unused_result)), because GCC does not silence them via
 // (void) cast.
-#  define _LIBCPP_NODISCARD_ATTRIBUTE
+#  define _LIBCPP_NODISCARD
 #endif
 
 // _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
 // specified as such as an extension.
 #if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
-#  define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD_ATTRIBUTE
+#  define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
 #else
 #  define _LIBCPP_NODISCARD_EXT
 #endif
 
 #if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
     (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
-#  define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD_ATTRIBUTE
+#  define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
 #else
 #  define _LIBCPP_NODISCARD_AFTER_CXX17
 #endif
 
-#if _LIBCPP_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L)
-#  define _LIBCPP_INLINE_VAR inline
-#else
-#  define _LIBCPP_INLINE_VAR
-#endif
-
-#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
-#   define _LIBCPP_CONSTEXPR_IF_NODEBUG
-#else
-#   define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr
-#endif
-
 #if __has_attribute(no_destroy)
 #  define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
 #else
@@ -1138,16 +1140,13 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
       defined(__wasi__) || \
       defined(__NetBSD__) || \
       defined(__OpenBSD__) || \
-      defined(__DragonFly__) || \
       defined(__NuttX__) || \
       defined(__linux__) || \
       defined(__GNU__) || \
       defined(__APPLE__) || \
-      defined(__CloudABI__) || \
       defined(__sun__) || \
       defined(__MVS__) || \
-      defined(_AIX) || \
-      (defined(__MINGW32__) && __has_include(<pthread.h>))
+      defined(_AIX)
 #    define _LIBCPP_HAS_THREAD_API_PTHREAD
 #  elif defined(__Fuchsia__)
      // TODO(44575): Switch to C11 thread API when possible.
@@ -1217,21 +1216,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
 #endif
 
-// Systems that use capability-based security (FreeBSD with Capsicum,
-// Nuxi CloudABI) may only provide local filesystem access (using *at()).
-// Functions like open(), rename(), unlink() and stat() should not be
-// used, as they attempt to access the global filesystem namespace.
-#ifdef __CloudABI__
-#define _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
-#endif
-
-// CloudABI is intended for running networked services. Processes do not
-// have standard input and output channels.
-#ifdef __CloudABI__
-#define _LIBCPP_HAS_NO_STDIN
-#define _LIBCPP_HAS_NO_STDOUT
-#endif
-
 // Some systems do not provide gets() in their C library, for security reasons.
 #if defined(_LIBCPP_MSVCRT) || \
     (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \
@@ -1239,28 +1223,21 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #   define _LIBCPP_C_HAS_NO_GETS
 #endif
 
-#if defined(__BIONIC__) || defined(__CloudABI__) || defined(__NuttX__) ||      \
-    defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) || \
-    defined(__MVS__) || defined(__OpenBSD__)
+#if defined(__BIONIC__) || defined(__NuttX__) ||           \
+    defined(__Fuchsia__) || defined(__wasi__) ||           \
+    defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
 #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
 #endif
 
-// Thread-unsafe functions such as strtok() and localtime()
-// are not available.
-#ifdef __CloudABI__
-#define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
-#endif
-
 #if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
 #  define _LIBCPP_HAS_C_ATOMIC_IMP
 #elif defined(_LIBCPP_COMPILER_GCC)
 #  define _LIBCPP_HAS_GCC_ATOMIC_IMP
 #endif
 
-#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
-     !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
-     !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)) \
-     || defined(_LIBCPP_HAS_NO_THREADS)
+#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
+    !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
+    !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
 #  define _LIBCPP_HAS_NO_ATOMIC_HEADER
 #else
 #  ifndef _LIBCPP_ATOMIC_FLAG_TYPE
@@ -1279,8 +1256,9 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #  if defined(__clang__) && __has_attribute(acquire_capability)
 // Work around the attribute handling in clang.  When both __declspec and
 // __attribute__ are present, the processing goes awry preventing the definition
-// of the types.
-#    if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
+// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
+// combining the two does work.
+#    if !defined(_MSC_VER)
 #      define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
 #    endif
 #  endif
@@ -1298,14 +1276,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #  define _LIBCPP_SAFE_STATIC
 #endif
 
-#if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700
-#define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
-#endif
-
-#if !__has_builtin(__builtin_is_constant_evaluated) && _GNUC_VER < 900
-#define _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
-#endif
-
 #if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
 #  define _LIBCPP_DIAGNOSE_WARNING(...) \
      __attribute__((diagnose_if(__VA_ARGS__, "warning")))
@@ -1321,7 +1291,7 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #  define _LIBCPP_FALLTHROUGH() [[fallthrough]]
 #elif __has_cpp_attribute(clang::fallthrough)
 #  define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
-#elif __has_attribute(fallthrough) || _GNUC_VER >= 700
+#elif __has_attribute(__fallthrough__)
 #  define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
 #else
 #  define _LIBCPP_FALLTHROUGH() ((void)0)
@@ -1333,12 +1303,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #define _LIBCPP_NODEBUG
 #endif
 
-#if __has_attribute(__nodebug__) && (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 900)
-#   define _LIBCPP_NODEBUG_TYPE __attribute__((nodebug))
-#else
-#   define _LIBCPP_NODEBUG_TYPE
-#endif
-
 #if __has_attribute(__standalone_debug__)
 #define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
 #else
@@ -1351,6 +1315,16 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #define _LIBCPP_PREFERRED_NAME(x)
 #endif
 
+// We often repeat things just for handling wide characters in the library.
+// When wide characters are disabled, it can be useful to have a quick way of
+// disabling it without having to resort to #if-#endif, which has a larger
+// impact on readability.
+#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
+# define _LIBCPP_IF_WIDE_CHARACTERS(...)
+#else
+# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
+#endif
+
 #if defined(_LIBCPP_ABI_MICROSOFT) && \
     (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
 #  define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
@@ -1373,20 +1347,8 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
 #endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
 
-#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611
-#define _LIBCPP_HAS_NO_DEDUCTION_GUIDES
-#endif
-
-#if !__has_keyword(__is_aggregate) && (_GNUC_VER_NEW < 7001)
-#define _LIBCPP_HAS_NO_IS_AGGREGATE
-#endif
-
-#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
-#define _LIBCPP_HAS_NO_COROUTINES
-#endif
-
-#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201907L
-#define _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
+#if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
+#define _LIBCPP_HAS_NO_CXX20_COROUTINES
 #endif
 
 #if defined(_LIBCPP_COMPILER_IBM)
@@ -1440,12 +1402,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #  define _LIBCPP_FOPEN_CLOEXEC_MODE
 #endif
 
-#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
-#define _LIBCPP_BUILTIN_CONSTANT_P(x) __builtin_constant_p(x)
-#else
-#define _LIBCPP_BUILTIN_CONSTANT_P(x) false
-#endif
-
 // Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
 // of functions used in cstdio may not be available for low API levels when
 // using 64-bit file offsets on LP32.
@@ -1454,16 +1410,24 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
 #endif
 
 #if __has_attribute(init_priority)
-# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
+    // TODO: Remove this once we drop support for building libc++ with old Clangs
+#   if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
+       (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
+#     define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
+#   else
+#     define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
+#   endif
 #else
 # define _LIBCPP_INIT_PRIORITY_MAX
 #endif
 
 #if defined(__GNUC__) || defined(__clang__)
-#define _LIBCPP_FORMAT_PRINTF(a, b)                                            \
-  __attribute__((__format__(__printf__, a, b)))
+  // The attribute uses 1-based indices for ordinary and static member functions.
+  // The attribute uses 2-based indices for non-static member functions.
+# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
+    __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
 #else
-#define _LIBCPP_FORMAT_PRINTF(a, b)
+# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
 #endif
 
 #endif // __cplusplus
lib/libcxx/include/__debug
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- __debug ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -12,6 +12,7 @@
 
 #include <__config>
 #include <iosfwd>
+#include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -22,9 +23,9 @@
 #endif
 
 #if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY)
-#   include <cstdlib>
-#   include <cstdio>
 #   include <cstddef>
+#   include <cstdio>
+#   include <cstdlib>
 #endif
 
 #if _LIBCPP_DEBUG_LEVEL == 0
@@ -34,7 +35,7 @@
 #   define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
 #   define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
 #elif _LIBCPP_DEBUG_LEVEL == 2
-#   define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m)
+#   define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(__libcpp_is_constant_evaluated() || (x), m)
 #   define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
 #else
 #   error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2
@@ -268,6 +269,26 @@ _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
 
 #endif // _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY)
 
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_c(_Tp* __c) {
+#if _LIBCPP_DEBUG_LEVEL == 2
+    if (!__libcpp_is_constant_evaluated())
+        __get_db()->__insert_c(__c);
+#else
+    (void)(__c);
+#endif
+}
+
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_i(_Tp* __i) {
+#if _LIBCPP_DEBUG_LEVEL == 2
+    if (!__libcpp_is_constant_evaluated())
+        __get_db()->__insert_i(__i);
+#else
+    (void)(__i);
+#endif
+}
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP_DEBUG_H
lib/libcxx/include/__errc
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- __errc ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/__function_like.h
@@ -1,56 +0,0 @@
-// -*- 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___ITERATOR_FUNCTION_LIKE_H
-#define _LIBCPP___ITERATOR_FUNCTION_LIKE_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
-
-#if !defined(_LIBCPP_HAS_NO_RANGES)
-
-namespace ranges {
-// Per [range.iter.ops.general] and [algorithms.requirements], functions in namespace std::ranges
-// can't be found by ADL and inhibit ADL when found by unqualified lookup. The easiest way to
-// facilitate this is to use function objects.
-//
-// Since these are still standard library functions, we use `__function_like` to eliminate most of
-// the properties that function objects get by default (e.g. semiregularity, addressability), to
-// limit the surface area of the unintended public interface, so as to curb the effect of Hyrum's
-// law.
-struct __function_like {
-  __function_like() = delete;
-  __function_like(__function_like const&) = delete;
-  __function_like& operator=(__function_like const&) = delete;
-
-  void operator&() const = delete;
-
-  struct __tag { };
-
-protected:
-  constexpr explicit __function_like(__tag) noexcept {}
-  ~__function_like() = default;
-};
-} // namespace ranges
-
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
-
-_LIBCPP_END_NAMESPACE_STD
-
-_LIBCPP_POP_MACROS
-
-#endif // _LIBCPP___ITERATOR_FUNCTION_LIKE_H
lib/libcxx/include/__hash_table
@@ -288,9 +288,7 @@ public:
     typedef typename _NodeTypes::__node_value_type_pointer pointer;
 
     _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_i(this);
-#endif
+        _VSTD::__debug_db_insert_i(this);
     }
 
 #if _LIBCPP_DEBUG_LEVEL == 2
@@ -298,7 +296,7 @@ public:
     __hash_iterator(const __hash_iterator& __i)
         : __node_(__i.__node_)
     {
-        __get_db()->__iterator_copy(this, &__i);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -310,9 +308,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __hash_iterator& operator=(const __hash_iterator& __i)
     {
-        if (this != &__i)
+        if (this != _VSTD::addressof(__i))
         {
-            __get_db()->__iterator_copy(this, &__i);
+            __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
             __node_ = __i.__node_;
         }
         return *this;
@@ -400,9 +398,7 @@ public:
 
 
     _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_i(this);
-#endif
+        _VSTD::__debug_db_insert_i(this);
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -410,7 +406,7 @@ public:
         : __node_(__x.__node_)
     {
 #if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__iterator_copy(this, &__x);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
 #endif
     }
 
@@ -419,7 +415,7 @@ public:
     __hash_const_iterator(const __hash_const_iterator& __i)
         : __node_(__i.__node_)
     {
-        __get_db()->__iterator_copy(this, &__i);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -431,9 +427,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __hash_const_iterator& operator=(const __hash_const_iterator& __i)
     {
-        if (this != &__i)
+        if (this != _VSTD::addressof(__i))
         {
-            __get_db()->__iterator_copy(this, &__i);
+            __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
             __node_ = __i.__node_;
         }
         return *this;
@@ -517,9 +513,7 @@ public:
     typedef typename _NodeTypes::__node_value_type_pointer      pointer;
 
     _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_i(this);
-#endif
+        _VSTD::__debug_db_insert_i(this);
     }
 
 #if _LIBCPP_DEBUG_LEVEL == 2
@@ -529,7 +523,7 @@ public:
           __bucket_(__i.__bucket_),
           __bucket_count_(__i.__bucket_count_)
     {
-        __get_db()->__iterator_copy(this, &__i);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -541,9 +535,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __hash_local_iterator& operator=(const __hash_local_iterator& __i)
     {
-        if (this != &__i)
+        if (this != _VSTD::addressof(__i))
         {
-            __get_db()->__iterator_copy(this, &__i);
+            __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
             __node_ = __i.__node_;
             __bucket_ = __i.__bucket_;
             __bucket_count_ = __i.__bucket_count_;
@@ -651,9 +645,7 @@ public:
 
 
     _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_i(this);
-#endif
+        _VSTD::__debug_db_insert_i(this);
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -663,7 +655,7 @@ public:
           __bucket_count_(__x.__bucket_count_)
     {
 #if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__iterator_copy(this, &__x);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
 #endif
     }
 
@@ -674,7 +666,7 @@ public:
           __bucket_(__i.__bucket_),
           __bucket_count_(__i.__bucket_count_)
     {
-        __get_db()->__iterator_copy(this, &__i);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -686,9 +678,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
     {
-        if (this != &__i)
+        if (this != _VSTD::addressof(__i))
         {
-            __get_db()->__iterator_copy(this, &__i);
+            __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
             __node_ = __i.__node_;
             __bucket_ = __i.__bucket_;
             __bucket_count_ = __i.__bucket_count_;
@@ -1541,7 +1533,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
 __hash_table<_Tp, _Hash, _Equal, _Alloc>&
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
 {
-    if (this != &__u)
+    if (this != _VSTD::addressof(__u))
     {
         __copy_assign_alloc(__u);
         hash_function() = __u.hash_function();
@@ -1623,7 +1615,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
         __u.size() = 0;
     }
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->swap(this, &__u);
+    __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -2029,11 +2021,9 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
         const_iterator __p, __node_pointer __cp)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
-        " referring to this unordered container");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
+                         " referring to this unordered container");
     if (__p != end() && key_eq()(*__p, __cp->__value_))
     {
         __next_pointer __np = __p.__node_;
@@ -2158,11 +2148,9 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
         const_iterator __p, _Args&&... __args)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
-        " referring to this unordered container");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
+                         " referring to this unordered container");
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     iterator __r = __node_insert_multi(__p, __h.get());
     __h.release();
@@ -2348,7 +2336,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
             size_type __chash = __constrain_hash(__cp->__hash(), __nbc);
             __bucket_list_[__chash] = __pp;
             size_type __phash = __chash;
-            for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
+            for (__pp = __cp, void(), __cp = __cp->__next_; __cp != nullptr;
                                                            __cp = __pp->__next_)
             {
                 __chash = __constrain_hash(__cp->__hash(), __nbc);
@@ -2484,12 +2472,12 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
 {
     __next_pointer __np = __p.__node_;
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "unordered container erase(iterator) called with an iterator not"
+                         " referring to this container");
+    _LIBCPP_DEBUG_ASSERT(__p != end(),
+                         "unordered container erase(iterator) called with a non-dereferenceable iterator");
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "unordered container erase(iterator) called with an iterator not"
-        " referring to this container");
-    _LIBCPP_ASSERT(__p != end(),
-        "unordered container erase(iterator) called with a non-dereferenceable iterator");
     iterator __r(__np, this);
 #else
     iterator __r(__np);
@@ -2504,14 +2492,12 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
                                                 const_iterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
-        "unordered container::erase(iterator, iterator) called with an iterator not"
-        " referring to this container");
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
-        "unordered container::erase(iterator, iterator) called with an iterator not"
-        " referring to this container");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
+                         "unordered container::erase(iterator, iterator) called with an iterator not"
+                         " referring to this container");
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
+                         "unordered container::erase(iterator, iterator) called with an iterator not"
+                         " referring to this container");
     for (const_iterator __p = __first; __first != __last; __p = __first)
     {
         ++__first;
@@ -2741,7 +2727,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
         __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
             __u.__p1_.first().__ptr();
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->swap(this, &__u);
+    __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -2758,7 +2744,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
     {
         for (__np = __np->__next_; __np != nullptr &&
                                    __constrain_hash(__np->__hash(), __bc) == __n;
-                                                    __np = __np->__next_, ++__r)
+                                                    __np = __np->__next_, (void) ++__r)
             ;
     }
     return __r;
lib/libcxx/include/__libcpp_version
@@ -1,1 +1,1 @@
-13000
+14000
lib/libcxx/include/__locale
@@ -12,18 +12,17 @@
 
 #include <__availability>
 #include <__config>
-#include <string>
-#include <memory>
-#include <utility>
-#include <mutex>
-#include <cstdint>
 #include <cctype>
+#include <cstdint>
 #include <locale.h>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <utility>
+
 #if defined(_LIBCPP_MSVCRT_LIKE)
 # include <cstring>
 # include <__support/win32/locale_win32.h>
-#elif defined(__NuttX__)
-# include <__support/nuttx/xlocale.h>
 #elif defined(_AIX) || defined(__MVS__)
 # include <__support/ibm/xlocale.h>
 #elif defined(__ANDROID__)
@@ -35,7 +34,7 @@
 # include <__support/newlib/xlocale.h>
 #elif defined(__OpenBSD__)
 # include <__support/openbsd/xlocale.h>
-#elif (defined(__APPLE__)      || defined(__FreeBSD__) || defined(__DragonFly__) \
+#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
 # include <xlocale.h>
 #elif defined(__Fuchsia__)
@@ -210,10 +209,11 @@ class _LIBCPP_TYPE_VIS locale::id
     static int32_t __next_id;
 public:
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
+    void operator=(const id&) = delete;
+    id(const id&) = delete;
+
 private:
     void __init();
-    void operator=(const id&); // = delete;
-    id(const id&); // = delete;
 public:  // only needed for tests
     long __get();
 
@@ -340,7 +340,9 @@ collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
+#endif
 
 // template <class CharT> class collate_byname;
 
@@ -365,6 +367,7 @@ protected:
     virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
 };
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
     : public collate<wchar_t>
@@ -384,6 +387,7 @@ protected:
                            const char_type* __lo2, const char_type* __hi2) const;
     virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
 };
+#endif
 
 template <class _CharT, class _Traits, class _Allocator>
 bool
@@ -448,12 +452,12 @@ public:
     static const mask punct  = _PUNCT;
     static const mask xdigit = _HEX;
     static const mask blank  = _BLANK;
-    static const mask __regex_word = 0x80;
+    static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
-#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__DragonFly__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
 # ifdef __APPLE__
     typedef __uint32_t mask;
-# elif defined(__FreeBSD__) || defined(__DragonFly__)
+# elif defined(__FreeBSD__)
     typedef unsigned long mask;
 # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
     typedef unsigned short mask;
@@ -507,6 +511,33 @@ public:
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
+#elif defined(__MVS__)
+# if defined(__NATIVE_ASCII_F)
+    typedef unsigned int mask;
+    static const mask space  = _ISSPACE_A;
+    static const mask print  = _ISPRINT_A;
+    static const mask cntrl  = _ISCNTRL_A;
+    static const mask upper  = _ISUPPER_A;
+    static const mask lower  = _ISLOWER_A;
+    static const mask alpha  = _ISALPHA_A;
+    static const mask digit  = _ISDIGIT_A;
+    static const mask punct  = _ISPUNCT_A;
+    static const mask xdigit = _ISXDIGIT_A;
+    static const mask blank  = _ISBLANK_A;
+# else
+    typedef unsigned short mask;
+    static const mask space  = __ISSPACE;
+    static const mask print  = __ISPRINT;
+    static const mask cntrl  = __ISCNTRL;
+    static const mask upper  = __ISUPPER;
+    static const mask lower  = __ISLOWER;
+    static const mask alpha  = __ISALPHA;
+    static const mask digit  = __ISDIGIT;
+    static const mask punct  = __ISPUNCT;
+    static const mask xdigit = __ISXDIGIT;
+    static const mask blank  = __ISBLANK;
+# endif
+    static const mask __regex_word = 0x8000;
 #else
 # error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
 #endif
@@ -514,10 +545,17 @@ public:
     static const mask graph  = alnum | punct;
 
     _LIBCPP_INLINE_VISIBILITY ctype_base() {}
+
+// TODO: Remove the ifndef when the assert no longer fails on AIX.
+#ifndef _AIX
+    static_assert((__regex_word & ~(space | print | cntrl | upper | lower | alpha | digit | punct | xdigit | blank)) == __regex_word,
+                  "__regex_word can't overlap other bits");
+#endif
 };
 
 template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS ctype<wchar_t>
     : public locale::facet,
@@ -619,6 +657,7 @@ protected:
     virtual char do_narrow(char_type, char __dfault) const;
     virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template <>
 class _LIBCPP_TYPE_VIS ctype<char>
@@ -728,6 +767,10 @@ public:
     static const short* __classic_upper_table() _NOEXCEPT;
     static const short* __classic_lower_table() _NOEXCEPT;
 #endif
+#if defined(__MVS__)
+    static const unsigned short* __classic_upper_table() _NOEXCEPT;
+    static const unsigned short* __classic_lower_table() _NOEXCEPT;
+#endif
 
 protected:
     ~ctype();
@@ -763,6 +806,7 @@ protected:
     virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
 };
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
     : public ctype<wchar_t>
@@ -788,6 +832,7 @@ protected:
     virtual char do_narrow(char_type, char __dfault) const;
     virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template <class _CharT>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -994,6 +1039,7 @@ protected:
 
 // template <> class codecvt<wchar_t, char, mbstate_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
     : public locale::facet,
@@ -1074,6 +1120,7 @@ protected:
     virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
     virtual int do_max_length() const  _NOEXCEPT;
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
 
@@ -1452,7 +1499,9 @@ codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
 _LIBCPP_SUPPRESS_DEPRECATED_POP
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
+#endif
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>) // deprecated in C++20
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>) // deprecated in C++20
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
@@ -1683,6 +1732,7 @@ protected:
     string __grouping_;
 };
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS numpunct<wchar_t>
     : public locale::facet
@@ -1713,6 +1763,7 @@ protected:
     char_type __thousands_sep_;
     string __grouping_;
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // template <class charT> class numpunct_byname
 
@@ -1736,6 +1787,7 @@ private:
     void __init(const char*);
 };
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
 : public numpunct<wchar_t>
@@ -1753,6 +1805,7 @@ protected:
 private:
     void __init(const char*);
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/__mbstate_t.h
@@ -0,0 +1,44 @@
+// -*- 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___MBSTATE_T_H
+#define _LIBCPP___MBSTATE_T_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+// TODO(ldionne):
+// The goal of this header is to provide mbstate_t without having to pull in
+// <wchar.h> or <uchar.h>. This is necessary because we need that type even
+// when we don't have (or try to provide) support for wchar_t, because several
+// types like std::fpos are defined in terms of mbstate_t.
+//
+// This is a gruesome hack, but I don't know how to make it cleaner for
+// the time being.
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#   include <wchar.h> // for mbstate_t
+#elif __has_include(<bits/types/mbstate_t.h>)
+#   include <bits/types/mbstate_t.h> // works on most Unixes
+#elif __has_include(<sys/_types/_mbstate_t.h>)
+#   include <sys/_types/_mbstate_t.h> // works on Darwin
+#else
+#   error "The library was configured without support for wide-characters, but we don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___MBSTATE_T_H
lib/libcxx/include/__mutex_base
@@ -13,6 +13,7 @@
 #include <__config>
 #include <__threading_support>
 #include <chrono>
+#include <ratio>
 #include <system_error>
 #include <time.h>
 
@@ -68,9 +69,9 @@ extern _LIBCPP_EXPORTED_FROM_ABI const adopt_lock_t  adopt_lock;
 
 #else
 
-/* _LIBCPP_INLINE_VAR */ constexpr defer_lock_t  defer_lock  = defer_lock_t();
-/* _LIBCPP_INLINE_VAR */ constexpr try_to_lock_t try_to_lock = try_to_lock_t();
-/* _LIBCPP_INLINE_VAR */ constexpr adopt_lock_t  adopt_lock  = adopt_lock_t();
+/* inline */ constexpr defer_lock_t  defer_lock  = defer_lock_t();
+/* inline */ constexpr try_to_lock_t try_to_lock = try_to_lock_t();
+/* inline */ constexpr adopt_lock_t  adopt_lock  = adopt_lock_t();
 
 #endif
 
@@ -96,8 +97,8 @@ public:
     ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();}
 
 private:
-    lock_guard(lock_guard const&) _LIBCPP_EQUAL_DELETE;
-    lock_guard& operator=(lock_guard const&) _LIBCPP_EQUAL_DELETE;
+    lock_guard(lock_guard const&) = delete;
+    lock_guard& operator=(lock_guard const&) = delete;
 };
 
 template <class _Mutex>
@@ -140,11 +141,9 @@ public:
             __m_->unlock();
     }
 
-private:
-    unique_lock(unique_lock const&); // = delete;
-    unique_lock& operator=(unique_lock const&); // = delete;
+    unique_lock(unique_lock const&) = delete;
+    unique_lock& operator=(unique_lock const&) = delete;
 
-public:
     _LIBCPP_INLINE_VISIBILITY
     unique_lock(unique_lock&& __u) _NOEXCEPT
         : __m_(__u.__m_), __owns_(__u.__owns_)
lib/libcxx/include/__node_handle
@@ -10,6 +10,54 @@
 #ifndef _LIBCPP___NODE_HANDLE
 #define _LIBCPP___NODE_HANDLE
 
+/*
+
+template<unspecified>
+class node-handle {
+public:
+  using value_type     = see below;     // not present for map containers
+  using key_type       = see below;     // not present for set containers
+  using mapped_type    = see below;     // not present for set containers
+  using allocator_type = see below;
+
+private:
+  using container_node_type = unspecified;                  // exposition only
+  using ator_traits = allocator_traits<allocator_type>;     // exposition only
+
+  typename ator_traits::template
+    rebind_traits<container_node_type>::pointer ptr_;       // exposition only
+  optional<allocator_type> alloc_;                          // exposition only
+
+public:
+  // [container.node.cons], constructors, copy, and assignment
+  constexpr node-handle() noexcept : ptr_(), alloc_() {}
+  node-handle(node-handle&&) noexcept;
+  node-handle& operator=(node-handle&&);
+
+  // [container.node.dtor], destructor
+  ~node-handle();
+
+  // [container.node.observers], observers
+  value_type& value() const;            // not present for map containers
+  key_type& key() const;                // not present for set containers
+  mapped_type& mapped() const;          // not present for set containers
+
+  allocator_type get_allocator() const;
+  explicit operator bool() const noexcept;
+  [[nodiscard]] bool empty() const noexcept; // nodiscard since C++20
+
+  // [container.node.modifiers], modifiers
+  void swap(node-handle&)
+    noexcept(ator_traits::propagate_on_container_swap::value ||
+             ator_traits::is_always_equal::value);
+
+  friend void swap(node-handle& x, node-handle& y) noexcept(noexcept(x.swap(y))) {
+    x.swap(y);
+  }
+};
+
+*/
+
 #include <__config>
 #include <__debug>
 #include <memory>
@@ -19,9 +67,6 @@
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
@@ -204,6 +249,5 @@ struct _LIBCPP_TEMPLATE_VIS __insert_return_type
 #endif // _LIBCPP_STD_VER > 14
 
 _LIBCPP_END_NAMESPACE_STD
-_LIBCPP_POP_MACROS
 
 #endif  // _LIBCPP___NODE_HANDLE
lib/libcxx/include/__nullptr
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- __nullptr --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -54,7 +54,7 @@ _LIBCPP_END_NAMESPACE_STD
 namespace std
 {
     typedef decltype(nullptr) nullptr_t;
-}
+} // namespace std
 
 #endif // _LIBCPP_HAS_NO_NULLPTR
 
lib/libcxx/include/__split_buffer
@@ -17,17 +17,8 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <bool>
-class __split_buffer_common
-{
-protected:
-    _LIBCPP_NORETURN void __throw_length_error() const;
-    _LIBCPP_NORETURN void __throw_out_of_range() const;
-};
-
 template <class _Tp, class _Allocator = allocator<_Tp> >
 struct __split_buffer
-    : private __split_buffer_common<true>
 {
 private:
     __split_buffer(const __split_buffer&);
@@ -248,7 +239,7 @@ __split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIt
             size_type __old_cap = __end_cap() - __first_;
             size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8);
             __split_buffer __buf(__new_cap, 0, __a);
-            for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_)
+            for (pointer __p = __begin_; __p != __end_; ++__p, (void) ++__buf.__end_)
                 __alloc_traits::construct(__buf.__alloc(),
                         _VSTD::__to_address(__buf.__end_), _VSTD::move(*__p));
             swap(__buf);
@@ -268,7 +259,7 @@ typename enable_if
 __split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
 {
     _ConstructTransaction __tx(&this->__end_, _VSTD::distance(__first, __last));
-    for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, ++__first) {
+    for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void) ++__first) {
         __alloc_traits::construct(this->__alloc(),
             _VSTD::__to_address(__tx.__pos_), *__first);
     }
lib/libcxx/include/__string
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- __string ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,22 +10,26 @@
 #ifndef _LIBCPP___STRING
 #define _LIBCPP___STRING
 
-#include <__config>
 #include <__algorithm/copy.h>
 #include <__algorithm/copy_backward.h>
 #include <__algorithm/copy_n.h>
 #include <__algorithm/fill_n.h>
-#include <__algorithm/find_first_of.h>
 #include <__algorithm/find_end.h>
+#include <__algorithm/find_first_of.h>
 #include <__algorithm/min.h>
+#include <__config>
 #include <__functional/hash.h>     // for __murmur2_or_cityhash
 #include <__iterator/iterator_traits.h>
-#include <cstdio>      // for EOF
 #include <cstdint>     // for uint_least16_t
+#include <cstdio>      // for EOF
 #include <cstring>     // for memcpy
-#include <cwchar>      // for wmemcpy
+#include <iosfwd>      // for streampos & friends
 #include <type_traits> // for __libcpp_is_constant_evaluated
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#   include <cwchar> // for wmemcpy
+#endif
+
 #include <__debug>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -38,9 +42,6 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-// The the extern template ABI lists are kept outside of <string> to improve the
-// readability of that header.
-
 // The extern template ABI lists are kept outside of <string> to improve the
 // readability of that header. We maintain 2 ABI lists:
 // - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST
@@ -265,7 +266,9 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX17
 _CharT*
 char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
 {
-    _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+    if (!__libcpp_is_constant_evaluated()) {
+        _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+    }
     char_type* __r = __s1;
     for (; __n; --__n, ++__s1, ++__s2)
         assign(*__s1, *__s2);
@@ -287,31 +290,34 @@ char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
 
 template <class _CharT>
 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
-_CharT* __move_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT
+_CharT* __copy_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT
 {
-    if (__n == 0) return __s1;
-    if (__s1 < __s2) {
-      _VSTD::copy(__s2, __s2 + __n, __s1);
-    } else if (__s2 < __s1) {
-      _VSTD::copy_backward(__s2, __s2 + __n, __s1 + __n);
-    }
-    return __s1;
+  _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__copy_constexpr() should always be constant evaluated");
+  _VSTD::copy_n(__source, __n, __dest);
+  return __dest;
 }
 
 template <class _CharT>
 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
-_CharT* __copy_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT
+_CharT* __move_constexpr(_CharT* __dest, const _CharT* __source, size_t __n) _NOEXCEPT
 {
-    _VSTD::copy_n(__s2, __n, __s1);
-    return __s1;
+  _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__move_constexpr() should always be constant evaluated");
+  if (__n == 0)
+    return __dest;
+  _CharT* __allocation = new _CharT[__n];
+  _VSTD::__copy_constexpr(__allocation, __source, __n);
+  _VSTD::__copy_constexpr(__dest, static_cast<const _CharT*>(__allocation), __n);
+  delete[] __allocation;
+  return __dest;
 }
 
 template <class _CharT>
 static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
 _CharT* __assign_constexpr(_CharT* __s, size_t __n, _CharT __a) _NOEXCEPT
 {
-     _VSTD::fill_n(__s, __n, __a);
-     return __s;
+  _LIBCPP_ASSERT(__libcpp_is_constant_evaluated(), "__assign_constexpr() should always be constant evaluated");
+  _VSTD::fill_n(__s, __n, __a);
+  return __s;
 }
 
 // char_traits<char>
@@ -334,8 +340,21 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char>
 
     static _LIBCPP_CONSTEXPR_AFTER_CXX14
     int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
-    static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14
-    length(const char_type* __s)  _NOEXCEPT {return __builtin_strlen(__s);}
+
+    static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 length(const char_type* __s)  _NOEXCEPT {
+      // GCC currently does not support __builtin_strlen during constant evaluation.
+      // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
+#ifdef _LIBCPP_COMPILER_GCC
+      if (__libcpp_is_constant_evaluated()) {
+        size_t __i = 0;
+        for (; __s[__i] != char_type('\0'); ++__i)
+            ;
+        return __i;
+      }
+#endif
+      return __builtin_strlen(__s);
+    }
+
     static _LIBCPP_CONSTEXPR_AFTER_CXX14
     const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
     static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
@@ -348,7 +367,9 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char>
     static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
     char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+            if (!__libcpp_is_constant_evaluated()) {
+                _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+            }
             return __libcpp_is_constant_evaluated()
                        ? _VSTD::__copy_constexpr(__s1, __s2, __n)
                        : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n);
@@ -419,6 +440,7 @@ char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a)
 
 // char_traits<wchar_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
 {
@@ -451,7 +473,9 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
     static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
     char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+            if (!__libcpp_is_constant_evaluated()) {
+                _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+            }
             return __libcpp_is_constant_evaluated()
                        ? _VSTD::__copy_constexpr(__s1, __s2, __n)
                        : __n == 0 ? __s1 : _VSTD::wmemcpy(__s1, __s2, __n);
@@ -497,18 +521,6 @@ char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size
 #endif
 }
 
-
-template <class _Traits>
-_LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
-#if _LIBCPP_DEBUG_LEVEL >= 1
-  return __s ? _Traits::length(__s) : (_VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, "p == nullptr", "null pointer pass to non-null argument of char_traits<...>::length")), 0);
-#else
-  return _Traits::length(__s);
-#endif
-}
-
 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
 size_t
 char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
@@ -545,7 +557,18 @@ char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __
     return nullptr;
 #endif
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
+template <class _Traits>
+_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
+#if _LIBCPP_DEBUG_LEVEL >= 1
+  return __s ? _Traits::length(__s) : (_VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, "p == nullptr", "null pointer pass to non-null argument of char_traits<...>::length")), 0);
+#else
+  return _Traits::length(__s);
+#endif
+}
 
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
 
@@ -584,8 +607,10 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
 
     static _LIBCPP_CONSTEXPR_AFTER_CXX17
     char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
-       {
-            _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+        {
+            if (!__libcpp_is_constant_evaluated()) {
+                _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+            }
             return __libcpp_is_constant_evaluated()
                        ? _VSTD::__copy_constexpr(__s1, __s2, __n)
                        : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n);
@@ -761,7 +786,9 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX17
 char16_t*
 char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+    if (!__libcpp_is_constant_evaluated()) {
+        _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+    }
     char_type* __r = __s1;
     for (; __n; --__n, ++__s1, ++__s2)
         assign(*__s1, *__s2);
@@ -881,7 +908,9 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX17
 char32_t*
 char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+    if (!__libcpp_is_constant_evaluated()) {
+        _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
+    }
     char_type* __r = __s1;
     for (; __n; --__n, ++__s1, ++__s2)
         assign(*__s1, *__s2);
lib/libcxx/include/__threading_support
@@ -12,6 +12,7 @@
 
 #include <__availability>
 #include <__config>
+#include <__thread/poll_with_backoff.h>
 #include <chrono>
 #include <errno.h>
 #include <iosfwd>
@@ -29,16 +30,9 @@
 # include <__external_threading>
 #elif !defined(_LIBCPP_HAS_NO_THREADS)
 
-#if defined(__APPLE__) || defined(__MVS__)
-# define _LIBCPP_NO_NATIVE_SEMAPHORES
-#endif
-
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 # include <pthread.h>
 # include <sched.h>
-# ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
-#   include <semaphore.h>
-# endif
 #elif defined(_LIBCPP_HAS_THREAD_API_C11)
 # include <threads.h>
 #endif
@@ -60,9 +54,6 @@
 typedef ::timespec __libcpp_timespec_t;
 #endif // !defined(_LIBCPP_HAS_NO_THREADS)
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if !defined(_LIBCPP_HAS_NO_THREADS)
@@ -78,12 +69,6 @@ typedef pthread_mutex_t __libcpp_recursive_mutex_t;
 typedef pthread_cond_t __libcpp_condvar_t;
 #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
 
-#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
-// Semaphore
-typedef sem_t __libcpp_semaphore_t;
-# define _LIBCPP_SEMAPHORE_MAX SEM_VALUE_MAX
-#endif
-
 // Execute once
 typedef pthread_once_t __libcpp_exec_once_flag;
 #define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
@@ -149,12 +134,6 @@ typedef void* __libcpp_recursive_mutex_t[5];
 typedef void* __libcpp_condvar_t;
 #define _LIBCPP_CONDVAR_INITIALIZER 0
 
-// Semaphore
-typedef void* __libcpp_semaphore_t;
-#if defined(_LIBCPP_HAS_THREAD_API_WIN32)
-# define _LIBCPP_SEMAPHORE_MAX (::std::numeric_limits<long>::max())
-#endif
-
 // Execute Once
 typedef void* __libcpp_exec_once_flag;
 #define _LIBCPP_EXEC_ONCE_INITIALIZER 0
@@ -219,26 +198,6 @@ int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
 
-#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
-
-// Semaphore
-_LIBCPP_THREAD_ABI_VISIBILITY
-bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init);
-
-_LIBCPP_THREAD_ABI_VISIBILITY
-bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem);
-
-_LIBCPP_THREAD_ABI_VISIBILITY
-bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem);
-
-_LIBCPP_THREAD_ABI_VISIBILITY
-bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem);
-
-_LIBCPP_THREAD_ABI_VISIBILITY
-bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns);
-
-#endif // _LIBCPP_NO_NATIVE_SEMAPHORES
-
 // Execute once
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
@@ -290,75 +249,9 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
 #endif // !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 
-struct __libcpp_timed_backoff_policy {
-  _LIBCPP_INLINE_VISIBILITY
-  bool operator()(chrono::nanoseconds __elapsed) const
-  {
-      if(__elapsed > chrono::milliseconds(128))
-          __libcpp_thread_sleep_for(chrono::milliseconds(8));
-      else if(__elapsed > chrono::microseconds(64))
-          __libcpp_thread_sleep_for(__elapsed / 2);
-      else if(__elapsed > chrono::microseconds(4))
-        __libcpp_thread_yield();
-      else
-        {} // poll
-      return false;
-  }
-};
-
-static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
-
-template<class _Fn, class _BFn>
-_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
-bool __libcpp_thread_poll_with_backoff(
-  _Fn && __f, _BFn && __bf, chrono::nanoseconds __max_elapsed = chrono::nanoseconds::zero())
-{
-    auto const __start = chrono::high_resolution_clock::now();
-    for(int __count = 0;;) {
-      if(__f())
-        return true; // _Fn completion means success
-      if(__count < __libcpp_polling_count) {
-        __count += 1;
-        continue;
-      }
-      chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
-      if(__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
-          return false; // timeout failure
-      if(__bf(__elapsed))
-        return false; // _BFn completion means failure
-    }
-}
-
 #if (!defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
      defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL))
 
-
-namespace __thread_detail {
-
-inline __libcpp_timespec_t __convert_to_timespec(const chrono::nanoseconds& __ns)
-{
-  using namespace chrono;
-  seconds __s = duration_cast<seconds>(__ns);
-  __libcpp_timespec_t __ts;
-  typedef decltype(__ts.tv_sec) __ts_sec;
-  const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
-
-  if (__s.count() < __ts_sec_max)
-  {
-    __ts.tv_sec = static_cast<__ts_sec>(__s.count());
-    __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
-  }
-  else
-  {
-    __ts.tv_sec = __ts_sec_max;
-    __ts.tv_nsec = 999999999; // (10^9 - 1)
-  }
-
-  return __ts;
-}
-
-}
-
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 
 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
@@ -452,38 +345,6 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
   return pthread_cond_destroy(__cv);
 }
 
-#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
-
-// Semaphore
-bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init)
-{
-    return sem_init(__sem, 0, __init) == 0;
-}
-
-bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem)
-{
-    return sem_destroy(__sem) == 0;
-}
-
-bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem)
-{
-    return sem_post(__sem) == 0;
-}
-
-bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
-{
-    return sem_wait(__sem) == 0;
-}
-
-bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns)
-{
-    auto const __abs_time = chrono::system_clock::now().time_since_epoch() + __ns;
-    __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__abs_time);
-    return sem_timedwait(__sem, &__ts) == 0;
-}
-
-#endif //_LIBCPP_NO_NATIVE_SEMAPHORES
-
 // Execute once
 int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
                           void (*init_routine)()) {
@@ -546,7 +407,7 @@ void __libcpp_thread_yield()
 
 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
 {
-   __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns);
+   __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
    while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
 }
 
@@ -703,7 +564,7 @@ void __libcpp_thread_yield()
 
 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
 {
-   __libcpp_timespec_t __ts = __thread_detail::__convert_to_timespec(__ns);
+   __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
   thrd_sleep(&__ts, nullptr);
 }
 
@@ -736,7 +597,7 @@ namespace this_thread
 
 _LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT;
 
-}  // this_thread
+} // namespace this_thread
 
 template<> struct hash<__thread_id>;
 
@@ -806,12 +667,10 @@ get_id() _NOEXCEPT
     return __libcpp_thread_get_current_id();
 }
 
-}  // this_thread
+} // namespace this_thread
 
 #endif // !_LIBCPP_HAS_NO_THREADS
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP_THREADING_SUPPORT
lib/libcxx/include/__tree
@@ -738,9 +738,9 @@ public:
     }
 
 private:
-  ~__tree_node_base() _LIBCPP_EQUAL_DELETE;
-  __tree_node_base(__tree_node_base const&) _LIBCPP_EQUAL_DELETE;
-  __tree_node_base& operator=(__tree_node_base const&) _LIBCPP_EQUAL_DELETE;
+  ~__tree_node_base() = delete;
+  __tree_node_base(__tree_node_base const&) = delete;
+  __tree_node_base& operator=(__tree_node_base const&) = delete;
 };
 
 template <class _Tp, class _VoidPtr>
@@ -753,9 +753,9 @@ public:
     __node_value_type __value_;
 
 private:
-  ~__tree_node() _LIBCPP_EQUAL_DELETE;
-  __tree_node(__tree_node const&) _LIBCPP_EQUAL_DELETE;
-  __tree_node& operator=(__tree_node const&) _LIBCPP_EQUAL_DELETE;
+  ~__tree_node() = delete;
+  __tree_node(__tree_node const&) = delete;
+  __tree_node& operator=(__tree_node const&) = delete;
 };
 
 
@@ -1612,7 +1612,7 @@ template <class _Tp, class _Compare, class _Allocator>
 __tree<_Tp, _Compare, _Allocator>&
 __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t)
 {
-    if (this != &__t)
+    if (this != _VSTD::addressof(__t))
     {
         value_comp() = __t.value_comp();
         __copy_assign_alloc(__t);
lib/libcxx/include/__tuple
@@ -58,19 +58,19 @@ template <size_t _Ip, class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_element;
 template <size_t _Ip, class _Tp>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
+    typedef _LIBCPP_NODEBUG typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
 };
 
 template <size_t _Ip, class _Tp>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
+    typedef _LIBCPP_NODEBUG typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
 };
 
 template <size_t _Ip, class _Tp>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
+    typedef _LIBCPP_NODEBUG typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
 };
 
 template <class _Tp> struct __tuple_like : false_type {};
@@ -99,7 +99,7 @@ namespace __detail {
 
 template<typename _Tp, size_t ..._Extra> struct __repeat;
 template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
-  typedef _LIBCPP_NODEBUG_TYPE __integer_sequence<_Tp,
+  typedef _LIBCPP_NODEBUG __integer_sequence<_Tp,
                            _Np...,
                            sizeof...(_Np) + _Np...,
                            2 * sizeof...(_Np) + _Np...,
@@ -253,7 +253,7 @@ template <class ..._Tp> struct __tuple_types {};
 namespace __indexer_detail {
 
 template <size_t _Idx, class _Tp>
-struct __indexed { using type _LIBCPP_NODEBUG_TYPE = _Tp; };
+struct __indexed { using type _LIBCPP_NODEBUG = _Tp; };
 
 template <class _Types, class _Indexes> struct __indexer;
 
@@ -268,7 +268,7 @@ __indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
 } // namespace __indexer_detail
 
 template <size_t _Idx, class ..._Types>
-using __type_pack_element _LIBCPP_NODEBUG_TYPE = typename decltype(
+using __type_pack_element _LIBCPP_NODEBUG = typename decltype(
     __indexer_detail::__at_index<_Idx>(
         __indexer_detail::__indexer<
             __tuple_types<_Types...>,
@@ -281,7 +281,7 @@ template <size_t _Ip, class ..._Types>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>>
 {
     static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
-    typedef _LIBCPP_NODEBUG_TYPE __type_pack_element<_Ip, _Types...> type;
+    typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
 };
 
 
@@ -301,34 +301,34 @@ struct __apply_cv_mf<false, false, false> {
 };
 template <>
 struct __apply_cv_mf<false, true, false> {
-  template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE  = const _Tp;
+  template <class _Tp> using __apply _LIBCPP_NODEBUG = const _Tp;
 };
 template <>
 struct __apply_cv_mf<false, false, true> {
-  template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE  = volatile _Tp;
+  template <class _Tp> using __apply _LIBCPP_NODEBUG = volatile _Tp;
 };
 template <>
 struct __apply_cv_mf<false, true, true> {
-  template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE  = const volatile _Tp;
+  template <class _Tp> using __apply _LIBCPP_NODEBUG = const volatile _Tp;
 };
 template <>
 struct __apply_cv_mf<true, false, false> {
-  template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE  = _Tp&;
+  template <class _Tp> using __apply _LIBCPP_NODEBUG = _Tp&;
 };
 template <>
 struct __apply_cv_mf<true, true, false> {
-  template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE  = const _Tp&;
+  template <class _Tp> using __apply _LIBCPP_NODEBUG = const _Tp&;
 };
 template <>
 struct __apply_cv_mf<true, false, true> {
-  template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE  = volatile _Tp&;
+  template <class _Tp> using __apply _LIBCPP_NODEBUG = volatile _Tp&;
 };
 template <>
 struct __apply_cv_mf<true, true, true> {
-  template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const volatile _Tp&;
+  template <class _Tp> using __apply _LIBCPP_NODEBUG = const volatile _Tp&;
 };
 template <class _Tp, class _RawTp = typename remove_reference<_Tp>::type>
-using __apply_cv_t _LIBCPP_NODEBUG_TYPE  = __apply_cv_mf<
+using __apply_cv_t _LIBCPP_NODEBUG = __apply_cv_mf<
     is_lvalue_reference<_Tp>::value,
     is_const<_RawTp>::value,
     is_volatile<_RawTp>::value>;
@@ -347,7 +347,7 @@ template <template <class...> class _Tuple, class ..._Types, size_t ..._Idx>
 struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
   // Specialization for pair, tuple, and __tuple_types
   template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
-  using __apply_quals _LIBCPP_NODEBUG_TYPE = __tuple_types<
+  using __apply_quals _LIBCPP_NODEBUG = __tuple_types<
       typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>...
     >;
 };
@@ -375,19 +375,19 @@ struct __make_tuple_types
 
 template <class ..._Types, size_t _Ep>
 struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
-  typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type;
+  typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
 };
 
 template <class ..._Types, size_t _Ep>
 struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
-  typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type;
+  typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
 };
 
 template <bool ..._Preds>
 struct __all_dummy;
 
 template <bool ..._Pred>
-using __all = _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>;
+struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>> {};
 
 struct __tuple_sfinae_base {
   template <template <class, class...> class _Trait,
@@ -454,12 +454,12 @@ struct __tuple_assignable<_Tp, _Up, true, true>
 template <size_t _Ip, class ..._Tp>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> >
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
+    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
 };
 
 #if _LIBCPP_STD_VER > 11
 template <size_t _Ip, class ..._Tp>
-using tuple_element_t _LIBCPP_NODEBUG_TYPE  = typename tuple_element <_Ip, _Tp...>::type;
+using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element <_Ip, _Tp...>::type;
 #endif
 
 template <bool _IsTuple, class _SizeTrait, size_t _Expected>
@@ -471,7 +471,7 @@ struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
 
 template <class _Tuple, size_t _ExpectedSize,
           class _RawTuple = typename __uncvref<_Tuple>::type>
-using __tuple_like_with_size _LIBCPP_NODEBUG_TYPE = __tuple_like_with_size_imp<
+using __tuple_like_with_size _LIBCPP_NODEBUG = __tuple_like_with_size_imp<
                                    __tuple_like<_RawTuple>::value,
                                    tuple_size<_RawTuple>, _ExpectedSize
                               >;
lib/libcxx/include/__undef_macros
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ __undef_macros ------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/algorithm
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- algorithm ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -18,6 +18,14 @@
 namespace std
 {
 
+namespace ranges {
+  template <class I1, class I2>
+    struct in_in_result;     // since C++20
+
+  template <class I1, class I2, class O>
+    struct in_in_out_result; // since C++20
+}
+
 template <class InputIterator, class Predicate>
     constexpr bool     // constexpr in C++20
     all_of(InputIterator first, InputIterator last, Predicate pred);
@@ -641,19 +649,23 @@ template <class BidirectionalIterator, class Compare>
     constexpr bool     // constexpr in C++20
     prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
 
+namespace ranges {
+// [algorithms.results], algorithm result types
+template<class InputIterator, class OutputIterator>
+    struct in_out_result;
+}
+
 }  // std
 
 */
 
+#include <__bits> // __libcpp_clz
 #include <__config>
 #include <__debug>
-#include <__bits> // __libcpp_clz
 #include <cstddef>
 #include <cstring>
 #include <functional>
 #include <initializer_list>
-#include <utility> // needed to provide swap_ranges.
-#include <memory>
 #include <iterator>
 #include <memory>
 #include <type_traits>
@@ -675,8 +687,8 @@ template <class BidirectionalIterator, class Compare>
 #include <__algorithm/count_if.h>
 #include <__algorithm/equal.h>
 #include <__algorithm/equal_range.h>
-#include <__algorithm/fill_n.h>
 #include <__algorithm/fill.h>
+#include <__algorithm/fill_n.h>
 #include <__algorithm/find.h>
 #include <__algorithm/find_end.h>
 #include <__algorithm/find_first_of.h>
@@ -684,9 +696,12 @@ template <class BidirectionalIterator, class Compare>
 #include <__algorithm/find_if_not.h>
 #include <__algorithm/for_each.h>
 #include <__algorithm/for_each_n.h>
-#include <__algorithm/generate_n.h>
 #include <__algorithm/generate.h>
+#include <__algorithm/generate_n.h>
 #include <__algorithm/half_positive.h>
+#include <__algorithm/in_in_out_result.h>
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/in_out_result.h>
 #include <__algorithm/includes.h>
 #include <__algorithm/inplace_merge.h>
 #include <__algorithm/is_heap.h>
@@ -749,8 +764,8 @@ template <class BidirectionalIterator, class Compare>
 #include <__algorithm/stable_sort.h>
 #include <__algorithm/swap_ranges.h>
 #include <__algorithm/transform.h>
-#include <__algorithm/unique_copy.h>
 #include <__algorithm/unique.h>
+#include <__algorithm/unique_copy.h>
 #include <__algorithm/unwrap_iter.h>
 #include <__algorithm/upper_bound.h>
 
@@ -758,11 +773,6 @@ template <class BidirectionalIterator, class Compare>
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-_LIBCPP_POP_MACROS
-
 #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
 #   include <__pstl_algorithm>
 #endif
lib/libcxx/include/any
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------------ any -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/array
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- array -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -356,9 +356,9 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
 };
 
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _Tp, class... _Args,
-         class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value>
+         class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value>
          >
 array(_Tp, _Args...)
   -> array<_Tp, 1 + sizeof...(_Args)>;
lib/libcxx/include/atomic
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- atomic -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -263,196 +263,137 @@ struct atomic<T*>
 };
 
 
-template <class T>
-  bool atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
-
-template <class T>
-  bool atomic_is_lock_free(const atomic<T>* obj) noexcept;
-
-template <class T>
-  void atomic_store(volatile atomic<T>* obj, T desr) noexcept;
-
-template <class T>
-  void atomic_store(atomic<T>* obj, T desr) noexcept;
-
-template <class T>
-  void atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
-
-template <class T>
-  void atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
-
-template <class T>
-  T atomic_load(const volatile atomic<T>* obj) noexcept;
-
-template <class T>
-  T atomic_load(const atomic<T>* obj) noexcept;
-
-template <class T>
-  T atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
-
-template <class T>
-  T atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
-
-template <class T>
-  T atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
-
-template <class T>
-  T atomic_exchange(atomic<T>* obj, T desr) noexcept;
-
-template <class T>
-  T atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
-
-template <class T>
-  T atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
-                                             T desr,
-                                             memory_order s, memory_order f) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
-                                             memory_order s, memory_order f) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
-                                               T* expc, T desr,
-                                               memory_order s, memory_order f) noexcept;
-
-template <class T>
-  bool atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
-                                               T desr,
-                                               memory_order s, memory_order f) noexcept;
-
-template <class T>
-  void atomic_wait(const volatile atomic<T>* obj, T old) noexcept;
-
-template <class T>
-  void atomic_wait(const atomic<T>* obj, T old) noexcept;
-
-template <class T>
-  void atomic_wait_explicit(const volatile atomic<T>* obj, T old, memory_order m) noexcept;
-
-template <class T>
-  void atomic_wait_explicit(const atomic<T>* obj, T old, memory_order m) noexcept;
-
-template <class T>
-  void atomic_one(volatile atomic<T>* obj) noexcept;
-
-template <class T>
-  void atomic_one(atomic<T>* obj) noexcept;
-
-template <class T>
-  void atomic_all(volatile atomic<T>* obj) noexcept;
-
-template <class T>
-  void atomic_all(atomic<T>* obj) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
-                              memory_order m) noexcept;
-template <class Integral>
-  Integral atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
-                              memory_order m) noexcept;
-template <class Integral>
-  Integral atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
-                                     memory_order m) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
-                                     memory_order m) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
-                                     memory_order m) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
-                                     memory_order m) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
-                             memory_order m) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
-                             memory_order m) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
-                                     memory_order m) noexcept;
-
-template <class Integral>
-  Integral atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
-                                     memory_order m) noexcept;
-
-template <class T>
-  T* atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
-
-template <class T>
-  T* atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
-
-template <class T>
-  T* atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
-                               memory_order m) noexcept;
-
-template <class T>
-  T* atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
-
-template <class T>
-  T* atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
-
-template <class T>
-  T* atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
-
-template <class T>
-  T* atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
-                               memory_order m) noexcept;
-
-template <class T>
-  T* atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
+// [atomics.nonmembers], non-member functions
+template<class T>
+  bool atomic_is_lock_free(const volatile atomic<T>*) noexcept;
+template<class T>
+  bool atomic_is_lock_free(const atomic<T>*) noexcept;
+template<class T>
+  void atomic_store(volatile atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  void atomic_store(atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  void atomic_store_explicit(volatile atomic<T>*, atomic<T>::value_type,
+                             memory_order) noexcept;
+template<class T>
+  void atomic_store_explicit(atomic<T>*, atomic<T>::value_type,
+                             memory_order) noexcept;
+template<class T>
+  T atomic_load(const volatile atomic<T>*) noexcept;
+template<class T>
+  T atomic_load(const atomic<T>*) noexcept;
+template<class T>
+  T atomic_load_explicit(const volatile atomic<T>*, memory_order) noexcept;
+template<class T>
+  T atomic_load_explicit(const atomic<T>*, memory_order) noexcept;
+template<class T>
+  T atomic_exchange(volatile atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_exchange(atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_exchange_explicit(volatile atomic<T>*, atomic<T>::value_type,
+                             memory_order) noexcept;
+template<class T>
+  T atomic_exchange_explicit(atomic<T>*, atomic<T>::value_type,
+                             memory_order) noexcept;
+template<class T>
+  bool atomic_compare_exchange_weak(volatile atomic<T>*, atomic<T>::value_type*,
+                                    atomic<T>::value_type) noexcept;
+template<class T>
+  bool atomic_compare_exchange_weak(atomic<T>*, atomic<T>::value_type*,
+                                    atomic<T>::value_type) noexcept;
+template<class T>
+  bool atomic_compare_exchange_strong(volatile atomic<T>*, atomic<T>::value_type*,
+                                      atomic<T>::value_type) noexcept;
+template<class T>
+  bool atomic_compare_exchange_strong(atomic<T>*, atomic<T>::value_type*,
+                                      atomic<T>::value_type) noexcept;
+template<class T>
+  bool atomic_compare_exchange_weak_explicit(volatile atomic<T>*, atomic<T>::value_type*,
+                                             atomic<T>::value_type,
+                                             memory_order, memory_order) noexcept;
+template<class T>
+  bool atomic_compare_exchange_weak_explicit(atomic<T>*, atomic<T>::value_type*,
+                                             atomic<T>::value_type,
+                                             memory_order, memory_order) noexcept;
+template<class T>
+  bool atomic_compare_exchange_strong_explicit(volatile atomic<T>*, atomic<T>::value_type*,
+                                               atomic<T>::value_type,
+                                               memory_order, memory_order) noexcept;
+template<class T>
+  bool atomic_compare_exchange_strong_explicit(atomic<T>*, atomic<T>::value_type*,
+                                               atomic<T>::value_type,
+                                               memory_order, memory_order) noexcept;
+
+template<class T>
+  T atomic_fetch_add(volatile atomic<T>*, atomic<T>::difference_type) noexcept;
+template<class T>
+  T atomic_fetch_add(atomic<T>*, atomic<T>::difference_type) noexcept;
+template<class T>
+  T atomic_fetch_add_explicit(volatile atomic<T>*, atomic<T>::difference_type,
+                              memory_order) noexcept;
+template<class T>
+  T atomic_fetch_add_explicit(atomic<T>*, atomic<T>::difference_type,
+                              memory_order) noexcept;
+template<class T>
+  T atomic_fetch_sub(volatile atomic<T>*, atomic<T>::difference_type) noexcept;
+template<class T>
+  T atomic_fetch_sub(atomic<T>*, atomic<T>::difference_type) noexcept;
+template<class T>
+  T atomic_fetch_sub_explicit(volatile atomic<T>*, atomic<T>::difference_type,
+                              memory_order) noexcept;
+template<class T>
+  T atomic_fetch_sub_explicit(atomic<T>*, atomic<T>::difference_type,
+                              memory_order) noexcept;
+template<class T>
+  T atomic_fetch_and(volatile atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_fetch_and(atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_fetch_and_explicit(volatile atomic<T>*, atomic<T>::value_type,
+                              memory_order) noexcept;
+template<class T>
+  T atomic_fetch_and_explicit(atomic<T>*, atomic<T>::value_type,
+                              memory_order) noexcept;
+template<class T>
+  T atomic_fetch_or(volatile atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_fetch_or(atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_fetch_or_explicit(volatile atomic<T>*, atomic<T>::value_type,
+                             memory_order) noexcept;
+template<class T>
+  T atomic_fetch_or_explicit(atomic<T>*, atomic<T>::value_type,
+                             memory_order) noexcept;
+template<class T>
+  T atomic_fetch_xor(volatile atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_fetch_xor(atomic<T>*, atomic<T>::value_type) noexcept;
+template<class T>
+  T atomic_fetch_xor_explicit(volatile atomic<T>*, atomic<T>::value_type,
+                              memory_order) noexcept;
+template<class T>
+  T atomic_fetch_xor_explicit(atomic<T>*, atomic<T>::value_type,
+                              memory_order) noexcept;
+
+template<class T>
+  void atomic_wait(const volatile atomic<T>*, atomic<T>::value_type);
+template<class T>
+  void atomic_wait(const atomic<T>*, atomic<T>::value_type);
+template<class T>
+  void atomic_wait_explicit(const volatile atomic<T>*, atomic<T>::value_type,
+                            memory_order);
+template<class T>
+  void atomic_wait_explicit(const atomic<T>*, atomic<T>::value_type,
+                            memory_order);
+template<class T>
+  void atomic_notify_one(volatile atomic<T>*);
+template<class T>
+  void atomic_notify_one(atomic<T>*);
+template<class T>
+  void atomic_notify_all(volatile atomic<T>*);
+template<class T>
+  void atomic_notify_all(atomic<T>*);
 
 // Atomics for standard typedef types
 
@@ -564,10 +505,10 @@ void atomic_signal_fence(memory_order m) noexcept;
 // deprecated
 
 template <class T>
-  void atomic_init(volatile atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
+  void atomic_init(volatile atomic<T>* obj, atomic<T>::value_type desr) noexcept;
 
 template <class T>
-  void atomic_init(atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
+  void atomic_init(atomic<T>* obj, atomic<T>::value_type desr) noexcept;
 
 #define ATOMIC_VAR_INIT(value) see below
 
@@ -579,20 +520,22 @@ template <class T>
 
 #include <__availability>
 #include <__config>
-#include <__threading_support>
+#include <__thread/poll_with_backoff.h>
+#include <__thread/timed_backoff_policy.h>
 #include <cstddef>
 #include <cstdint>
 #include <cstring>
 #include <type_traits>
 #include <version>
 
+#ifndef _LIBCPP_HAS_NO_THREADS
+# include <__threading_support>
+#endif
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-#ifdef _LIBCPP_HAS_NO_THREADS
-# error <atomic> is not supported on this single threaded system
-#endif
 #ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
 # error <atomic> is not implemented
 #endif
@@ -1473,7 +1416,9 @@ template<> struct __cxx_is_always_lock_free<char8_t> { enum { __value = 2 == ATO
 #endif
 template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; };
 template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; };
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; };
+#endif
 template<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
 template<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
 template<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
@@ -1496,13 +1441,10 @@ template <typename _Tp,
           typename _Base = __cxx_atomic_base_impl<_Tp> >
 #endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS
 struct __cxx_atomic_impl : public _Base {
-
-#if _GNUC_VER >= 501
     static_assert(is_trivially_copyable<_Tp>::value,
-      "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
-#endif
+      "std::atomic<T> requires that 'T' be a trivially copyable type");
 
-  _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT
+  _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT = default;
   _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT
     : _Base(value) {}
 };
@@ -1515,6 +1457,16 @@ struct __cxx_atomic_impl : public _Base {
 
 using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;
 
+#if defined(_LIBCPP_HAS_NO_THREADS)
+#   define _LIBCPP_HAS_NO_PLATFORM_WAIT
+#endif
+
+// TODO:
+// _LIBCPP_HAS_NO_PLATFORM_WAIT is currently a "dead" macro, in the sense that
+// it is not tied anywhere into the build system or even documented. We should
+// clean it up because it is technically never defined except when threads are
+// disabled. We should clean it up in its own changeset in case we break "bad"
+// users.
 #ifndef _LIBCPP_HAS_NO_PLATFORM_WAIT
 
 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*);
@@ -1566,7 +1518,12 @@ _LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_one(__cxx_atomic_impl<_Tp> co
 template <class _Atp, class _Fn>
 _LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp*, _Fn && __test_fn)
 {
-    return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
+#if defined(_LIBCPP_HAS_NO_THREADS)
+    using _Policy = __spinning_backoff_policy;
+#else
+    using _Policy = __libcpp_timed_backoff_policy;
+#endif
+    return __libcpp_thread_poll_with_backoff(__test_fn, _Policy());
 }
 
 #endif // _LIBCPP_HAS_NO_PLATFORM_WAIT
@@ -1688,7 +1645,7 @@ struct __atomic_base  // false
     __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {}
 #else
     _LIBCPP_INLINE_VISIBILITY
-    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
+    __atomic_base() _NOEXCEPT = default;
 #endif
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
@@ -1717,7 +1674,7 @@ struct __atomic_base<_Tp, true>
     typedef __atomic_base<_Tp, false> __base;
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
+    __atomic_base() _NOEXCEPT = default;
 
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
@@ -1806,7 +1763,7 @@ struct atomic
     atomic() = default;
 #else
     _LIBCPP_INLINE_VISIBILITY
-    atomic() _NOEXCEPT _LIBCPP_DEFAULT
+    atomic() _NOEXCEPT = default;
 #endif
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1834,7 +1791,7 @@ struct atomic<_Tp*>
     typedef ptrdiff_t difference_type;
 
     _LIBCPP_INLINE_VISIBILITY
-    atomic() _NOEXCEPT _LIBCPP_DEFAULT
+    atomic() _NOEXCEPT = default;
 
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
@@ -1847,19 +1804,32 @@ struct atomic<_Tp*>
         {__base::store(__d); return __d;}
 
     _LIBCPP_INLINE_VISIBILITY
-    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
-                                                                        volatile _NOEXCEPT
-        {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
+    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
+        // __atomic_fetch_add accepts function pointers, guard against them.
+        static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
+        return __cxx_atomic_fetch_add(&this->__a_, __op, __m);
+    }
+
     _LIBCPP_INLINE_VISIBILITY
-    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
-        {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
+    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
+        // __atomic_fetch_add accepts function pointers, guard against them.
+        static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
+        return __cxx_atomic_fetch_add(&this->__a_, __op, __m);
+    }
+
     _LIBCPP_INLINE_VISIBILITY
-    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
-                                                                        volatile _NOEXCEPT
-        {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
+    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
+        // __atomic_fetch_add accepts function pointers, guard against them.
+        static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
+        return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);
+    }
+
     _LIBCPP_INLINE_VISIBILITY
-    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
-        {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
+    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
+        // __atomic_fetch_add accepts function pointers, guard against them.
+        static_assert(!is_function<typename remove_pointer<_Tp>::type>::value, "Pointer to function isn't allowed");
+        return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);
+    }
 
     _LIBCPP_INLINE_VISIBILITY
     _Tp* operator++(int) volatile _NOEXCEPT            {return fetch_add(1);}
@@ -2195,11 +2165,7 @@ void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
+_Tp
 atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
 {
     return __o->fetch_add(__op);
@@ -2207,70 +2173,24 @@ atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_typ
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
+_Tp
 atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
 {
     return __o->fetch_add(__op);
 }
 
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_add(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
-{
-    return __o->fetch_add(__op);
-}
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_add(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
-{
-    return __o->fetch_add(__op);
-}
-
 // atomic_fetch_add_explicit
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
-atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
+_Tp atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
 {
     return __o->fetch_add(__op, __m);
 }
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
-atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
-{
-    return __o->fetch_add(__op, __m);
-}
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
-{
-    return __o->fetch_add(__op, __m);
-}
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_add_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
+_Tp atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
 {
     return __o->fetch_add(__op, __m);
 }
@@ -2279,40 +2199,14 @@ atomic_fetch_add_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_t
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
-atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
-{
-    return __o->fetch_sub(__op);
-}
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
-atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
-{
-    return __o->fetch_sub(__op);
-}
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_sub(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
+_Tp atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
 {
     return __o->fetch_sub(__op);
 }
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_sub(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
+_Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
 {
     return __o->fetch_sub(__op);
 }
@@ -2321,40 +2215,14 @@ atomic_fetch_sub(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op)
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
-atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
+_Tp atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
 {
     return __o->fetch_sub(__op, __m);
 }
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
-    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
-    _Tp
->::type
-atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
-{
-    return __o->fetch_sub(__op, __m);
-}
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
-{
-    return __o->fetch_sub(__op, __m);
-}
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-_Tp*
-atomic_fetch_sub_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
+_Tp atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
 {
     return __o->fetch_sub(__op, __m);
 }
@@ -2565,7 +2433,7 @@ typedef struct atomic_flag
     atomic_flag() _NOEXCEPT : __a_(false) {}
 #else
     _LIBCPP_INLINE_VISIBILITY
-    atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT
+    atomic_flag() _NOEXCEPT = default;
 #endif
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
@@ -2764,7 +2632,9 @@ typedef atomic<char8_t>            atomic_char8_t;
 #endif
 typedef atomic<char16_t>           atomic_char16_t;
 typedef atomic<char32_t>           atomic_char32_t;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 typedef atomic<wchar_t>            atomic_wchar_t;
+#endif
 
 typedef atomic<int_least8_t>   atomic_int_least8_t;
 typedef atomic<uint_least8_t>  atomic_uint_least8_t;
@@ -2822,14 +2692,24 @@ typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, char>::typ
 typedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned char>::type      __libcpp_unsigned_lock_free;
 #else
     // No signed/unsigned lock-free types
+#define _LIBCPP_NO_LOCK_FREE_TYPES
 #endif
 
+#if !defined(_LIBCPP_NO_LOCK_FREE_TYPES)
 typedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
 typedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
+#endif
 
 #define ATOMIC_FLAG_INIT {false}
 #define ATOMIC_VAR_INIT(__v) {__v}
 
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
+# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1400
+#  pragma clang deprecated(ATOMIC_FLAG_INIT)
+#  pragma clang deprecated(ATOMIC_VAR_INIT)
+# endif
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP_ATOMIC
lib/libcxx/include/barrier
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- barrier ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -47,6 +47,7 @@ namespace std
 
 #include <__availability>
 #include <__config>
+#include <__thread/timed_backoff_policy.h>
 #include <atomic>
 #ifndef _LIBCPP_HAS_NO_TREE_BARRIER
 # include <memory>
lib/libcxx/include/bit
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------------ bit ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -14,6 +14,13 @@
     bit synopsis
 
 namespace std {
+  // [bit.cast], bit_cast
+  template<class To, class From>
+    constexpr To bit_cast(const From& from) noexcept; // C++20
+
+  // [bit.byteswap], byteswap
+  template<class T>
+    constexpr T byteswap(T value) noexcept;      // C++23
 
   // [bit.pow.two], integral powers of 2
   template <class T>
@@ -48,14 +55,16 @@ namespace std {
     little = see below,        // C++20
     big = see below,           // C++20
     native = see below         // C++20
-};
+  };
 
 } // namespace std
 
 */
 
-#include <__config>
+#include <__bit/bit_cast.h>
+#include <__bit/byteswap.h>
 #include <__bits> // __libcpp_clz
+#include <__config>
 #include <__debug>
 #include <limits>
 #include <type_traits>
@@ -222,7 +231,7 @@ bool __has_single_bit(_Tp __t) _NOEXCEPT
 
 template<class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
 rotl(_Tp __t, unsigned int __cnt) noexcept
 {
     return __rotl(__t, __cnt);
@@ -230,7 +239,7 @@ rotl(_Tp __t, unsigned int __cnt) noexcept
 
 template<class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
 rotr(_Tp __t, unsigned int __cnt) noexcept
 {
     return __rotr(__t, __cnt);
@@ -238,7 +247,7 @@ rotr(_Tp __t, unsigned int __cnt) noexcept
 
 template<class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
 countl_zero(_Tp __t) noexcept
 {
     return __countl_zero(__t);
@@ -246,7 +255,7 @@ countl_zero(_Tp __t) noexcept
 
 template<class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
 countl_one(_Tp __t) noexcept
 {
     return __countl_one(__t);
@@ -254,7 +263,7 @@ countl_one(_Tp __t) noexcept
 
 template<class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
 countr_zero(_Tp __t) noexcept
 {
     return __countr_zero(__t);
@@ -262,7 +271,7 @@ countr_zero(_Tp __t) noexcept
 
 template<class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
 countr_one(_Tp __t) noexcept
 {
     return __countr_one(__t);
@@ -270,7 +279,7 @@ countr_one(_Tp __t) noexcept
 
 template<class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, int>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
 popcount(_Tp __t) noexcept
 {
     return __popcount(__t);
@@ -278,7 +287,7 @@ popcount(_Tp __t) noexcept
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, bool>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, bool>
 has_single_bit(_Tp __t) noexcept
 {
     return __has_single_bit(__t);
@@ -286,7 +295,7 @@ has_single_bit(_Tp __t) noexcept
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
 bit_floor(_Tp __t) noexcept
 {
     return __t == 0 ? 0 : _Tp{1} << __bit_log2(__t);
@@ -294,12 +303,12 @@ bit_floor(_Tp __t) noexcept
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
 bit_ceil(_Tp __t) noexcept
 {
     if (__t < 2) return 1;
     const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u));
-    _LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
+    _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
 
     if constexpr (sizeof(_Tp) >= sizeof(unsigned))
         return _Tp{1} << __n;
@@ -313,7 +322,7 @@ bit_ceil(_Tp __t) noexcept
 
 template <class _Tp>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
+enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
 bit_width(_Tp __t) noexcept
 {
     return __t == 0 ? 0 : __bit_log2(__t) + 1;
lib/libcxx/include/bitset
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- bitset ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -112,14 +112,15 @@ template <size_t N> struct hash<std::bitset<N>>;
 
 */
 
-#include <__config>
 #include <__bit_reference>
+#include <__config>
 #include <__functional_base>
 #include <climits>
 #include <cstddef>
 #include <iosfwd>
 #include <stdexcept>
 #include <string>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -679,7 +680,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
         bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
-    template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> >
+    template<class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> >
         explicit bitset(const _CharT* __str,
                         typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
                         _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
lib/libcxx/include/cassert
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- cassert -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ccomplex
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- ccomplex ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cctype
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- cctype ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cerrno
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- cerrno ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cfenv
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- cfenv -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cfloat
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cfloat -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/charconv
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------------ charconv ------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -27,10 +27,13 @@ namespace std {
   struct to_chars_result {
     char* ptr;
     errc ec;
+    friend bool operator==(const to_chars_result&, const to_chars_result&) = default; // since C++20
   };
 
   to_chars_result to_chars(char* first, char* last, see below value,
                            int base = 10);
+  to_chars_result to_chars(char* first, char* last, bool value,
+                           int base = 10) = delete;
 
   to_chars_result to_chars(char* first, char* last, float value);
   to_chars_result to_chars(char* first, char* last, double value);
@@ -54,6 +57,7 @@ namespace std {
   struct from_chars_result {
     const char* ptr;
     errc ec;
+    friend bool operator==(const from_chars_result&, const from_chars_result&) = default; // since C++20
   };
 
   from_chars_result from_chars(const char* first, const char* last,
@@ -74,9 +78,12 @@ namespace std {
 */
 
 #include <__availability>
+#include <__bits>
+#include <__charconv/chars_format.h>
+#include <__charconv/from_chars_result.h>
+#include <__charconv/to_chars_result.h>
 #include <__config>
 #include <__errc>
-#include <__utility/to_underlying.h>
 #include <cmath> // for log2f
 #include <cstdint>
 #include <cstdlib> // for _LIBCPP_UNREACHABLE
@@ -98,73 +105,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace __itoa {
 _LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer) _NOEXCEPT;
 _LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer) _NOEXCEPT;
-}
+} // namespace __itoa
 
 #ifndef _LIBCPP_CXX03_LANG
 
-enum class _LIBCPP_ENUM_VIS chars_format
-{
-    scientific = 0x1,
-    fixed = 0x2,
-    hex = 0x4,
-    general = fixed | scientific
-};
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator~(chars_format __x) {
-  return chars_format(~_VSTD::__to_underlying(__x));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator&(chars_format __x, chars_format __y) {
-  return chars_format(_VSTD::__to_underlying(__x) &
-                      _VSTD::__to_underlying(__y));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator|(chars_format __x, chars_format __y) {
-  return chars_format(_VSTD::__to_underlying(__x) |
-                      _VSTD::__to_underlying(__y));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator^(chars_format __x, chars_format __y) {
-  return chars_format(_VSTD::__to_underlying(__x) ^
-                      _VSTD::__to_underlying(__y));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
-operator&=(chars_format& __x, chars_format __y) {
-  __x = __x & __y;
-  return __x;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
-operator|=(chars_format& __x, chars_format __y) {
-  __x = __x | __y;
-  return __x;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
-operator^=(chars_format& __x, chars_format __y) {
-  __x = __x ^ __y;
-  return __x;
-}
-
-struct _LIBCPP_TYPE_VIS to_chars_result
-{
-    char* ptr;
-    errc ec;
-};
-
-struct _LIBCPP_TYPE_VIS from_chars_result
-{
-    const char* ptr;
-    errc ec;
-};
-
-void to_chars(char*, char*, bool, int = 10) = delete;
-void from_chars(const char*, const char*, bool, int = 10) = delete;
+to_chars_result to_chars(char*, char*, bool, int = 10) = delete;
+from_chars_result from_chars(const char*, const char*, bool, int = 10) = delete;
 
 namespace __itoa
 {
@@ -204,13 +150,11 @@ struct _LIBCPP_HIDDEN __traits_base
 {
     using type = uint64_t;
 
-#if !defined(_LIBCPP_COMPILER_MSVC)
     static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
     {
-        auto __t = (64 - __builtin_clzll(__v | 1)) * 1233 >> 12;
+        auto __t = (64 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
         return __t - (__v < __pow10_64[__t]) + 1;
     }
-#endif
 
     _LIBCPP_AVAILABILITY_TO_CHARS
     static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
@@ -227,13 +171,11 @@ struct _LIBCPP_HIDDEN
 {
     using type = uint32_t;
 
-#if !defined(_LIBCPP_COMPILER_MSVC)
     static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
     {
-        auto __t = (32 - __builtin_clz(__v | 1)) * 1233 >> 12;
+        auto __t = (32 - _VSTD::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
         return __t - (__v < __pow10_32[__t]) + 1;
     }
-#endif
 
     _LIBCPP_AVAILABILITY_TO_CHARS
     static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
@@ -354,28 +296,10 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type)
     using __tx = __itoa::__traits<_Tp>;
     auto __diff = __last - __first;
 
-#if !defined(_LIBCPP_COMPILER_MSVC)
     if (__tx::digits <= __diff || __tx::__width(__value) <= __diff)
         return {__tx::__convert(__value, __first), errc(0)};
     else
         return {__last, errc::value_too_large};
-#else
-    if (__tx::digits <= __diff)
-        return {__tx::__convert(__value, __first), {}};
-    else
-    {
-        char __buf[__tx::digits];
-        auto __p = __tx::__convert(__value, __buf);
-        auto __len = __p - __buf;
-        if (__len <= __diff)
-        {
-            _VSTD::memcpy(__first, __buf, __len);
-            return {__first + __len, {}};
-        }
-        else
-            return {__last, errc::value_too_large};
-    }
-#endif
 }
 
 template <typename _Tp>
@@ -674,6 +598,38 @@ from_chars(const char* __first, const char* __last, _Tp& __value, int __base)
     return __from_chars_integral(__first, __last, __value, __base);
 }
 
+// Floating-point implementation starts here.
+// Unlike the other parts of charconv this is only available in C++17 and newer.
+#if _LIBCPP_STD_VER > 14
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, float __value);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, double __value);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, long double __value);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision);
+
+_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_FUNC_VIS
+to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision);
+
+#  endif // _LIBCPP_STD_VER > 14
 #endif // _LIBCPP_CXX03_LANG
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/chrono
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- chrono ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -148,11 +148,6 @@ template <class Clock, class Duration1, class Duration2>
 
 namespace chrono {
 
-
-template<class T> struct is_clock;  // C++20
-template<class T> inline constexpr bool is_clock_v = is_clock<T>::value;   // C++20
-
-
 // duration arithmetic
 template <class Rep1, class Period1, class Rep2, class Period2>
   constexpr
@@ -281,19 +276,23 @@ template <class Duration>
 using sys_seconds = sys_time<seconds>;                  // C++20
 using sys_days    = sys_time<days>;                     // C++20
 
-class utc_clock;                                        // C++20
-
-template <class Duration>
-  using utc_time  = time_point<utc_clock, Duration>;    // C++20
-using utc_seconds = utc_time<seconds>;                  // C++20
+class file_clock                                        // C++20
+{
+public:
+    typedef see-below                      rep;
+    typedef nano                           period;
+    typedef chrono::duration<rep, period>  duration;
+    typedef chrono::time_point<file_clock> time_point;
+    static constexpr bool is_steady =      false;
 
-class tai_clock;                                        // C++20
+    static time_point now() noexcept;
 
-template <class Duration>
-  using tai_time  = time_point<tai_clock, Duration>;    // C++20
-using tai_seconds = tai_time<seconds>;                  // C++20
+    template<class Duration>
+    static sys_time<see-below> to_sys(const file_time<Duration>&);
 
-class file_clock;                                       // C++20
+    template<class Duration>
+    static file_time<see-below> from_sys(const sys_time<Duration>&);
+};
 
 template<class Duration>
   using file_time = time_point<file_clock, Duration>;   // C++20
@@ -319,12 +318,6 @@ template<class Duration>
 using local_seconds = local_time<seconds>;
 using local_days    = local_time<days>;
 
-// 25.7.9, time_point conversions template<class DestClock, class SourceClock>    // C++20
-struct clock_time_conversion;
-
-template<class DestClock, class SourceClock, class Duration>
-  auto clock_cast(const time_point<SourceClock, Duration>& t);
-
 // 25.8.2, class last_spec    // C++20
 struct last_spec;
 
@@ -639,39 +632,12 @@ public:
     constexpr          precision to_duration() const noexcept;
 };
 
-template <class charT, class traits, class Duration>
-  basic_ostream<charT, traits>&
-    operator<<(basic_ostream<charT, traits>& os, hh_mm_ss<Duration> const& hms);
-
 // 26.10, 12/24 hour functions
 constexpr bool is_am(hours const& h) noexcept;
 constexpr bool is_pm(hours const& h) noexcept;
 constexpr hours make12(const hours& h) noexcept;
 constexpr hours make24(const hours& h, bool is_pm) noexcept;
 
-
-// 25.10.2, time zone database     // C++20
-struct tzdb;
-class tzdb_list;
-
-// 25.10.2.3, time zone database access    // C++20
-const tzdb& get_tzdb();
-tzdb_list& get_tzdb_list();
-const time_zone* locate_zone(string_view tz_name);
-const time_zone* current_zone();
-
-// 25.10.2.4, remote time zone database support    // C++20
-const tzdb& reload_tzdb();
-string remote_version();
-
-// 25.10.3, exception classes    // C++20
-class nonexistent_local_time;
-class ambiguous_local_time;
-
-// 25.10.4, information classes    // C++20
-struct sys_info;
-struct local_info;
-
 // 25.10.5, class time_zone    // C++20
 enum class choose {earliest, latest};
 class time_zone;
@@ -682,101 +648,6 @@ bool operator>(const time_zone& x, const time_zone& y) noexcept;
 bool operator<=(const time_zone& x, const time_zone& y) noexcept;
 bool operator>=(const time_zone& x, const time_zone& y) noexcept;
 
-// 25.10.6, class template zoned_traits    // C++20
-template<class T> struct zoned_traits;
-
-// 25.10.7, class template zoned_time    // C++20
-template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time;
-using zoned_seconds = zoned_time<seconds>;
-
-template<class Duration1, class Duration2, class TimeZonePtr>
-  bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
-                  const zoned_time<Duration2, TimeZonePtr>& y);
-template<class Duration1, class Duration2, class TimeZonePtr>
-  bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
-                  const zoned_time<Duration2, TimeZonePtr>& y);
-
-// 25.10.8, leap second support    // C++20
-class leap;
-
-bool operator==(const leap& x, const leap& y);
-bool operator!=(const leap& x, const leap& y);
-bool operator< (const leap& x, const leap& y);
-bool operator> (const leap& x, const leap& y);
-bool operator<=(const leap& x, const leap& y);
-bool operator>=(const leap& x, const leap& y);
-template<class Duration>
-  bool operator==(const leap& x, const sys_time<Duration>& y);
-template<class Duration>
-  bool operator==(const sys_time<Duration>& x, const leap& y);
-template<class Duration>
-  bool operator!=(const leap& x, const sys_time<Duration>& y);
-template<class Duration>
-  bool operator!=(const sys_time<Duration>& x, const leap& y);
-template<class Duration>
-  bool operator< (const leap& x, const sys_time<Duration>& y);
-template<class Duration>
-  bool operator< (const sys_time<Duration>& x, const leap& y);
-template<class Duration>
-  bool operator> (const leap& x, const sys_time<Duration>& y);
-template<class Duration>
-  bool operator> (const sys_time<Duration>& x, const leap& y);
-template<class Duration>
-  bool operator<=(const leap& x, const sys_time<Duration>& y);
-template<class Duration>
-  bool operator<=(const sys_time<Duration>& x, const leap& y);
-template<class Duration>
-  bool operator>=(const leap& x, const sys_time<Duration>& y);
-template<class Duration>
-  bool operator>=(const sys_time<Duration>& x, const leap& y);
-
-// 25.10.9, class link    // C++20
-class link;
-bool operator==(const link& x, const link& y);
-bool operator!=(const link& x, const link& y);
-bool operator< (const link& x, const link& y);
-bool operator> (const link& x, const link& y);
-bool operator<=(const link& x, const link& y);
-bool operator>=(const link& x, const link& y);
-
-// 25.11, formatting    // C++20
-template<class charT, class Streamable>
-  basic_string<charT>
-    format(const charT* fmt, const Streamable& s);
-
-template<class charT, class Streamable>
-  basic_string<charT>
-    format(const locale& loc, const charT* fmt, const Streamable& s);
-
-template<class charT, class traits, class Alloc, class Streamable>
-  basic_string<charT, traits, Alloc>
-    format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s);
-
-template<class charT, class traits, class Alloc, class Streamable>
-  basic_string<charT, traits, Alloc>
-    format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt,
-           const Streamable& s);
-
-// 25.12, parsing    // C++20
-template<class charT, class traits, class Alloc, class Parsable>
-unspecified
-    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp);
-
-template<class charT, class traits, class Alloc, class Parsable>
-unspecified
-    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
-          basic_string<charT, traits, Alloc>& abbrev);
-
-template<class charT, class traits, class Alloc, class Parsable>
-unspecified
-    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
-          minutes& offset);
-
-template<class charT, class traits, class Alloc, class Parsable>
-unspecified
-    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
-          basic_string<charT, traits, Alloc>& abbrev, minutes& offset);
-
 // calendrical constants
 inline constexpr last_spec                              last{};       // C++20
 inline constexpr chrono::weekday                        Sunday{0};    // C++20
@@ -823,2146 +694,20 @@ constexpr chrono::year                                  operator ""y(unsigned lo
 }  // std
 */
 
-#include <__availability>
+#include <__chrono/calendar.h>
+#include <__chrono/convert_to_timespec.h>
+#include <__chrono/duration.h>
+#include <__chrono/file_clock.h>
+#include <__chrono/high_resolution_clock.h>
+#include <__chrono/steady_clock.h>
+#include <__chrono/system_clock.h>
+#include <__chrono/time_point.h>
 #include <__config>
 #include <compare>
-#include <ctime>
-#include <limits>
-#include <ratio>
-#include <type_traits>
 #include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-#ifndef _LIBCPP_CXX03_LANG
-_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
-struct _FilesystemClock;
-_LIBCPP_END_NAMESPACE_FILESYSTEM
-#endif // !_LIBCPP_CXX03_LANG
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-namespace chrono
-{
-
-template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
-
-template <class _Tp>
-struct __is_duration : false_type {};
-
-template <class _Rep, class _Period>
-struct __is_duration<duration<_Rep, _Period> > : true_type  {};
-
-template <class _Rep, class _Period>
-struct __is_duration<const duration<_Rep, _Period> > : true_type  {};
-
-template <class _Rep, class _Period>
-struct __is_duration<volatile duration<_Rep, _Period> > : true_type  {};
-
-template <class _Rep, class _Period>
-struct __is_duration<const volatile duration<_Rep, _Period> > : true_type  {};
-
-} // chrono
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
-                                         chrono::duration<_Rep2, _Period2> >
-{
-    typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
-                             typename __ratio_gcd<_Period1, _Period2>::type> type;
-};
-
-namespace chrono {
-
-// duration_cast
-
-template <class _FromDuration, class _ToDuration,
-          class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
-          bool = _Period::num == 1,
-          bool = _Period::den == 1>
-struct __duration_cast;
-
-template <class _FromDuration, class _ToDuration, class _Period>
-struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    _ToDuration operator()(const _FromDuration& __fd) const
-    {
-        return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
-    }
-};
-
-template <class _FromDuration, class _ToDuration, class _Period>
-struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    _ToDuration operator()(const _FromDuration& __fd) const
-    {
-        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
-        return _ToDuration(static_cast<typename _ToDuration::rep>(
-                           static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
-    }
-};
-
-template <class _FromDuration, class _ToDuration, class _Period>
-struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    _ToDuration operator()(const _FromDuration& __fd) const
-    {
-        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
-        return _ToDuration(static_cast<typename _ToDuration::rep>(
-                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
-    }
-};
-
-template <class _FromDuration, class _ToDuration, class _Period>
-struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    _ToDuration operator()(const _FromDuration& __fd) const
-    {
-        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
-        return _ToDuration(static_cast<typename _ToDuration::rep>(
-                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
-                                                          / static_cast<_Ct>(_Period::den)));
-    }
-};
-
-template <class _ToDuration, class _Rep, class _Period>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename enable_if
-<
-    __is_duration<_ToDuration>::value,
-    _ToDuration
->::type
-duration_cast(const duration<_Rep, _Period>& __fd)
-{
-    return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
-}
-
-template <class _Rep>
-struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
-
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Rep>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
-    = treat_as_floating_point<_Rep>::value;
-#endif
-
-template <class _Rep>
-struct _LIBCPP_TEMPLATE_VIS duration_values
-{
-public:
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max()  _NOEXCEPT {return numeric_limits<_Rep>::max();}
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min()  _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
-};
-
-#if _LIBCPP_STD_VER > 14
-template <class _ToDuration, class _Rep, class _Period>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
-    __is_duration<_ToDuration>::value,
-    _ToDuration
->::type
-floor(const duration<_Rep, _Period>& __d)
-{
-    _ToDuration __t = duration_cast<_ToDuration>(__d);
-    if (__t > __d)
-        __t = __t - _ToDuration{1};
-    return __t;
-}
-
-template <class _ToDuration, class _Rep, class _Period>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
-    __is_duration<_ToDuration>::value,
-    _ToDuration
->::type
-ceil(const duration<_Rep, _Period>& __d)
-{
-    _ToDuration __t = duration_cast<_ToDuration>(__d);
-    if (__t < __d)
-        __t = __t + _ToDuration{1};
-    return __t;
-}
-
-template <class _ToDuration, class _Rep, class _Period>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
-    __is_duration<_ToDuration>::value,
-    _ToDuration
->::type
-round(const duration<_Rep, _Period>& __d)
-{
-    _ToDuration __lower = floor<_ToDuration>(__d);
-    _ToDuration __upper = __lower + _ToDuration{1};
-    auto __lowerDiff = __d - __lower;
-    auto __upperDiff = __upper - __d;
-    if (__lowerDiff < __upperDiff)
-        return __lower;
-    if (__lowerDiff > __upperDiff)
-        return __upper;
-    return __lower.count() & 1 ? __upper : __lower;
-}
-#endif
-
-// duration
-
-template <class _Rep, class _Period>
-class _LIBCPP_TEMPLATE_VIS duration
-{
-    static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
-    static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
-    static_assert(_Period::num > 0, "duration period must be positive");
-
-    template <class _R1, class _R2>
-    struct __no_overflow
-    {
-    private:
-        static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
-        static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
-        static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
-        static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
-        static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
-        static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
-        static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
-
-        template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
-        struct __mul    // __overflow == false
-        {
-            static const intmax_t value = _Xp * _Yp;
-        };
-
-        template <intmax_t _Xp, intmax_t _Yp>
-        struct __mul<_Xp, _Yp, true>
-        {
-            static const intmax_t value = 1;
-        };
-
-    public:
-        static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
-        typedef ratio<__mul<__n1, __d2, !value>::value,
-                      __mul<__n2, __d1, !value>::value> type;
-    };
-
-public:
-    typedef _Rep rep;
-    typedef typename _Period::type period;
-private:
-    rep __rep_;
-public:
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-#ifndef _LIBCPP_CXX03_LANG
-        duration() = default;
-#else
-        duration() {}
-#endif
-
-    template <class _Rep2>
-        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-        explicit duration(const _Rep2& __r,
-            typename enable_if
-            <
-               is_convertible<_Rep2, rep>::value &&
-               (treat_as_floating_point<rep>::value ||
-               !treat_as_floating_point<_Rep2>::value)
-            >::type* = nullptr)
-                : __rep_(__r) {}
-
-    // conversions
-    template <class _Rep2, class _Period2>
-        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-        duration(const duration<_Rep2, _Period2>& __d,
-            typename enable_if
-            <
-                __no_overflow<_Period2, period>::value && (
-                treat_as_floating_point<rep>::value ||
-                (__no_overflow<_Period2, period>::type::den == 1 &&
-                 !treat_as_floating_point<_Rep2>::value))
-            >::type* = nullptr)
-                : __rep_(chrono::duration_cast<duration>(__d).count()) {}
-
-    // observer
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
-
-    // arithmetic
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++()      {++__rep_; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator++(int)   {return duration(__rep_++);}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--()      {--__rep_; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator--(int)   {return duration(__rep_--);}
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
-
-    // special values
-
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min()  _NOEXCEPT {return duration(duration_values<rep>::min());}
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max()  _NOEXCEPT {return duration(duration_values<rep>::max());}
-};
-
-typedef duration<long long,         nano> nanoseconds;
-typedef duration<long long,        micro> microseconds;
-typedef duration<long long,        milli> milliseconds;
-typedef duration<long long              > seconds;
-typedef duration<     long, ratio<  60> > minutes;
-typedef duration<     long, ratio<3600> > hours;
-#if _LIBCPP_STD_VER > 17
-typedef duration<     int, ratio_multiply<ratio<24>, hours::period>>         days;
-typedef duration<     int, ratio_multiply<ratio<7>,   days::period>>         weeks;
-typedef duration<     int, ratio_multiply<ratio<146097, 400>, days::period>> years;
-typedef duration<     int, ratio_divide<years::period, ratio<12>>>           months;
-#endif
-// Duration ==
-
-template <class _LhsDuration, class _RhsDuration>
-struct __duration_eq
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
-        {
-            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
-            return _Ct(__lhs).count() == _Ct(__rhs).count();
-        }
-};
-
-template <class _LhsDuration>
-struct __duration_eq<_LhsDuration, _LhsDuration>
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
-        {return __lhs.count() == __rhs.count();}
-};
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-bool
-operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
-}
-
-// Duration !=
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-bool
-operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    return !(__lhs == __rhs);
-}
-
-// Duration <
-
-template <class _LhsDuration, class _RhsDuration>
-struct __duration_lt
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
-        {
-            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
-            return _Ct(__lhs).count() < _Ct(__rhs).count();
-        }
-};
-
-template <class _LhsDuration>
-struct __duration_lt<_LhsDuration, _LhsDuration>
-{
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
-        {return __lhs.count() < __rhs.count();}
-};
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-bool
-operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
-}
-
-// Duration >
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-bool
-operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    return __rhs < __lhs;
-}
-
-// Duration <=
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-bool
-operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    return !(__rhs < __lhs);
-}
-
-// Duration >=
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-bool
-operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    return !(__lhs < __rhs);
-}
-
-// Duration +
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
-operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
-    return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
-}
-
-// Duration -
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
-operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
-    return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
-}
-
-// Duration *
-
-template <class _Rep1, class _Period, class _Rep2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename enable_if
-<
-    is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
-    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
->::type
-operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
-{
-    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
-    typedef duration<_Cr, _Period> _Cd;
-    return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
-}
-
-template <class _Rep1, class _Period, class _Rep2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename enable_if
-<
-    is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
-    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
->::type
-operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
-{
-    return __d * __s;
-}
-
-// Duration /
-
-template <class _Rep1, class _Period, class _Rep2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename enable_if
-<
-    !__is_duration<_Rep2>::value &&
-      is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
-    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
->::type
-operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
-{
-    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
-    typedef duration<_Cr, _Period> _Cd;
-    return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
-}
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename common_type<_Rep1, _Rep2>::type
-operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
-    return _Ct(__lhs).count() / _Ct(__rhs).count();
-}
-
-// Duration %
-
-template <class _Rep1, class _Period, class _Rep2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename enable_if
-<
-    !__is_duration<_Rep2>::value &&
-      is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
-    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
->::type
-operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
-{
-    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
-    typedef duration<_Cr, _Period> _Cd;
-    return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
-}
-
-template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
-operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
-    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
-    return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
-}
-
-//////////////////////////////////////////////////////////
-///////////////////// time_point /////////////////////////
-//////////////////////////////////////////////////////////
-
-template <class _Clock, class _Duration = typename _Clock::duration>
-class _LIBCPP_TEMPLATE_VIS time_point
-{
-    static_assert(__is_duration<_Duration>::value,
-                  "Second template parameter of time_point must be a std::chrono::duration");
-public:
-    typedef _Clock                    clock;
-    typedef _Duration                 duration;
-    typedef typename duration::rep    rep;
-    typedef typename duration::period period;
-private:
-    duration __d_;
-
-public:
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
-
-    // conversions
-    template <class _Duration2>
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-    time_point(const time_point<clock, _Duration2>& t,
-        typename enable_if
-        <
-            is_convertible<_Duration2, duration>::value
-        >::type* = nullptr)
-            : __d_(t.time_since_epoch()) {}
-
-    // observer
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
-
-    // arithmetic
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
-
-    // special values
-
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
-    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
-};
-
-} // chrono
-
-template <class _Clock, class _Duration1, class _Duration2>
-struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
-                                         chrono::time_point<_Clock, _Duration2> >
-{
-    typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
-};
-
-namespace chrono {
-
-template <class _ToDuration, class _Clock, class _Duration>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-time_point<_Clock, _ToDuration>
-time_point_cast(const time_point<_Clock, _Duration>& __t)
-{
-    return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
-}
-
-#if _LIBCPP_STD_VER > 14
-template <class _ToDuration, class _Clock, class _Duration>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
-    __is_duration<_ToDuration>::value,
-    time_point<_Clock, _ToDuration>
->::type
-floor(const time_point<_Clock, _Duration>& __t)
-{
-    return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
-}
-
-template <class _ToDuration, class _Clock, class _Duration>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
-    __is_duration<_ToDuration>::value,
-    time_point<_Clock, _ToDuration>
->::type
-ceil(const time_point<_Clock, _Duration>& __t)
-{
-    return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
-}
-
-template <class _ToDuration, class _Clock, class _Duration>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
-    __is_duration<_ToDuration>::value,
-    time_point<_Clock, _ToDuration>
->::type
-round(const time_point<_Clock, _Duration>& __t)
-{
-    return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
-}
-
-template <class _Rep, class _Period>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-typename enable_if
-<
-    numeric_limits<_Rep>::is_signed,
-    duration<_Rep, _Period>
->::type
-abs(duration<_Rep, _Period> __d)
-{
-    return __d >= __d.zero() ? +__d : -__d;
-}
-#endif
-
-// time_point ==
-
-template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-bool
-operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return __lhs.time_since_epoch() == __rhs.time_since_epoch();
-}
-
-// time_point !=
-
-template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-bool
-operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return !(__lhs == __rhs);
-}
-
-// time_point <
-
-template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-bool
-operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return __lhs.time_since_epoch() < __rhs.time_since_epoch();
-}
-
-// time_point >
-
-template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-bool
-operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return __rhs < __lhs;
-}
-
-// time_point <=
-
-template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-bool
-operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return !(__rhs < __lhs);
-}
-
-// time_point >=
-
-template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-bool
-operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return !(__lhs < __rhs);
-}
-
-// time_point operator+(time_point x, duration y);
-
-template <class _Clock, class _Duration1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
-operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
-    return _Tr (__lhs.time_since_epoch() + __rhs);
-}
-
-// time_point operator+(duration x, time_point y);
-
-template <class _Rep1, class _Period1, class _Clock, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
-operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return __rhs + __lhs;
-}
-
-// time_point operator-(time_point x, duration y);
-
-template <class _Clock, class _Duration1, class _Rep2, class _Period2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
-operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
-{
-    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
-    return _Ret(__lhs.time_since_epoch() -__rhs);
-}
-
-// duration operator-(time_point x, time_point y);
-
-template <class _Clock, class _Duration1, class _Duration2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-typename common_type<_Duration1, _Duration2>::type
-operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
-{
-    return __lhs.time_since_epoch() - __rhs.time_since_epoch();
-}
-
-//////////////////////////////////////////////////////////
-/////////////////////// clocks ///////////////////////////
-//////////////////////////////////////////////////////////
-
-class _LIBCPP_TYPE_VIS system_clock
-{
-public:
-    typedef microseconds                     duration;
-    typedef duration::rep                    rep;
-    typedef duration::period                 period;
-    typedef chrono::time_point<system_clock> time_point;
-    static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
-
-    static time_point now() _NOEXCEPT;
-    static time_t     to_time_t  (const time_point& __t) _NOEXCEPT;
-    static time_point from_time_t(time_t __t) _NOEXCEPT;
-};
-
-#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
-class _LIBCPP_TYPE_VIS steady_clock
-{
-public:
-    typedef nanoseconds                                   duration;
-    typedef duration::rep                                 rep;
-    typedef duration::period                              period;
-    typedef chrono::time_point<steady_clock, duration>    time_point;
-    static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
-
-    static time_point now() _NOEXCEPT;
-};
-
-typedef steady_clock high_resolution_clock;
-#else
-typedef system_clock high_resolution_clock;
-#endif
-
-#if _LIBCPP_STD_VER > 17
-// [time.clock.file], type file_clock
-using file_clock = _VSTD_FS::_FilesystemClock;
-
-template<class _Duration>
-using file_time = time_point<file_clock, _Duration>;
-
-
-template <class _Duration>
-using sys_time    = time_point<system_clock, _Duration>;
-using sys_seconds = sys_time<seconds>;
-using sys_days    = sys_time<days>;
-
-struct local_t {};
-template<class Duration>
-using local_time  = time_point<local_t, Duration>;
-using local_seconds = local_time<seconds>;
-using local_days    = local_time<days>;
-
-
-struct last_spec { explicit last_spec() = default; };
-
-class day {
-private:
-    unsigned char __d;
-public:
-    day() = default;
-    explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
-    inline constexpr day& operator++()    noexcept { ++__d; return *this; }
-    inline constexpr day  operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
-    inline constexpr day& operator--()    noexcept { --__d; return *this; }
-    inline constexpr day  operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
-           constexpr day& operator+=(const days& __dd) noexcept;
-           constexpr day& operator-=(const days& __dd) noexcept;
-    explicit inline constexpr operator unsigned() const noexcept { return __d; }
-    inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
-  };
-
-
-inline constexpr
-bool operator==(const day& __lhs, const day& __rhs) noexcept
-{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
-
-inline constexpr
-bool operator!=(const day& __lhs, const day& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const day& __lhs, const day& __rhs) noexcept
-{ return static_cast<unsigned>(__lhs) <  static_cast<unsigned>(__rhs); }
-
-inline constexpr
-bool operator> (const day& __lhs, const day& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const day& __lhs, const day& __rhs) noexcept
-{ return !(__rhs < __lhs);}
-
-inline constexpr
-bool operator>=(const day& __lhs, const day& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-inline constexpr
-day operator+ (const day& __lhs, const days& __rhs) noexcept
-{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
-
-inline constexpr
-day operator+ (const days& __lhs, const day& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-day operator- (const day& __lhs, const days& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-inline constexpr
-days operator-(const day& __lhs, const day& __rhs) noexcept
-{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
-              static_cast<int>(static_cast<unsigned>(__rhs))); }
-
-inline constexpr day& day::operator+=(const days& __dd) noexcept
-{ *this = *this + __dd; return *this; }
-
-inline constexpr day& day::operator-=(const days& __dd) noexcept
-{ *this = *this - __dd; return *this; }
-
-
-class month {
-private:
-    unsigned char __m;
-public:
-    month() = default;
-    explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
-    inline constexpr month& operator++()    noexcept { ++__m; return *this; }
-    inline constexpr month  operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
-    inline constexpr month& operator--()    noexcept { --__m; return *this; }
-    inline constexpr month  operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
-           constexpr month& operator+=(const months& __m1) noexcept;
-           constexpr month& operator-=(const months& __m1) noexcept;
-    explicit inline constexpr operator unsigned() const noexcept { return __m; }
-    inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
-};
-
-
-inline constexpr
-bool operator==(const month& __lhs, const month& __rhs) noexcept
-{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
-
-inline constexpr
-bool operator!=(const month& __lhs, const month& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const month& __lhs, const month& __rhs) noexcept
-{ return static_cast<unsigned>(__lhs)  < static_cast<unsigned>(__rhs); }
-
-inline constexpr
-bool operator> (const month& __lhs, const month& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const month& __lhs, const month& __rhs) noexcept
-{ return !(__rhs < __lhs); }
-
-inline constexpr
-bool operator>=(const month& __lhs, const month& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-inline constexpr
-month operator+ (const month& __lhs, const months& __rhs) noexcept
-{
-    auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
-    auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
-    return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
-}
-
-inline constexpr
-month operator+ (const months& __lhs, const month& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-month operator- (const month& __lhs, const months& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-inline constexpr
-months operator-(const month& __lhs, const month& __rhs) noexcept
-{
-    auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
-    return months(__dm <= 11 ? __dm : __dm + 12);
-}
-
-inline constexpr month& month::operator+=(const months& __dm) noexcept
-{ *this = *this + __dm; return *this; }
-
-inline constexpr month& month::operator-=(const months& __dm) noexcept
-{ *this = *this - __dm; return *this; }
-
-
-class year {
-private:
-    short __y;
-public:
-    year() = default;
-    explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
-
-    inline constexpr year& operator++()    noexcept { ++__y; return *this; }
-    inline constexpr year  operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
-    inline constexpr year& operator--()    noexcept { --__y; return *this; }
-    inline constexpr year  operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
-           constexpr year& operator+=(const years& __dy) noexcept;
-           constexpr year& operator-=(const years& __dy) noexcept;
-    inline constexpr year operator+() const noexcept { return *this; }
-    inline constexpr year operator-() const noexcept { return year{-__y}; }
-
-    inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
-    explicit inline constexpr operator int() const noexcept { return __y; }
-           constexpr bool ok() const noexcept;
-    static inline constexpr year min() noexcept { return year{-32767}; }
-    static inline constexpr year max() noexcept { return year{ 32767}; }
-};
-
-
-inline constexpr
-bool operator==(const year& __lhs, const year& __rhs) noexcept
-{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
-
-inline constexpr
-bool operator!=(const year& __lhs, const year& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const year& __lhs, const year& __rhs) noexcept
-{ return static_cast<int>(__lhs)  < static_cast<int>(__rhs); }
-
-inline constexpr
-bool operator> (const year& __lhs, const year& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const year& __lhs, const year& __rhs) noexcept
-{ return !(__rhs < __lhs); }
-
-inline constexpr
-bool operator>=(const year& __lhs, const year& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-inline constexpr
-year operator+ (const year& __lhs, const years& __rhs) noexcept
-{ return year(static_cast<int>(__lhs) + __rhs.count()); }
-
-inline constexpr
-year operator+ (const years& __lhs, const year& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year operator- (const year& __lhs, const years& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-inline constexpr
-years operator-(const year& __lhs, const year& __rhs) noexcept
-{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
-
-
-inline constexpr year& year::operator+=(const years& __dy) noexcept
-{ *this = *this + __dy; return *this; }
-
-inline constexpr year& year::operator-=(const years& __dy) noexcept
-{ *this = *this - __dy; return *this; }
-
-inline constexpr bool year::ok() const noexcept
-{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
-
-class weekday_indexed;
-class weekday_last;
-
-class weekday {
-private:
-    unsigned char __wd;
-public:
-  weekday() = default;
-  inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
-  inline constexpr          weekday(const sys_days& __sysd) noexcept
-          : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
-  inline explicit constexpr weekday(const local_days& __locd) noexcept
-          : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
-
-  inline constexpr weekday& operator++()    noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
-  inline constexpr weekday  operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
-  inline constexpr weekday& operator--()    noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
-  inline constexpr weekday  operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
-         constexpr weekday& operator+=(const days& __dd) noexcept;
-         constexpr weekday& operator-=(const days& __dd) noexcept;
-  inline constexpr unsigned c_encoding()   const noexcept { return __wd; }
-  inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; }
-  inline constexpr bool ok() const noexcept { return __wd <= 6; }
-         constexpr weekday_indexed operator[](unsigned __index) const noexcept;
-         constexpr weekday_last    operator[](last_spec) const noexcept;
-
-  // TODO: Make private?
-  static constexpr unsigned char __weekday_from_days(int __days) noexcept;
-};
-
-
-// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
-inline constexpr
-unsigned char weekday::__weekday_from_days(int __days) noexcept
-{
-    return static_cast<unsigned char>(
-              static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
-           );
-}
-
-inline constexpr
-bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
-{ return __lhs.c_encoding() == __rhs.c_encoding(); }
-
-inline constexpr
-bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
-{ return __lhs.c_encoding() < __rhs.c_encoding(); }
-
-inline constexpr
-bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
-{ return !(__rhs < __lhs);}
-
-inline constexpr
-bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
-{
-    auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
-    auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
-    return weekday{static_cast<unsigned>(__mu - __yr * 7)};
-}
-
-constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
-{
-    const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
-    const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
-    return days{__wdu - __wk * 7};
-}
-
-inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
-{ *this = *this + __dd; return *this; }
-
-inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
-{ *this = *this - __dd; return *this; }
-
-
-class weekday_indexed {
-private:
-    chrono::weekday __wd;
-    unsigned char          __idx;
-public:
-    weekday_indexed() = default;
-    inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept
-        : __wd{__wdval}, __idx(__idxval) {}
-    inline constexpr chrono::weekday weekday() const noexcept { return __wd; }
-    inline constexpr unsigned                 index() const noexcept { return __idx; }
-    inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
-};
-
-inline constexpr
-bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
-{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
-
-inline constexpr
-bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-
-class weekday_last {
-private:
-    chrono::weekday __wd;
-public:
-    explicit constexpr weekday_last(const chrono::weekday& __val) noexcept
-        : __wd{__val} {}
-    constexpr chrono::weekday weekday() const noexcept { return __wd; }
-    constexpr bool ok() const noexcept { return __wd.ok(); }
-};
-
-inline constexpr
-bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
-{ return __lhs.weekday() == __rhs.weekday(); }
-
-inline constexpr
-bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
-
-inline constexpr
-weekday_last    weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
-
-
-inline constexpr last_spec last{};
-inline constexpr weekday   Sunday{0};
-inline constexpr weekday   Monday{1};
-inline constexpr weekday   Tuesday{2};
-inline constexpr weekday   Wednesday{3};
-inline constexpr weekday   Thursday{4};
-inline constexpr weekday   Friday{5};
-inline constexpr weekday   Saturday{6};
-
-inline constexpr month January{1};
-inline constexpr month February{2};
-inline constexpr month March{3};
-inline constexpr month April{4};
-inline constexpr month May{5};
-inline constexpr month June{6};
-inline constexpr month July{7};
-inline constexpr month August{8};
-inline constexpr month September{9};
-inline constexpr month October{10};
-inline constexpr month November{11};
-inline constexpr month December{12};
-
-
-class month_day {
-private:
-   chrono::month __m;
-   chrono::day   __d;
-public:
-    month_day() = default;
-    constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
-        : __m{__mval}, __d{__dval} {}
-    inline constexpr chrono::month month() const noexcept { return __m; }
-    inline constexpr chrono::day   day()   const noexcept { return __d; }
-    constexpr bool ok() const noexcept;
-};
-
-inline constexpr
-bool month_day::ok() const noexcept
-{
-    if (!__m.ok()) return false;
-    const unsigned __dval = static_cast<unsigned>(__d);
-    if (__dval < 1 || __dval > 31) return false;
-    if (__dval <= 29) return true;
-//  Now we've got either 30 or 31
-    const unsigned __mval = static_cast<unsigned>(__m);
-    if (__mval == 2) return false;
-    if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
-        return __dval == 30;
-    return true;
-}
-
-inline constexpr
-bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
-{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
-
-inline constexpr
-bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-month_day operator/(const month& __lhs, const day& __rhs) noexcept
-{ return month_day{__lhs, __rhs}; }
-
-constexpr
-month_day operator/(const day& __lhs, const month& __rhs) noexcept
-{ return __rhs / __lhs; }
-
-inline constexpr
-month_day operator/(const month& __lhs, int __rhs) noexcept
-{ return __lhs / day(__rhs); }
-
-constexpr
-month_day operator/(int __lhs, const day& __rhs) noexcept
-{ return month(__lhs) / __rhs; }
-
-constexpr
-month_day operator/(const day& __lhs, int __rhs) noexcept
-{ return month(__rhs) / __lhs; }
-
-
-inline constexpr
-bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
-{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
-
-inline constexpr
-bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
-{ return !(__rhs < __lhs);}
-
-inline constexpr
-bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-
-
-class month_day_last {
-private:
-    chrono::month __m;
-public:
-    explicit constexpr month_day_last(const chrono::month& __val) noexcept
-        : __m{__val} {}
-    inline constexpr chrono::month month() const noexcept { return __m; }
-    inline constexpr bool ok() const noexcept { return __m.ok(); }
-};
-
-inline constexpr
-bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
-{ return __lhs.month() == __rhs.month(); }
-
-inline constexpr
-bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
-{ return __lhs.month() < __rhs.month(); }
-
-inline constexpr
-bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
-{ return !(__rhs < __lhs);}
-
-inline constexpr
-bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-inline constexpr
-month_day_last operator/(const month& __lhs, last_spec) noexcept
-{ return month_day_last{__lhs}; }
-
-inline constexpr
-month_day_last operator/(last_spec, const month& __rhs) noexcept
-{ return month_day_last{__rhs}; }
-
-inline constexpr
-month_day_last operator/(int __lhs, last_spec) noexcept
-{ return month_day_last{month(__lhs)}; }
-
-inline constexpr
-month_day_last operator/(last_spec, int __rhs) noexcept
-{ return month_day_last{month(__rhs)}; }
-
-
-class month_weekday {
-private:
-    chrono::month __m;
-    chrono::weekday_indexed __wdi;
-public:
-    month_weekday() = default;
-    constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
-        : __m{__mval}, __wdi{__wdival} {}
-    inline constexpr chrono::month                     month() const noexcept { return __m; }
-    inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
-    inline constexpr bool                                 ok() const noexcept { return __m.ok() && __wdi.ok(); }
-};
-
-inline constexpr
-bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
-{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
-
-inline constexpr
-bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
-{ return month_weekday{__lhs, __rhs}; }
-
-inline constexpr
-month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
-{ return month_weekday{month(__lhs), __rhs}; }
-
-inline constexpr
-month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
-{ return month_weekday{__rhs, __lhs}; }
-
-inline constexpr
-month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
-{ return month_weekday{month(__rhs), __lhs}; }
-
-
-class month_weekday_last {
-    chrono::month        __m;
-    chrono::weekday_last __wdl;
-  public:
-    constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
-        : __m{__mval}, __wdl{__wdlval} {}
-    inline constexpr chrono::month               month() const noexcept { return __m; }
-    inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
-    inline constexpr bool                           ok() const noexcept { return __m.ok() && __wdl.ok(); }
-};
-
-inline constexpr
-bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
-{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
-
-inline constexpr
-bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-
-inline constexpr
-month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
-{ return month_weekday_last{__lhs, __rhs}; }
-
-inline constexpr
-month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
-{ return month_weekday_last{month(__lhs), __rhs}; }
-
-inline constexpr
-month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
-{ return month_weekday_last{__rhs, __lhs}; }
-
-inline constexpr
-month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
-{ return month_weekday_last{month(__rhs), __lhs}; }
-
-
-class year_month {
-    chrono::year  __y;
-    chrono::month __m;
-public:
-    year_month() = default;
-    constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
-        : __y{__yval}, __m{__mval} {}
-    inline constexpr chrono::year  year()  const noexcept { return __y; }
-    inline constexpr chrono::month month() const noexcept { return __m; }
-    inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
-    inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
-    inline constexpr year_month& operator+=(const years& __dy)  noexcept { this->__y += __dy; return *this; }
-    inline constexpr year_month& operator-=(const years& __dy)  noexcept { this->__y -= __dy; return *this; }
-    inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
-};
-
-inline constexpr
-year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
-
-inline constexpr
-year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
-
-inline constexpr
-bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
-{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
-
-inline constexpr
-bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
-{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
-
-inline constexpr
-bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
-{ return !(__rhs < __lhs);}
-
-inline constexpr
-bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
-{
-    int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
-    const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
-    __dmi = __dmi - __dy * 12 + 1;
-    return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
-}
-
-constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
-{ return (__lhs.year() + __rhs) / __lhs.month(); }
-
-constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-constexpr months     operator-(const year_month& __lhs, const year_month& __rhs) noexcept
-{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
-
-constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-class year_month_day_last;
-
-class year_month_day {
-private:
-    chrono::year  __y;
-    chrono::month __m;
-    chrono::day   __d;
-public:
-     year_month_day() = default;
-     inline constexpr year_month_day(
-            const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
-            : __y{__yval}, __m{__mval}, __d{__dval} {}
-            constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
-     inline constexpr year_month_day(const sys_days& __sysd) noexcept
-            : year_month_day(__from_days(__sysd.time_since_epoch())) {}
-     inline explicit constexpr year_month_day(const local_days& __locd) noexcept
-            : year_month_day(__from_days(__locd.time_since_epoch())) {}
-
-            constexpr year_month_day& operator+=(const months& __dm) noexcept;
-            constexpr year_month_day& operator-=(const months& __dm) noexcept;
-            constexpr year_month_day& operator+=(const years& __dy)  noexcept;
-            constexpr year_month_day& operator-=(const years& __dy)  noexcept;
-
-     inline constexpr chrono::year   year() const noexcept { return __y; }
-     inline constexpr chrono::month month() const noexcept { return __m; }
-     inline constexpr chrono::day     day() const noexcept { return __d; }
-     inline constexpr operator   sys_days() const noexcept          { return   sys_days{__to_days()}; }
-     inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
-
-            constexpr bool             ok() const noexcept;
-
-     static constexpr year_month_day __from_days(days __d) noexcept;
-     constexpr days __to_days() const noexcept;
-};
-
-
-// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
-inline constexpr
-year_month_day
-year_month_day::__from_days(days __d) noexcept
-{
-    static_assert(numeric_limits<unsigned>::digits >= 18, "");
-    static_assert(numeric_limits<int>::digits >= 20     , "");
-    const int      __z = __d.count() + 719468;
-    const int      __era = (__z >= 0 ? __z : __z - 146096) / 146097;
-    const unsigned __doe = static_cast<unsigned>(__z - __era * 146097);              // [0, 146096]
-    const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365;  // [0, 399]
-    const int      __yr = static_cast<int>(__yoe) + __era * 400;
-    const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100);              // [0, 365]
-    const unsigned __mp = (5 * __doy + 2)/153;                                       // [0, 11]
-    const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1;                            // [1, 31]
-    const unsigned __mth = __mp + (__mp < 10 ? 3 : -9);                              // [1, 12]
-    return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
-}
-
-// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
-inline constexpr days year_month_day::__to_days() const noexcept
-{
-    static_assert(numeric_limits<unsigned>::digits >= 18, "");
-    static_assert(numeric_limits<int>::digits >= 20     , "");
-
-    const int      __yr  = static_cast<int>(__y) - (__m <= February);
-    const unsigned __mth = static_cast<unsigned>(__m);
-    const unsigned __dy  = static_cast<unsigned>(__d);
-
-    const int      __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
-    const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400);                // [0, 399]
-    const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1;  // [0, 365]
-    const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy;                // [0, 146096]
-    return days{__era * 146097 + static_cast<int>(__doe) - 719468};
-}
-
-inline constexpr
-bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
-{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
-
-inline constexpr
-bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
-{
-    if (__lhs.year() < __rhs.year()) return true;
-    if (__lhs.year() > __rhs.year()) return false;
-    if (__lhs.month() < __rhs.month()) return true;
-    if (__lhs.month() > __rhs.month()) return false;
-    return __lhs.day() < __rhs.day();
-}
-
-inline constexpr
-bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
-{ return !(__rhs < __lhs);}
-
-inline constexpr
-bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-inline constexpr
-year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
-{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
-
-inline constexpr
-year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
-{ return __lhs / day(__rhs); }
-
-inline constexpr
-year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
-{ return __lhs / __rhs.month() / __rhs.day(); }
-
-inline constexpr
-year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
-{ return year(__lhs) / __rhs; }
-
-inline constexpr
-year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
-{ return __rhs / __lhs; }
-
-inline constexpr
-year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
-{ return year(__rhs) / __lhs; }
-
-
-inline constexpr
-year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
-{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
-
-inline constexpr
-year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-inline constexpr
-year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
-{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
-
-inline constexpr
-year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
-{ return __lhs + -__rhs; }
-
-inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
-inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
-inline constexpr year_month_day& year_month_day::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
-inline constexpr year_month_day& year_month_day::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
-
-class year_month_day_last {
-private:
-    chrono::year           __y;
-    chrono::month_day_last __mdl;
-public:
-     constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
-        : __y{__yval}, __mdl{__mdlval} {}
-
-     constexpr year_month_day_last& operator+=(const months& __m) noexcept;
-     constexpr year_month_day_last& operator-=(const months& __m) noexcept;
-     constexpr year_month_day_last& operator+=(const years& __y)  noexcept;
-     constexpr year_month_day_last& operator-=(const years& __y)  noexcept;
-
-     inline constexpr chrono::year                     year() const noexcept { return __y; }
-     inline constexpr chrono::month                   month() const noexcept { return __mdl.month(); }
-     inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
-            constexpr chrono::day                       day() const noexcept;
-     inline constexpr operator                     sys_days() const noexcept { return   sys_days{year()/month()/day()}; }
-     inline explicit constexpr operator          local_days() const noexcept { return local_days{year()/month()/day()}; }
-     inline constexpr bool                               ok() const noexcept { return __y.ok() && __mdl.ok(); }
-};
-
-inline constexpr
-chrono::day year_month_day_last::day() const noexcept
-{
-    constexpr chrono::day __d[] =
-    {
-        chrono::day(31), chrono::day(28), chrono::day(31),
-        chrono::day(30), chrono::day(31), chrono::day(30),
-        chrono::day(31), chrono::day(31), chrono::day(30),
-        chrono::day(31), chrono::day(30), chrono::day(31)
-    };
-    return (month() != February || !__y.is_leap()) && month().ok() ?
-        __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
-}
-
-inline constexpr
-bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
-{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
-
-inline constexpr
-bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
-{
-    if (__lhs.year() < __rhs.year()) return true;
-    if (__lhs.year() > __rhs.year()) return false;
-    return __lhs.month_day_last() < __rhs.month_day_last();
-}
-
-inline constexpr
-bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
-{ return __rhs < __lhs; }
-
-inline constexpr
-bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
-{ return !(__rhs < __lhs);}
-
-inline constexpr
-bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
-{ return !(__lhs < __rhs); }
-
-inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
-{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
-
-inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
-{ return year_month_day_last{__lhs, __rhs}; }
-
-inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
-{ return year_month_day_last{year{__lhs}, __rhs}; }
-
-inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
-{ return __rhs / __lhs; }
-
-inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
-{ return year{__rhs} / __lhs; }
-
-
-inline constexpr
-year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
-{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
-
-inline constexpr
-year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
-{ return __lhs + (-__rhs); }
-
-inline constexpr
-year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
-{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
-
-inline constexpr
-year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
-{ return __lhs + (-__rhs); }
-
-inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
-inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
-inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
-inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
-
-inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
-    : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
-
-inline constexpr bool year_month_day::ok() const noexcept
-{
-    if (!__y.ok() || !__m.ok()) return false;
-    return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
-}
-
-class year_month_weekday {
-    chrono::year            __y;
-    chrono::month           __m;
-    chrono::weekday_indexed __wdi;
-public:
-    year_month_weekday() = default;
-    constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
-                               const chrono::weekday_indexed& __wdival) noexcept
-        : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
-    constexpr year_month_weekday(const sys_days& __sysd) noexcept
-            : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
-    inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
-            : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
-    constexpr year_month_weekday& operator+=(const months& m) noexcept;
-    constexpr year_month_weekday& operator-=(const months& m) noexcept;
-    constexpr year_month_weekday& operator+=(const years& y)  noexcept;
-    constexpr year_month_weekday& operator-=(const years& y)  noexcept;
-
-    inline constexpr chrono::year                       year() const noexcept { return __y; }
-    inline constexpr chrono::month                     month() const noexcept { return __m; }
-    inline constexpr chrono::weekday                 weekday() const noexcept { return __wdi.weekday(); }
-    inline constexpr unsigned                          index() const noexcept { return __wdi.index(); }
-    inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
-
-    inline constexpr                       operator sys_days() const noexcept { return   sys_days{__to_days()}; }
-    inline explicit constexpr operator            local_days() const noexcept { return local_days{__to_days()}; }
-    inline constexpr bool ok() const noexcept
-    {
-        if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
-        if (__wdi.index() <= 4) return true;
-        auto __nth_weekday_day =
-            __wdi.weekday() -
-            chrono::weekday{static_cast<sys_days>(__y / __m / 1)} +
-            days{(__wdi.index() - 1) * 7 + 1};
-        return static_cast<unsigned>(__nth_weekday_day.count()) <=
-               static_cast<unsigned>((__y / __m / last).day());
-    }
-
-    static constexpr year_month_weekday __from_days(days __d) noexcept;
-    constexpr days __to_days() const noexcept;
-};
-
-inline constexpr
-year_month_weekday year_month_weekday::__from_days(days __d) noexcept
-{
-    const sys_days      __sysd{__d};
-    const chrono::weekday __wd = chrono::weekday(__sysd);
-    const year_month_day __ymd = year_month_day(__sysd);
-    return year_month_weekday{__ymd.year(), __ymd.month(),
-                              __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
-}
-
-inline constexpr
-days year_month_weekday::__to_days() const noexcept
-{
-    const sys_days __sysd = sys_days(__y/__m/1);
-    return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
-                .time_since_epoch();
-}
-
-inline constexpr
-bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
-{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
-
-inline constexpr
-bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-inline constexpr
-year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
-{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
-
-inline constexpr
-year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
-{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
-
-inline constexpr
-year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
-{ return year(__lhs) / __rhs; }
-
-inline constexpr
-year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
-{ return __rhs / __lhs; }
-
-inline constexpr
-year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
-{ return year(__rhs) / __lhs; }
-
-
-inline constexpr
-year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
-{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
-
-inline constexpr
-year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
-{ return __lhs + (-__rhs); }
-
-inline constexpr
-year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
-{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
-
-inline constexpr
-year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
-{ return __lhs + (-__rhs); }
-
-
-inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
-inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
-inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
-inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
-
-class year_month_weekday_last {
-private:
-    chrono::year         __y;
-    chrono::month        __m;
-    chrono::weekday_last __wdl;
-public:
-    constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
-                                      const chrono::weekday_last& __wdlval) noexcept
-                : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
-    constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
-    constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
-    constexpr year_month_weekday_last& operator+=(const years& __dy)  noexcept;
-    constexpr year_month_weekday_last& operator-=(const years& __dy)  noexcept;
-
-    inline constexpr chrono::year                 year() const noexcept { return __y; }
-    inline constexpr chrono::month               month() const noexcept { return __m; }
-    inline constexpr chrono::weekday           weekday() const noexcept { return __wdl.weekday(); }
-    inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
-    inline constexpr operator                 sys_days() const noexcept { return   sys_days{__to_days()}; }
-    inline explicit constexpr operator      local_days() const noexcept { return local_days{__to_days()}; }
-    inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
-
-    constexpr days __to_days() const noexcept;
-
-};
-
-inline constexpr
-days year_month_weekday_last::__to_days() const noexcept
-{
-    const sys_days __last = sys_days{__y/__m/last};
-    return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
-
-}
-
-inline constexpr
-bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
-{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
-
-inline constexpr
-bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
-{ return !(__lhs == __rhs); }
-
-
-inline constexpr
-year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
-{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
-
-inline constexpr
-year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
-{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
-
-inline constexpr
-year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
-{ return year(__lhs) / __rhs; }
-
-inline constexpr
-year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
-{ return __rhs / __lhs; }
-
-inline constexpr
-year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
-{ return year(__rhs) / __lhs; }
-
-
-inline constexpr
-year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
-{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
-
-inline constexpr
-year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
-{ return __lhs + (-__rhs); }
-
-inline constexpr
-year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
-{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
-
-inline constexpr
-year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
-{ return __rhs + __lhs; }
-
-inline constexpr
-year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
-{ return __lhs + (-__rhs); }
-
-inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
-inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
-inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
-inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
-
-
-template <class _Duration>
-class hh_mm_ss
-{
-private:
-    static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
-    using __CommonType = common_type_t<_Duration, chrono::seconds>;
-
-    static constexpr uint64_t __pow10(unsigned __exp)
-    {
-        uint64_t __ret = 1;
-        for (unsigned __i = 0; __i < __exp; ++__i)
-            __ret *= 10U;
-        return __ret;
-    }
-
-    static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0)
-    {
-        if (__n >= 2 && __d != 0 && __w < 19)
-            return 1 + __width(__n, __d % __n * 10, __w+1);
-        return 0;
-    }
-
-public:
-    static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ?
-                                                 __width(__CommonType::period::den) : 6u;
-    using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
-
-    constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
-
-    constexpr explicit hh_mm_ss(_Duration __d) noexcept :
-        __is_neg(__d < _Duration(0)),
-        __h(duration_cast<chrono::hours>  (abs(__d))),
-        __m(duration_cast<chrono::minutes>(abs(__d) - hours())),
-        __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())),
-        __f(duration_cast<precision>      (abs(__d) - hours() - minutes() - seconds()))
-        {}
-
-    constexpr bool is_negative()        const noexcept { return __is_neg; }
-    constexpr chrono::hours hours()     const noexcept { return __h; }
-    constexpr chrono::minutes minutes() const noexcept { return __m; }
-    constexpr chrono::seconds seconds() const noexcept { return __s; }
-    constexpr precision subseconds()    const noexcept { return __f; }
-
-    constexpr precision to_duration() const noexcept
-    {
-        auto __dur = __h + __m + __s + __f;
-        return __is_neg ? -__dur : __dur;
-    }
-
-    constexpr explicit operator precision() const noexcept { return to_duration(); }
-
-private:
-    bool            __is_neg;
-    chrono::hours   __h;
-    chrono::minutes __m;
-    chrono::seconds __s;
-    precision       __f;
-};
-
-constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
-constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
-
-constexpr hours make12(const hours& __h) noexcept
-{
-    if      (__h == hours( 0)) return hours(12);
-    else if (__h <= hours(12)) return __h;
-    else                       return __h - hours(12);
-}
-
-constexpr hours make24(const hours& __h, bool __is_pm) noexcept
-{
-    if (__is_pm)
-        return __h == hours(12) ? __h : __h + hours(12);
-    else
-        return __h == hours(12) ? hours(0) : __h;
-}
-
-#endif // _LIBCPP_STD_VER > 17
-} // chrono
-
-#if _LIBCPP_STD_VER > 11
-// Suffixes for duration literals [time.duration.literals]
-inline namespace literals
-{
-  inline namespace chrono_literals
-  {
-
-    constexpr chrono::hours operator""h(unsigned long long __h)
-    {
-        return chrono::hours(static_cast<chrono::hours::rep>(__h));
-    }
-
-    constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
-    {
-        return chrono::duration<long double, ratio<3600,1>>(__h);
-    }
-
-
-    constexpr chrono::minutes operator""min(unsigned long long __m)
-    {
-        return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
-    }
-
-    constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
-    {
-        return chrono::duration<long double, ratio<60,1>> (__m);
-    }
-
-
-    constexpr chrono::seconds operator""s(unsigned long long __s)
-    {
-        return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
-    }
-
-    constexpr chrono::duration<long double> operator""s(long double __s)
-    {
-        return chrono::duration<long double> (__s);
-    }
-
-
-    constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
-    {
-        return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
-    }
-
-    constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
-    {
-        return chrono::duration<long double, milli>(__ms);
-    }
-
-
-    constexpr chrono::microseconds operator""us(unsigned long long __us)
-    {
-        return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
-    }
-
-    constexpr chrono::duration<long double, micro> operator""us(long double __us)
-    {
-        return chrono::duration<long double, micro> (__us);
-    }
-
-
-    constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
-    {
-        return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
-    }
-
-    constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
-    {
-        return chrono::duration<long double, nano> (__ns);
-    }
-
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
-    constexpr chrono::day operator ""d(unsigned long long __d) noexcept
-    {
-        return chrono::day(static_cast<unsigned>(__d));
-    }
-
-    constexpr chrono::year operator ""y(unsigned long long __y) noexcept
-    {
-        return chrono::year(static_cast<int>(__y));
-    }
-#endif
-}}
-
-namespace chrono { // hoist the literals into namespace std::chrono
-   using namespace literals::chrono_literals;
-}
-
-#endif
-
-_LIBCPP_END_NAMESPACE_STD
-
-#ifndef _LIBCPP_CXX03_LANG
-_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
-struct _FilesystemClock {
-#if !defined(_LIBCPP_HAS_NO_INT128)
-  typedef __int128_t rep;
-  typedef nano period;
-#else
-  typedef long long rep;
-  typedef nano period;
-#endif
-
-  typedef chrono::duration<rep, period> duration;
-  typedef chrono::time_point<_FilesystemClock> time_point;
-
-  _LIBCPP_EXPORTED_FROM_ABI
-  static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
-
-  _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
-
-  _LIBCPP_INLINE_VISIBILITY
-  static time_t to_time_t(const time_point& __t) noexcept {
-      typedef chrono::duration<rep> __secs;
-      return time_t(
-          chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  static time_point from_time_t(time_t __t) noexcept {
-      typedef chrono::duration<rep> __secs;
-      return time_point(__secs(__t));
-  }
-};
-_LIBCPP_END_NAMESPACE_FILESYSTEM
-#endif // !_LIBCPP_CXX03_LANG
-
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP_CHRONO
lib/libcxx/include/cinttypes
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cinttypes --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ciso646
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- ciso646 ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/climits
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- climits ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/clocale
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- clocale ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -44,9 +44,7 @@ lconv* localeconv();
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::lconv _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
 using ::setlocale _LIBCPP_USING_IF_EXISTS;
-#endif
 using ::localeconv _LIBCPP_USING_IF_EXISTS;
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/cmath
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- cmath -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -306,8 +306,8 @@ constexpr long double lerp(long double a, long double b, long double t) noexcept
 
 #include <__config>
 #include <math.h>
-#include <version>
 #include <type_traits>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -535,7 +535,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y
 
 template <class _A1, class _A2, class _A3>
 inline _LIBCPP_INLINE_VISIBILITY
-typename _EnableIf
+typename enable_if_t
 <
     is_arithmetic<_A1>::value &&
     is_arithmetic<_A2>::value &&
@@ -636,37 +636,24 @@ lerp(double __a, double __b, double __t)                _NOEXCEPT { return __ler
 constexpr long double
 lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
 
-#endif // _LIBCPP_STD_VER > 17
-
-template <class _IntT, class _FloatT,
-    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
-    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
-_LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT {
-  static_assert(is_floating_point<_FloatT>::value, "must be a floating point type");
-  static_assert(is_integral<_IntT>::value, "must be an integral type");
-  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
-  static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value
-                 || _IsSame<_FloatT,long double>::value), "unsupported floating point type");
-  return _FloatBigger ? numeric_limits<_IntT>::max() :  (numeric_limits<_IntT>::max() >> _Bits << _Bits);
-}
-
-// Convert a floating point number to the specified integral type after
-// clamping to the integral types representable range.
-//
-// The behavior is undefined if `__r` is NaN.
-template <class _IntT, class _RealT>
-_LIBCPP_INLINE_VISIBILITY
-_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
-  using _Lim = numeric_limits<_IntT>;
-  const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>();
-  if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {
-    return _Lim::max();
-  } else if (__r <= _Lim::lowest()) {
-    return _Lim::min();
-  }
-  return static_cast<_IntT>(__r);
+template <class _A1, class _A2, class _A3>
+inline _LIBCPP_HIDE_FROM_ABI
+constexpr typename enable_if_t
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value &&
+    is_arithmetic<_A3>::value,
+    __promote<_A1, _A2, _A3>
+>::type
+lerp(_A1 __a, _A2 __b, _A3 __t) noexcept
+{
+    typedef typename __promote<_A1, _A2, _A3>::type __result_type;
+    static_assert(!(_IsSame<_A1, __result_type>::value &&
+                    _IsSame<_A2, __result_type>::value &&
+                    _IsSame<_A3, __result_type>::value));
+    return __lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);
 }
+#endif // _LIBCPP_STD_VER > 17
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/codecvt
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- codecvt -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -56,6 +56,7 @@ class codecvt_utf8_utf16
 
 #include <__config>
 #include <__locale>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -74,6 +75,7 @@ enum codecvt_mode
 
 template <class _Elem> class __codecvt_utf8;
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
     : public codecvt<wchar_t, char, mbstate_t>
@@ -108,6 +110,7 @@ protected:
                           size_t __mx) const;
     virtual int do_max_length() const _NOEXCEPT;
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <>
@@ -203,6 +206,7 @@ public:
 
 template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
     : public codecvt<wchar_t, char, mbstate_t>
@@ -272,6 +276,7 @@ protected:
                           size_t __mx) const;
     virtual int do_max_length() const _NOEXCEPT;
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <>
@@ -443,6 +448,7 @@ public:
 
 template <class _Elem> class __codecvt_utf8_utf16;
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
     : public codecvt<wchar_t, char, mbstate_t>
@@ -477,6 +483,7 @@ protected:
                           size_t __mx) const;
     virtual int do_max_length() const _NOEXCEPT;
 };
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <>
lib/libcxx/include/compare
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- compare -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -20,8 +20,8 @@ namespace std {
   class strong_ordering;
 
   // named comparison functions
-  constexpr bool is_eq  (partial_ordering cmp) noexcept    { return cmp == 0; }
-  constexpr bool is_neq (partial_ordering cmp) noexcept    { return cmp != 0; }
+  constexpr bool is_eq  (partial_ordering cmp) noexcept { return cmp == 0; }
+  constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
   constexpr bool is_lt  (partial_ordering cmp) noexcept { return cmp < 0; }
   constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
   constexpr bool is_gt  (partial_ordering cmp) noexcept { return cmp > 0; }
@@ -35,10 +35,30 @@ namespace std {
   template<class... Ts>
     using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
 
+  // [cmp.concept], concept three_way_comparable
+  template<class T, class Cat = partial_ordering>
+    concept three_way_comparable = see below;
+  template<class T, class U, class Cat = partial_ordering>
+    concept three_way_comparable_with = see below;
+
+  // [cmp.result], result of three-way comparison
+  template<class T, class U = T> struct compare_three_way_result;
+
+  template<class T, class U = T>
+    using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
+
+  // [comparisons.three.way], class compare_three_way
+  struct compare_three_way; // C++20
+
   // [cmp.alg], comparison algorithms
-  template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
-  template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
-  template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
+  inline namespace unspecified {
+    inline constexpr unspecified strong_order = unspecified;
+    inline constexpr unspecified weak_order = unspecified;
+    inline constexpr unspecified partial_order = unspecified;
+    inline constexpr unspecified compare_strong_order_fallback = unspecified;
+    inline constexpr unspecified compare_weak_order_fallback = unspecified;
+    inline constexpr unspecified compare_partial_order_fallback = unspecified;
+  }
 
   // [cmp.partialord], Class partial_ordering
   class partial_ordering {
@@ -120,370 +140,23 @@ namespace std {
 }
 */
 
+#include <__compare/common_comparison_category.h>
+#include <__compare/compare_partial_order_fallback.h>
+#include <__compare/compare_strong_order_fallback.h>
+#include <__compare/compare_three_way.h>
+#include <__compare/compare_three_way_result.h>
+#include <__compare/compare_weak_order_fallback.h>
+#include <__compare/is_eq.h>
+#include <__compare/ordering.h>
+#include <__compare/partial_order.h>
+#include <__compare/strong_order.h>
+#include <__compare/three_way_comparable.h>
+#include <__compare/weak_order.h>
 #include <__config>
-#include <type_traits>
+#include <version>
 
-#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
-// exposition only
-enum class _LIBCPP_ENUM_VIS _EqResult : unsigned char {
-  __zero = 0,
-  __equal = __zero,
-  __equiv = __equal,
-  __nonequal = 1,
-  __nonequiv = __nonequal
-};
-
-enum class _LIBCPP_ENUM_VIS _OrdResult : signed char {
-  __less = -1,
-  __greater = 1
-};
-
-enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {
-  __unordered = -127
-};
-
-class partial_ordering;
-class weak_ordering;
-class strong_ordering;
-
-template<class _Tp, class... _Args>
-inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
-
-struct _CmpUnspecifiedParam {
-  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEVAL
-  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
-
-  template<class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
-  _CmpUnspecifiedParam(_Tp) = delete;
-};
-
-class partial_ordering {
-  using _ValueT = signed char;
-
-  _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr partial_ordering(_EqResult __v) noexcept
-      : __value_(_ValueT(__v)) {}
-
-  _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr partial_ordering(_OrdResult __v) noexcept
-      : __value_(_ValueT(__v)) {}
-
-  _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr partial_ordering(_NCmpResult __v) noexcept
-      : __value_(_ValueT(__v)) {}
-
-  constexpr bool __is_ordered() const noexcept {
-    return __value_ != _ValueT(_NCmpResult::__unordered);
-  }
-public:
-  // valid values
-  static const partial_ordering less;
-  static const partial_ordering equivalent;
-  static const partial_ordering greater;
-  static const partial_ordering unordered;
-
-  // comparisons
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__is_ordered() && __v.__value_ == 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__is_ordered() && __v.__value_ < 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
-    return __v.__is_ordered() && __v.__value_ <= 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
-    return __v.__is_ordered() && __v.__value_ > 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
-    return __v.__is_ordered() && __v.__value_ >= 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
-    return __v.__is_ordered() && 0 < __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
-    return __v.__is_ordered() && 0 <= __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
-    return __v.__is_ordered() && 0 > __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
-    return __v.__is_ordered() && 0 >= __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept  {
-    return __v;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept  {
-    return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
-  }
-private:
-  _ValueT __value_;
-};
-
-_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
-_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::equivalent(_EqResult::__equiv);
-_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
-_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
-
-class weak_ordering {
-  using _ValueT = signed char;
-
-  _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr weak_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
-  _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
-
-public:
-  static const weak_ordering less;
-  static const weak_ordering equivalent;
-  static const weak_ordering greater;
-
-  _LIBCPP_INLINE_VISIBILITY
-  constexpr operator partial_ordering() const noexcept {
-    return __value_ == 0 ? partial_ordering::equivalent
-        : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
-  }
-
-  // comparisons
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ == 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ < 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ <= 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ > 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ >= 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
-    return 0 < __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
-    return 0 <= __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
-    return 0 > __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
-    return 0 >= __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
-    return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
-  }
-
-private:
-  _ValueT __value_;
-};
-
-_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::less(_OrdResult::__less);
-_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::equivalent(_EqResult::__equiv);
-_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
-class strong_ordering {
-  using _ValueT = signed char;
-
-  _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr strong_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
-  _LIBCPP_INLINE_VISIBILITY
-  explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
-
-public:
-  static const strong_ordering less;
-  static const strong_ordering equal;
-  static const strong_ordering equivalent;
-  static const strong_ordering greater;
-
-  // conversions
-  _LIBCPP_INLINE_VISIBILITY
-  constexpr operator partial_ordering() const noexcept {
-    return __value_ == 0 ? partial_ordering::equivalent
-        : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  constexpr operator weak_ordering() const noexcept {
-    return __value_ == 0 ? weak_ordering::equivalent
-        : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
-  }
-
-  // comparisons
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ == 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ < 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ <= 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ > 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v.__value_ >= 0;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
-    return 0 < __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
-    return 0 <= __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
-    return 0 > __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
-    return 0 >= __v.__value_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
-    return __v;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
-    return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
-  }
-
-private:
-  _ValueT __value_;
-};
-
-_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::less(_OrdResult::__less);
-_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equal(_EqResult::__equal);
-_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equivalent(_EqResult::__equiv);
-_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater);
-
-// named comparison functions
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool is_lt(partial_ordering __cmp) noexcept { return __cmp < 0; }
-
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool is_lteq(partial_ordering __cmp) noexcept { return __cmp <= 0; }
-
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool is_gt(partial_ordering __cmp) noexcept { return __cmp > 0; }
-
-_LIBCPP_INLINE_VISIBILITY
-constexpr bool is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; }
-
-namespace __comp_detail {
-
-enum _ClassifyCompCategory : unsigned{
-  _None,
-  _PartialOrd,
-  _WeakOrd,
-  _StrongOrd,
-  _CCC_Size
-};
-
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY
-constexpr _ClassifyCompCategory __type_to_enum() noexcept {
-  if (is_same_v<_Tp, partial_ordering>)
-    return _PartialOrd;
-  if (is_same_v<_Tp, weak_ordering>)
-    return _WeakOrd;
-  if (is_same_v<_Tp, strong_ordering>)
-    return _StrongOrd;
-  return _None;
-}
-
-template <size_t _Size>
-constexpr _ClassifyCompCategory
-__compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
-  int __seen[_CCC_Size] = {};
-  for (auto __type : __types)
-    ++__seen[__type];
-  if (__seen[_None])
-    return _None;
-  if (__seen[_PartialOrd])
-    return _PartialOrd;
-  if (__seen[_WeakOrd])
-    return _WeakOrd;
-  return _StrongOrd;
-}
-
-template <class ..._Ts, bool _False = false>
-constexpr auto __get_comp_type() {
-  using _CCC = _ClassifyCompCategory;
-  constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
-  constexpr _CCC _Cat = __compute_comp_type(__type_kinds);
-  if constexpr (_Cat == _None)
-    return void();
-  else if constexpr (_Cat == _PartialOrd)
-    return partial_ordering::equivalent;
-  else if constexpr (_Cat == _WeakOrd)
-    return weak_ordering::equivalent;
-  else if constexpr (_Cat == _StrongOrd)
-    return strong_ordering::equivalent;
-  else
-    static_assert(_False, "unhandled case");
-}
-} // namespace __comp_detail
-
-// [cmp.common], common comparison category type
-template<class... _Ts>
-struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
-  using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
-};
-
-template<class... _Ts>
-using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
-
-// [cmp.alg], comparison algorithms
-// TODO: unimplemented
-template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
-template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
-template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
-
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
-
-_LIBCPP_END_NAMESPACE_STD
-
 #endif // _LIBCPP_COMPARE
lib/libcxx/include/complex
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- complex ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -1056,6 +1056,9 @@ complex<_Tp>
 exp(const complex<_Tp>& __x)
 {
     _Tp __i = __x.imag();
+    if (__i == 0) {
+        return complex<_Tp>(exp(__x.real()), copysign(_Tp(0), __x.imag()));
+    }
     if (__libcpp_isinf_or_builtin(__x.real()))
     {
         if (__x.real() < _Tp(0))
@@ -1070,8 +1073,6 @@ exp(const complex<_Tp>& __x)
             return complex<_Tp>(__x.real(), __i);
         }
     }
-    else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
-        return __x;
     _Tp __e = exp(__x.real());
     return complex<_Tp>(__e * cos(__i), __e * sin(__i));
 }
@@ -1269,8 +1270,8 @@ tanh(const complex<_Tp>& __x)
     if (__libcpp_isinf_or_builtin(__x.real()))
     {
         if (!__libcpp_isfinite_or_builtin(__x.imag()))
-            return complex<_Tp>(_Tp(1), _Tp(0));
-        return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
+            return complex<_Tp>(copysign(_Tp(1), __x.real()), _Tp(0));
+        return complex<_Tp>(copysign(_Tp(1), __x.real()), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
     }
     if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
         return __x;
@@ -1484,8 +1485,8 @@ inline namespace literals
     {
         return { 0.0f, static_cast<float>(__im) };
     }
-  }
-}
+  } // namespace complex_literals
+} // namespace literals
 #endif
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/complex.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- complex.h --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/concepts
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- concepts ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -129,327 +129,33 @@ namespace std {
 
 */
 
+#include <__concepts/arithmetic.h>
+#include <__concepts/assignable.h>
+#include <__concepts/boolean_testable.h>
+#include <__concepts/class_or_enum.h>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/common_with.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/destructible.h>
+#include <__concepts/different_from.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__concepts/predicate.h>
+#include <__concepts/regular.h>
+#include <__concepts/relation.h>
+#include <__concepts/same_as.h>
+#include <__concepts/semiregular.h>
+#include <__concepts/swappable.h>
+#include <__concepts/totally_ordered.h>
 #include <__config>
-#include <__functional/invoke.h>
-#include <__functional_base>
-#include <type_traits>
-#include <utility>
 #include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
-
-// [concept.same]
-
-template<class _Tp, class _Up>
-concept __same_as_impl = _VSTD::_IsSame<_Tp, _Up>::value;
-
-template<class _Tp, class _Up>
-concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
-
-// [concept.derived]
-template<class _Dp, class _Bp>
-concept derived_from =
-  is_base_of_v<_Bp, _Dp> &&
-  is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
-
-// [concept.convertible]
-template<class _From, class _To>
-concept convertible_to =
-  is_convertible_v<_From, _To> &&
-  requires(add_rvalue_reference_t<_From> (&__f)()) {
-    static_cast<_To>(__f());
-  };
-
-// [concept.commonref]
-template<class _Tp, class _Up>
-concept common_reference_with =
-  same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>> &&
-  convertible_to<_Tp, common_reference_t<_Tp, _Up>> &&
-  convertible_to<_Up, common_reference_t<_Tp, _Up>>;
-
-// [concept.common]
-template<class _Tp, class _Up>
-concept common_with =
-  same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>> &&
-  requires {
-    static_cast<common_type_t<_Tp, _Up>>(declval<_Tp>());
-    static_cast<common_type_t<_Tp, _Up>>(declval<_Up>());
-  } &&
-  common_reference_with<
-    add_lvalue_reference_t<const _Tp>,
-    add_lvalue_reference_t<const _Up>> &&
-  common_reference_with<
-    add_lvalue_reference_t<common_type_t<_Tp, _Up>>,
-    common_reference_t<
-      add_lvalue_reference_t<const _Tp>,
-      add_lvalue_reference_t<const _Up>>>;
-
-// [concepts.arithmetic], arithmetic concepts
-template<class _Tp>
-concept integral = is_integral_v<_Tp>;
-
-template<class _Tp>
-concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
-
-template<class _Tp>
-concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
-
-template<class _Tp>
-concept floating_point = is_floating_point_v<_Tp>;
-
-// [concept.assignable]
-template<class _Lhs, class _Rhs>
-concept assignable_from =
-  is_lvalue_reference_v<_Lhs> &&
-  common_reference_with<__make_const_lvalue_ref<_Lhs>, __make_const_lvalue_ref<_Rhs>> &&
-  requires (_Lhs __lhs, _Rhs&& __rhs) {
-    { __lhs = _VSTD::forward<_Rhs>(__rhs) } -> same_as<_Lhs>;
-  };
-
-// [concept.destructible]
-
-template<class _Tp>
-concept destructible = is_nothrow_destructible_v<_Tp>;
-
-// [concept.constructible]
-template<class _Tp, class... _Args>
-concept constructible_from =
-    destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
-
-// [concept.default.init]
-
-template<class _Tp>
-concept __default_initializable = requires { ::new _Tp; };
-
-template<class _Tp>
-concept default_initializable = constructible_from<_Tp> &&
-    requires { _Tp{}; } && __default_initializable<_Tp>;
-
-// [concept.moveconstructible]
-template<class _Tp>
-concept move_constructible =
-  constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
-
-// [concept.copyconstructible]
-template<class _Tp>
-concept copy_constructible =
-  move_constructible<_Tp> &&
-  constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
-  constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
-  constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
-
-// Whether a type is a class type or enumeration type according to the Core wording.
-template<class _Tp>
-concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
-
-// [concept.swappable]
-namespace ranges::__swap {
-  // Deleted to inhibit ADL
-  template<class _Tp>
-  void swap(_Tp&, _Tp&) = delete;
-
-
-  // [1]
-  template<class _Tp, class _Up>
-  concept __unqualified_swappable_with =
-    (__class_or_enum<remove_cvref_t<_Tp>> || __class_or_enum<remove_cvref_t<_Up>>) &&
-    requires(_Tp&& __t, _Up&& __u) {
-      swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
-    };
-
-  struct __fn;
-
-  template<class _Tp, class _Up, size_t _Size>
-  concept __swappable_arrays =
-    !__unqualified_swappable_with<_Tp(&)[_Size], _Up(&)[_Size]> &&
-    extent_v<_Tp> == extent_v<_Up> &&
-    requires(_Tp(& __t)[_Size], _Up(& __u)[_Size], const __fn& __swap) {
-      __swap(__t[0], __u[0]);
-    };
-
-  template<class _Tp>
-  concept __exchangeable =
-    !__unqualified_swappable_with<_Tp&, _Tp&> &&
-    move_constructible<_Tp> &&
-    assignable_from<_Tp&, _Tp>;
-
-  struct __fn {
-    // 2.1   `S` is `(void)swap(E1, E2)`* if `E1` or `E2` has class or enumeration type and...
-    // *The name `swap` is used here unqualified.
-    template<class _Tp, class _Up>
-    requires __unqualified_swappable_with<_Tp, _Up>
-    constexpr void operator()(_Tp&& __t, _Up&& __u) const
-    noexcept(noexcept(swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u))))
-    {
-      swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
-    }
-
-    // 2.2   Otherwise, if `E1` and `E2` are lvalues of array types with equal extent and...
-    template<class _Tp, class _Up, size_t _Size>
-    requires __swappable_arrays<_Tp, _Up, _Size>
-    constexpr void operator()(_Tp(& __t)[_Size], _Up(& __u)[_Size]) const
-    noexcept(noexcept((*this)(*__t, *__u)))
-    {
-      // TODO(cjdb): replace with `ranges::swap_ranges`.
-      for (size_t __i = 0; __i < _Size; ++__i) {
-        (*this)(__t[__i], __u[__i]);
-      }
-    }
-
-    // 2.3   Otherwise, if `E1` and `E2` are lvalues of the same type `T` that models...
-    template<__exchangeable _Tp>
-    constexpr void operator()(_Tp& __x, _Tp& __y) const
-    noexcept(is_nothrow_move_constructible_v<_Tp> && is_nothrow_move_assignable_v<_Tp>)
-    {
-      __y = _VSTD::exchange(__x, _VSTD::move(__y));
-    }
-  };
-} // namespace ranges::__swap
-
-namespace ranges::inline __cpo {
-  inline constexpr auto swap = __swap::__fn{};
-} // namespace ranges::__cpo
-
-template<class _Tp>
-concept swappable = requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); };
-
-template<class _Tp, class _Up>
-concept swappable_with =
-  common_reference_with<_Tp, _Up> &&
-  requires(_Tp&& __t, _Up&& __u) {
-    ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Tp>(__t));
-    ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Up>(__u));
-    ranges::swap(_VSTD::forward<_Tp>(__t), _VSTD::forward<_Up>(__u));
-    ranges::swap(_VSTD::forward<_Up>(__u), _VSTD::forward<_Tp>(__t));
-  };
-
-// [concept.booleantestable]
-template<class _Tp>
-concept __boolean_testable_impl = convertible_to<_Tp, bool>;
-
-template<class _Tp>
-concept __boolean_testable = __boolean_testable_impl<_Tp> && requires(_Tp&& __t) {
-  { !std::forward<_Tp>(__t) } -> __boolean_testable_impl;
-};
-
-// [concept.equalitycomparable]
-template<class _Tp, class _Up>
-concept __weakly_equality_comparable_with =
-  requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
-    { __t == __u } -> __boolean_testable;
-    { __t != __u } -> __boolean_testable;
-    { __u == __t } -> __boolean_testable;
-    { __u != __t } -> __boolean_testable;
-  };
-
-template<class _Tp>
-concept equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>;
-
-template<class _Tp, class _Up>
-concept equality_comparable_with =
-  equality_comparable<_Tp> && equality_comparable<_Up> &&
-  common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
-  equality_comparable<
-    common_reference_t<
-      __make_const_lvalue_ref<_Tp>,
-      __make_const_lvalue_ref<_Up>>> &&
-  __weakly_equality_comparable_with<_Tp, _Up>;
-
-// [concept.totallyordered]
-
-template<class _Tp, class _Up>
-concept __partially_ordered_with =
-  requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
-    { __t <  __u } -> __boolean_testable;
-    { __t >  __u } -> __boolean_testable;
-    { __t <= __u } -> __boolean_testable;
-    { __t >= __u } -> __boolean_testable;
-    { __u <  __t } -> __boolean_testable;
-    { __u >  __t } -> __boolean_testable;
-    { __u <= __t } -> __boolean_testable;
-    { __u >= __t } -> __boolean_testable;
-  };
-
-template<class _Tp>
-concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>;
-
-template<class _Tp, class _Up>
-concept totally_ordered_with =
-  totally_ordered<_Tp> && totally_ordered<_Up> &&
-  equality_comparable_with<_Tp, _Up> &&
-  totally_ordered<
-    common_reference_t<
-      __make_const_lvalue_ref<_Tp>,
-      __make_const_lvalue_ref<_Up>>> &&
-  __partially_ordered_with<_Tp, _Up>;
-
-// [concepts.object]
-template<class _Tp>
-concept movable =
-  is_object_v<_Tp> &&
-  move_constructible<_Tp> &&
-  assignable_from<_Tp&, _Tp> &&
-  swappable<_Tp>;
-
-template<class _Tp>
-concept copyable =
-  copy_constructible<_Tp> &&
-  movable<_Tp> &&
-  assignable_from<_Tp&, _Tp&> &&
-  assignable_from<_Tp&, const _Tp&> &&
-  assignable_from<_Tp&, const _Tp>;
-
-template<class _Tp>
-concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
-
-template<class _Tp>
-concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
-
-// [concept.invocable]
-template<class _Fn, class... _Args>
-concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
-  _VSTD::invoke(_VSTD::forward<_Fn>(__fn), _VSTD::forward<_Args>(__args)...); // not required to be equality preserving
-};
-
-// [concept.regular.invocable]
-template<class _Fn, class... _Args>
-concept regular_invocable = invocable<_Fn, _Args...>;
-
-// [concept.predicate]
-template<class _Fn, class... _Args>
-concept predicate =
-  regular_invocable<_Fn, _Args...> && __boolean_testable<invoke_result_t<_Fn, _Args...>>;
-
-// [concept.relation]
-template<class _Rp, class _Tp, class _Up>
-concept relation =
-  predicate<_Rp, _Tp, _Tp> && predicate<_Rp, _Up, _Up> &&
-  predicate<_Rp, _Tp, _Up> && predicate<_Rp, _Up, _Tp>;
-
-// [concept.equiv]
-template<class _Rp, class _Tp, class _Up>
-concept equivalence_relation = relation<_Rp, _Tp, _Up>;
-
-// [concept.strictweakorder]
-template<class _Rp, class _Tp, class _Up>
-concept strict_weak_order = relation<_Rp, _Tp, _Up>;
-
-template<class _Tp, class _Up>
-concept __different_from = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
-
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
-
-_LIBCPP_END_NAMESPACE_STD
-
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP_CONCEPTS
lib/libcxx/include/condition_variable
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------- condition_variable ----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -109,6 +109,7 @@ public:
 #include <__config>
 #include <__mutex_base>
 #include <memory>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/coroutine
@@ -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_COROUTINE
+#define _LIBCPP_COROUTINE
+
+/**
+    coroutine synopsis
+
+namespace std {
+// [coroutine.traits]
+template <class R, class... ArgTypes>
+  struct coroutine_traits;
+// [coroutine.handle]
+template <class Promise = void>
+  struct coroutine_handle;
+// [coroutine.handle.compare]
+constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept;
+constexpr strong_ordering operator<=>(coroutine_handle<> x, coroutine_handle<> y) noexcept;
+// [coroutine.handle.hash]
+template <class T> struct hash;
+template <class P> struct hash<coroutine_handle<P>>;
+// [coroutine.noop]
+struct noop_coroutine_promise;
+template<> struct coroutine_handle<noop_coroutine_promise>;
+using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
+noop_coroutine_handle noop_coroutine() noexcept;
+// [coroutine.trivial.awaitables]
+struct suspend_never;
+struct suspend_always;
+} // namespace std
+
+ */
+
+#include <__config>
+#include <__coroutine/coroutine_handle.h>
+#include <__coroutine/coroutine_traits.h>
+#include <__coroutine/noop_coroutine_handle.h>
+#include <__coroutine/trivial_awaitables.h>
+#include <version>
+
+#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+#endif // _LIBCPP_COROUTINE
lib/libcxx/include/csetjmp
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- csetjmp ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/csignal
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- csignal ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstdarg
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstdarg ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstdbool
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstdbool ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstddef
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstddef ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -58,14 +58,16 @@ template <>          struct __libcpp_is_integral<bool>               { enum { va
 template <>          struct __libcpp_is_integral<char>               { enum { value = 1 }; };
 template <>          struct __libcpp_is_integral<signed char>        { enum { value = 1 }; };
 template <>          struct __libcpp_is_integral<unsigned char>      { enum { value = 1 }; };
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>          struct __libcpp_is_integral<wchar_t>            { enum { value = 1 }; };
+#endif
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
 template <>          struct __libcpp_is_integral<char8_t>            { enum { value = 1 }; };
 #endif
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
 template <>          struct __libcpp_is_integral<char16_t>           { enum { value = 1 }; };
 template <>          struct __libcpp_is_integral<char32_t>           { enum { value = 1 }; };
-#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
+#endif
 template <>          struct __libcpp_is_integral<short>              { enum { value = 1 }; };
 template <>          struct __libcpp_is_integral<unsigned short>     { enum { value = 1 }; };
 template <>          struct __libcpp_is_integral<int>                { enum { value = 1 }; };
@@ -154,7 +156,8 @@ template <class _Integer>
 template <class _Integer, class = _EnableByteOverload<_Integer> >
   _LIBCPP_NODISCARD_EXT constexpr _Integer
   to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
-}
+
+} // namespace std
 
 #endif
 
lib/libcxx/include/cstdint
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstdint ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cstdio
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- cstdio ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -145,30 +145,24 @@ using ::feof _LIBCPP_USING_IF_EXISTS;
 using ::ferror _LIBCPP_USING_IF_EXISTS;
 using ::perror _LIBCPP_USING_IF_EXISTS;
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 using ::fopen _LIBCPP_USING_IF_EXISTS;
 using ::freopen _LIBCPP_USING_IF_EXISTS;
 using ::remove _LIBCPP_USING_IF_EXISTS;
 using ::rename _LIBCPP_USING_IF_EXISTS;
 using ::tmpfile _LIBCPP_USING_IF_EXISTS;
 using ::tmpnam _LIBCPP_USING_IF_EXISTS;
-#endif
 
-#ifndef _LIBCPP_HAS_NO_STDIN
 using ::getchar _LIBCPP_USING_IF_EXISTS;
 #if _LIBCPP_STD_VER <= 11 && !defined(_LIBCPP_C_HAS_NO_GETS)
 using ::gets _LIBCPP_USING_IF_EXISTS;
 #endif
 using ::scanf _LIBCPP_USING_IF_EXISTS;
 using ::vscanf _LIBCPP_USING_IF_EXISTS;
-#endif
 
-#ifndef _LIBCPP_HAS_NO_STDOUT
 using ::printf _LIBCPP_USING_IF_EXISTS;
 using ::putchar _LIBCPP_USING_IF_EXISTS;
 using ::puts _LIBCPP_USING_IF_EXISTS;
 using ::vprintf _LIBCPP_USING_IF_EXISTS;
-#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/cstdlib
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstdlib ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -99,26 +99,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 using ::size_t _LIBCPP_USING_IF_EXISTS;
 using ::div_t _LIBCPP_USING_IF_EXISTS;
 using ::ldiv_t _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::lldiv_t _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::atof _LIBCPP_USING_IF_EXISTS;
 using ::atoi _LIBCPP_USING_IF_EXISTS;
 using ::atol _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::atoll _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::strtod _LIBCPP_USING_IF_EXISTS;
 using ::strtof _LIBCPP_USING_IF_EXISTS;
 using ::strtold _LIBCPP_USING_IF_EXISTS;
 using ::strtol _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::strtoll _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::strtoul _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::strtoull _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::rand _LIBCPP_USING_IF_EXISTS;
 using ::srand _LIBCPP_USING_IF_EXISTS;
 using ::calloc _LIBCPP_USING_IF_EXISTS;
@@ -137,14 +129,10 @@ using ::bsearch _LIBCPP_USING_IF_EXISTS;
 using ::qsort _LIBCPP_USING_IF_EXISTS;
 using ::abs _LIBCPP_USING_IF_EXISTS;
 using ::labs _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::llabs _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::div _LIBCPP_USING_IF_EXISTS;
 using ::ldiv _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::lldiv _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::mblen _LIBCPP_USING_IF_EXISTS;
 using ::mbtowc _LIBCPP_USING_IF_EXISTS;
 using ::wctomb _LIBCPP_USING_IF_EXISTS;
lib/libcxx/include/cstring
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstring ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -84,9 +84,7 @@ using ::strpbrk _LIBCPP_USING_IF_EXISTS;
 using ::strrchr _LIBCPP_USING_IF_EXISTS;
 using ::strspn _LIBCPP_USING_IF_EXISTS;
 using ::strstr _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
 using ::strtok _LIBCPP_USING_IF_EXISTS;
-#endif
 using ::memset _LIBCPP_USING_IF_EXISTS;
 using ::strerror _LIBCPP_USING_IF_EXISTS;
 using ::strlen _LIBCPP_USING_IF_EXISTS;
lib/libcxx/include/ctgmath
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- ctgmath -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ctime
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- ctime -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -79,12 +79,10 @@ using ::clock _LIBCPP_USING_IF_EXISTS;
 using ::difftime _LIBCPP_USING_IF_EXISTS;
 using ::mktime _LIBCPP_USING_IF_EXISTS;
 using ::time _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
 using ::asctime _LIBCPP_USING_IF_EXISTS;
 using ::ctime _LIBCPP_USING_IF_EXISTS;
 using ::gmtime _LIBCPP_USING_IF_EXISTS;
 using ::localtime _LIBCPP_USING_IF_EXISTS;
-#endif
 using ::strftime _LIBCPP_USING_IF_EXISTS;
 #if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED)
 using ::timespec_get _LIBCPP_USING_IF_EXISTS;
lib/libcxx/include/ctype.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- ctype.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/cwchar
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cwchar -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -137,13 +137,9 @@ using ::wcstod _LIBCPP_USING_IF_EXISTS;
 using ::wcstof _LIBCPP_USING_IF_EXISTS;
 using ::wcstold _LIBCPP_USING_IF_EXISTS;
 using ::wcstol _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::wcstoll _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::wcstoul _LIBCPP_USING_IF_EXISTS;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::wcstoull _LIBCPP_USING_IF_EXISTS;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::wcscpy _LIBCPP_USING_IF_EXISTS;
 using ::wcsncpy _LIBCPP_USING_IF_EXISTS;
 using ::wcscat _LIBCPP_USING_IF_EXISTS;
@@ -175,17 +171,13 @@ using ::wcrtomb _LIBCPP_USING_IF_EXISTS;
 using ::mbsrtowcs _LIBCPP_USING_IF_EXISTS;
 using ::wcsrtombs _LIBCPP_USING_IF_EXISTS;
 
-#ifndef _LIBCPP_HAS_NO_STDIN
 using ::getwchar _LIBCPP_USING_IF_EXISTS;
 using ::vwscanf _LIBCPP_USING_IF_EXISTS;
 using ::wscanf _LIBCPP_USING_IF_EXISTS;
-#endif
 
-#ifndef _LIBCPP_HAS_NO_STDOUT
 using ::putwchar _LIBCPP_USING_IF_EXISTS;
 using ::vwprintf _LIBCPP_USING_IF_EXISTS;
 using ::wprintf _LIBCPP_USING_IF_EXISTS;
-#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/cwctype
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cwctype ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/deque
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- deque -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -129,7 +129,7 @@ public:
 
 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
    deque(InputIterator, InputIterator, Allocator = Allocator())
-   -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
+   -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
 
 template <class T, class Allocator>
     bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
@@ -162,6 +162,7 @@ template <class T, class Allocator, class Predicate>
 
 #include <__config>
 #include <__debug>
+#include <__iterator/iterator_traits.h>
 #include <__split_buffer>
 #include <__utility/forward.h>
 #include <algorithm>
@@ -908,45 +909,22 @@ move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
     return __r;
 }
 
-template <bool>
-class __deque_base_common
-{
-protected:
-    _LIBCPP_NORETURN void __throw_length_error() const;
-    _LIBCPP_NORETURN void __throw_out_of_range() const;
-};
-
-template <bool __b>
-void
-__deque_base_common<__b>::__throw_length_error() const
-{
-    _VSTD::__throw_length_error("deque");
-}
-
-template <bool __b>
-void
-__deque_base_common<__b>::__throw_out_of_range() const
-{
-    _VSTD::__throw_out_of_range("deque");
-}
-
 template <class _Tp, class _Allocator>
 class __deque_base
-    : protected __deque_base_common<true>
 {
     __deque_base(const __deque_base& __c);
     __deque_base& operator=(const __deque_base& __c);
 public:
-    typedef _Allocator                               allocator_type;
-    typedef allocator_traits<allocator_type>         __alloc_traits;
-    typedef typename __alloc_traits::size_type       size_type;
+    typedef _Allocator                                allocator_type;
+    typedef allocator_traits<allocator_type>          __alloc_traits;
+    typedef typename __alloc_traits::size_type        size_type;
 
-    typedef _Tp                                      value_type;
-    typedef value_type&                              reference;
-    typedef const value_type&                        const_reference;
-    typedef typename __alloc_traits::difference_type difference_type;
-    typedef typename __alloc_traits::pointer         pointer;
-    typedef typename __alloc_traits::const_pointer   const_pointer;
+    typedef _Tp                                       value_type;
+    typedef value_type&                               reference;
+    typedef const value_type&                         const_reference;
+    typedef typename __alloc_traits::difference_type  difference_type;
+    typedef typename __alloc_traits::pointer          pointer;
+    typedef typename __alloc_traits::const_pointer    const_pointer;
 
     static const difference_type __block_size;
 
@@ -1281,20 +1259,20 @@ public:
     static_assert((is_same<typename allocator_type::value_type, value_type>::value),
                   "Allocator::value_type must be same type as value_type");
 
-    typedef __deque_base<value_type, allocator_type> __base;
+    typedef __deque_base<value_type, allocator_type>      __base;
 
-    typedef typename __base::__alloc_traits        __alloc_traits;
-    typedef typename __base::reference             reference;
-    typedef typename __base::const_reference       const_reference;
-    typedef typename __base::iterator              iterator;
-    typedef typename __base::const_iterator        const_iterator;
-    typedef typename __base::size_type             size_type;
-    typedef typename __base::difference_type       difference_type;
+    typedef typename __base::__alloc_traits               __alloc_traits;
+    typedef typename __base::reference                    reference;
+    typedef typename __base::const_reference              const_reference;
+    typedef typename __base::iterator                     iterator;
+    typedef typename __base::const_iterator               const_iterator;
+    typedef typename __base::size_type                    size_type;
+    typedef typename __base::difference_type              difference_type;
 
-    typedef typename __base::pointer               pointer;
-    typedef typename __base::const_pointer         const_pointer;
-    typedef _VSTD::reverse_iterator<iterator>       reverse_iterator;
-    typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
+    typedef typename __base::pointer                      pointer;
+    typedef typename __base::const_pointer                const_pointer;
+    typedef _VSTD::reverse_iterator<iterator>             reverse_iterator;
+    typedef _VSTD::reverse_iterator<const_iterator>       const_reverse_iterator;
 
     using typename __base::__deque_range;
     using typename __base::__deque_block_range;
@@ -1311,7 +1289,14 @@ public:
     explicit deque(size_type __n, const _Allocator& __a);
 #endif
     deque(size_type __n, const value_type& __v);
-    deque(size_type __n, const value_type& __v, const allocator_type& __a);
+
+    template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
+    deque(size_type __n, const value_type& __v, const allocator_type& __a) : __base(__a)
+    {
+        if (__n > 0)
+            __append(__n, __v);
+    }
+
     template <class _InputIter>
         deque(_InputIter __f, _InputIter __l,
               typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0);
@@ -1588,23 +1573,24 @@ public:
     void __move_assign(deque& __c, false_type);
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Alloc = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 deque(_InputIterator, _InputIterator)
   -> deque<__iter_value_type<_InputIterator>, _Alloc>;
 
 template<class _InputIterator,
          class _Alloc,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 deque(_InputIterator, _InputIterator, _Alloc)
   -> deque<__iter_value_type<_InputIterator>, _Alloc>;
 #endif
 
-
 template <class _Tp, class _Allocator>
 deque<_Tp, _Allocator>::deque(size_type __n)
 {
@@ -1629,14 +1615,6 @@ deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
         __append(__n, __v);
 }
 
-template <class _Tp, class _Allocator>
-deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
-    : __base(__a)
-{
-    if (__n > 0)
-        __append(__n, __v);
-}
-
 template <class _Tp, class _Allocator>
 template <class _InputIter>
 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
@@ -1672,7 +1650,7 @@ template <class _Tp, class _Allocator>
 deque<_Tp, _Allocator>&
 deque<_Tp, _Allocator>::operator=(const deque& __c)
 {
-    if (this != &__c)
+    if (this != _VSTD::addressof(__c))
     {
         __copy_assign_alloc(__c);
         assign(__c.begin(), __c.end());
@@ -1873,7 +1851,7 @@ typename deque<_Tp, _Allocator>::reference
 deque<_Tp, _Allocator>::at(size_type __i)
 {
     if (__i >= __base::size())
-        __base::__throw_out_of_range();
+        _VSTD::__throw_out_of_range("deque");
     size_type __p = __base::__start_ + __i;
     return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
 }
@@ -1884,7 +1862,7 @@ typename deque<_Tp, _Allocator>::const_reference
 deque<_Tp, _Allocator>::at(size_type __i) const
 {
     if (__i >= __base::size())
-        __base::__throw_out_of_range();
+        _VSTD::__throw_out_of_range("deque");
     size_type __p = __base::__start_ + __i;
     return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
 }
@@ -2237,7 +2215,7 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_ty
         size_type __de = __base::size() - __pos;
         if (__n > __de)
         {
-            for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size())
+            for (size_type __m = __n - __de; __m; --__m, (void) ++__i, ++__base::size())
                 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
             __n = __de;
         }
@@ -2340,7 +2318,7 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
         if (__n > 0)
         {
             iterator __oen = __old_end - __n;
-            for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
+            for (iterator __j = __oen; __j != __old_end; ++__i, (void) ++__j, ++__base::size())
                 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j));
             if (__n < __de)
                 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end);
lib/libcxx/include/errno.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- errno.h -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/exception
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- exception ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -328,6 +328,6 @@ rethrow_if_nested(const _Ep&,
 {
 }
 
-}  // std
+} // namespace std
 
 #endif // _LIBCPP_EXCEPTION
lib/libcxx/include/execution
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------- execution ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -11,9 +11,14 @@
 #define _LIBCPP_EXECUTION
 
 #include <__config>
+#include <version>
 
 #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
 #   include <__pstl_execution>
 #endif
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
 #endif // _LIBCPP_EXECUTION
lib/libcxx/include/fenv.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- math.h ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/filesystem
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- filesystem -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,7 @@
 /*
     filesystem synopsis
 
-    namespace std { namespace filesystem {
+    namespace std::filesystem {
 
     class path;
 
@@ -48,13 +48,13 @@
 
     // enable directory_iterator range-based for statements
     directory_iterator begin(directory_iterator iter) noexcept;
-    directory_iterator end(const directory_iterator&) noexcept;
+    directory_iterator end(directory_iterator) noexcept;
 
     class recursive_directory_iterator;
 
     // enable recursive_directory_iterator range-based for statements
     recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
-    recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
+    recursive_directory_iterator end(recursive_directory_iterator) noexcept;
 
     class file_status;
 
@@ -224,2789 +224,46 @@
     path weakly_canonical(path const& p);
     path weakly_canonical(path const& p, error_code& ec);
 
+} // namespace std::filesystem
 
-} }  // namespaces std::filesystem
+template <>
+inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::directory_iterator> = true;
+template <>
+inline constexpr bool std::ranges::enable_borrowed_range<std::filesystem::recursive_directory_iterator> = true;
+
+template <>
+inline constexpr bool std::ranges::enable_view<std::filesystem::directory_iterator> = true;
+template <>
+inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_directory_iterator> = true;
 
 */
 
-#include <__availability>
 #include <__config>
-#include <__debug>
-#include <__utility/forward.h>
-#include <chrono>
+#include <__filesystem/copy_options.h>
+#include <__filesystem/directory_entry.h>
+#include <__filesystem/directory_iterator.h>
+#include <__filesystem/directory_options.h>
+#include <__filesystem/file_status.h>
+#include <__filesystem/file_time_type.h>
+#include <__filesystem/file_type.h>
+#include <__filesystem/filesystem_error.h>
+#include <__filesystem/operations.h>
+#include <__filesystem/path.h>
+#include <__filesystem/path_iterator.h>
+#include <__filesystem/perm_options.h>
+#include <__filesystem/perms.h>
+#include <__filesystem/recursive_directory_iterator.h>
+#include <__filesystem/space_info.h>
+#include <__filesystem/u8path.h>
 #include <compare>
-#include <cstddef>
-#include <cstdlib>
-#include <iosfwd>
-#include <iterator>
-#include <memory>
-#include <stack>
-#include <string>
-#include <string_view>
-#include <system_error>
-#include <utility>
 #include <version>
 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-# include <locale>
-# include <iomanip> // for quoted
-#endif
-
 #if defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
-# error "The Filesystem library is not supported by this configuration of libc++"
+# error "The Filesystem library is not supported since libc++ has been configured with LIBCXX_ENABLE_FILESYSTEM disabled"
 #endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-#ifndef _LIBCPP_CXX03_LANG
-
-_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
-
-_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
-
-typedef chrono::time_point<_FilesystemClock> file_time_type;
-
-struct _LIBCPP_TYPE_VIS space_info {
-  uintmax_t capacity;
-  uintmax_t free;
-  uintmax_t available;
-};
-
-// On Windows, the library never identifies files as  block, character, fifo
-// or socket.
-enum class _LIBCPP_ENUM_VIS file_type : signed char {
-  none = 0,
-  not_found = -1,
-  regular = 1,
-  directory = 2,
-  symlink = 3,
-  block = 4,
-  character = 5,
-  fifo = 6,
-  socket = 7,
-  unknown = 8
-};
-
-// On Windows, these permission bits map to one single readonly flag per
-// file, and the executable bit is always returned as set. When setting
-// permissions, as long as the write bit is set for either owner, group or
-// others, the readonly flag is cleared.
-enum class _LIBCPP_ENUM_VIS perms : unsigned {
-  none = 0,
-
-  owner_read = 0400,
-  owner_write = 0200,
-  owner_exec = 0100,
-  owner_all = 0700,
-
-  group_read = 040,
-  group_write = 020,
-  group_exec = 010,
-  group_all = 070,
-
-  others_read = 04,
-  others_write = 02,
-  others_exec = 01,
-  others_all = 07,
-
-  all = 0777,
-
-  set_uid = 04000,
-  set_gid = 02000,
-  sticky_bit = 01000,
-  mask = 07777,
-  unknown = 0xFFFF,
-};
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perms operator&(perms _LHS, perms _RHS) {
-  return static_cast<perms>(static_cast<unsigned>(_LHS) &
-                            static_cast<unsigned>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perms operator|(perms _LHS, perms _RHS) {
-  return static_cast<perms>(static_cast<unsigned>(_LHS) |
-                            static_cast<unsigned>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perms operator^(perms _LHS, perms _RHS) {
-  return static_cast<perms>(static_cast<unsigned>(_LHS) ^
-                            static_cast<unsigned>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perms operator~(perms _LHS) {
-  return static_cast<perms>(~static_cast<unsigned>(_LHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; }
-
-_LIBCPP_INLINE_VISIBILITY
-inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; }
-
-_LIBCPP_INLINE_VISIBILITY
-inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; }
-
-enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
-  replace = 1,
-  add = 2,
-  remove = 4,
-  nofollow = 8
-};
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) {
-  return static_cast<perm_options>(static_cast<unsigned>(_LHS) &
-                                   static_cast<unsigned>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) {
-  return static_cast<perm_options>(static_cast<unsigned>(_LHS) |
-                                   static_cast<unsigned>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) {
-  return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^
-                                   static_cast<unsigned>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr perm_options operator~(perm_options _LHS) {
-  return static_cast<perm_options>(~static_cast<unsigned>(_LHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) {
-  return _LHS = _LHS & _RHS;
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) {
-  return _LHS = _LHS | _RHS;
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) {
-  return _LHS = _LHS ^ _RHS;
-}
-
-enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
-  none = 0,
-  skip_existing = 1,
-  overwrite_existing = 2,
-  update_existing = 4,
-  recursive = 8,
-  copy_symlinks = 16,
-  skip_symlinks = 32,
-  directories_only = 64,
-  create_symlinks = 128,
-  create_hard_links = 256,
-  __in_recursive_copy = 512,
-};
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) {
-  return static_cast<copy_options>(static_cast<unsigned short>(_LHS) &
-                                   static_cast<unsigned short>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) {
-  return static_cast<copy_options>(static_cast<unsigned short>(_LHS) |
-                                   static_cast<unsigned short>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) {
-  return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^
-                                   static_cast<unsigned short>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr copy_options operator~(copy_options _LHS) {
-  return static_cast<copy_options>(~static_cast<unsigned short>(_LHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) {
-  return _LHS = _LHS & _RHS;
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) {
-  return _LHS = _LHS | _RHS;
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) {
-  return _LHS = _LHS ^ _RHS;
-}
-
-enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
-  none = 0,
-  follow_directory_symlink = 1,
-  skip_permission_denied = 2
-};
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr directory_options operator&(directory_options _LHS,
-                                             directory_options _RHS) {
-  return static_cast<directory_options>(static_cast<unsigned char>(_LHS) &
-                                        static_cast<unsigned char>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr directory_options operator|(directory_options _LHS,
-                                             directory_options _RHS) {
-  return static_cast<directory_options>(static_cast<unsigned char>(_LHS) |
-                                        static_cast<unsigned char>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr directory_options operator^(directory_options _LHS,
-                                             directory_options _RHS) {
-  return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^
-                                        static_cast<unsigned char>(_RHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline constexpr directory_options operator~(directory_options _LHS) {
-  return static_cast<directory_options>(~static_cast<unsigned char>(_LHS));
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline directory_options& operator&=(directory_options& _LHS,
-                                     directory_options _RHS) {
-  return _LHS = _LHS & _RHS;
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline directory_options& operator|=(directory_options& _LHS,
-                                     directory_options _RHS) {
-  return _LHS = _LHS | _RHS;
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline directory_options& operator^=(directory_options& _LHS,
-                                     directory_options _RHS) {
-  return _LHS = _LHS ^ _RHS;
-}
-
-class _LIBCPP_TYPE_VIS file_status {
-public:
-  // constructors
-  _LIBCPP_INLINE_VISIBILITY
-  file_status() noexcept : file_status(file_type::none) {}
-  _LIBCPP_INLINE_VISIBILITY
-  explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept
-      : __ft_(__ft),
-        __prms_(__prms) {}
-
-  file_status(const file_status&) noexcept = default;
-  file_status(file_status&&) noexcept = default;
-
-  _LIBCPP_INLINE_VISIBILITY
-  ~file_status() {}
-
-  file_status& operator=(const file_status&) noexcept = default;
-  file_status& operator=(file_status&&) noexcept = default;
-
-  // observers
-  _LIBCPP_INLINE_VISIBILITY
-  file_type type() const noexcept { return __ft_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  perms permissions() const noexcept { return __prms_; }
-
-  // modifiers
-  _LIBCPP_INLINE_VISIBILITY
-  void type(file_type __ft) noexcept { __ft_ = __ft; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void permissions(perms __p) noexcept { __prms_ = __p; }
-
-private:
-  file_type __ft_;
-  perms __prms_;
-};
-
-class _LIBCPP_TYPE_VIS directory_entry;
-
-template <class _Tp>
-struct __can_convert_char {
-  static const bool value = false;
-};
-template <class _Tp>
-struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
-template <>
-struct __can_convert_char<char> {
-  static const bool value = true;
-  using __char_type = char;
-};
-template <>
-struct __can_convert_char<wchar_t> {
-  static const bool value = true;
-  using __char_type = wchar_t;
-};
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-template <>
-struct __can_convert_char<char8_t> {
-  static const bool value = true;
-  using __char_type = char8_t;
-};
-#endif
-template <>
-struct __can_convert_char<char16_t> {
-  static const bool value = true;
-  using __char_type = char16_t;
-};
-template <>
-struct __can_convert_char<char32_t> {
-  static const bool value = true;
-  using __char_type = char32_t;
-};
-
-template <class _ECharT>
-typename enable_if<__can_convert_char<_ECharT>::value, bool>::type
-__is_separator(_ECharT __e) {
-#if defined(_LIBCPP_WIN32API)
-  return __e == _ECharT('/') || __e == _ECharT('\\');
-#else
-  return __e == _ECharT('/');
-#endif
-}
-
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-typedef u8string __u8_string;
-#else
-typedef string __u8_string;
-#endif
-
-struct _NullSentinel {};
-
-template <class _Tp>
-using _Void = void;
-
-template <class _Tp, class = void>
-struct __is_pathable_string : public false_type {};
-
-template <class _ECharT, class _Traits, class _Alloc>
-struct __is_pathable_string<
-    basic_string<_ECharT, _Traits, _Alloc>,
-    _Void<typename __can_convert_char<_ECharT>::__char_type> >
-    : public __can_convert_char<_ECharT> {
-  using _Str = basic_string<_ECharT, _Traits, _Alloc>;
-  using _Base = __can_convert_char<_ECharT>;
-  static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
-  static _ECharT const* __range_end(_Str const& __s) {
-    return __s.data() + __s.length();
-  }
-  static _ECharT __first_or_null(_Str const& __s) {
-    return __s.empty() ? _ECharT{} : __s[0];
-  }
-};
-
-template <class _ECharT, class _Traits>
-struct __is_pathable_string<
-    basic_string_view<_ECharT, _Traits>,
-    _Void<typename __can_convert_char<_ECharT>::__char_type> >
-    : public __can_convert_char<_ECharT> {
-  using _Str = basic_string_view<_ECharT, _Traits>;
-  using _Base = __can_convert_char<_ECharT>;
-  static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
-  static _ECharT const* __range_end(_Str const& __s) {
-    return __s.data() + __s.length();
-  }
-  static _ECharT __first_or_null(_Str const& __s) {
-    return __s.empty() ? _ECharT{} : __s[0];
-  }
-};
-
-template <class _Source, class _DS = typename decay<_Source>::type,
-          class _UnqualPtrType =
-              typename remove_const<typename remove_pointer<_DS>::type>::type,
-          bool _IsCharPtr = is_pointer<_DS>::value&&
-              __can_convert_char<_UnqualPtrType>::value>
-struct __is_pathable_char_array : false_type {};
-
-template <class _Source, class _ECharT, class _UPtr>
-struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true>
-    : __can_convert_char<typename remove_const<_ECharT>::type> {
-  using _Base = __can_convert_char<typename remove_const<_ECharT>::type>;
-
-  static _ECharT const* __range_begin(const _ECharT* __b) { return __b; }
-  static _ECharT const* __range_end(const _ECharT* __b) {
-    using _Iter = const _ECharT*;
-    const _ECharT __sentinel = _ECharT{};
-    _Iter __e = __b;
-    for (; *__e != __sentinel; ++__e)
-      ;
-    return __e;
-  }
-
-  static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
-};
-
-template <class _Iter, bool _IsIt = __is_cpp17_input_iterator<_Iter>::value,
-          class = void>
-struct __is_pathable_iter : false_type {};
-
-template <class _Iter>
-struct __is_pathable_iter<
-    _Iter, true,
-    _Void<typename __can_convert_char<
-        typename iterator_traits<_Iter>::value_type>::__char_type> >
-    : __can_convert_char<typename iterator_traits<_Iter>::value_type> {
-  using _ECharT = typename iterator_traits<_Iter>::value_type;
-  using _Base = __can_convert_char<_ECharT>;
-
-  static _Iter __range_begin(_Iter __b) { return __b; }
-  static _NullSentinel __range_end(_Iter) { return _NullSentinel{}; }
-
-  static _ECharT __first_or_null(_Iter __b) { return *__b; }
-};
-
-template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value,
-          bool _IsCharIterT = __is_pathable_char_array<_Tp>::value,
-          bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value>
-struct __is_pathable : false_type {
-  static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false");
-};
-
-template <class _Tp>
-struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {};
-
-template <class _Tp>
-struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {
-};
-
-template <class _Tp>
-struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {};
-
-#if defined(_LIBCPP_WIN32API)
-typedef wstring __path_string;
-typedef wchar_t __path_value;
-#else
-typedef string __path_string;
-typedef char __path_value;
-#endif
-
-#if defined(_LIBCPP_WIN32API)
-_LIBCPP_FUNC_VIS
-size_t __wide_to_char(const wstring&, char*, size_t);
-_LIBCPP_FUNC_VIS
-size_t __char_to_wide(const string&, wchar_t*, size_t);
-#endif
-
-template <class _ECharT>
-struct _PathCVT;
-
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-template <class _ECharT>
-struct _PathCVT {
-  static_assert(__can_convert_char<_ECharT>::value,
-                "Char type not convertible");
-
-  typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower;
-#if defined(_LIBCPP_WIN32API)
-  typedef __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Widener;
-#endif
-
-  static void __append_range(__path_string& __dest, _ECharT const* __b,
-                             _ECharT const* __e) {
-#if defined(_LIBCPP_WIN32API)
-    string __utf8;
-    _Narrower()(back_inserter(__utf8), __b, __e);
-    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
-#else
-    _Narrower()(back_inserter(__dest), __b, __e);
-#endif
-  }
-
-  template <class _Iter>
-  static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
-    static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
-    if (__b == __e)
-      return;
-    basic_string<_ECharT> __tmp(__b, __e);
-#if defined(_LIBCPP_WIN32API)
-    string __utf8;
-    _Narrower()(back_inserter(__utf8), __tmp.data(),
-                __tmp.data() + __tmp.length());
-    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
-#else
-    _Narrower()(back_inserter(__dest), __tmp.data(),
-                __tmp.data() + __tmp.length());
-#endif
-  }
-
-  template <class _Iter>
-  static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
-    static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
-    const _ECharT __sentinel = _ECharT{};
-    if (*__b == __sentinel)
-      return;
-    basic_string<_ECharT> __tmp;
-    for (; *__b != __sentinel; ++__b)
-      __tmp.push_back(*__b);
-#if defined(_LIBCPP_WIN32API)
-    string __utf8;
-    _Narrower()(back_inserter(__utf8), __tmp.data(),
-                __tmp.data() + __tmp.length());
-    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
-#else
-    _Narrower()(back_inserter(__dest), __tmp.data(),
-                __tmp.data() + __tmp.length());
-#endif
-  }
-
-  template <class _Source>
-  static void __append_source(__path_string& __dest, _Source const& __s) {
-    using _Traits = __is_pathable<_Source>;
-    __append_range(__dest, _Traits::__range_begin(__s),
-                   _Traits::__range_end(__s));
-  }
-};
-#endif // !_LIBCPP_HAS_NO_LOCALIZATION
-
-template <>
-struct _PathCVT<__path_value> {
-
-  template <class _Iter>
-  static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
-  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
-    for (; __b != __e; ++__b)
-      __dest.push_back(*__b);
-  }
-
-  template <class _Iter>
-  static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
-  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
-    __dest.append(__b, __e);
-  }
-
-  template <class _Iter>
-  static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
-    const char __sentinel = char{};
-    for (; *__b != __sentinel; ++__b)
-      __dest.push_back(*__b);
-  }
-
-  template <class _Source>
-  static void __append_source(__path_string& __dest, _Source const& __s) {
-    using _Traits = __is_pathable<_Source>;
-    __append_range(__dest, _Traits::__range_begin(__s),
-                   _Traits::__range_end(__s));
-  }
-};
-
-#if defined(_LIBCPP_WIN32API)
-template <>
-struct _PathCVT<char> {
-
-  static void
-  __append_string(__path_string& __dest, const basic_string<char> &__str) {
-      size_t __size = __char_to_wide(__str, nullptr, 0);
-      size_t __pos = __dest.size();
-      __dest.resize(__pos + __size);
-      __char_to_wide(__str, const_cast<__path_value*>(__dest.data()) + __pos, __size);
-  }
-
-  template <class _Iter>
-  static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
-  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
-    basic_string<char> __tmp(__b, __e);
-    __append_string(__dest, __tmp);
-  }
-
-  template <class _Iter>
-  static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
-  __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
-    basic_string<char> __tmp(__b, __e);
-    __append_string(__dest, __tmp);
-  }
-
-  template <class _Iter>
-  static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) {
-    const char __sentinel = char{};
-    basic_string<char> __tmp;
-    for (; *__b != __sentinel; ++__b)
-      __tmp.push_back(*__b);
-    __append_string(__dest, __tmp);
-  }
-
-  template <class _Source>
-  static void __append_source(__path_string& __dest, _Source const& __s) {
-    using _Traits = __is_pathable<_Source>;
-    __append_range(__dest, _Traits::__range_begin(__s),
-                   _Traits::__range_end(__s));
-  }
-};
-
-template <class _ECharT>
-struct _PathExport {
-  typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
-  typedef __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Widener;
-
-  template <class _Str>
-  static void __append(_Str& __dest, const __path_string& __src) {
-    string __utf8;
-    _Narrower()(back_inserter(__utf8), __src.data(), __src.data() + __src.size());
-    _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size());
-  }
-};
-
-template <>
-struct _PathExport<char> {
-  template <class _Str>
-  static void __append(_Str& __dest, const __path_string& __src) {
-    size_t __size = __wide_to_char(__src, nullptr, 0);
-    size_t __pos = __dest.size();
-    __dest.resize(__size);
-    __wide_to_char(__src, const_cast<char*>(__dest.data()) + __pos, __size);
-  }
-};
-
-template <>
-struct _PathExport<wchar_t> {
-  template <class _Str>
-  static void __append(_Str& __dest, const __path_string& __src) {
-    __dest.append(__src.begin(), __src.end());
-  }
-};
-
-template <>
-struct _PathExport<char16_t> {
-  template <class _Str>
-  static void __append(_Str& __dest, const __path_string& __src) {
-    __dest.append(__src.begin(), __src.end());
-  }
-};
-
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-template <>
-struct _PathExport<char8_t> {
-  typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
-
-  template <class _Str>
-  static void __append(_Str& __dest, const __path_string& __src) {
-    _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size());
-  }
-};
-#endif /* !_LIBCPP_HAS_NO_CHAR8_T */
-#endif /* _LIBCPP_WIN32API */
-
-class _LIBCPP_TYPE_VIS path {
-  template <class _SourceOrIter, class _Tp = path&>
-  using _EnableIfPathable =
-      typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type;
-
-  template <class _Tp>
-  using _SourceChar = typename __is_pathable<_Tp>::__char_type;
-
-  template <class _Tp>
-  using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
-
-public:
-#if defined(_LIBCPP_WIN32API)
-  typedef wchar_t value_type;
-  static constexpr value_type preferred_separator = L'\\';
-#else
-  typedef char value_type;
-  static constexpr value_type preferred_separator = '/';
-#endif
-  typedef basic_string<value_type> string_type;
-  typedef basic_string_view<value_type> __string_view;
-
-  enum _LIBCPP_ENUM_VIS format : unsigned char {
-    auto_format,
-    native_format,
-    generic_format
-  };
-
-  // constructors and destructor
-  _LIBCPP_INLINE_VISIBILITY path() noexcept {}
-  _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {}
-  _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept
-      : __pn_(_VSTD::move(__p.__pn_)) {}
-
-  _LIBCPP_INLINE_VISIBILITY
-  path(string_type&& __s, format = format::auto_format) noexcept
-      : __pn_(_VSTD::move(__s)) {}
-
-  template <class _Source, class = _EnableIfPathable<_Source, void> >
-  path(const _Source& __src, format = format::auto_format) {
-    _SourceCVT<_Source>::__append_source(__pn_, __src);
-  }
-
-  template <class _InputIt>
-  path(_InputIt __first, _InputIt __last, format = format::auto_format) {
-    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
-    _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
-  }
-
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-  // TODO Implement locale conversions.
-  template <class _Source, class = _EnableIfPathable<_Source, void> >
-  path(const _Source& __src, const locale& __loc, format = format::auto_format);
-  template <class _InputIt>
-  path(_InputIt __first, _InputIt _last, const locale& __loc,
-       format = format::auto_format);
-#endif
-
-  _LIBCPP_INLINE_VISIBILITY
-  ~path() = default;
-
-  // assignments
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator=(const path& __p) {
-    __pn_ = __p.__pn_;
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator=(path&& __p) noexcept {
-    __pn_ = _VSTD::move(__p.__pn_);
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator=(string_type&& __s) noexcept {
-    __pn_ = _VSTD::move(__s);
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& assign(string_type&& __s) noexcept {
-    __pn_ = _VSTD::move(__s);
-    return *this;
-  }
-
-  template <class _Source>
-  _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
-  operator=(const _Source& __src) {
-    return this->assign(__src);
-  }
-
-  template <class _Source>
-  _EnableIfPathable<_Source> assign(const _Source& __src) {
-    __pn_.clear();
-    _SourceCVT<_Source>::__append_source(__pn_, __src);
-    return *this;
-  }
-
-  template <class _InputIt>
-  path& assign(_InputIt __first, _InputIt __last) {
-    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
-    __pn_.clear();
-    _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
-    return *this;
-  }
-
-public:
-  // appends
-#if defined(_LIBCPP_WIN32API)
-  path& operator/=(const path& __p) {
-    auto __p_root_name = __p.__root_name();
-    auto __p_root_name_size = __p_root_name.size();
-    if (__p.is_absolute() ||
-        (!__p_root_name.empty() && __p_root_name != root_name())) {
-      __pn_ = __p.__pn_;
-      return *this;
-    }
-    if (__p.has_root_directory()) {
-      path __root_name_str = root_name();
-      __pn_ = __root_name_str.native();
-      __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
-      return *this;
-    }
-    if (has_filename() || (!has_root_directory() && is_absolute()))
-      __pn_ += preferred_separator;
-    __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size);
-    return *this;
-  }
-  template <class _Source>
-  _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
-  operator/=(const _Source& __src) {
-    return operator/=(path(__src));
-  }
-
-  template <class _Source>
-  _EnableIfPathable<_Source> append(const _Source& __src) {
-    return operator/=(path(__src));
-  }
-
-  template <class _InputIt>
-  path& append(_InputIt __first, _InputIt __last) {
-    return operator/=(path(__first, __last));
-  }
-#else
-  path& operator/=(const path& __p) {
-    if (__p.is_absolute()) {
-      __pn_ = __p.__pn_;
-      return *this;
-    }
-    if (has_filename())
-      __pn_ += preferred_separator;
-    __pn_ += __p.native();
-    return *this;
-  }
-
-  // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
-  // is known at compile time to be "/' since the user almost certainly intended
-  // to append a separator instead of overwriting the path with "/"
-  template <class _Source>
-  _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source>
-  operator/=(const _Source& __src) {
-    return this->append(__src);
-  }
-
-  template <class _Source>
-  _EnableIfPathable<_Source> append(const _Source& __src) {
-    using _Traits = __is_pathable<_Source>;
-    using _CVT = _PathCVT<_SourceChar<_Source> >;
-    bool __source_is_absolute = __is_separator(_Traits::__first_or_null(__src));
-    if (__source_is_absolute)
-      __pn_.clear();
-    else if (has_filename())
-      __pn_ += preferred_separator;
-    _CVT::__append_source(__pn_, __src);
-    return *this;
-  }
-
-  template <class _InputIt>
-  path& append(_InputIt __first, _InputIt __last) {
-    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
-    static_assert(__can_convert_char<_ItVal>::value, "Must convertible");
-    using _CVT = _PathCVT<_ItVal>;
-    if (__first != __last && __is_separator(*__first))
-      __pn_.clear();
-    else if (has_filename())
-      __pn_ += preferred_separator;
-    _CVT::__append_range(__pn_, __first, __last);
-    return *this;
-  }
-#endif
-
-  // concatenation
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator+=(const path& __x) {
-    __pn_ += __x.__pn_;
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator+=(const string_type& __x) {
-    __pn_ += __x;
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator+=(__string_view __x) {
-    __pn_ += __x;
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator+=(const value_type* __x) {
-    __pn_ += __x;
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& operator+=(value_type __x) {
-    __pn_ += __x;
-    return *this;
-  }
-
-  template <class _ECharT>
-  typename enable_if<__can_convert_char<_ECharT>::value, path&>::type
-  operator+=(_ECharT __x) {
-    _PathCVT<_ECharT>::__append_source(__pn_,
-                                       basic_string_view<_ECharT>(&__x, 1));
-    return *this;
-  }
-
-  template <class _Source>
-  _EnableIfPathable<_Source> operator+=(const _Source& __x) {
-    return this->concat(__x);
-  }
-
-  template <class _Source>
-  _EnableIfPathable<_Source> concat(const _Source& __x) {
-    _SourceCVT<_Source>::__append_source(__pn_, __x);
-    return *this;
-  }
-
-  template <class _InputIt>
-  path& concat(_InputIt __first, _InputIt __last) {
-    typedef typename iterator_traits<_InputIt>::value_type _ItVal;
-    _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
-    return *this;
-  }
-
-  // modifiers
-  _LIBCPP_INLINE_VISIBILITY
-  void clear() noexcept { __pn_.clear(); }
-
-  path& make_preferred() {
-#if defined(_LIBCPP_WIN32API)
-    _VSTD::replace(__pn_.begin(), __pn_.end(), L'/', L'\\');
-#endif
-    return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  path& remove_filename() {
-    auto __fname = __filename();
-    if (!__fname.empty())
-      __pn_.erase(__fname.data() - __pn_.data());
-    return *this;
-  }
-
-  path& replace_filename(const path& __replacement) {
-    remove_filename();
-    return (*this /= __replacement);
-  }
-
-  path& replace_extension(const path& __replacement = path());
-
-  _LIBCPP_INLINE_VISIBILITY
-  void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); }
-
-  // private helper to allow reserving memory in the path
-  _LIBCPP_INLINE_VISIBILITY
-  void __reserve(size_t __s) { __pn_.reserve(__s); }
-
-  // native format observers
-  _LIBCPP_INLINE_VISIBILITY
-  const string_type& native() const noexcept { return __pn_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  const value_type* c_str() const noexcept { return __pn_.c_str(); }
-
-  _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; }
-
-#if defined(_LIBCPP_WIN32API)
-  _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const { return __pn_; }
-
-  _VSTD::wstring generic_wstring() const {
-    _VSTD::wstring __s;
-    __s.resize(__pn_.size());
-    _VSTD::replace_copy(__pn_.begin(), __pn_.end(), __s.begin(), '\\', '/');
-    return __s;
-  }
-
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-  template <class _ECharT, class _Traits = char_traits<_ECharT>,
-            class _Allocator = allocator<_ECharT> >
-  basic_string<_ECharT, _Traits, _Allocator>
-  string(const _Allocator& __a = _Allocator()) const {
-    using _Str = basic_string<_ECharT, _Traits, _Allocator>;
-    _Str __s(__a);
-    __s.reserve(__pn_.size());
-    _PathExport<_ECharT>::__append(__s, __pn_);
-    return __s;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const {
-    return string<char>();
-  }
-  _LIBCPP_INLINE_VISIBILITY __u8_string u8string() const {
-    using _CVT = __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
-    __u8_string __s;
-    __s.reserve(__pn_.size());
-    _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
-    return __s;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
-    return string<char16_t>();
-  }
-  _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
-    return string<char32_t>();
-  }
-
-  // generic format observers
-  template <class _ECharT, class _Traits = char_traits<_ECharT>,
-            class _Allocator = allocator<_ECharT> >
-  basic_string<_ECharT, _Traits, _Allocator>
-  generic_string(const _Allocator& __a = _Allocator()) const {
-    using _Str = basic_string<_ECharT, _Traits, _Allocator>;
-    _Str __s = string<_ECharT, _Traits, _Allocator>(__a);
-    // Note: This (and generic_u8string below) is slightly suboptimal as
-    // it iterates twice over the string; once to convert it to the right
-    // character type, and once to replace path delimiters.
-    _VSTD::replace(__s.begin(), __s.end(),
-                   static_cast<_ECharT>('\\'), static_cast<_ECharT>('/'));
-    return __s;
-  }
-
-  _VSTD::string generic_string() const { return generic_string<char>(); }
-  _VSTD::u16string generic_u16string() const { return generic_string<char16_t>(); }
-  _VSTD::u32string generic_u32string() const { return generic_string<char32_t>(); }
-  __u8_string generic_u8string() const {
-    __u8_string __s = u8string();
-    _VSTD::replace(__s.begin(), __s.end(), '\\', '/');
-    return __s;
-  }
-#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
-#else /* _LIBCPP_WIN32API */
-
-  _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const { return __pn_; }
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-  _LIBCPP_INLINE_VISIBILITY _VSTD::u8string u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
-#else
-  _LIBCPP_INLINE_VISIBILITY _VSTD::string u8string() const { return __pn_; }
-#endif
-
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-  template <class _ECharT, class _Traits = char_traits<_ECharT>,
-            class _Allocator = allocator<_ECharT> >
-  basic_string<_ECharT, _Traits, _Allocator>
-  string(const _Allocator& __a = _Allocator()) const {
-    using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
-    using _Str = basic_string<_ECharT, _Traits, _Allocator>;
-    _Str __s(__a);
-    __s.reserve(__pn_.size());
-    _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size());
-    return __s;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const {
-    return string<wchar_t>();
-  }
-  _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const {
-    return string<char16_t>();
-  }
-  _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const {
-    return string<char32_t>();
-  }
-#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
-
-  // generic format observers
-  _VSTD::string generic_string() const { return __pn_; }
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-  _VSTD::u8string generic_u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); }
-#else
-  _VSTD::string generic_u8string() const { return __pn_; }
-#endif
-
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-  template <class _ECharT, class _Traits = char_traits<_ECharT>,
-            class _Allocator = allocator<_ECharT> >
-  basic_string<_ECharT, _Traits, _Allocator>
-  generic_string(const _Allocator& __a = _Allocator()) const {
-    return string<_ECharT, _Traits, _Allocator>(__a);
-  }
-
-  _VSTD::wstring generic_wstring() const { return string<wchar_t>(); }
-  _VSTD::u16string generic_u16string() const { return string<char16_t>(); }
-  _VSTD::u32string generic_u32string() const { return string<char32_t>(); }
-#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
-#endif /* !_LIBCPP_WIN32API */
-
-private:
-  int __compare(__string_view) const;
-  __string_view __root_name() const;
-  __string_view __root_directory() const;
-  __string_view __root_path_raw() const;
-  __string_view __relative_path() const;
-  __string_view __parent_path() const;
-  __string_view __filename() const;
-  __string_view __stem() const;
-  __string_view __extension() const;
-
-public:
-  // compare
-  _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept {
-    return __compare(__p.__pn_);
-  }
-  _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const {
-    return __compare(__s);
-  }
-  _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const {
-    return __compare(__s);
-  }
-  _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const {
-    return __compare(__s);
-  }
-
-  // decomposition
-  _LIBCPP_INLINE_VISIBILITY path root_name() const {
-    return string_type(__root_name());
-  }
-  _LIBCPP_INLINE_VISIBILITY path root_directory() const {
-    return string_type(__root_directory());
-  }
-  _LIBCPP_INLINE_VISIBILITY path root_path() const {
-#if defined(_LIBCPP_WIN32API)
-    return string_type(__root_path_raw());
-#else
-    return root_name().append(string_type(__root_directory()));
-#endif
-  }
-  _LIBCPP_INLINE_VISIBILITY path relative_path() const {
-    return string_type(__relative_path());
-  }
-  _LIBCPP_INLINE_VISIBILITY path parent_path() const {
-    return string_type(__parent_path());
-  }
-  _LIBCPP_INLINE_VISIBILITY path filename() const {
-    return string_type(__filename());
-  }
-  _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); }
-  _LIBCPP_INLINE_VISIBILITY path extension() const {
-    return string_type(__extension());
-  }
-
-  // query
-  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool
-  empty() const noexcept {
-    return __pn_.empty();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY bool has_root_name() const {
-    return !__root_name().empty();
-  }
-  _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const {
-    return !__root_directory().empty();
-  }
-  _LIBCPP_INLINE_VISIBILITY bool has_root_path() const {
-    return !__root_path_raw().empty();
-  }
-  _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const {
-    return !__relative_path().empty();
-  }
-  _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const {
-    return !__parent_path().empty();
-  }
-  _LIBCPP_INLINE_VISIBILITY bool has_filename() const {
-    return !__filename().empty();
-  }
-  _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); }
-  _LIBCPP_INLINE_VISIBILITY bool has_extension() const {
-    return !__extension().empty();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
-#if defined(_LIBCPP_WIN32API)
-    __string_view __root_name_str = __root_name();
-    __string_view __root_dir = __root_directory();
-    if (__root_name_str.size() == 2 && __root_name_str[1] == ':') {
-      // A drive letter with no root directory is relative, e.g. x:example.
-      return !__root_dir.empty();
-    }
-    // If no root name, it's relative, e.g. \example is relative to the current drive
-    if (__root_name_str.empty())
-      return false;
-    if (__root_name_str.size() < 3)
-      return false;
-    // A server root name, like \\server, is always absolute
-    if (__root_name_str[0] != '/' && __root_name_str[0] != '\\')
-      return false;
-    if (__root_name_str[1] != '/' && __root_name_str[1] != '\\')
-      return false;
-    // Seems to be a server root name
-    return true;
-#else
-    return has_root_directory();
-#endif
-  }
-  _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
-
-  // relative paths
-  path lexically_normal() const;
-  path lexically_relative(const path& __base) const;
-
-  _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const {
-    path __result = this->lexically_relative(__base);
-    if (__result.native().empty())
-      return *this;
-    return __result;
-  }
-
-  // iterators
-  class _LIBCPP_TYPE_VIS iterator;
-  typedef iterator const_iterator;
-
-  iterator begin() const;
-  iterator end() const;
-
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-  template <class _CharT, class _Traits>
-  _LIBCPP_INLINE_VISIBILITY friend
-      typename enable_if<is_same<_CharT, value_type>::value &&
-                             is_same<_Traits, char_traits<value_type> >::value,
-                         basic_ostream<_CharT, _Traits>&>::type
-      operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
-    __os << _VSTD::__quoted(__p.native());
-    return __os;
-  }
-
-  template <class _CharT, class _Traits>
-  _LIBCPP_INLINE_VISIBILITY friend
-      typename enable_if<!is_same<_CharT, value_type>::value ||
-                             !is_same<_Traits, char_traits<value_type> >::value,
-                         basic_ostream<_CharT, _Traits>&>::type
-      operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
-    __os << _VSTD::__quoted(__p.string<_CharT, _Traits>());
-    return __os;
-  }
-
-  template <class _CharT, class _Traits>
-  _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>&
-  operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) {
-    basic_string<_CharT, _Traits> __tmp;
-    __is >> __quoted(__tmp);
-    __p = __tmp;
-    return __is;
-  }
-#endif // !_LIBCPP_HAS_NO_LOCALIZATION
-
-  friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
-    return __lhs.compare(__rhs) == 0;
-  }
-  friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
-    return __lhs.compare(__rhs) != 0;
-  }
-  friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
-    return __lhs.compare(__rhs) < 0;
-  }
-  friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
-    return __lhs.compare(__rhs) <= 0;
-  }
-  friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
-    return __lhs.compare(__rhs) > 0;
-  }
-  friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
-    return __lhs.compare(__rhs) >= 0;
-  }
-
-  friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
-                                                  const path& __rhs) {
-    path __result(__lhs);
-    __result /= __rhs;
-    return __result;
-  }
-private:
-  inline _LIBCPP_INLINE_VISIBILITY path&
-  __assign_view(__string_view const& __s) noexcept {
-    __pn_ = string_type(__s);
-    return *this;
-  }
-  string_type __pn_;
-};
-
-inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept {
-  __lhs.swap(__rhs);
-}
-
-_LIBCPP_FUNC_VIS
-size_t hash_value(const path& __p) noexcept;
-
-template <class _InputIt>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
-    typename enable_if<__is_pathable<_InputIt>::value, path>::type
-    u8path(_InputIt __f, _InputIt __l) {
-  static_assert(
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-      is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
-#endif
-      is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
-      "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
-      " or 'char8_t'");
-#if defined(_LIBCPP_WIN32API)
-  string __tmp(__f, __l);
-  using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
-  _VSTD::wstring __w;
-  __w.reserve(__tmp.size());
-  _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
-  return path(__w);
-#else
-  return path(__f, __l);
-#endif /* !_LIBCPP_WIN32API */
-}
-
-#if defined(_LIBCPP_WIN32API)
-template <class _InputIt>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
-    typename enable_if<__is_pathable<_InputIt>::value, path>::type
-    u8path(_InputIt __f, _NullSentinel) {
-  static_assert(
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-      is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
-#endif
-      is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
-      "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
-      " or 'char8_t'");
-  string __tmp;
-  const char __sentinel = char{};
-  for (; *__f != __sentinel; ++__f)
-    __tmp.push_back(*__f);
-  using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;
-  _VSTD::wstring __w;
-  __w.reserve(__tmp.size());
-  _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());
-  return path(__w);
-}
-#endif /* _LIBCPP_WIN32API */
-
-template <class _Source>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
-    typename enable_if<__is_pathable<_Source>::value, path>::type
-    u8path(const _Source& __s) {
-  static_assert(
-#ifndef _LIBCPP_HAS_NO_CHAR8_T
-      is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value ||
-#endif
-      is_same<typename __is_pathable<_Source>::__char_type, char>::value,
-      "u8path(Source const&) requires Source have a character type of type "
-      "'char' or 'char8_t'");
-#if defined(_LIBCPP_WIN32API)
-  using _Traits = __is_pathable<_Source>;
-  return u8path(_VSTD::__unwrap_iter(_Traits::__range_begin(__s)), _VSTD::__unwrap_iter(_Traits::__range_end(__s)));
-#else
-  return path(__s);
-#endif
-}
-
-class _LIBCPP_TYPE_VIS path::iterator {
-public:
-  enum _ParserState : unsigned char {
-    _Singular,
-    _BeforeBegin,
-    _InRootName,
-    _InRootDir,
-    _InFilenames,
-    _InTrailingSep,
-    _AtEnd
-  };
-
-public:
-  typedef bidirectional_iterator_tag iterator_category;
-
-  typedef path value_type;
-  typedef ptrdiff_t difference_type;
-  typedef const path* pointer;
-  typedef const path& reference;
-
-  typedef void
-      __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
-
-public:
-  _LIBCPP_INLINE_VISIBILITY
-  iterator()
-      : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
-        __state_(_Singular) {}
-
-  iterator(const iterator&) = default;
-  ~iterator() = default;
-
-  iterator& operator=(const iterator&) = default;
-
-  _LIBCPP_INLINE_VISIBILITY
-  reference operator*() const { return __stashed_elem_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  pointer operator->() const { return &__stashed_elem_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  iterator& operator++() {
-    _LIBCPP_ASSERT(__state_ != _Singular,
-                   "attempting to increment a singular iterator");
-    _LIBCPP_ASSERT(__state_ != _AtEnd,
-                   "attempting to increment the end iterator");
-    return __increment();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  iterator operator++(int) {
-    iterator __it(*this);
-    this->operator++();
-    return __it;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  iterator& operator--() {
-    _LIBCPP_ASSERT(__state_ != _Singular,
-                   "attempting to decrement a singular iterator");
-    _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
-                   "attempting to decrement the begin iterator");
-    return __decrement();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  iterator operator--(int) {
-    iterator __it(*this);
-    this->operator--();
-    return __it;
-  }
-
-private:
-  friend class path;
-
-  inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
-                                                          const iterator&);
-
-  iterator& __increment();
-  iterator& __decrement();
-
-  path __stashed_elem_;
-  const path* __path_ptr_;
-  path::__string_view __entry_;
-  _ParserState __state_;
-};
-
-inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
-                                                 const path::iterator& __rhs) {
-  return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
-         __lhs.__entry_.data() == __rhs.__entry_.data();
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
-                                                 const path::iterator& __rhs) {
-  return !(__lhs == __rhs);
-}
-
-// TODO(ldionne): We need to pop the pragma and push it again after
-//                filesystem_error to work around PR41078.
-_LIBCPP_AVAILABILITY_FILESYSTEM_POP
-
-class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
-public:
-  _LIBCPP_INLINE_VISIBILITY
-  filesystem_error(const string& __what, error_code __ec)
-      : system_error(__ec, __what),
-        __storage_(make_shared<_Storage>(path(), path())) {
-    __create_what(0);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  filesystem_error(const string& __what, const path& __p1, error_code __ec)
-      : system_error(__ec, __what),
-        __storage_(make_shared<_Storage>(__p1, path())) {
-    __create_what(1);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  filesystem_error(const string& __what, const path& __p1, const path& __p2,
-                   error_code __ec)
-      : system_error(__ec, __what),
-        __storage_(make_shared<_Storage>(__p1, __p2)) {
-    __create_what(2);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  const path& path1() const noexcept { return __storage_->__p1_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  const path& path2() const noexcept { return __storage_->__p2_; }
-
-  filesystem_error(const filesystem_error&) = default;
-  ~filesystem_error() override; // key function
-
-  _LIBCPP_INLINE_VISIBILITY
-  const char* what() const noexcept override {
-    return __storage_->__what_.c_str();
-  }
-
-  void __create_what(int __num_paths);
-
-private:
-  struct _LIBCPP_HIDDEN _Storage {
-    _LIBCPP_INLINE_VISIBILITY
-    _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
-
-    path __p1_;
-    path __p2_;
-    string __what_;
-  };
-  shared_ptr<_Storage> __storage_;
-};
-
-_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
-
-template <class... _Args>
-_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_NO_EXCEPTIONS
-void __throw_filesystem_error(_Args&&... __args) {
-  throw filesystem_error(_VSTD::forward<_Args>(__args)...);
-}
-#else
-void __throw_filesystem_error(_Args&&...) {
-  _VSTD::abort();
-}
-#endif
-
-// operational functions
-
-_LIBCPP_FUNC_VIS
-path __absolute(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-path __canonical(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __copy(const path& __from, const path& __to, copy_options __opt,
-            error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-bool __copy_file(const path& __from, const path& __to, copy_options __opt,
-                 error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __copy_symlink(const path& __existing_symlink, const path& __new_symlink,
-                    error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-bool __create_directories(const path& p, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-bool __create_directory(const path& p, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-bool __create_directory(const path& p, const path& attributes,
-                        error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __create_directory_symlink(const path& __to, const path& __new_symlink,
-                                error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __create_hard_link(const path& __to, const path& __new_hard_link,
-                        error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __create_symlink(const path& __to, const path& __new_symlink,
-                      error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-path __current_path(error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __current_path(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-bool __equivalent(const path&, const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-uintmax_t __file_size(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-bool __fs_is_empty(const path& p, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-file_time_type __last_write_time(const path& p, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __last_write_time(const path& p, file_time_type new_time,
-                       error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __permissions(const path&, perms, perm_options, error_code* = nullptr);
-_LIBCPP_FUNC_VIS
-path __read_symlink(const path& p, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-bool __remove(const path& p, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-uintmax_t __remove_all(const path& p, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __rename(const path& from, const path& to, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr);
-_LIBCPP_FUNC_VIS
-space_info __space(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-file_status __status(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-file_status __symlink_status(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-path __system_complete(const path&, error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-path __temp_directory_path(error_code* __ec = nullptr);
-_LIBCPP_FUNC_VIS
-path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
-
-inline _LIBCPP_INLINE_VISIBILITY path current_path() {
-  return __current_path();
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) {
-  return __current_path(&__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) {
-  __current_path(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p,
-                                                   error_code& __ec) noexcept {
-  __current_path(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) {
-  return __absolute(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p,
-                                               error_code& __ec) {
-  return __absolute(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) {
-  return __canonical(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p,
-                                                error_code& __ec) {
-  return __canonical(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from,
-                                           const path& __to) {
-  __copy(__from, __to, copy_options::none);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
-                                           error_code& __ec) {
-  __copy(__from, __to, copy_options::none, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
-                                           copy_options __opt) {
-  __copy(__from, __to, __opt);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
-                                           copy_options __opt,
-                                           error_code& __ec) {
-  __copy(__from, __to, __opt, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
-                                                const path& __to) {
-  return __copy_file(__from, __to, copy_options::none);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-copy_file(const path& __from, const path& __to, error_code& __ec) {
-  return __copy_file(__from, __to, copy_options::none, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-copy_file(const path& __from, const path& __to, copy_options __opt) {
-  return __copy_file(__from, __to, __opt);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
-                                                const path& __to,
-                                                copy_options __opt,
-                                                error_code& __ec) {
-  return __copy_file(__from, __to, __opt, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing,
-                                                   const path& __new) {
-  __copy_symlink(__existing, __new);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
-  __copy_symlink(__ext, __new, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) {
-  return __create_directories(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p,
-                                                         error_code& __ec) {
-  return __create_directories(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) {
-  return __create_directory(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-create_directory(const path& __p, error_code& __ec) noexcept {
-  return __create_directory(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p,
-                                                       const path& __attrs) {
-  return __create_directory(__p, __attrs);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-create_directory(const path& __p, const path& __attrs,
-                 error_code& __ec) noexcept {
-  return __create_directory(__p, __attrs, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-create_directory_symlink(const path& __to, const path& __new) {
-  __create_directory_symlink(__to, __new);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-create_directory_symlink(const path& __to, const path& __new,
-                         error_code& __ec) noexcept {
-  __create_directory_symlink(__to, __new, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to,
-                                                       const path& __new) {
-  __create_hard_link(__to, __new);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-create_hard_link(const path& __to, const path& __new,
-                 error_code& __ec) noexcept {
-  __create_hard_link(__to, __new, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to,
-                                                     const path& __new) {
-  __create_symlink(__to, __new);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-create_symlink(const path& __to, const path& __new, error_code& __ec) noexcept {
-  return __create_symlink(__to, __new, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept {
-  return __s.type() != file_type::none;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept {
-  return status_known(__s) && __s.type() != file_type::not_found;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) {
-  return exists(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p,
-                                             error_code& __ec) noexcept {
-  auto __s = __status(__p, &__ec);
-  if (status_known(__s))
-    __ec.clear();
-  return exists(__s);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1,
-                                                 const path& __p2) {
-  return __equivalent(__p1, __p2);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
-  return __equivalent(__p1, __p2, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) {
-  return __file_size(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY uintmax_t
-file_size(const path& __p, error_code& __ec) noexcept {
-  return __file_size(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) {
-  return __hard_link_count(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY uintmax_t
-hard_link_count(const path& __p, error_code& __ec) noexcept {
-  return __hard_link_count(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept {
-  return __s.type() == file_type::block;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) {
-  return is_block_file(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p,
-                                                    error_code& __ec) noexcept {
-  return is_block_file(__status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-is_character_file(file_status __s) noexcept {
-  return __s.type() == file_type::character;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) {
-  return is_character_file(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-is_character_file(const path& __p, error_code& __ec) noexcept {
-  return is_character_file(__status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept {
-  return __s.type() == file_type::directory;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) {
-  return is_directory(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p,
-                                                   error_code& __ec) noexcept {
-  return is_directory(__status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) {
-  return __fs_is_empty(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p,
-                                               error_code& __ec) {
-  return __fs_is_empty(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept {
-  return __s.type() == file_type::fifo;
-}
-inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) {
-  return is_fifo(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p,
-                                              error_code& __ec) noexcept {
-  return is_fifo(__status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-is_regular_file(file_status __s) noexcept {
-  return __s.type() == file_type::regular;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) {
-  return is_regular_file(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-is_regular_file(const path& __p, error_code& __ec) noexcept {
-  return is_regular_file(__status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept {
-  return __s.type() == file_type::socket;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) {
-  return is_socket(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p,
-                                                error_code& __ec) noexcept {
-  return is_socket(__status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept {
-  return __s.type() == file_type::symlink;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) {
-  return is_symlink(__symlink_status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p,
-                                                 error_code& __ec) noexcept {
-  return is_symlink(__symlink_status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept {
-  return exists(__s) && !is_regular_file(__s) && !is_directory(__s) &&
-         !is_symlink(__s);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) {
-  return is_other(__status(__p));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p,
-                                               error_code& __ec) noexcept {
-  return is_other(__status(__p, &__ec));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY file_time_type
-last_write_time(const path& __p) {
-  return __last_write_time(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY file_time_type
-last_write_time(const path& __p, error_code& __ec) noexcept {
-  return __last_write_time(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p,
-                                                      file_time_type __t) {
-  __last_write_time(__p, __t);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-last_write_time(const path& __p, file_time_type __t,
-                error_code& __ec) noexcept {
-  __last_write_time(__p, __t, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-permissions(const path& __p, perms __prms,
-            perm_options __opts = perm_options::replace) {
-  __permissions(__p, __prms, __opts);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
-                                                  error_code& __ec) noexcept {
-  __permissions(__p, __prms, perm_options::replace, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
-                                                  perm_options __opts,
-                                                  error_code& __ec) {
-  __permissions(__p, __prms, __opts, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
-                                                const path& __base,
-                                                error_code& __ec) {
-  path __tmp = __weakly_canonical(__p, &__ec);
-  if (__ec)
-    return {};
-  path __tmp_base = __weakly_canonical(__base, &__ec);
-  if (__ec)
-    return {};
-  return __tmp.lexically_proximate(__tmp_base);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p,
-                                                error_code& __ec) {
-  return proximate(__p, current_path(), __ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path
-proximate(const path& __p, const path& __base = current_path()) {
-  return __weakly_canonical(__p).lexically_proximate(
-      __weakly_canonical(__base));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) {
-  return __read_symlink(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p,
-                                                   error_code& __ec) {
-  return __read_symlink(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
-                                               const path& __base,
-                                               error_code& __ec) {
-  path __tmp = __weakly_canonical(__p, &__ec);
-  if (__ec)
-    return path();
-  path __tmpbase = __weakly_canonical(__base, &__ec);
-  if (__ec)
-    return path();
-  return __tmp.lexically_relative(__tmpbase);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p,
-                                               error_code& __ec) {
-  return relative(__p, current_path(), __ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path
-relative(const path& __p, const path& __base = current_path()) {
-  return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) {
-  return __remove(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p,
-                                             error_code& __ec) noexcept {
-  return __remove(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) {
-  return __remove_all(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p,
-                                                      error_code& __ec) {
-  return __remove_all(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from,
-                                             const path& __to) {
-  return __rename(__from, __to);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-rename(const path& __from, const path& __to, error_code& __ec) noexcept {
-  return __rename(__from, __to, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p,
-                                                  uintmax_t __ns) {
-  return __resize_file(__p, __ns);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY void
-resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
-  return __resize_file(__p, __ns, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) {
-  return __space(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p,
-                                                  error_code& __ec) noexcept {
-  return __space(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) {
-  return __status(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p,
-                                                    error_code& __ec) noexcept {
-  return __status(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) {
-  return __symlink_status(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY file_status
-symlink_status(const path& __p, error_code& __ec) noexcept {
-  return __symlink_status(__p, &__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() {
-  return __temp_directory_path();
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) {
-  return __temp_directory_path(&__ec);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) {
-  return __weakly_canonical(__p);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p,
-                                                       error_code& __ec) {
-  return __weakly_canonical(__p, &__ec);
-}
-
-class directory_iterator;
-class recursive_directory_iterator;
-class _LIBCPP_HIDDEN __dir_stream;
-
-class directory_entry {
-  typedef _VSTD_FS::path _Path;
-
-public:
-  // constructors and destructors
-  directory_entry() noexcept = default;
-  directory_entry(directory_entry const&) = default;
-  directory_entry(directory_entry&&) noexcept = default;
-
-  _LIBCPP_INLINE_VISIBILITY
-  explicit directory_entry(_Path const& __p) : __p_(__p) {
-    error_code __ec;
-    __refresh(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) {
-    __refresh(&__ec);
-  }
-
-  ~directory_entry() {}
-
-  directory_entry& operator=(directory_entry const&) = default;
-  directory_entry& operator=(directory_entry&&) noexcept = default;
-
-  _LIBCPP_INLINE_VISIBILITY
-  void assign(_Path const& __p) {
-    __p_ = __p;
-    error_code __ec;
-    __refresh(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void assign(_Path const& __p, error_code& __ec) {
-    __p_ = __p;
-    __refresh(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void replace_filename(_Path const& __p) {
-    __p_.replace_filename(__p);
-    error_code __ec;
-    __refresh(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void replace_filename(_Path const& __p, error_code& __ec) {
-    __p_ = __p_.parent_path() / __p;
-    __refresh(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void refresh() { __refresh(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void refresh(error_code& __ec) noexcept { __refresh(&__ec); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  _Path const& path() const noexcept { return __p_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  operator const _Path&() const noexcept { return __p_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool exists(error_code& __ec) const noexcept {
-    return _VSTD_FS::exists(file_status{__get_ft(&__ec)});
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_block_file() const { return __get_ft() == file_type::block; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_block_file(error_code& __ec) const noexcept {
-    return __get_ft(&__ec) == file_type::block;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_character_file() const { return __get_ft() == file_type::character; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_character_file(error_code& __ec) const noexcept {
-    return __get_ft(&__ec) == file_type::character;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_directory() const { return __get_ft() == file_type::directory; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_directory(error_code& __ec) const noexcept {
-    return __get_ft(&__ec) == file_type::directory;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_fifo() const { return __get_ft() == file_type::fifo; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_fifo(error_code& __ec) const noexcept {
-    return __get_ft(&__ec) == file_type::fifo;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_other(error_code& __ec) const noexcept {
-    return _VSTD_FS::is_other(file_status{__get_ft(&__ec)});
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_regular_file() const { return __get_ft() == file_type::regular; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_regular_file(error_code& __ec) const noexcept {
-    return __get_ft(&__ec) == file_type::regular;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_socket() const { return __get_ft() == file_type::socket; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_socket(error_code& __ec) const noexcept {
-    return __get_ft(&__ec) == file_type::socket;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_symlink() const { return __get_sym_ft() == file_type::symlink; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool is_symlink(error_code& __ec) const noexcept {
-    return __get_sym_ft(&__ec) == file_type::symlink;
-  }
-  _LIBCPP_INLINE_VISIBILITY
-  uintmax_t file_size() const { return __get_size(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  uintmax_t file_size(error_code& __ec) const noexcept {
-    return __get_size(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  uintmax_t hard_link_count() const { return __get_nlink(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  uintmax_t hard_link_count(error_code& __ec) const noexcept {
-    return __get_nlink(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_time_type last_write_time() const { return __get_write_time(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_time_type last_write_time(error_code& __ec) const noexcept {
-    return __get_write_time(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_status status() const { return __get_status(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_status status(error_code& __ec) const noexcept {
-    return __get_status(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_status symlink_status() const { return __get_symlink_status(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_status symlink_status(error_code& __ec) const noexcept {
-    return __get_symlink_status(&__ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool operator<(directory_entry const& __rhs) const noexcept {
-    return __p_ < __rhs.__p_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool operator==(directory_entry const& __rhs) const noexcept {
-    return __p_ == __rhs.__p_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool operator!=(directory_entry const& __rhs) const noexcept {
-    return __p_ != __rhs.__p_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool operator<=(directory_entry const& __rhs) const noexcept {
-    return __p_ <= __rhs.__p_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool operator>(directory_entry const& __rhs) const noexcept {
-    return __p_ > __rhs.__p_;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool operator>=(directory_entry const& __rhs) const noexcept {
-    return __p_ >= __rhs.__p_;
-  }
-
-private:
-  friend class directory_iterator;
-  friend class recursive_directory_iterator;
-  friend class __dir_stream;
-
-  enum _CacheType : unsigned char {
-    _Empty,
-    _IterSymlink,
-    _IterNonSymlink,
-    _RefreshSymlink,
-    _RefreshSymlinkUnresolved,
-    _RefreshNonSymlink
-  };
-
-  struct __cached_data {
-    uintmax_t __size_;
-    uintmax_t __nlink_;
-    file_time_type __write_time_;
-    perms __sym_perms_;
-    perms __non_sym_perms_;
-    file_type __type_;
-    _CacheType __cache_type_;
-
-    _LIBCPP_INLINE_VISIBILITY
-    __cached_data() noexcept { __reset(); }
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __reset() {
-      __cache_type_ = _Empty;
-      __type_ = file_type::none;
-      __sym_perms_ = __non_sym_perms_ = perms::unknown;
-      __size_ = __nlink_ = uintmax_t(-1);
-      __write_time_ = file_time_type::min();
-    }
-  };
-
-  _LIBCPP_INLINE_VISIBILITY
-  static __cached_data __create_iter_result(file_type __ft) {
-    __cached_data __data;
-    __data.__type_ = __ft;
-    __data.__cache_type_ = [&]() {
-      switch (__ft) {
-      case file_type::none:
-        return _Empty;
-      case file_type::symlink:
-        return _IterSymlink;
-      default:
-        return _IterNonSymlink;
-      }
-    }();
-    return __data;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
-    __p_ = _VSTD::move(__p);
-    __data_ = __dt;
-  }
-
-  _LIBCPP_FUNC_VIS
-  error_code __do_refresh() noexcept;
-
-  _LIBCPP_INLINE_VISIBILITY
-  static bool __is_dne_error(error_code const& __ec) {
-    if (!__ec)
-      return true;
-    switch (static_cast<errc>(__ec.value())) {
-    case errc::no_such_file_or_directory:
-    case errc::not_a_directory:
-      return true;
-    default:
-      return false;
-    }
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void __handle_error(const char* __msg, error_code* __dest_ec,
-                      error_code const& __ec, bool __allow_dne = false) const {
-    if (__dest_ec) {
-      *__dest_ec = __ec;
-      return;
-    }
-    if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
-      __throw_filesystem_error(__msg, __p_, __ec);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void __refresh(error_code* __ec = nullptr) {
-    __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
-                   /*allow_dne*/ true);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_type __get_sym_ft(error_code* __ec = nullptr) const {
-    switch (__data_.__cache_type_) {
-    case _Empty:
-      return __symlink_status(__p_, __ec).type();
-    case _IterSymlink:
-    case _RefreshSymlink:
-    case _RefreshSymlinkUnresolved:
-      if (__ec)
-        __ec->clear();
-      return file_type::symlink;
-    case _IterNonSymlink:
-    case _RefreshNonSymlink:
-      file_status __st(__data_.__type_);
-      if (__ec && !_VSTD_FS::exists(__st))
-        *__ec = make_error_code(errc::no_such_file_or_directory);
-      else if (__ec)
-        __ec->clear();
-      return __data_.__type_;
-    }
-    _LIBCPP_UNREACHABLE();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_type __get_ft(error_code* __ec = nullptr) const {
-    switch (__data_.__cache_type_) {
-    case _Empty:
-    case _IterSymlink:
-    case _RefreshSymlinkUnresolved:
-      return __status(__p_, __ec).type();
-    case _IterNonSymlink:
-    case _RefreshNonSymlink:
-    case _RefreshSymlink: {
-      file_status __st(__data_.__type_);
-      if (__ec && !_VSTD_FS::exists(__st))
-        *__ec = make_error_code(errc::no_such_file_or_directory);
-      else if (__ec)
-        __ec->clear();
-      return __data_.__type_;
-    }
-    }
-    _LIBCPP_UNREACHABLE();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_status __get_status(error_code* __ec = nullptr) const {
-    switch (__data_.__cache_type_) {
-    case _Empty:
-    case _IterNonSymlink:
-    case _IterSymlink:
-    case _RefreshSymlinkUnresolved:
-      return __status(__p_, __ec);
-    case _RefreshNonSymlink:
-    case _RefreshSymlink:
-      return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
-    }
-    _LIBCPP_UNREACHABLE();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_status __get_symlink_status(error_code* __ec = nullptr) const {
-    switch (__data_.__cache_type_) {
-    case _Empty:
-    case _IterNonSymlink:
-    case _IterSymlink:
-      return __symlink_status(__p_, __ec);
-    case _RefreshNonSymlink:
-      return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
-    case _RefreshSymlink:
-    case _RefreshSymlinkUnresolved:
-      return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
-    }
-    _LIBCPP_UNREACHABLE();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  uintmax_t __get_size(error_code* __ec = nullptr) const {
-    switch (__data_.__cache_type_) {
-    case _Empty:
-    case _IterNonSymlink:
-    case _IterSymlink:
-    case _RefreshSymlinkUnresolved:
-      return _VSTD_FS::__file_size(__p_, __ec);
-    case _RefreshSymlink:
-    case _RefreshNonSymlink: {
-      error_code __m_ec;
-      file_status __st(__get_ft(&__m_ec));
-      __handle_error("in directory_entry::file_size", __ec, __m_ec);
-      if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) {
-        errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory
-                                                       : errc::not_supported;
-        __handle_error("in directory_entry::file_size", __ec,
-                       make_error_code(__err_kind));
-      }
-      return __data_.__size_;
-    }
-    }
-    _LIBCPP_UNREACHABLE();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  uintmax_t __get_nlink(error_code* __ec = nullptr) const {
-    switch (__data_.__cache_type_) {
-    case _Empty:
-    case _IterNonSymlink:
-    case _IterSymlink:
-    case _RefreshSymlinkUnresolved:
-      return _VSTD_FS::__hard_link_count(__p_, __ec);
-    case _RefreshSymlink:
-    case _RefreshNonSymlink: {
-      error_code __m_ec;
-      (void)__get_ft(&__m_ec);
-      __handle_error("in directory_entry::hard_link_count", __ec, __m_ec);
-      return __data_.__nlink_;
-    }
-    }
-    _LIBCPP_UNREACHABLE();
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  file_time_type __get_write_time(error_code* __ec = nullptr) const {
-    switch (__data_.__cache_type_) {
-    case _Empty:
-    case _IterNonSymlink:
-    case _IterSymlink:
-    case _RefreshSymlinkUnresolved:
-      return _VSTD_FS::__last_write_time(__p_, __ec);
-    case _RefreshSymlink:
-    case _RefreshNonSymlink: {
-      error_code __m_ec;
-      file_status __st(__get_ft(&__m_ec));
-      __handle_error("in directory_entry::last_write_time", __ec, __m_ec);
-      if (_VSTD_FS::exists(__st) &&
-          __data_.__write_time_ == file_time_type::min())
-        __handle_error("in directory_entry::last_write_time", __ec,
-                       make_error_code(errc::value_too_large));
-      return __data_.__write_time_;
-    }
-    }
-    _LIBCPP_UNREACHABLE();
-  }
-
-private:
-  _Path __p_;
-  __cached_data __data_;
-};
-
-class __dir_element_proxy {
-public:
-  inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() {
-    return _VSTD::move(__elem_);
-  }
-
-private:
-  friend class directory_iterator;
-  friend class recursive_directory_iterator;
-  explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {}
-  __dir_element_proxy(__dir_element_proxy&& __o)
-      : __elem_(_VSTD::move(__o.__elem_)) {}
-  directory_entry __elem_;
-};
-
-class directory_iterator {
-public:
-  typedef directory_entry value_type;
-  typedef ptrdiff_t difference_type;
-  typedef value_type const* pointer;
-  typedef value_type const& reference;
-  typedef input_iterator_tag iterator_category;
-
-public:
-  //ctor & dtor
-  directory_iterator() noexcept {}
-
-  explicit directory_iterator(const path& __p)
-      : directory_iterator(__p, nullptr) {}
-
-  directory_iterator(const path& __p, directory_options __opts)
-      : directory_iterator(__p, nullptr, __opts) {}
-
-  directory_iterator(const path& __p, error_code& __ec)
-      : directory_iterator(__p, &__ec) {}
-
-  directory_iterator(const path& __p, directory_options __opts,
-                     error_code& __ec)
-      : directory_iterator(__p, &__ec, __opts) {}
-
-  directory_iterator(const directory_iterator&) = default;
-  directory_iterator(directory_iterator&&) = default;
-  directory_iterator& operator=(const directory_iterator&) = default;
-
-  directory_iterator& operator=(directory_iterator&& __o) noexcept {
-    // non-default implementation provided to support self-move assign.
-    if (this != &__o) {
-      __imp_ = _VSTD::move(__o.__imp_);
-    }
-    return *this;
-  }
-
-  ~directory_iterator() = default;
-
-  const directory_entry& operator*() const {
-    _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced");
-    return __dereference();
-  }
-
-  const directory_entry* operator->() const { return &**this; }
-
-  directory_iterator& operator++() { return __increment(); }
-
-  __dir_element_proxy operator++(int) {
-    __dir_element_proxy __p(**this);
-    __increment();
-    return __p;
-  }
-
-  directory_iterator& increment(error_code& __ec) { return __increment(&__ec); }
-
-private:
-  inline _LIBCPP_INLINE_VISIBILITY friend bool
-  operator==(const directory_iterator& __lhs,
-             const directory_iterator& __rhs) noexcept;
-
-  // construct the dir_stream
-  _LIBCPP_FUNC_VIS
-  directory_iterator(const path&, error_code*,
-                     directory_options = directory_options::none);
-
-  _LIBCPP_FUNC_VIS
-  directory_iterator& __increment(error_code* __ec = nullptr);
-
-  _LIBCPP_FUNC_VIS
-  const directory_entry& __dereference() const;
-
-private:
-  shared_ptr<__dir_stream> __imp_;
-};
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-operator==(const directory_iterator& __lhs,
-           const directory_iterator& __rhs) noexcept {
-  return __lhs.__imp_ == __rhs.__imp_;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-operator!=(const directory_iterator& __lhs,
-           const directory_iterator& __rhs) noexcept {
-  return !(__lhs == __rhs);
-}
-
-// enable directory_iterator range-based for statements
-inline _LIBCPP_INLINE_VISIBILITY directory_iterator
-begin(directory_iterator __iter) noexcept {
-  return __iter;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY directory_iterator
-end(const directory_iterator&) noexcept {
-  return directory_iterator();
-}
-
-class recursive_directory_iterator {
-public:
-  using value_type = directory_entry;
-  using difference_type = ptrdiff_t;
-  using pointer = directory_entry const*;
-  using reference = directory_entry const&;
-  using iterator_category = input_iterator_tag;
-
-public:
-  // constructors and destructor
-  _LIBCPP_INLINE_VISIBILITY
-  recursive_directory_iterator() noexcept : __rec_(false) {}
-
-  _LIBCPP_INLINE_VISIBILITY
-  explicit recursive_directory_iterator(
-      const path& __p, directory_options __xoptions = directory_options::none)
-      : recursive_directory_iterator(__p, __xoptions, nullptr) {}
-
-  _LIBCPP_INLINE_VISIBILITY
-  recursive_directory_iterator(const path& __p, directory_options __xoptions,
-                               error_code& __ec)
-      : recursive_directory_iterator(__p, __xoptions, &__ec) {}
-
-  _LIBCPP_INLINE_VISIBILITY
-  recursive_directory_iterator(const path& __p, error_code& __ec)
-      : recursive_directory_iterator(__p, directory_options::none, &__ec) {}
-
-  recursive_directory_iterator(const recursive_directory_iterator&) = default;
-  recursive_directory_iterator(recursive_directory_iterator&&) = default;
-
-  recursive_directory_iterator&
-  operator=(const recursive_directory_iterator&) = default;
-
-  _LIBCPP_INLINE_VISIBILITY
-  recursive_directory_iterator&
-  operator=(recursive_directory_iterator&& __o) noexcept {
-    // non-default implementation provided to support self-move assign.
-    if (this != &__o) {
-      __imp_ = _VSTD::move(__o.__imp_);
-      __rec_ = __o.__rec_;
-    }
-    return *this;
-  }
-
-  ~recursive_directory_iterator() = default;
-
-  _LIBCPP_INLINE_VISIBILITY
-  const directory_entry& operator*() const { return __dereference(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  const directory_entry* operator->() const { return &__dereference(); }
-
-  recursive_directory_iterator& operator++() { return __increment(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  __dir_element_proxy operator++(int) {
-    __dir_element_proxy __p(**this);
-    __increment();
-    return __p;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  recursive_directory_iterator& increment(error_code& __ec) {
-    return __increment(&__ec);
-  }
-
-  _LIBCPP_FUNC_VIS directory_options options() const;
-  _LIBCPP_FUNC_VIS int depth() const;
-
-  _LIBCPP_INLINE_VISIBILITY
-  void pop() { __pop(); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void pop(error_code& __ec) { __pop(&__ec); }
-
-  _LIBCPP_INLINE_VISIBILITY
-  bool recursion_pending() const { return __rec_; }
-
-  _LIBCPP_INLINE_VISIBILITY
-  void disable_recursion_pending() { __rec_ = false; }
-
-private:
-  _LIBCPP_FUNC_VIS
-  recursive_directory_iterator(const path& __p, directory_options __opt,
-                               error_code* __ec);
-
-  _LIBCPP_FUNC_VIS
-  const directory_entry& __dereference() const;
-
-  _LIBCPP_FUNC_VIS
-  bool __try_recursion(error_code* __ec);
-
-  _LIBCPP_FUNC_VIS
-  void __advance(error_code* __ec = nullptr);
-
-  _LIBCPP_FUNC_VIS
-  recursive_directory_iterator& __increment(error_code* __ec = nullptr);
-
-  _LIBCPP_FUNC_VIS
-  void __pop(error_code* __ec = nullptr);
-
-  inline _LIBCPP_INLINE_VISIBILITY friend bool
-  operator==(const recursive_directory_iterator&,
-             const recursive_directory_iterator&) noexcept;
-
-  struct _LIBCPP_HIDDEN __shared_imp;
-  shared_ptr<__shared_imp> __imp_;
-  bool __rec_;
-}; // class recursive_directory_iterator
-
-inline _LIBCPP_INLINE_VISIBILITY bool
-operator==(const recursive_directory_iterator& __lhs,
-           const recursive_directory_iterator& __rhs) noexcept {
-  return __lhs.__imp_ == __rhs.__imp_;
-}
-
-_LIBCPP_INLINE_VISIBILITY
-inline bool operator!=(const recursive_directory_iterator& __lhs,
-                       const recursive_directory_iterator& __rhs) noexcept {
-  return !(__lhs == __rhs);
-}
-// enable recursive_directory_iterator range-based for statements
-inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
-begin(recursive_directory_iterator __iter) noexcept {
-  return __iter;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator
-end(const recursive_directory_iterator&) noexcept {
-  return recursive_directory_iterator();
-}
-
-_LIBCPP_AVAILABILITY_FILESYSTEM_POP
-
-_LIBCPP_END_NAMESPACE_FILESYSTEM
-
-#endif // !_LIBCPP_CXX03_LANG
-
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP_FILESYSTEM
lib/libcxx/include/float.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- float.h ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/format
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- format -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -13,59 +13,146 @@
 /*
 
 namespace std {
-  // [format.error], class format_error
-  class format_error : public runtime_error {
-  public:
-    explicit format_error(const string& what_arg);
-    explicit format_error(const char* what_arg);
+  // [format.context], class template basic_format_context
+  template<class Out, class charT> class basic_format_context;
+  using format_context = basic_format_context<unspecified, char>;
+  using wformat_context = basic_format_context<unspecified, wchar_t>;
+
+  // [format.args], class template basic_format_args
+  template<class Context> class basic_format_args;
+  using format_args = basic_format_args<format_context>;
+  using wformat_args = basic_format_args<wformat_context>;
+
+  // [format.functions], formatting functions
+  template<class... Args>
+    string format(string_view fmt, const Args&... args);
+  template<class... Args>
+    wstring format(wstring_view fmt, const Args&... args);
+  template<class... Args>
+    string format(const locale& loc, string_view fmt, const Args&... args);
+  template<class... Args>
+    wstring format(const locale& loc, wstring_view fmt, const Args&... args);
+
+  string vformat(string_view fmt, format_args args);
+  wstring vformat(wstring_view fmt, wformat_args args);
+  string vformat(const locale& loc, string_view fmt, format_args args);
+  wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
+
+  template<class Out, class... Args>
+    Out format_to(Out out, string_view fmt, const Args&... args);
+  template<class Out, class... Args>
+    Out format_to(Out out, wstring_view fmt, const Args&... args);
+  template<class Out, class... Args>
+    Out format_to(Out out, const locale& loc, string_view fmt, const Args&... args);
+  template<class Out, class... Args>
+    Out format_to(Out out, const locale& loc, wstring_view fmt, const Args&... args);
+
+  template<class Out>
+    Out vformat_to(Out out, string_view fmt, format_args args);
+  template<class Out>
+    Out vformat_to(Out out, wstring_view fmt, wformat_args args);
+  template<class Out>
+    Out vformat_to(Out out, const locale& loc, string_view fmt,
+                   format_args char> args);
+  template<class Out>
+    Out vformat_to(Out out, const locale& loc, wstring_view fmt,
+                   wformat_args args);
+
+  template<class Out> struct format_to_n_result {
+    Out out;
+    iter_difference_t<Out> size;
   };
+  template<class Out, class... Args>
+    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
+                                        string_view fmt, const Args&... args);
+  template<class Out, class... Args>
+    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
+                                        wstring_view fmt, const Args&... args);
+  template<class Out, class... Args>
+    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
+                                        const locale& loc, string_view fmt,
+                                        const Args&... args);
+  template<class Out, class... Args>
+    format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
+                                        const locale& loc, wstring_view fmt,
+                                        const Args&... args);
+
+  template<class... Args>
+    size_t formatted_size(string_view fmt, const Args&... args);
+  template<class... Args>
+    size_t formatted_size(wstring_view fmt, const Args&... args);
+  template<class... Args>
+    size_t formatted_size(const locale& loc, string_view fmt, const Args&... args);
+  template<class... Args>
+    size_t formatted_size(const locale& loc, wstring_view fmt, const Args&... args);
+
+  // [format.formatter], formatter
+  template<class T, class charT = char> struct formatter;
 
   // [format.parse.ctx], class template basic_format_parse_context
-  template<class charT>
-  class basic_format_parse_context {
-  public:
-    using char_type = charT;
-    using const_iterator = typename basic_string_view<charT>::const_iterator;
-    using iterator = const_iterator;
-
-  private:
-    iterator begin_;                                    // exposition only
-    iterator end_;                                      // exposition only
-    enum indexing { unknown, manual, automatic };       // exposition only
-    indexing indexing_;                                 // exposition only
-    size_t next_arg_id_;                                // exposition only
-    size_t num_args_;                                   // exposition only
-
-  public:
-    constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
-                                                  size_t num_args = 0) noexcept;
-    basic_format_parse_context(const basic_format_parse_context&) = delete;
-    basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
-
-    constexpr const_iterator begin() const noexcept;
-    constexpr const_iterator end() const noexcept;
-    constexpr void advance_to(const_iterator it);
-
-    constexpr size_t next_arg_id();
-    constexpr void check_arg_id(size_t id);
-  };
+  template<class charT> class basic_format_parse_context;
   using format_parse_context = basic_format_parse_context<char>;
   using wformat_parse_context = basic_format_parse_context<wchar_t>;
+
+  // [format.arguments], arguments
+  // [format.arg], class template basic_format_arg
+  template<class Context> class basic_format_arg;
+
+  template<class Visitor, class Context>
+    see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
+
+  // [format.arg.store], class template format-arg-store
+  template<class Context, class... Args> struct format-arg-store;      // exposition only
+
+  template<class Context = format_context, class... Args>
+    format-arg-store<Context, Args...>
+      make_format_args(const Args&... args);
+  template<class... Args>
+    format-arg-store<wformat_context, Args...>
+      make_wformat_args(const Args&... args);
+
+  // [format.error], class format_error
+  class format_error;
 }
 
 */
 
-// Make sure all feature tests macros are always available.
+// Make sure all feature-test macros are available.
 #include <version>
-// Only enable the contents of the header when libc++ was build with LIBCXX_ENABLE_INCOMPLETE_FEATURES enabled
+// Enable the contents of the header only when libc++ was built with LIBCXX_ENABLE_INCOMPLETE_FEATURES.
 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
 
 #include <__config>
+#include <__debug>
+#include <__format/format_arg.h>
+#include <__format/format_args.h>
+#include <__format/format_context.h>
 #include <__format/format_error.h>
+#include <__format/format_fwd.h>
 #include <__format/format_parse_context.h>
+#include <__format/format_string.h>
+#include <__format/format_to_n_result.h>
+#include <__format/formatter.h>
+#include <__format/formatter_bool.h>
+#include <__format/formatter_char.h>
+#include <__format/formatter_floating_point.h>
+#include <__format/formatter_integer.h>
+#include <__format/formatter_pointer.h>
+#include <__format/formatter_string.h>
+#include <__format/parser_std_format_spec.h>
+#include <__variant/monostate.h>
+#include <array>
+#include <concepts>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#include <locale>
+#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
+#pragma GCC system_header
 #endif
 
 _LIBCPP_PUSH_MACROS
@@ -75,6 +162,397 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 17
 
+// TODO FMT Remove this once we require compilers with proper C++20 support.
+// If the compiler has no concepts support, the format header will be disabled.
+// Without concepts support enable_if needs to be used and that too much effort
+// to support compilers with partial C++20 support.
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// TODO FMT Move the implementation in this file to its own granular headers.
+
+// TODO FMT Evaluate which templates should be external templates. This
+// improves the efficiency of the header. However since the header is still
+// under heavy development and not all classes are stable it makes no sense
+// to do this optimization now.
+
+using format_args = basic_format_args<format_context>;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+using wformat_args = basic_format_args<wformat_context>;
+#endif
+
+template <class _Context, class... _Args>
+struct _LIBCPP_TEMPLATE_VIS __format_arg_store {
+  // TODO FMT Use a built-in array.
+  array<basic_format_arg<_Context>, sizeof...(_Args)> __args;
+};
+
+template <class _Context = format_context, class... _Args>
+_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...>
+make_format_args(const _Args&... __args) {
+  return {basic_format_arg<_Context>(__args)...};
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...>
+make_wformat_args(const _Args&... __args) {
+  return _VSTD::make_format_args<wformat_context>(__args...);
+}
+#endif
+
+namespace __format {
+
+template <class _CharT, class _ParseCtx, class _Ctx>
+_LIBCPP_HIDE_FROM_ABI const _CharT*
+__handle_replacement_field(const _CharT* __begin, const _CharT* __end,
+                           _ParseCtx& __parse_ctx, _Ctx& __ctx) {
+  __format::__parse_number_result __r =
+      __format::__parse_arg_id(__begin, __end, __parse_ctx);
+
+  switch (*__r.__ptr) {
+  case _CharT(':'):
+    // The arg-id has a format-specifier, advance the input to the format-spec.
+    __parse_ctx.advance_to(__r.__ptr + 1);
+    break;
+  case _CharT('}'):
+    // The arg-id has no format-specifier.
+    __parse_ctx.advance_to(__r.__ptr);
+    break;
+  default:
+    __throw_format_error(
+        "The replacement field arg-id should terminate at a ':' or '}'");
+  }
+
+  _VSTD::visit_format_arg(
+      [&](auto __arg) {
+        if constexpr (same_as<decltype(__arg), monostate>)
+          __throw_format_error("Argument index out of bounds");
+        else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Ctx>::handle>)
+          __arg.format(__parse_ctx, __ctx);
+        else {
+          formatter<decltype(__arg), _CharT> __formatter;
+          __parse_ctx.advance_to(__formatter.parse(__parse_ctx));
+          __ctx.advance_to(__formatter.format(__arg, __ctx));
+        }
+      },
+      __ctx.arg(__r.__value));
+
+  __begin = __parse_ctx.begin();
+  if (__begin == __end || *__begin != _CharT('}'))
+    __throw_format_error("The replacement field misses a terminating '}'");
+
+  return ++__begin;
+}
+
+template <class _ParseCtx, class _Ctx>
+_LIBCPP_HIDE_FROM_ABI typename _Ctx::iterator
+__vformat_to(_ParseCtx&& __parse_ctx, _Ctx&& __ctx) {
+  using _CharT = typename _ParseCtx::char_type;
+  static_assert(same_as<typename _Ctx::char_type, _CharT>);
+
+  const _CharT* __begin = __parse_ctx.begin();
+  const _CharT* __end = __parse_ctx.end();
+  typename _Ctx::iterator __out_it = __ctx.out();
+  while (__begin != __end) {
+    switch (*__begin) {
+    case _CharT('{'):
+      ++__begin;
+      if (__begin == __end)
+        __throw_format_error("The format string terminates at a '{'");
+
+      if (*__begin != _CharT('{')) [[likely]] {
+        __ctx.advance_to(_VSTD::move(__out_it));
+        __begin =
+            __handle_replacement_field(__begin, __end, __parse_ctx, __ctx);
+        __out_it = __ctx.out();
+
+        // The output is written and __begin points to the next character. So
+        // start the next iteration.
+        continue;
+      }
+      // The string is an escape character.
+      break;
+
+    case _CharT('}'):
+      ++__begin;
+      if (__begin == __end || *__begin != _CharT('}'))
+        __throw_format_error(
+            "The format string contains an invalid escape sequence");
+
+      break;
+    }
+
+    // Copy the character to the output verbatim.
+    *__out_it++ = *__begin++;
+  }
+  return __out_it;
+}
+
+} // namespace __format
+
+template <class _OutIt, class _CharT, class _FormatOutIt>
+requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
+    __vformat_to(
+        _OutIt __out_it, basic_string_view<_CharT> __fmt,
+        basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
+  if constexpr (same_as<_OutIt, _FormatOutIt>)
+    return _VSTD::__format::__vformat_to(
+        basic_format_parse_context{__fmt, __args.__size()},
+        _VSTD::__format_context_create(_VSTD::move(__out_it), __args));
+  else {
+    basic_string<_CharT> __str;
+    _VSTD::__format::__vformat_to(
+        basic_format_parse_context{__fmt, __args.__size()},
+        _VSTD::__format_context_create(_VSTD::back_inserter(__str), __args));
+    return _VSTD::copy_n(__str.begin(), __str.size(), _VSTD::move(__out_it));
+  }
+}
+
+template <output_iterator<const char&> _OutIt>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
+vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) {
+  return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args);
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <output_iterator<const wchar_t&> _OutIt>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
+vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
+  return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args);
+}
+#endif
+
+template <output_iterator<const char&> _OutIt, class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
+format_to(_OutIt __out_it, string_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt,
+                           _VSTD::make_format_args(__args...));
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <output_iterator<const wchar_t&> _OutIt, class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
+format_to(_OutIt __out_it, wstring_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt,
+                           _VSTD::make_wformat_args(__args...));
+}
+#endif
+
+_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
+vformat(string_view __fmt, format_args __args) {
+  string __res;
+  _VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args);
+  return __res;
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
+vformat(wstring_view __fmt, wformat_args __args) {
+  wstring __res;
+  _VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args);
+  return __res;
+}
+#endif
+
+template <class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
+format(string_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...));
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
+format(wstring_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...));
+}
+#endif
+
+template <output_iterator<const char&> _OutIt, class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
+format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, string_view __fmt,
+            const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  string __str = _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...));
+  iter_difference_t<_OutIt> __s = __str.size();
+  iter_difference_t<_OutIt> __m =
+      _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
+  __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
+  return {_VSTD::move(__out_it), __s};
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <output_iterator<const wchar_t&> _OutIt, class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
+format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wstring_view __fmt,
+            const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  wstring __str = _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...));
+  iter_difference_t<_OutIt> __s = __str.size();
+  iter_difference_t<_OutIt> __m =
+      _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
+  __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
+  return {_VSTD::move(__out_it), __s};
+}
+#endif
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
+formatted_size(string_view __fmt, const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  return _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...)).size();
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
+formatted_size(wstring_view __fmt, const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  return _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...)).size();
+}
+#endif
+
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+
+template <class _OutIt, class _CharT, class _FormatOutIt>
+requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
+    __vformat_to(
+        _OutIt __out_it, locale __loc, basic_string_view<_CharT> __fmt,
+        basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
+  if constexpr (same_as<_OutIt, _FormatOutIt>)
+    return _VSTD::__format::__vformat_to(
+        basic_format_parse_context{__fmt, __args.__size()},
+        _VSTD::__format_context_create(_VSTD::move(__out_it), __args,
+                                       _VSTD::move(__loc)));
+  else {
+    basic_string<_CharT> __str;
+    _VSTD::__format::__vformat_to(
+        basic_format_parse_context{__fmt, __args.__size()},
+        _VSTD::__format_context_create(_VSTD::back_inserter(__str), __args,
+                                       _VSTD::move(__loc)));
+    return _VSTD::copy_n(__str.begin(), __str.size(), _VSTD::move(__out_it));
+  }
+}
+
+template <output_iterator<const char&> _OutIt>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to(
+    _OutIt __out_it, locale __loc, string_view __fmt, format_args __args) {
+  return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
+                             __args);
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <output_iterator<const wchar_t&> _OutIt>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to(
+    _OutIt __out_it, locale __loc, wstring_view __fmt, wformat_args __args) {
+  return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
+                             __args);
+}
+#endif
+
+template <output_iterator<const char&> _OutIt, class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt format_to(
+    _OutIt __out_it, locale __loc, string_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
+                           _VSTD::make_format_args(__args...));
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <output_iterator<const wchar_t&> _OutIt, class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt format_to(
+    _OutIt __out_it, locale __loc, wstring_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
+                           _VSTD::make_wformat_args(__args...));
+}
+#endif
+
+_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
+vformat(locale __loc, string_view __fmt, format_args __args) {
+  string __res;
+  _VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt,
+                    __args);
+  return __res;
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
+vformat(locale __loc, wstring_view __fmt, wformat_args __args) {
+  wstring __res;
+  _VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt,
+                    __args);
+  return __res;
+}
+#endif
+
+template <class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
+format(locale __loc, string_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat(_VSTD::move(__loc), __fmt,
+                        _VSTD::make_format_args(__args...));
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <class... _Args>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
+format(locale __loc, wstring_view __fmt, const _Args&... __args) {
+  return _VSTD::vformat(_VSTD::move(__loc), __fmt,
+                        _VSTD::make_wformat_args(__args...));
+}
+#endif
+
+template <output_iterator<const char&> _OutIt, class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
+format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc,
+            string_view __fmt, const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  string __str = _VSTD::vformat(_VSTD::move(__loc), __fmt,
+                                _VSTD::make_format_args(__args...));
+  iter_difference_t<_OutIt> __s = __str.size();
+  iter_difference_t<_OutIt> __m =
+      _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
+  __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
+  return {_VSTD::move(__out_it), __s};
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <output_iterator<const wchar_t&> _OutIt, class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
+format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc,
+            wstring_view __fmt, const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  wstring __str = _VSTD::vformat(_VSTD::move(__loc), __fmt,
+                                 _VSTD::make_wformat_args(__args...));
+  iter_difference_t<_OutIt> __s = __str.size();
+  iter_difference_t<_OutIt> __m =
+      _VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
+  __out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
+  return {_VSTD::move(__out_it), __s};
+}
+#endif
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
+formatted_size(locale __loc, string_view __fmt, const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  return _VSTD::vformat(_VSTD::move(__loc), __fmt,
+                        _VSTD::make_format_args(__args...))
+      .size();
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
+formatted_size(locale __loc, wstring_view __fmt, const _Args&... __args) {
+  // TODO FMT Improve PoC: using std::string is inefficient.
+  return _VSTD::vformat(_VSTD::move(__loc), __fmt,
+                        _VSTD::make_wformat_args(__args...))
+      .size();
+}
+#endif
+
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
+
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 #endif //_LIBCPP_STD_VER > 17
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/forward_list
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------- forward_list ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -186,6 +186,7 @@ template <class T, class Allocator, class Predicate>
 #include <iterator>
 #include <limits>
 #include <memory>
+#include <type_traits>
 #include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -643,12 +644,12 @@ public:
     static_assert((is_same<typename allocator_type::value_type, value_type>::value),
                   "Allocator::value_type must be same type as value_type");
 
-    typedef value_type&                                                reference;
-    typedef const value_type&                                          const_reference;
-    typedef typename allocator_traits<allocator_type>::pointer         pointer;
-    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
-    typedef typename allocator_traits<allocator_type>::size_type       size_type;
-    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+    typedef value_type&                                                 reference;
+    typedef const value_type&                                           const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer          pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer    const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type        size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type  difference_type;
 
     typedef typename base::iterator       iterator;
     typedef typename base::const_iterator const_iterator;
@@ -669,7 +670,13 @@ public:
     explicit forward_list(size_type __n, const allocator_type& __a);
 #endif
     forward_list(size_type __n, const value_type& __v);
-    forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
+
+    template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
+    forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : base(__a)
+    {
+        insert_after(cbefore_begin(), __n, __v);
+    }
+
     template <class _InputIterator>
         forward_list(_InputIterator __f, _InputIterator __l,
                      typename enable_if<
@@ -870,17 +877,19 @@ private:
 };
 
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Alloc = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 forward_list(_InputIterator, _InputIterator)
   -> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
 
 template<class _InputIterator,
          class _Alloc,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 forward_list(_InputIterator, _InputIterator, _Alloc)
   -> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
@@ -941,14 +950,6 @@ forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
     insert_after(cbefore_begin(), __n, __v);
 }
 
-template <class _Tp, class _Alloc>
-forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
-                                        const allocator_type& __a)
-    : base(__a)
-{
-    insert_after(cbefore_begin(), __n, __v);
-}
-
 template <class _Tp, class _Alloc>
 template <class _InputIterator>
 forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
@@ -990,7 +991,7 @@ template <class _Tp, class _Alloc>
 forward_list<_Tp, _Alloc>&
 forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
 {
-    if (this != &__x)
+    if (this != _VSTD::addressof(__x))
     {
         base::__copy_assign_alloc(__x);
         assign(__x.begin(), __x.end());
@@ -1585,7 +1586,7 @@ template <class _Compare>
 void
 forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
 {
-    if (this != &__x)
+    if (this != _VSTD::addressof(__x))
     {
         base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
                                                     __x.__before_begin()->__next_,
lib/libcxx/include/fstream
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------- fstream ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -187,6 +187,7 @@ typedef basic_fstream<wchar_t> wfstream;
 #include <cstdlib>
 #include <istream>
 #include <ostream>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
 #   include <filesystem>
@@ -230,7 +231,6 @@ public:
     // 27.9.1.4 Members:
     _LIBCPP_INLINE_VISIBILITY
     bool is_open() const;
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
     basic_filebuf* open(const char* __s, ios_base::openmode __mode);
 #ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
     basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode);
@@ -246,7 +246,6 @@ public:
 #endif
     _LIBCPP_INLINE_VISIBILITY
     basic_filebuf* __open(int __fd, ios_base::openmode __mode);
-#endif
     basic_filebuf* close();
 
     _LIBCPP_INLINE_VISIBILITY
@@ -542,7 +541,6 @@ const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(
   _LIBCPP_UNREACHABLE();
 }
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
 basic_filebuf<_CharT, _Traits>*
 basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
@@ -685,7 +683,6 @@ basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mod
 {
     return open(__s.c_str(), __mode);
 }
-#endif
 
 template <class _CharT, class _Traits>
 basic_filebuf<_CharT, _Traits>*
@@ -1141,7 +1138,6 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY
     basic_ifstream();
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
     _LIBCPP_INLINE_VISIBILITY
     explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in);
 #ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
@@ -1155,7 +1151,6 @@ public:
     explicit basic_ifstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in)
       : basic_ifstream(__p.c_str(), __mode) {}
 #endif // _LIBCPP_STD_VER >= 17
-#endif
     _LIBCPP_INLINE_VISIBILITY
     basic_ifstream(basic_ifstream&& __rhs);
     _LIBCPP_INLINE_VISIBILITY
@@ -1167,7 +1162,6 @@ public:
     basic_filebuf<char_type, traits_type>* rdbuf() const;
     _LIBCPP_INLINE_VISIBILITY
     bool is_open() const;
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
     void open(const char* __s, ios_base::openmode __mode = ios_base::in);
 #ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
     void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
@@ -1183,7 +1177,6 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY
     void __open(int __fd, ios_base::openmode __mode);
-#endif
     _LIBCPP_INLINE_VISIBILITY
     void close();
 
@@ -1198,7 +1191,6 @@ basic_ifstream<_CharT, _Traits>::basic_ifstream()
 {
 }
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
 inline
 basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
@@ -1227,7 +1219,6 @@ basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::ope
     if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
         this->setstate(ios_base::failbit);
 }
-#endif
 
 template <class _CharT, class _Traits>
 inline
@@ -1281,7 +1272,6 @@ basic_ifstream<_CharT, _Traits>::is_open() const
     return __sb_.is_open();
 }
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
 void
 basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
@@ -1323,7 +1313,6 @@ void basic_ifstream<_CharT, _Traits>::__open(int __fd,
   else
     this->setstate(ios_base::failbit);
 }
-#endif
 
 template <class _CharT, class _Traits>
 inline
@@ -1375,7 +1364,6 @@ public:
     basic_filebuf<char_type, traits_type>* rdbuf() const;
     _LIBCPP_INLINE_VISIBILITY
     bool is_open() const;
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
     void open(const char* __s, ios_base::openmode __mode = ios_base::out);
 #ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
     void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
@@ -1390,7 +1378,6 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY
     void __open(int __fd, ios_base::openmode __mode);
-#endif
     _LIBCPP_INLINE_VISIBILITY
     void close();
 
@@ -1405,7 +1392,6 @@ basic_ofstream<_CharT, _Traits>::basic_ofstream()
 {
 }
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
 inline
 basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
@@ -1434,7 +1420,6 @@ basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::ope
     if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
         this->setstate(ios_base::failbit);
 }
-#endif
 
 template <class _CharT, class _Traits>
 inline
@@ -1488,7 +1473,6 @@ basic_ofstream<_CharT, _Traits>::is_open() const
     return __sb_.is_open();
 }
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
 void
 basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
@@ -1530,7 +1514,6 @@ void basic_ofstream<_CharT, _Traits>::__open(int __fd,
   else
     this->setstate(ios_base::failbit);
 }
-#endif
 
 template <class _CharT, class _Traits>
 inline
@@ -1556,7 +1539,6 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY
     basic_fstream();
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
     _LIBCPP_INLINE_VISIBILITY
     explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
 #ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
@@ -1572,7 +1554,6 @@ public:
       : basic_fstream(__p.c_str(), __mode) {}
 #endif // _LIBCPP_STD_VER >= 17
 
-#endif
     _LIBCPP_INLINE_VISIBILITY
     basic_fstream(basic_fstream&& __rhs);
 
@@ -1586,7 +1567,6 @@ public:
     basic_filebuf<char_type, traits_type>* rdbuf() const;
     _LIBCPP_INLINE_VISIBILITY
     bool is_open() const;
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
     void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
 #ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
     void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
@@ -1599,7 +1579,6 @@ public:
     { return open(__p.c_str(), __mode); }
 #endif // _LIBCPP_STD_VER >= 17
 
-#endif
     _LIBCPP_INLINE_VISIBILITY
     void close();
 
@@ -1614,7 +1593,6 @@ basic_fstream<_CharT, _Traits>::basic_fstream()
 {
 }
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
 inline
 basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
@@ -1643,7 +1621,6 @@ basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openm
     if (__sb_.open(__s, __mode) == nullptr)
         this->setstate(ios_base::failbit);
 }
-#endif
 
 template <class _CharT, class _Traits>
 inline
@@ -1697,7 +1674,6 @@ basic_fstream<_CharT, _Traits>::is_open() const
     return __sb_.is_open();
 }
 
-#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
 void
 basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
@@ -1729,7 +1705,6 @@ basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mod
     else
         this->setstate(ios_base::failbit);
 }
-#endif
 
 template <class _CharT, class _Traits>
 inline
lib/libcxx/include/functional
@@ -135,6 +135,9 @@ struct less_equal {
     bool operator()(const T& x, const T& y) const;
 };
 
+// [comparisons.three.way], class compare_three_way
+struct compare_three_way;
+
 template <class T> // <class T=void> in C++14
 struct logical_and {
     bool operator()(const T& x, const T& y) const;
@@ -488,14 +491,17 @@ POLICY:  For non-variadic implementations, the number of arguments is limited
 */
 
 #include <__algorithm/search.h>
+#include <__compare/compare_three_way.h>
 #include <__config>
 #include <__debug>
 #include <__functional/binary_function.h> // TODO: deprecate
 #include <__functional/binary_negate.h>
-#include <__functional/bind_front.h>
 #include <__functional/bind.h>
+#include <__functional/bind_back.h>
+#include <__functional/bind_front.h>
 #include <__functional/binder1st.h>
 #include <__functional/binder2nd.h>
+#include <__functional/compose.h>
 #include <__functional/default_searcher.h>
 #include <__functional/function.h>
 #include <__functional/hash.h>
lib/libcxx/include/future
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- future -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -366,7 +366,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #include <__debug>
 #include <__memory/allocator_arg_t.h>
 #include <__memory/uses_allocator.h>
-#include <__utility/__decay_copy.h>
+#include <__utility/auto_cast.h>
 #include <__utility/forward.h>
 #include <chrono>
 #include <exception>
@@ -374,6 +374,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #include <mutex>
 #include <system_error>
 #include <thread>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -2207,16 +2208,16 @@ async(launch __policy, _Fp&& __f, _Args&&... __args)
     {
 #endif
         if (__does_policy_contain(__policy, launch::async))
-        return _VSTD::__make_async_assoc_state<_Rp>(_BF(_VSTD::__decay_copy(_VSTD::forward<_Fp>(__f)),
-                                                     _VSTD::__decay_copy(_VSTD::forward<_Args>(__args))...));
+        return _VSTD::__make_async_assoc_state<_Rp>(_BF(_LIBCPP_AUTO_CAST(_VSTD::forward<_Fp>(__f)),
+                                                        _LIBCPP_AUTO_CAST(_VSTD::forward<_Args>(__args))...));
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch ( ... ) { if (__policy == launch::async) throw ; }
 #endif
 
     if (__does_policy_contain(__policy, launch::deferred))
-        return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(_VSTD::__decay_copy(_VSTD::forward<_Fp>(__f)),
-                                                        _VSTD::__decay_copy(_VSTD::forward<_Args>(__args))...));
+        return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(_LIBCPP_AUTO_CAST(_VSTD::forward<_Fp>(__f)),
+                                                           _LIBCPP_AUTO_CAST(_VSTD::forward<_Args>(__args))...));
     return future<_Rp>{};
 }
 
lib/libcxx/include/initializer_list
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------- initializer_list -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -112,6 +112,6 @@ end(initializer_list<_Ep> __il) _NOEXCEPT
 
 #endif // !defined(_LIBCPP_CXX03_LANG)
 
-}  // std
+} // namespace std
 
 #endif // _LIBCPP_INITIALIZER_LIST
lib/libcxx/include/inttypes.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- inttypes.h -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/iomanip
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- iomanip ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/ios
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- ios -------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -214,6 +214,7 @@ storage-class-specifier const error_category& iostream_category() noexcept;
 #include <__locale>
 #include <iosfwd>
 #include <system_error>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
 #include <atomic>     // for __xindex_
@@ -308,11 +309,9 @@ public:
     typedef void (*event_callback)(event, ios_base&, int __index);
     void register_callback(event_callback __fn, int __index);
 
-private:
-    ios_base(const ios_base&); // = delete;
-    ios_base& operator=(const ios_base&); // = delete;
+    ios_base(const ios_base&) = delete;
+    ios_base& operator=(const ios_base&) = delete;
 
-public:
     static bool sync_with_stdio(bool __sync = true);
 
     _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
lib/libcxx/include/iosfwd
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- iosfwd -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -95,7 +95,8 @@ using u32streampos = fpos<char_traits<char32_t>::state_type>;
 */
 
 #include <__config>
-#include <wchar.h>  // for mbstate_t
+#include <__mbstate_t.h>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -112,7 +113,9 @@ template<> struct char_traits<char8_t>;
 #endif
 template<> struct char_traits<char16_t>;
 template<> struct char_traits<char32_t>;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template<> struct char_traits<wchar_t>;
+#endif
 
 template<class _Tp>     class _LIBCPP_TEMPLATE_VIS allocator;
 
@@ -156,7 +159,9 @@ template <class _CharT, class _Traits = char_traits<_CharT> >
     class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator;
 
 typedef basic_ios<char>              ios;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 typedef basic_ios<wchar_t>           wios;
+#endif
 
 typedef basic_streambuf<char>        streambuf;
 typedef basic_istream<char>          istream;
@@ -173,6 +178,7 @@ typedef basic_ifstream<char>         ifstream;
 typedef basic_ofstream<char>         ofstream;
 typedef basic_fstream<char>          fstream;
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 typedef basic_streambuf<wchar_t>     wstreambuf;
 typedef basic_istream<wchar_t>       wistream;
 typedef basic_ostream<wchar_t>       wostream;
@@ -187,36 +193,37 @@ typedef basic_filebuf<wchar_t>       wfilebuf;
 typedef basic_ifstream<wchar_t>      wifstream;
 typedef basic_ofstream<wchar_t>      wofstream;
 typedef basic_fstream<wchar_t>       wfstream;
+#endif
 
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_PREFERRED_NAME(wios) basic_ios;
+    class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wios)) basic_ios;
 
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(streambuf) _LIBCPP_PREFERRED_NAME(wstreambuf) basic_streambuf;
+    class _LIBCPP_PREFERRED_NAME(streambuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstreambuf)) basic_streambuf;
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(istream) _LIBCPP_PREFERRED_NAME(wistream) basic_istream;
+    class _LIBCPP_PREFERRED_NAME(istream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistream)) basic_istream;
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(ostream) _LIBCPP_PREFERRED_NAME(wostream) basic_ostream;
+    class _LIBCPP_PREFERRED_NAME(ostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostream)) basic_ostream;
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(iostream) _LIBCPP_PREFERRED_NAME(wiostream) basic_iostream;
+    class _LIBCPP_PREFERRED_NAME(iostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wiostream)) basic_iostream;
 
 template <class _CharT, class _Traits, class _Allocator>
-    class _LIBCPP_PREFERRED_NAME(stringbuf) _LIBCPP_PREFERRED_NAME(wstringbuf) basic_stringbuf;
+    class _LIBCPP_PREFERRED_NAME(stringbuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringbuf)) basic_stringbuf;
 template <class _CharT, class _Traits, class _Allocator>
-    class _LIBCPP_PREFERRED_NAME(istringstream) _LIBCPP_PREFERRED_NAME(wistringstream) basic_istringstream;
+    class _LIBCPP_PREFERRED_NAME(istringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistringstream)) basic_istringstream;
 template <class _CharT, class _Traits, class _Allocator>
-    class _LIBCPP_PREFERRED_NAME(ostringstream) _LIBCPP_PREFERRED_NAME(wostringstream) basic_ostringstream;
+    class _LIBCPP_PREFERRED_NAME(ostringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostringstream)) basic_ostringstream;
 template <class _CharT, class _Traits, class _Allocator>
-    class _LIBCPP_PREFERRED_NAME(stringstream) _LIBCPP_PREFERRED_NAME(wstringstream) basic_stringstream;
+    class _LIBCPP_PREFERRED_NAME(stringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringstream)) basic_stringstream;
 
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(filebuf) _LIBCPP_PREFERRED_NAME(wfilebuf) basic_filebuf;
+    class _LIBCPP_PREFERRED_NAME(filebuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfilebuf)) basic_filebuf;
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(ifstream) _LIBCPP_PREFERRED_NAME(wifstream) basic_ifstream;
+    class _LIBCPP_PREFERRED_NAME(ifstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wifstream)) basic_ifstream;
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(ofstream) _LIBCPP_PREFERRED_NAME(wofstream) basic_ofstream;
+    class _LIBCPP_PREFERRED_NAME(ofstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wofstream)) basic_ofstream;
 template <class _CharT, class _Traits>
-    class _LIBCPP_PREFERRED_NAME(fstream) _LIBCPP_PREFERRED_NAME(wfstream) basic_fstream;
+    class _LIBCPP_PREFERRED_NAME(fstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfstream)) basic_fstream;
 
 template <class _State>             class _LIBCPP_TEMPLATE_VIS fpos;
 typedef fpos<mbstate_t>    streampos;
@@ -227,7 +234,7 @@ typedef fpos<mbstate_t>    u8streampos;
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
 typedef fpos<mbstate_t>    u16streampos;
 typedef fpos<mbstate_t>    u32streampos;
-#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
+#endif
 
 #if defined(_NEWLIB_VERSION)
 // On newlib, off_t is 'long int'
@@ -241,10 +248,12 @@ template <class _CharT,             // for <stdexcept>
           class _Allocator = allocator<_CharT> >
     class _LIBCPP_TEMPLATE_VIS basic_string;
 typedef basic_string<char, char_traits<char>, allocator<char> > string;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring;
+#endif
 
 template <class _CharT, class _Traits, class _Allocator>
-    class _LIBCPP_PREFERRED_NAME(string) _LIBCPP_PREFERRED_NAME(wstring) basic_string;
+    class _LIBCPP_PREFERRED_NAME(string) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring)) basic_string;
 
 // Include other forward declarations here
 template <class _Tp, class _Alloc = allocator<_Tp> >
lib/libcxx/include/iostream
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- iostream ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -38,6 +38,7 @@ extern wostream wclog;
 #include <istream>
 #include <ostream>
 #include <streambuf>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -45,18 +46,17 @@ extern wostream wclog;
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#ifndef _LIBCPP_HAS_NO_STDIN
 extern _LIBCPP_FUNC_VIS istream cin;
-extern _LIBCPP_FUNC_VIS wistream wcin;
-#endif
-#ifndef _LIBCPP_HAS_NO_STDOUT
 extern _LIBCPP_FUNC_VIS ostream cout;
-extern _LIBCPP_FUNC_VIS wostream wcout;
-#endif
 extern _LIBCPP_FUNC_VIS ostream cerr;
-extern _LIBCPP_FUNC_VIS wostream wcerr;
 extern _LIBCPP_FUNC_VIS ostream clog;
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+extern _LIBCPP_FUNC_VIS wistream wcin;
+extern _LIBCPP_FUNC_VIS wostream wcout;
+extern _LIBCPP_FUNC_VIS wostream wcerr;
 extern _LIBCPP_FUNC_VIS wostream wclog;
+#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/istream
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- istream ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -291,15 +291,15 @@ class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
 {
     bool __ok_;
 
-    sentry(const sentry&); // = delete;
-    sentry& operator=(const sentry&); // = delete;
-
 public:
     explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
 //    ~sentry() = default;
 
     _LIBCPP_INLINE_VISIBILITY
     explicit operator bool() const {return __ok_;}
+
+    sentry(const sentry&) = delete;
+    sentry& operator=(const sentry&) = delete;
 };
 
 template <class _CharT, class _Traits>
@@ -1628,7 +1628,9 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
 }
 
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
+#endif
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/iterator
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- iterator ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -140,6 +140,11 @@ template<class In, class Out>
 template<class I1, class I2 = I1>
   concept indirectly_swappable = see below;                // since C++20
 
+template<class I1, class I2, class R, class P1 = identity,
+         class P2 = identity>
+  concept indirectly_comparable =
+    indirect_binary_predicate<R, projected<I1, P1>, projected<I2, P2>>; // since C++20
+
 template<input_or_output_iterator I, sentinel_for<I> S>
   requires (!same_as<I, S> && copyable<I>)
 class common_iterator;                                     // since C++20
@@ -410,6 +415,10 @@ template<input_iterator I>
   requires see below
   struct iterator_traits<counted_iterator<I>>;
 
+// [unreachable.sentinel], unreachable sentinel
+struct unreachable_sentinel_t;
+inline constexpr unreachable_sentinel_t unreachable_sentinel{};
+
 template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
 class istream_iterator
     : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
@@ -589,23 +598,25 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
 #include <__iterator/erase_if_container.h>
 #include <__iterator/front_insert_iterator.h>
 #include <__iterator/incrementable_traits.h>
+#include <__iterator/indirectly_comparable.h>
 #include <__iterator/insert_iterator.h>
-#include <__iterator/istreambuf_iterator.h>
 #include <__iterator/istream_iterator.h>
-#include <__iterator/iterator.h>
-#include <__iterator/iterator_traits.h>
+#include <__iterator/istreambuf_iterator.h>
 #include <__iterator/iter_move.h>
 #include <__iterator/iter_swap.h>
+#include <__iterator/iterator.h>
+#include <__iterator/iterator_traits.h>
 #include <__iterator/move_iterator.h>
 #include <__iterator/next.h>
-#include <__iterator/ostreambuf_iterator.h>
 #include <__iterator/ostream_iterator.h>
+#include <__iterator/ostreambuf_iterator.h>
 #include <__iterator/prev.h>
 #include <__iterator/projected.h>
 #include <__iterator/readable_traits.h>
 #include <__iterator/reverse_access.h>
 #include <__iterator/reverse_iterator.h>
 #include <__iterator/size.h>
+#include <__iterator/unreachable_sentinel.h>
 #include <__iterator/wrap_iter.h>
 #include <__memory/addressof.h>
 #include <__memory/pointer_traits.h>
lib/libcxx/include/latch
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- latch -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -43,6 +43,7 @@ namespace std
 #include <__availability>
 #include <__config>
 #include <atomic>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/limits
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- limits ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/limits.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- limits.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/list
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- list ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -319,9 +319,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __list_iterator() _NOEXCEPT : __ptr_(nullptr)
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_i(this);
-#endif
+        _VSTD::__debug_db_insert_i(this);
     }
 
 #if _LIBCPP_DEBUG_LEVEL == 2
@@ -330,7 +328,7 @@ public:
     __list_iterator(const __list_iterator& __p)
         : __ptr_(__p.__ptr_)
     {
-        __get_db()->__iterator_copy(this, &__p);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -342,9 +340,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __list_iterator& operator=(const __list_iterator& __p)
     {
-        if (this != &__p)
+        if (this != _VSTD::addressof(__p))
         {
-            __get_db()->__iterator_copy(this, &__p);
+            __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
             __ptr_ = __p.__ptr_;
         }
         return *this;
@@ -355,29 +353,23 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     reference operator*() const
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to dereference a non-dereferenceable list::iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to dereference a non-dereferenceable list::iterator");
         return __ptr_->__as_node()->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
     pointer operator->() const
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to dereference a non-dereferenceable list::iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to dereference a non-dereferenceable list::iterator");
         return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
     }
 
     _LIBCPP_INLINE_VISIBILITY
     __list_iterator& operator++()
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to increment a non-incrementable list::iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to increment a non-incrementable list::iterator");
         __ptr_ = __ptr_->__next_;
         return *this;
     }
@@ -387,10 +379,8 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __list_iterator& operator--()
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
-                       "Attempted to decrement a non-decrementable list::iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
+                             "Attempted to decrement a non-decrementable list::iterator");
         __ptr_ = __ptr_->__prev_;
         return *this;
     }
@@ -439,16 +429,14 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_i(this);
-#endif
+        _VSTD::__debug_db_insert_i(this);
     }
     _LIBCPP_INLINE_VISIBILITY
     __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
         : __ptr_(__p.__ptr_)
     {
 #if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__iterator_copy(this, &__p);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
 #endif
     }
 
@@ -458,7 +446,7 @@ public:
     __list_const_iterator(const __list_const_iterator& __p)
         : __ptr_(__p.__ptr_)
     {
-        __get_db()->__iterator_copy(this, &__p);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -470,9 +458,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __list_const_iterator& operator=(const __list_const_iterator& __p)
     {
-        if (this != &__p)
+        if (this != _VSTD::addressof(__p))
         {
-            __get_db()->__iterator_copy(this, &__p);
+            __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
             __ptr_ = __p.__ptr_;
         }
         return *this;
@@ -482,29 +470,23 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     reference operator*() const
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to dereference a non-dereferenceable list::const_iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to dereference a non-dereferenceable list::const_iterator");
         return __ptr_->__as_node()->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
     pointer operator->() const
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to dereference a non-dereferenceable list::const_iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to dereference a non-dereferenceable list::const_iterator");
         return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
     }
 
     _LIBCPP_INLINE_VISIBILITY
     __list_const_iterator& operator++()
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
-                       "Attempted to increment a non-incrementable list::const_iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
+                             "Attempted to increment a non-incrementable list::const_iterator");
         __ptr_ = __ptr_->__next_;
         return *this;
     }
@@ -514,10 +496,8 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     __list_const_iterator& operator--()
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
-                       "Attempted to decrement a non-decrementable list::const_iterator");
-#endif
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__decrementable(this),
+                             "Attempted to decrement a non-decrementable list::const_iterator");
         __ptr_ = __ptr_->__prev_;
         return *this;
     }
@@ -797,7 +777,7 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
 #if _LIBCPP_DEBUG_LEVEL == 2
     __libcpp_db* __db = __get_db();
     __c_node* __cn1 = __db->__find_c_and_lock(this);
-    __c_node* __cn2 = __db->__find_c(&__c);
+    __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
     _VSTD::swap(__cn1->beg_, __cn2->beg_);
     _VSTD::swap(__cn1->end_, __cn2->end_);
     _VSTD::swap(__cn1->cap_, __cn2->cap_);
@@ -845,47 +825,50 @@ class _LIBCPP_TEMPLATE_VIS list
     typedef typename base::__link_pointer __link_pointer;
 
 public:
-    typedef _Tp                                      value_type;
-    typedef _Alloc                                   allocator_type;
+    typedef _Tp                                            value_type;
+    typedef _Alloc                                         allocator_type;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),
                   "Invalid allocator::value_type");
-    typedef value_type&                              reference;
-    typedef const value_type&                        const_reference;
-    typedef typename base::pointer                   pointer;
-    typedef typename base::const_pointer             const_pointer;
-    typedef typename base::size_type                 size_type;
-    typedef typename base::difference_type           difference_type;
-    typedef typename base::iterator                  iterator;
-    typedef typename base::const_iterator            const_iterator;
-    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
-    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
+    typedef value_type&                                    reference;
+    typedef const value_type&                              const_reference;
+    typedef typename base::pointer                         pointer;
+    typedef typename base::const_pointer                   const_pointer;
+    typedef typename base::size_type                       size_type;
+    typedef typename base::difference_type                 difference_type;
+    typedef typename base::iterator                        iterator;
+    typedef typename base::const_iterator                  const_iterator;
+    typedef _VSTD::reverse_iterator<iterator>              reverse_iterator;
+    typedef _VSTD::reverse_iterator<const_iterator>        const_reverse_iterator;
 #if _LIBCPP_STD_VER > 17
-    typedef size_type                                __remove_return_type;
+    typedef size_type                                      __remove_return_type;
 #else
-    typedef void                                     __remove_return_type;
+    typedef void                                           __remove_return_type;
 #endif
 
     _LIBCPP_INLINE_VISIBILITY
     list()
         _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_c(this);
-#endif
+        _VSTD::__debug_db_insert_c(this);
     }
     _LIBCPP_INLINE_VISIBILITY
     explicit list(const allocator_type& __a) : base(__a)
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_c(this);
-#endif
+        _VSTD::__debug_db_insert_c(this);
     }
     explicit list(size_type __n);
 #if _LIBCPP_STD_VER > 11
     explicit list(size_type __n, const allocator_type& __a);
 #endif
     list(size_type __n, const value_type& __x);
-    list(size_type __n, const value_type& __x, const allocator_type& __a);
+    template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
+    list(size_type __n, const value_type& __x, const allocator_type& __a) : base(__a)
+    {
+        _VSTD::__debug_db_insert_c(this);
+        for (; __n > 0; --__n)
+            push_back(__x);
+    }
+
     template <class _InpIter>
         list(_InpIter __f, _InpIter __l,
              typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
@@ -1141,17 +1124,19 @@ private:
     void __move_assign(list& __c, false_type);
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Alloc = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 list(_InputIterator, _InputIterator)
   -> list<__iter_value_type<_InputIterator>, _Alloc>;
 
 template<class _InputIterator,
          class _Alloc,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 list(_InputIterator, _InputIterator, _Alloc)
   -> list<__iter_value_type<_InputIterator>, _Alloc>;
@@ -1206,9 +1191,7 @@ list<_Tp, _Alloc>::__iterator(size_type __n)
 template <class _Tp, class _Alloc>
 list<_Tp, _Alloc>::list(size_type __n)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (; __n > 0; --__n)
 #ifndef _LIBCPP_CXX03_LANG
         emplace_back();
@@ -1221,9 +1204,7 @@ list<_Tp, _Alloc>::list(size_type __n)
 template <class _Tp, class _Alloc>
 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (; __n > 0; --__n)
         emplace_back();
 }
@@ -1232,20 +1213,7 @@ list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
 template <class _Tp, class _Alloc>
 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
-    for (; __n > 0; --__n)
-        push_back(__x);
-}
-
-template <class _Tp, class _Alloc>
-list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
-    : base(__a)
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (; __n > 0; --__n)
         push_back(__x);
 }
@@ -1255,9 +1223,7 @@ template <class _InpIter>
 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
                         typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (; __f != __l; ++__f)
         __emplace_back(*__f);
 }
@@ -1268,9 +1234,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
                         typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
     : base(__a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (; __f != __l; ++__f)
         __emplace_back(*__f);
 }
@@ -1279,9 +1243,7 @@ template <class _Tp, class _Alloc>
 list<_Tp, _Alloc>::list(const list& __c)
     : base(__node_alloc_traits::select_on_container_copy_construction(
           __c.__node_alloc())) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
         push_back(*__i);
 }
@@ -1290,9 +1252,7 @@ template <class _Tp, class _Alloc>
 list<_Tp, _Alloc>::list(const list& __c, const __identity_t<allocator_type>& __a)
     : base(__a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
         push_back(*__i);
 }
@@ -1303,9 +1263,7 @@ template <class _Tp, class _Alloc>
 list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
     : base(__a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
             __e = __il.end(); __i != __e; ++__i)
         push_back(*__i);
@@ -1314,9 +1272,7 @@ list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type&
 template <class _Tp, class _Alloc>
 list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
             __e = __il.end(); __i != __e; ++__i)
         push_back(*__i);
@@ -1324,11 +1280,9 @@ list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
 
 template <class _Tp, class _Alloc>
 inline list<_Tp, _Alloc>::list(list&& __c)
-    _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
-    : base(_VSTD::move(__c.__node_alloc())) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
+        : base(_VSTD::move(__c.__node_alloc())) {
+    _VSTD::__debug_db_insert_c(this);
     splice(end(), __c);
 }
 
@@ -1337,9 +1291,7 @@ inline
 list<_Tp, _Alloc>::list(list&& __c, const __identity_t<allocator_type>& __a)
     : base(__a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__a == __c.get_allocator())
         splice(end(), __c);
     else
@@ -1392,7 +1344,7 @@ inline
 list<_Tp, _Alloc>&
 list<_Tp, _Alloc>::operator=(const list& __c)
 {
-    if (this != &__c)
+    if (this != _VSTD::addressof(__c))
     {
         base::__copy_assign_alloc(__c);
         assign(__c.begin(), __c.end());
@@ -1408,7 +1360,7 @@ list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
 {
     iterator __i = begin();
     iterator __e = end();
-    for (; __f != __l && __i != __e; ++__f, ++__i)
+    for (; __f != __l && __i != __e; ++__f, (void) ++__i)
         *__i = *__f;
     if (__i == __e)
         insert(__e, __f, __l);
@@ -1425,7 +1377,7 @@ list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
 {
     iterator __i = begin();
     iterator __e = end();
-    for (; __n > 0 && __i != __e; --__n, ++__i)
+    for (; __n > 0 && __i != __e; --__n, (void) ++__i)
         *__i = __x;
     if (__i == __e)
         insert(__e, __n, __x);
@@ -1448,11 +1400,8 @@ template <class _Tp, class _Alloc>
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::insert(iterator, x) called with an iterator not"
-        " referring to this list");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "list::insert(iterator, x) called with an iterator not referring to this list");
     __node_allocator& __na = base::__node_alloc();
     __hold_pointer __hold = __allocate_node(__na);
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
@@ -1469,10 +1418,9 @@ template <class _Tp, class _Alloc>
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
 {
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "list::insert(iterator, n, x) called with an iterator not referring to this list");
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::insert(iterator, n, x) called with an iterator not"
-        " referring to this list");
     iterator __r(__p.__ptr_, this);
 #else
     iterator __r(__p.__ptr_);
@@ -1495,7 +1443,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
         try
         {
 #endif // _LIBCPP_NO_EXCEPTIONS
-            for (--__n; __n != 0; --__n, ++__e, ++__ds)
+            for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
             {
                 __hold.reset(__node_alloc_traits::allocate(__na, 1));
                 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
@@ -1535,10 +1483,9 @@ typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
              typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
 {
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "list::insert(iterator, range) called with an iterator not referring to this list");
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::insert(iterator, range) called with an iterator not"
-        " referring to this list");
     iterator __r(__p.__ptr_, this);
 #else
     iterator __r(__p.__ptr_);
@@ -1561,7 +1508,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
         try
         {
 #endif // _LIBCPP_NO_EXCEPTIONS
-            for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
+            for (++__f; __f != __l; ++__f, (void) ++__e, ++__ds)
             {
                 __hold.reset(__node_alloc_traits::allocate(__na, 1));
                 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
@@ -1694,11 +1641,8 @@ template <class... _Args>
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::emplace(iterator, args...) called with an iterator not"
-        " referring to this list");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "list::emplace(iterator, args...) called with an iterator not referring to this list");
     __node_allocator& __na = base::__node_alloc();
     __hold_pointer __hold = __allocate_node(__na);
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
@@ -1717,11 +1661,8 @@ template <class _Tp, class _Alloc>
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::insert(iterator, x) called with an iterator not"
-        " referring to this list");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "list::insert(iterator, x) called with an iterator not referring to this list");
     __node_allocator& __na = base::__node_alloc();
     __hold_pointer __hold = __allocate_node(__na);
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
@@ -1800,11 +1741,8 @@ template <class _Tp, class _Alloc>
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::erase(const_iterator __p)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::erase(iterator) called with an iterator not"
-        " referring to this list");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "list::erase(iterator) called with an iterator not referring to this list");
     _LIBCPP_ASSERT(__p != end(),
         "list::erase(iterator) called with a non-dereferenceable iterator");
     __node_allocator& __na = base::__node_alloc();
@@ -1841,14 +1779,10 @@ template <class _Tp, class _Alloc>
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
-        "list::erase(iterator, iterator) called with an iterator not"
-        " referring to this list");
-   _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
-        "list::erase(iterator, iterator) called with an iterator not"
-        " referring to this list");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == this,
+                         "list::erase(iterator, iterator) called with an iterator not referring to this list");
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == this,
+                         "list::erase(iterator, iterator) called with an iterator not referring to this list");
     if (__f != __l)
     {
         __node_allocator& __na = base::__node_alloc();
@@ -1909,7 +1843,7 @@ list<_Tp, _Alloc>::resize(size_type __n)
         try
         {
 #endif // _LIBCPP_NO_EXCEPTIONS
-            for (--__n; __n != 0; --__n, ++__e, ++__ds)
+            for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
             {
                 __hold.reset(__node_alloc_traits::allocate(__na, 1));
                 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
@@ -1967,7 +1901,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
         try
         {
 #endif // _LIBCPP_NO_EXCEPTIONS
-            for (--__n; __n != 0; --__n, ++__e, ++__ds)
+            for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
             {
                 __hold.reset(__node_alloc_traits::allocate(__na, 1));
                 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
@@ -2004,13 +1938,10 @@ template <class _Tp, class _Alloc>
 void
 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
 {
-    _LIBCPP_ASSERT(this != &__c,
+    _LIBCPP_ASSERT(this != _VSTD::addressof(__c),
                    "list::splice(iterator, list) called with this == &list");
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::splice(iterator, list) called with an iterator not"
-        " referring to this list");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                         "list::splice(iterator, list) called with an iterator not referring to this list");
     if (!__c.empty())
     {
         __link_pointer __f = __c.__end_.__next_;
@@ -2020,10 +1951,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
         base::__sz() += __c.__sz();
         __c.__sz() = 0;
 #if _LIBCPP_DEBUG_LEVEL == 2
-        if (&__c != this) {
+        if (_VSTD::addressof(__c) != this) {
             __libcpp_db* __db = __get_db();
             __c_node* __cn1 = __db->__find_c_and_lock(this);
-            __c_node* __cn2 = __db->__find_c(&__c);
+            __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
             for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
             {
                 --__ip;
@@ -2046,17 +1977,13 @@ template <class _Tp, class _Alloc>
 void
 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::splice(iterator, list, iterator) called with the first iterator"
-        " not referring to this list");
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
-        "list::splice(iterator, list, iterator) called with the second iterator"
-        " not referring to the list argument");
-    _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
-        "list::splice(iterator, list, iterator) called with the second iterator"
-        " not dereferenceable");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+        "list::splice(iterator, list, iterator) called with the first iterator not referring to this list");
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__i)) == _VSTD::addressof(__c),
+        "list::splice(iterator, list, iterator) called with the second iterator not referring to the list argument");
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(_VSTD::addressof(__i)),
+        "list::splice(iterator, list, iterator) called with the second iterator not dereferenceable");
+
     if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
     {
         __link_pointer __f = __i.__ptr_;
@@ -2065,10 +1992,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
         --__c.__sz();
         ++base::__sz();
 #if _LIBCPP_DEBUG_LEVEL == 2
-        if (&__c != this) {
+        if (_VSTD::addressof(__c) != this) {
             __libcpp_db* __db = __get_db();
             __c_node* __cn1 = __db->__find_c_and_lock(this);
-            __c_node* __cn2 = __db->__find_c(&__c);
+            __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
             for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
             {
                 --__ip;
@@ -2091,23 +2018,20 @@ template <class _Tp, class _Alloc>
 void
 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
 {
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+        "list::splice(iterator, list, iterator, iterator) called with first iterator not referring to this list");
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == _VSTD::addressof(__c),
+        "list::splice(iterator, list, iterator, iterator) called with second iterator not referring to the list argument");
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == _VSTD::addressof(__c),
+        "list::splice(iterator, list, iterator, iterator) called with third iterator not referring to the list argument");
+
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-        "list::splice(iterator, list, iterator, iterator) called with first iterator not"
-        " referring to this list");
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
-        "list::splice(iterator, list, iterator, iterator) called with second iterator not"
-        " referring to the list argument");
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == &__c,
-        "list::splice(iterator, list, iterator, iterator) called with third iterator not"
-        " referring to the list argument");
-    if (this == &__c)
+    if (this == _VSTD::addressof(__c))
     {
         for (const_iterator __i = __f; __i != __l; ++__i)
-            _LIBCPP_ASSERT(__i != __p,
-                           "list::splice(iterator, list, iterator, iterator)"
-                           " called with the first iterator within the range"
-                           " of the second and third iterators");
+            _LIBCPP_DEBUG_ASSERT(__i != __p,
+                "list::splice(iterator, list, iterator, iterator)"
+                " called with the first iterator within the range of the second and third iterators");
     }
 #endif
     if (__f != __l)
@@ -2115,7 +2039,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
         __link_pointer __first = __f.__ptr_;
         --__l;
         __link_pointer __last = __l.__ptr_;
-        if (this != &__c)
+        if (this != _VSTD::addressof(__c))
         {
             size_type __s = _VSTD::distance(__f, __l) + 1;
             __c.__sz() -= __s;
@@ -2124,10 +2048,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
         base::__unlink_nodes(__first, __last);
         __link_nodes(__p.__ptr_, __first, __last);
 #if _LIBCPP_DEBUG_LEVEL == 2
-        if (&__c != this) {
+        if (_VSTD::addressof(__c) != this) {
             __libcpp_db* __db = __get_db();
             __c_node* __cn1 = __db->__find_c_and_lock(this);
-            __c_node* __cn2 = __db->__find_c(&__c);
+            __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
             for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
             {
                 --__ip;
@@ -2244,7 +2168,7 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
             {
                 size_type __ds = 1;
                 iterator __m2 = _VSTD::next(__f2);
-                for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
+                for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, (void) ++__ds)
                     ;
                 base::__sz() += __ds;
                 __c.__sz() -= __ds;
@@ -2263,7 +2187,7 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
 #if _LIBCPP_DEBUG_LEVEL == 2
         __libcpp_db* __db = __get_db();
         __c_node* __cn1 = __db->__find_c_and_lock(this);
-        __c_node* __cn2 = __db->__find_c(&__c);
+        __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c));
         for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
         {
             --__p;
lib/libcxx/include/locale
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- locale ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -228,9 +228,9 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #  define _LIBCPP_GET_C_LOCALE 0
-#elif defined(__CloudABI__) || defined(__NetBSD__)
+#elif defined(__NetBSD__)
 #  define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
 #else
 #  define _LIBCPP_GET_C_LOCALE __cloc()
@@ -416,11 +416,11 @@ struct __num_get
                   unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
                   unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
 private:
-    template<typename T>
-    const T* __do_widen_p(ios_base& __iob, T* __atoms) const
+    template<typename _Tp>
+    const _Tp* __do_widen_p(ios_base& __iob, _Tp* __atoms) const
     {
       locale __loc = __iob.getloc();
-      use_facet<ctype<T> >(__loc).widen(__src, __src + 26, __atoms);
+      use_facet<ctype<_Tp> >(__loc).widen(__src, __src + 26, __atoms);
       return __atoms;
     }
 
@@ -573,7 +573,9 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>)
+#endif
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
 class _LIBCPP_TEMPLATE_VIS num_get
@@ -1111,7 +1113,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>)
+#endif
 
 struct _LIBCPP_TYPE_VIS __num_put_base
 {
@@ -1261,7 +1265,9 @@ __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>)
+#endif
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
 class _LIBCPP_TEMPLATE_VIS num_put
@@ -1354,6 +1360,18 @@ protected:
                              long double __v) const;
     virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
                              const void* __v) const;
+
+    template <class _Integral>
+    _LIBCPP_HIDE_FROM_ABI inline
+    _OutputIterator __do_put_integral(iter_type __s, ios_base& __iob,
+                                      char_type __fl, _Integral __v,
+                                      char const* __len) const;
+
+    template <class _Float>
+    _LIBCPP_HIDE_FROM_ABI inline
+    _OutputIterator __do_put_floating_point(iter_type __s, ios_base& __iob,
+                                            char_type __fl, _Float __v,
+                                            char const* __len) const;
 };
 
 template <class _CharT, class _OutputIterator>
@@ -1450,22 +1468,28 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
 }
 
 template <class _CharT, class _OutputIterator>
+template <class _Integral>
+_LIBCPP_HIDE_FROM_ABI inline
 _OutputIterator
-num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
-                                         char_type __fl, long __v) const
+num_put<_CharT, _OutputIterator>::__do_put_integral(iter_type __s, ios_base& __iob,
+                                                    char_type __fl, _Integral __v,
+                                                    char const* __len) const
 {
     // Stage 1 - Get number in narrow char
-    char __fmt[6] = {'%', 0};
-    const char* __len = "l";
-    this->__format_int(__fmt+1, __len, true, __iob.flags());
+    char __fmt[8] = {'%', 0};
+    this->__format_int(__fmt+1, __len, is_signed<_Integral>::value, __iob.flags());
     // Worst case is octal, with showbase enabled. Note that octal is always
     // printed as an unsigned value.
+    using _Unsigned = typename make_unsigned<_Integral>::type;
     _LIBCPP_CONSTEXPR const unsigned __nbuf
-        = (numeric_limits<unsigned long>::digits / 3)        // 1 char per 3 bits
-        + ((numeric_limits<unsigned long>::digits % 3) != 0) // round up
+        = (numeric_limits<_Unsigned>::digits / 3)        // 1 char per 3 bits
+        + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up
         + 2; // base prefix + terminating null character
     char __nar[__nbuf];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
     int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#pragma clang diagnostic pop
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1478,33 +1502,20 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
     return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
 }
 
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, long __v) const
+{
+    return this->__do_put_integral(__s, __iob, __fl, __v, "l");
+}
+
 template <class _CharT, class _OutputIterator>
 _OutputIterator
 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
                                          char_type __fl, long long __v) const
 {
-    // Stage 1 - Get number in narrow char
-    char __fmt[8] = {'%', 0};
-    const char* __len = "ll";
-    this->__format_int(__fmt+1, __len, true, __iob.flags());
-    // Worst case is octal, with showbase enabled. Note that octal is always
-    // printed as an unsigned value.
-    _LIBCPP_CONSTEXPR const unsigned __nbuf
-        = (numeric_limits<unsigned long long>::digits / 3)        // 1 char per 3 bits
-        + ((numeric_limits<unsigned long long>::digits % 3) != 0) // round up
-        + 2; // base prefix + terminating null character
-    char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
-    char* __ne = __nar + __nc;
-    char* __np = this->__identify_padding(__nar, __ne, __iob);
-    // Stage 2 - Widen __nar while adding thousands separators
-    char_type __o[2*(__nbuf-1) - 1];
-    char_type* __op;  // pad here
-    char_type* __oe;  // end of output
-    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
-    // [__o, __oe) contains thousands_sep'd wide number
-    // Stage 3 & 4
-    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+    return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
 }
 
 template <class _CharT, class _OutputIterator>
@@ -1512,27 +1523,7 @@ _OutputIterator
 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
                                          char_type __fl, unsigned long __v) const
 {
-    // Stage 1 - Get number in narrow char
-    char __fmt[6] = {'%', 0};
-    const char* __len = "l";
-    this->__format_int(__fmt+1, __len, false, __iob.flags());
-    // Worst case is octal, with showbase enabled.
-    _LIBCPP_CONSTEXPR const unsigned __nbuf
-        = (numeric_limits<unsigned long>::digits / 3)        // 1 char per 3 bits
-        + ((numeric_limits<unsigned long>::digits % 3) != 0) // round up
-        + 2; // base prefix + terminating null character
-    char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
-    char* __ne = __nar + __nc;
-    char* __np = this->__identify_padding(__nar, __ne, __iob);
-    // Stage 2 - Widen __nar while adding thousands separators
-    char_type __o[2*(__nbuf-1) - 1];
-    char_type* __op;  // pad here
-    char_type* __oe;  // end of output
-    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
-    // [__o, __oe) contains thousands_sep'd wide number
-    // Stage 3 & 4
-    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+    return this->__do_put_integral(__s, __iob, __fl, __v, "l");
 }
 
 template <class _CharT, class _OutputIterator>
@@ -1540,42 +1531,26 @@ _OutputIterator
 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
                                          char_type __fl, unsigned long long __v) const
 {
-    // Stage 1 - Get number in narrow char
-    char __fmt[8] = {'%', 0};
-    const char* __len = "ll";
-    this->__format_int(__fmt+1, __len, false, __iob.flags());
-    // Worst case is octal, with showbase enabled.
-    _LIBCPP_CONSTEXPR const unsigned __nbuf
-        = (numeric_limits<unsigned long long>::digits / 3)        // 1 char per 3 bits
-        + ((numeric_limits<unsigned long long>::digits % 3) != 0) // round up
-        + 2; // base prefix + terminating null character
-    char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
-    char* __ne = __nar + __nc;
-    char* __np = this->__identify_padding(__nar, __ne, __iob);
-    // Stage 2 - Widen __nar while adding thousands separators
-    char_type __o[2*(__nbuf-1) - 1];
-    char_type* __op;  // pad here
-    char_type* __oe;  // end of output
-    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
-    // [__o, __oe) contains thousands_sep'd wide number
-    // Stage 3 & 4
-    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+    return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
 }
 
 template <class _CharT, class _OutputIterator>
+template <class _Float>
+_LIBCPP_HIDE_FROM_ABI inline
 _OutputIterator
-num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
-                                         char_type __fl, double __v) const
+num_put<_CharT, _OutputIterator>::__do_put_floating_point(iter_type __s, ios_base& __iob,
+                                                          char_type __fl, _Float __v,
+                                                          char const* __len) const
 {
     // Stage 1 - Get number in narrow char
     char __fmt[8] = {'%', 0};
-    const char* __len = "";
     bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
     const unsigned __nbuf = 30;
     char __nar[__nbuf];
     char* __nb = __nar;
     int __nc;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
     if (__specify_precision)
         __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
                                    (int)__iob.precision(), __v);
@@ -1592,6 +1567,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
             __throw_bad_alloc();
         __nbh.reset(__nb);
     }
+#pragma clang diagnostic pop
     char* __ne = __nb + __nc;
     char* __np = this->__identify_padding(__nb, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1614,55 +1590,20 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
     return __s;
 }
 
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, double __v) const
+{
+    return this->__do_put_floating_point(__s, __iob, __fl, __v, "");
+}
+
 template <class _CharT, class _OutputIterator>
 _OutputIterator
 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
                                          char_type __fl, long double __v) const
 {
-    // Stage 1 - Get number in narrow char
-    char __fmt[8] = {'%', 0};
-    const char* __len = "L";
-    bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
-    const unsigned __nbuf = 30;
-    char __nar[__nbuf];
-    char* __nb = __nar;
-    int __nc;
-    if (__specify_precision)
-        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
-                                   (int)__iob.precision(), __v);
-    else
-        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
-    unique_ptr<char, void(*)(void*)> __nbh(nullptr, free);
-    if (__nc > static_cast<int>(__nbuf-1))
-    {
-        if (__specify_precision)
-            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
-        else
-            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
-        if (__nc == -1)
-            __throw_bad_alloc();
-        __nbh.reset(__nb);
-    }
-    char* __ne = __nb + __nc;
-    char* __np = this->__identify_padding(__nb, __ne, __iob);
-    // Stage 2 - Widen __nar while adding thousands separators
-    char_type __o[2*(__nbuf-1) - 1];
-    char_type* __ob = __o;
-    unique_ptr<char_type, void(*)(void*)> __obh(0, free);
-    if (__nb != __nar)
-    {
-        __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
-        if (__ob == 0)
-            __throw_bad_alloc();
-        __obh.reset(__ob);
-    }
-    char_type* __op;  // pad here
-    char_type* __oe;  // end of output
-    this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
-    // [__o, __oe) contains thousands_sep'd wide number
-    // Stage 3 & 4
-    __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
-    return __s;
+    return this->__do_put_floating_point(__s, __iob, __fl, __v, "L");
 }
 
 template <class _CharT, class _OutputIterator>
@@ -1671,10 +1612,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
                                          char_type __fl, const void* __v) const
 {
     // Stage 1 - Get pointer in narrow char
-    char __fmt[6] = "%p";
     const unsigned __nbuf = 20;
     char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, "%p", __v);
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar
@@ -1694,7 +1634,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>)
+#endif
 
 template <class _CharT, class _InputIterator>
 _LIBCPP_HIDDEN
@@ -1761,6 +1703,7 @@ template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__r() con
 template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__x() const;
 template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__X() const;
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
 template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__months() const;
 template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
@@ -1768,6 +1711,7 @@ template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__c()
 template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__r() const;
 template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__x() const;
 template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__X() const;
+#endif
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
 class _LIBCPP_TEMPLATE_VIS time_get
@@ -2380,7 +2324,9 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>)
+#endif
 
 class _LIBCPP_TYPE_VIS __time_get
 {
@@ -2480,7 +2426,9 @@ private:
 };
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>)
+#endif
 
 class _LIBCPP_TYPE_VIS __time_put
 {
@@ -2593,7 +2541,9 @@ time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>)
+#endif
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
 class _LIBCPP_TEMPLATE_VIS time_put_byname
@@ -2614,7 +2564,9 @@ protected:
 };
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>)
+#endif
 
 // money_base
 
@@ -2682,8 +2634,10 @@ moneypunct<_CharT, _International>::intl;
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>)
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>)
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>)
+#endif
 
 // moneypunct_byname
 
@@ -2734,13 +2688,15 @@ private:
 
 template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, false>::init(const char*);
 template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, true>::init(const char*);
-template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*);
-template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*);
-
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>)
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>)
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*);
+template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*);
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>)
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>)
+#endif
 
 // money_get
 
@@ -2797,7 +2753,9 @@ __money_get<_CharT>::__gather_info(bool __intl, const locale& __loc,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>)
+#endif
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
 class _LIBCPP_TEMPLATE_VIS money_get
@@ -2891,6 +2849,10 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
                                             unique_ptr<char_type, void(*)(void*)>& __wb,
                                             char_type*& __wn, char_type* __we)
 {
+    if (__b == __e) {
+        __err |= ios_base::failbit;
+        return false;
+    }
     const unsigned __bz = 100;
     unsigned __gbuf[__bz];
     unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing);
@@ -2935,51 +2897,31 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
             }
             break;
         case money_base::sign:
-            if (__psn.size() + __nsn.size() > 0)
+            if (__psn.size() > 0 && *__b == __psn[0])
             {
-                if (__psn.size() == 0 || __nsn.size() == 0)
-                {   // sign is optional
-                    if (__psn.size() > 0)
-                    {   // __nsn.size() == 0
-                        if (*__b == __psn[0])
-                        {
-                            ++__b;
-                            if (__psn.size() > 1)
-                                __trailing_sign = &__psn;
-                        }
-                        else
-                            __neg = true;
-                    }
-                    else if (*__b == __nsn[0])  // __nsn.size() > 0 &&  __psn.size() == 0
-                    {
-                        ++__b;
-                        __neg = true;
-                        if (__nsn.size() > 1)
-                            __trailing_sign = &__nsn;
-                    }
-                }
-                else  // sign is required
-                {
-                    if (*__b == __psn[0])
-                    {
-                        ++__b;
-                        if (__psn.size() > 1)
-                            __trailing_sign = &__psn;
-                    }
-                    else if (*__b == __nsn[0])
-                    {
-                        ++__b;
-                        __neg = true;
-                        if (__nsn.size() > 1)
-                            __trailing_sign = &__nsn;
-                    }
-                    else
-                    {
-                        __err |= ios_base::failbit;
-                        return false;
-                    }
-                }
+                ++__b;
+                __neg = false;
+                if (__psn.size() > 1)
+                  __trailing_sign = &__psn;
+                break;
+            }
+            if (__nsn.size() > 0 && *__b == __nsn[0])
+            {
+                ++__b;
+                __neg = true;
+                if (__nsn.size() > 1)
+                    __trailing_sign = &__nsn;
+                break;
             }
+            if (__psn.size() > 0 && __nsn.size() > 0)
+            {   // sign is required
+                __err |= ios_base::failbit;
+                return false;
+            }
+            if (__psn.size() == 0 && __nsn.size() == 0)
+                // locale has no way of specifying a sign. Use the initial value of __neg as a default
+                break;
+            __neg = (__nsn.size() == 0);
             break;
         case money_base::symbol:
             {
@@ -3180,7 +3122,9 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>)
+#endif
 
 // money_put
 
@@ -3355,7 +3299,9 @@ __money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __m
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>)
+#endif
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
 class _LIBCPP_TEMPLATE_VIS money_put
@@ -3508,7 +3454,9 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>)
+#endif
 
 // messages
 
@@ -3624,7 +3572,9 @@ messages<_CharT>::do_close(catalog __c) const
 }
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>)
+#endif
 
 template <class _CharT>
 class _LIBCPP_TEMPLATE_VIS messages_byname
@@ -3648,7 +3598,9 @@ protected:
 };
 
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>)
+#endif
 
 template<class _Codecvt, class _Elem = wchar_t,
          class _Wide_alloc = allocator<_Elem>,
lib/libcxx/include/locale.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- locale.h --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -36,7 +36,7 @@ Functions:
 #include <__config>
 
 #if defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#   error "Localization is not supported by this configuration of libc++"
+#   error "The Localization library is not supported since libc++ has been configured with LIBCXX_ENABLE_LOCALIZATION disabled"
 #endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/map
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------------- map ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -223,6 +223,25 @@ public:
         pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
 };
 
+template <class InputIterator,
+      class Compare = less<iter_key_t<InputIterator>>,
+      class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
+map(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
+  -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
+
+template<class Key, class T, class Compare = less<Key>,
+    class Allocator = allocator<pair<const Key, T>>>
+map(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
+  -> map<Key, T, Compare, Allocator>; // C++17
+
+template <class InputIterator, class Allocator>
+map(InputIterator, InputIterator, Allocator)
+  -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, less<iter_key_t<InputIterator>>,
+    Allocator>; // C++17
+
+template<class Key, class T, class Allocator>
+map(initializer_list<pair<const Key, T>>, Allocator) -> map<Key, T, less<Key>, Allocator>; // C++17
+
 template <class Key, class T, class Compare, class Allocator>
 bool
 operator==(const map<Key, T, Compare, Allocator>& x,
@@ -444,6 +463,26 @@ public:
         pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
 };
 
+template <class InputIterator,
+      class Compare = less<iter_key_t<InputIterator>>,
+      class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
+multimap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
+  -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
+
+template<class Key, class T, class Compare = less<Key>,
+    class Allocator = allocator<pair<const Key, T>>>
+multimap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
+  -> multimap<Key, T, Compare, Allocator>; // C++17
+
+template <class InputIterator, class Allocator>
+multimap(InputIterator, InputIterator, Allocator)
+  -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
+    less<iter_key_t<InputIterator>>, Allocator>; // C++17
+
+template<class Key, class T, class Allocator>
+multimap(initializer_list<pair<const Key, T>>, Allocator)
+  -> multimap<Key, T, less<Key>, Allocator>; // C++17
+
 template <class Key, class T, class Compare, class Allocator>
 bool
 operator==(const multimap<Key, T, Compare, Allocator>& x,
@@ -492,6 +531,7 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);  // C++20
 #include <__config>
 #include <__debug>
 #include <__functional/is_transparent.h>
+#include <__iterator/iterator_traits.h>
 #include <__node_handle>
 #include <__tree>
 #include <__utility/forward.h>
@@ -535,7 +575,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _CP& __y) const
         {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
-    void swap(__map_value_compare&__y)
+    void swap(__map_value_compare& __y)
         _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
     {
       using _VSTD::swap;
@@ -545,15 +585,13 @@ public:
 #if _LIBCPP_STD_VER > 11
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
-    typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
-    operator () ( const _K2& __x, const _CP& __y ) const
-        {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
+    bool operator()(const _K2& __x, const _CP& __y) const
+        {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
 
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
-    typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
-    operator () (const _CP& __x, const _K2& __y) const
-        {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
+    bool operator()(const _CP& __x, const _K2& __y) const
+        {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
 #endif
 };
 
@@ -583,7 +621,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _CP& __y) const
         {return comp(__x, __y.__get_value().first);}
-    void swap(__map_value_compare&__y)
+    void swap(__map_value_compare& __y)
         _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
     {
         using _VSTD::swap;
@@ -593,15 +631,13 @@ public:
 #if _LIBCPP_STD_VER > 11
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
-    typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
-    operator () ( const _K2& __x, const _CP& __y ) const
-        {return comp (__x, __y.__get_value().first);}
+    bool operator()(const _K2& __x, const _CP& __y) const
+        {return comp(__x, __y.__get_value().first);}
 
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
-    typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
-    operator () (const _CP& __x, const _K2& __y) const
-        {return comp (__x.__get_value().first, __y);}
+    bool operator()(const _CP& __x, const _K2& __y) const
+        {return comp(__x.__get_value().first, __y);}
 #endif
 };
 
@@ -747,10 +783,10 @@ public:
     }
 
 private:
-    __value_type() _LIBCPP_EQUAL_DELETE;
-    ~__value_type() _LIBCPP_EQUAL_DELETE;
-    __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
-    __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
+    __value_type() = delete;
+    ~__value_type() = delete;
+    __value_type(const __value_type&) = delete;
+    __value_type(__value_type&&) = delete;
 };
 
 #else
@@ -1040,7 +1076,7 @@ public:
 #ifndef _LIBCPP_CXX03_LANG
             __tree_ = __m.__tree_;
 #else
-            if (this != &__m) {
+            if (this != _VSTD::addressof(__m)) {
                 __tree_.clear();
                 __tree_.value_comp() = __m.__tree_.value_comp();
                 __tree_.__copy_assign_alloc(__m.__tree_);
@@ -1502,29 +1538,31 @@ private:
 #endif
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
          class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
   -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
 
 template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
          class _Allocator = allocator<pair<const _Key, _Tp>>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
   -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 map(_InputIterator, _InputIterator, _Allocator)
   -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
          less<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 map(initializer_list<pair<_Key, _Tp>>, _Allocator)
   -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
 #endif
@@ -1824,7 +1862,7 @@ public:
 #ifndef _LIBCPP_CXX03_LANG
             __tree_ = __m.__tree_;
 #else
-            if (this != &__m) {
+            if (this != _VSTD::addressof(__m)) {
                 __tree_.clear();
                 __tree_.value_comp() = __m.__tree_.value_comp();
                 __tree_.__copy_assign_alloc(__m.__tree_);
@@ -2175,29 +2213,31 @@ private:
     typedef unique_ptr<__node, _Dp> __node_holder;
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
          class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
   -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
 
 template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
          class _Allocator = allocator<pair<const _Key, _Tp>>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
   -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 multimap(_InputIterator, _InputIterator, _Allocator)
   -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
          less<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
   -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
 #endif
lib/libcxx/include/math.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- math.h ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -305,9 +305,9 @@ long double    truncl(long double x);
 // back to C++ linkage before including these C++ headers.
 extern "C++" {
 
+#include <limits>
 #include <stdlib.h>
 #include <type_traits>
-#include <limits>
 
 // signbit
 
@@ -831,7 +831,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long do
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -926,7 +926,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long dou
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1004,7 +1004,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long doub
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1158,7 +1158,7 @@ template <class _A1, class _A2>
 _LIBCPP_CONSTEXPR
 #endif
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1185,7 +1185,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __lcpp_x, long
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1242,7 +1242,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long dou
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1277,7 +1277,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long doub
 
 template <class _A1, class _A2, class _A3>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value &&
@@ -1304,7 +1304,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long dou
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1325,7 +1325,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long dou
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1346,7 +1346,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long do
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1553,7 +1553,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, lon
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1584,7 +1584,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, lon
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
@@ -1605,7 +1605,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long d
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::_EnableIf
+typename std::__enable_if_t
 <
     std::is_arithmetic<_A1>::value &&
     std::is_arithmetic<_A2>::value,
lib/libcxx/include/memory
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- memory ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -181,47 +181,190 @@ template <class InputIterator, class ForwardIterator>
 ForwardIterator
 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
 
+namespace ranges {
+
+template<class InputIterator, class OutputIterator>
+using uninitialized_copy_result = in_out_result<InputIterator, OutputIterator>; // since C++20
+
+template<input_iterator InputIterator, sentinel-for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel2>
+  requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>>
+uninitialized_copy_result<InputIterator, OutputIterator>
+uninitialized_copy(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20
+
+template<input_range InputRange, nothrow-forward-range OutputRange>
+  requires constructible_from<range_value_t<OutputRange>, range_reference_t<InputRange>>
+uninitialized_copy_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>>
+uninitialized_copy(InputRange&& in_range, OutputRange&& out_range); // since C++20
+
+}
+
 template <class InputIterator, class Size, class ForwardIterator>
 ForwardIterator
 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
 
+namespace ranges {
+
+template<class InputIterator, class OutputIterator>
+using uninitialized_copy_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20
+
+template<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel>
+  requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>>
+uninitialized_copy_n_result<InputIterator, OutputIterator>
+uninitialized_copy_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20
+
+}
+
 template <class ForwardIterator, class T>
 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
 
+namespace ranges {
+
+template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel, class T>
+  requires constructible_from<iter_value_t<ForwardIterator>, const T&>
+ForwardIterator uninitialized_fill(ForwardIterator first, Sentinel last, const T& x); // since C++20
+
+template <nothrow-forward-range ForwardRange, class T>
+  requires constructible_from<range_value_t<ForwardRange>, const T&>
+borrowed_iterator_t<ForwardRange> uninitialized_fill(ForwardRange&& range, const T& x); // since C++20
+
+}
+
 template <class ForwardIterator, class Size, class T>
 ForwardIterator
 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
 
+namespace ranges {
+
+template <nothrow-forward-iterator ForwardIterator, class T>
+  requires constructible_from<iter_value_t<ForwardIterator>, const T&>
+ForwardIterator uninitialized_fill_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
+
+}
+
 template <class T, class ...Args>
 constexpr T* construct_at(T* location, Args&& ...args); // since C++20
 
+namespace ranges {
+  template<class T, class... Args>
+    constexpr T* construct_at(T* location, Args&&... args); // since C++20
+}
+
 template <class T>
 void destroy_at(T* location); // constexpr in C++20
 
+namespace ranges {
+  template<destructible T>
+    constexpr void destroy_at(T* location) noexcept; // since C++20
+}
+
 template <class ForwardIterator>
 void destroy(ForwardIterator first, ForwardIterator last); // constexpr in C++20
 
+namespace ranges {
+  template<nothrow-input-iterator InputIterator, nothrow-sentinel-for<InputIterator> Sentinel>
+    requires destructible<iter_value_t<InputIterator>>
+    constexpr InputIterator destroy(InputIterator first, Sentinel last) noexcept; // since C++20
+  template<nothrow-input-range InputRange>
+    requires destructible<range_value_t<InputRange>>
+    constexpr borrowed_iterator_t<InputRange> destroy(InputRange&& range) noexcept; // since C++20
+}
+
 template <class ForwardIterator, class Size>
 ForwardIterator destroy_n(ForwardIterator first, Size n); // constexpr in C++20
 
+namespace ranges {
+  template<nothrow-input-iterator InputIterator>
+    requires destructible<iter_value_t<InputIterator>>
+    constexpr InputIterator destroy_n(InputIterator first, iter_difference_t<InputIterator> n) noexcept; // since C++20
+}
+
 template <class InputIterator, class ForwardIterator>
  ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
 
+namespace ranges {
+
+template<class InputIterator, class OutputIterator>
+using uninitialized_move_result = in_out_result<InputIterator, OutputIterator>; // since C++20
+
+template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<O> Sentinel2>
+  requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>>
+uninitialized_move_result<InputIterator, OutputIterator>
+uninitialized_move(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20
+
+template<input_range InputRange, nothrow-forward-range OutputRange>
+  requires constructible_from<range_value_t<OutputRange>, range_rvalue_reference_t<InputRange>>
+uninitialized_move_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>>
+uninitialized_move(InputRange&& in_range, OutputRange&& out_range); // since C++20
+
+}
+
 template <class InputIterator, class Size, class ForwardIterator>
  pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
 
+namespace ranges {
+
+template<class InputIterator, class OutputIterator>
+using uninitialized_move_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20
+
+template<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel>
+  requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>>
+uninitialized_move_n_result<InputIterator, OutputIterator>
+uninitialized_move_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20
+
+}
+
 template <class ForwardIterator>
  void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
 
+namespace ranges {
+
+template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel>
+  requires default_initializable<iter_value_t<ForwardIterator>>
+ ForwardIterator uninitialized_value_construct(ForwardIterator first, Sentinel last); // since C++20
+
+template <nothrow-forward-range ForwardRange>
+  requires default_initializable<range_value_t<ForwardRange>>
+ borrowed_iterator_t<ForwardRange> uninitialized_value_construct(ForwardRange&& r); // since C++20
+
+}
+
 template <class ForwardIterator, class Size>
  ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
 
+namespace ranges {
+
+template <nothrow-forward-iterator ForwardIterator>
+  requires default_initializable<iter_value_t<ForwardIterator>>
+ ForwardIterator uninitialized_value_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
+
+}
+
 template <class ForwardIterator>
  void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
 
+namespace ranges {
+
+template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel>
+  requires default_initializable<iter_value_t<ForwardIterator>>
+ ForwardIterator uninitialized_default_construct(ForwardIterator first, Sentinel last); // since C++20
+
+template <nothrow-forward-range ForwardRange>
+  requires default_initializable<range_value_t<ForwardRange>>
+ borrowed_iterator_t<ForwardRange> uninitialized_default_construct(ForwardRange&& r); // since C++20
+
+}
+
 template <class ForwardIterator, class Size>
  ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
 
+namespace ranges {
+
+template <nothrow-forward-iterator ForwardIterator>
+  requires default_initializable<iter_value_t<ForwardIterator>>
+ ForwardIterator uninitialized_default_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
+
+}
+
 template <class Y> struct auto_ptr_ref {};      // deprecated in C++11, removed in C++17
 
 template<class X>
@@ -405,7 +548,8 @@ template<class T>
 class shared_ptr
 {
 public:
-    typedef T element_type;
+    typedef T element_type; // until C++17
+    typedef remove_extent_t<T> element_type; // since C++17
     typedef weak_ptr<T> weak_type; // C++17
 
     // constructors:
@@ -525,7 +669,8 @@ template<class T>
 class weak_ptr
 {
 public:
-    typedef T element_type;
+    typedef T element_type; // until C++17
+    typedef remove_extent_t<T> element_type; // since C++17
 
     // constructors
     constexpr weak_ptr() noexcept;
@@ -653,14 +798,6 @@ template <class T> struct hash<shared_ptr<T> >;
 template <class T, class Alloc>
   inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
 
-// Pointer safety
-enum class pointer_safety { relaxed, preferred, strict }; // since C++11
-void declare_reachable(void *p);                          // since C++11
-template <class T> T *undeclare_reachable(T *p);          // since C++11
-void declare_no_pointers(char *p, size_t n);              // since C++11
-void undeclare_no_pointers(char *p, size_t n);            // since C++11
-pointer_safety get_pointer_safety() noexcept;             // since C++11
-
 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
 
 }  // std
@@ -675,9 +812,11 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
 #include <__memory/allocator_arg_t.h>
 #include <__memory/allocator_traits.h>
 #include <__memory/compressed_pair.h>
+#include <__memory/concepts.h>
 #include <__memory/construct_at.h>
-#include <__memory/pointer_safety.h>
 #include <__memory/pointer_traits.h>
+#include <__memory/ranges_construct_at.h>
+#include <__memory/ranges_uninitialized_algorithms.h>
 #include <__memory/raw_storage_iterator.h>
 #include <__memory/shared_ptr.h>
 #include <__memory/temporary_buffer.h>
@@ -706,10 +845,6 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Alloc, class _Ptr>
@@ -842,9 +977,9 @@ _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t&
 
 // --- Helper for container swap --
 template <typename _Alloc>
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
-#if _LIBCPP_STD_VER >= 14
+#if _LIBCPP_STD_VER > 11
     _NOEXCEPT
 #else
     _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
@@ -855,13 +990,13 @@ void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
 }
 
 template <typename _Alloc>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
 
 template <typename _Alloc>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
-#if _LIBCPP_STD_VER >= 14
+#if _LIBCPP_STD_VER > 11
     _NOEXCEPT
 #else
     _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
@@ -960,8 +1095,6 @@ struct __builtin_new_allocator {
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
 #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
 #   include <__pstl_memory>
 #endif
lib/libcxx/include/module.modulemap
@@ -2,7 +2,8 @@
 // since __config may be included from C headers which may create an
 // include cycle.
 module std_config [system] [extern_c] {
-    header "__config"
+  textual header "__config"
+  textual header "__config_site"
 }
 
 module std [system] {
@@ -246,6 +247,9 @@ module std [system] {
       module generate                 { private header "__algorithm/generate.h" }
       module generate_n               { private header "__algorithm/generate_n.h" }
       module half_positive            { private header "__algorithm/half_positive.h" }
+      module in_in_out_result         { private header "__algorithm/in_in_out_result.h" }
+      module in_in_result             { private header "__algorithm/in_in_result.h" }
+      module in_out_result            { private header "__algorithm/in_out_result.h" }
       module includes                 { private header "__algorithm/includes.h" }
       module inplace_merge            { private header "__algorithm/inplace_merge.h" }
       module is_heap                  { private header "__algorithm/is_heap.h" }
@@ -335,6 +339,11 @@ module std [system] {
   module bit {
     header "bit"
     export *
+
+    module __bit {
+      module bit_cast { private header "__bit/bit_cast.h" }
+      module byteswap { private header "__bit/byteswap.h" }
+    }
   }
   module bitset {
     header "bitset"
@@ -346,10 +355,28 @@ module std [system] {
   module charconv {
     header "charconv"
     export *
+
+    module __charconv {
+      module chars_format      { private header "__charconv/chars_format.h" }
+      module from_chars_result { private header "__charconv/from_chars_result.h" }
+      module to_chars_result   { private header "__charconv/to_chars_result.h" }
+    }
+
   }
   module chrono {
     header "chrono"
     export *
+
+    module __chrono {
+      module calendar              { private header "__chrono/calendar.h" }
+      module convert_to_timespec   { private header "__chrono/convert_to_timespec.h" }
+      module duration              { private header "__chrono/duration.h" }
+      module file_clock            { private header "__chrono/file_clock.h" }
+      module high_resolution_clock { private header "__chrono/high_resolution_clock.h" }
+      module steady_clock          { private header "__chrono/steady_clock.h" }
+      module system_clock          { private header "__chrono/system_clock.h" }
+      module time_point            { private header "__chrono/time_point.h" }
+    }
   }
   module codecvt {
     header "codecvt"
@@ -358,6 +385,22 @@ module std [system] {
   module compare {
     header "compare"
     export *
+
+    module __compare {
+      module common_comparison_category     { private header "__compare/common_comparison_category.h" }
+      module compare_partial_order_fallback { private header "__compare/compare_partial_order_fallback.h" }
+      module compare_strong_order_fallback  { private header "__compare/compare_strong_order_fallback.h" }
+      module compare_three_way              { private header "__compare/compare_three_way.h" }
+      module compare_three_way_result       { private header "__compare/compare_three_way_result.h" }
+      module compare_weak_order_fallback    { private header "__compare/compare_weak_order_fallback.h" }
+      module is_eq                          { private header "__compare/is_eq.h" }
+      module ordering                       { private header "__compare/ordering.h" }
+      module partial_order                  { private header "__compare/partial_order.h" }
+      module strong_order                   { private header "__compare/strong_order.h" }
+      module synth_three_way                { private header "__compare/synth_three_way.h" }
+      module three_way_comparable           { private header "__compare/three_way_comparable.h" }
+      module weak_order                     { private header "__compare/weak_order.h" }
+    }
   }
   module complex {
     header "complex"
@@ -366,11 +409,49 @@ module std [system] {
   module concepts {
     header "concepts"
     export *
+
+    module __concepts {
+      module arithmetic                 { private header "__concepts/arithmetic.h" }
+      module assignable                 { private header "__concepts/assignable.h" }
+      module boolean_testable           { private header "__concepts/boolean_testable.h" }
+      module class_or_enum              { private header "__concepts/class_or_enum.h" }
+      module common_reference_with      { private header "__concepts/common_reference_with.h" }
+      module common_with                { private header "__concepts/common_with.h" }
+      module constructible              { private header "__concepts/constructible.h" }
+      module convertible_to             { private header "__concepts/convertible_to.h" }
+      module copyable                   { private header "__concepts/copyable.h" }
+      module derived_from               { private header "__concepts/derived_from.h" }
+      module destructible               { private header "__concepts/destructible.h" }
+      module different_from             { private header "__concepts/different_from.h" }
+      module equality_comparable        { private header "__concepts/equality_comparable.h" }
+      module invocable                  { private header "__concepts/invocable.h" }
+      module movable                    { private header "__concepts/movable.h" }
+      module predicate                  { private header "__concepts/predicate.h" }
+      module regular                    { private header "__concepts/regular.h" }
+      module relation                   { private header "__concepts/relation.h" }
+      module same_as                    { private header "__concepts/same_as.h" }
+      module semiregular                { private header "__concepts/semiregular.h" }
+      module swappable                  { private header "__concepts/swappable.h" }
+      module totally_ordered            { private header "__concepts/totally_ordered.h" }
+    }
   }
   module condition_variable {
     header "condition_variable"
     export *
   }
+  module coroutine {
+    requires coroutines
+    header "coroutine"
+    export compare
+    export *
+
+    module __coroutine {
+      module coroutine_handle           { private header "__coroutine/coroutine_handle.h" }
+      module coroutine_traits           { private header "__coroutine/coroutine_traits.h" }
+      module noop_coroutine_handle      { private header "__coroutine/noop_coroutine_handle.h" }
+      module trivial_awaitables         { private header "__coroutine/trivial_awaitables.h" }
+    }
+  }
   module deque {
     header "deque"
     export initializer_list
@@ -387,14 +468,52 @@ module std [system] {
   module filesystem {
     header "filesystem"
     export *
+
+    module __filesystem {
+      module copy_options                 { private header "__filesystem/copy_options.h" }
+      module directory_entry              { private header "__filesystem/directory_entry.h" }
+      module directory_iterator           { private header "__filesystem/directory_iterator.h" }
+      module directory_options            { private header "__filesystem/directory_options.h" }
+      module file_status                  { private header "__filesystem/file_status.h" }
+      module file_time_type               { private header "__filesystem/file_time_type.h" }
+      module file_type                    { private header "__filesystem/file_type.h" }
+      module filesystem_error             { private header "__filesystem/filesystem_error.h" }
+      module operations                   { private header "__filesystem/operations.h" }
+      module path                         { private header "__filesystem/path.h" }
+      module path_iterator                { private header "__filesystem/path_iterator.h" }
+      module perm_options                 { private header "__filesystem/perm_options.h" }
+      module perms                        { private header "__filesystem/perms.h" }
+      module recursive_directory_iterator { private header "__filesystem/recursive_directory_iterator.h" }
+      module space_info                   { private header "__filesystem/space_info.h" }
+      module u8path                       { private header "__filesystem/u8path.h" }
+    }
   }
   module format {
     header "format"
     export *
 
     module __format {
-      module format_error         { private header "__format/format_error.h"         }
-      module format_parse_context { private header "__format/format_parse_context.h" }
+      module format_arg               { private header "__format/format_arg.h" }
+      module format_args              { private header "__format/format_args.h" }
+      module format_context {
+        private header "__format/format_context.h"
+        export optional
+        export locale
+      }
+      module format_error             { private header "__format/format_error.h" }
+      module format_fwd               { private header "__format/format_fwd.h" }
+      module format_parse_context     { private header "__format/format_parse_context.h" }
+      module format_string            { private header "__format/format_string.h" }
+      module format_to_n_result       { private header "__format/format_to_n_result.h" }
+      module formatter                { private header "__format/formatter.h" }
+      module formatter_bool           { private header "__format/formatter_bool.h" }
+      module formatter_char           { private header "__format/formatter_char.h" }
+      module formatter_floating_point { private header "__format/formatter_floating_point.h" }
+      module formatter_integer        { private header "__format/formatter_integer.h" }
+      module formatter_integral       { private header "__format/formatter_integral.h" }
+      module formatter_pointer        { private header "__format/formatter_pointer.h" }
+      module formatter_string         { private header "__format/formatter_string.h" }
+      module parser_std_format_spec   { private header "__format/parser_std_format_spec.h" }
     }
   }
   module forward_list {
@@ -414,17 +533,19 @@ module std [system] {
       module binary_function            { private header "__functional/binary_function.h" }
       module binary_negate              { private header "__functional/binary_negate.h" }
       module bind                       { private header "__functional/bind.h" }
+      module bind_back                  { private header "__functional/bind_back.h" }
       module bind_front                 { private header "__functional/bind_front.h" }
       module binder1st                  { private header "__functional/binder1st.h" }
       module binder2nd                  { private header "__functional/binder2nd.h" }
+      module compose                    { private header "__functional/compose.h" }
       module default_searcher           { private header "__functional/default_searcher.h" }
       module function                   { private header "__functional/function.h" }
       module hash                       { private header "__functional/hash.h" }
       module identity                   { private header "__functional/identity.h" }
-      module is_transparent             { private header "__functional/is_transparent.h" }
       module invoke                     { private header "__functional/invoke.h" }
-      module mem_fn                     { private header "__functional/mem_fn.h"  }
-      module mem_fun_ref                { private header "__functional/mem_fun_ref.h"  }
+      module is_transparent             { private header "__functional/is_transparent.h" }
+      module mem_fn                     { private header "__functional/mem_fn.h" }
+      module mem_fun_ref                { private header "__functional/mem_fun_ref.h" }
       module not_fn                     { private header "__functional/not_fn.h" }
       module operations                 { private header "__functional/operations.h" }
       module perfect_forward            { private header "__functional/perfect_forward.h" }
@@ -478,10 +599,7 @@ module std [system] {
 
     module __iterator {
       module access                { private header "__iterator/access.h" }
-      module advance               {
-        private header "__iterator/advance.h"
-        export __function_like
-      }
+      module advance               { private header "__iterator/advance.h" }
       module back_insert_iterator  { private header "__iterator/back_insert_iterator.h" }
       module common_iterator       { private header "__iterator/common_iterator.h" }
       module concepts              { private header "__iterator/concepts.h" }
@@ -493,6 +611,7 @@ module std [system] {
       module erase_if_container    { private header "__iterator/erase_if_container.h" }
       module front_insert_iterator { private header "__iterator/front_insert_iterator.h" }
       module incrementable_traits  { private header "__iterator/incrementable_traits.h" }
+      module indirectly_comparable { private header "__iterator/indirectly_comparable.h" }
       module insert_iterator       { private header "__iterator/insert_iterator.h" }
       module istream_iterator      { private header "__iterator/istream_iterator.h" }
       module istreambuf_iterator   { private header "__iterator/istreambuf_iterator.h" }
@@ -501,21 +620,16 @@ module std [system] {
       module iterator              { private header "__iterator/iterator.h" }
       module iterator_traits       { private header "__iterator/iterator_traits.h" }
       module move_iterator         { private header "__iterator/move_iterator.h" }
-      module next                  {
-        private header "__iterator/next.h"
-        export __function_like
-      }
+      module next                  { private header "__iterator/next.h" }
       module ostream_iterator      { private header "__iterator/ostream_iterator.h" }
       module ostreambuf_iterator   { private header "__iterator/ostreambuf_iterator.h" }
-      module prev                  {
-        private header "__iterator/prev.h"
-        export __function_like
-      }
+      module prev                  { private header "__iterator/prev.h" }
       module projected             { private header "__iterator/projected.h" }
       module readable_traits       { private header "__iterator/readable_traits.h" }
       module reverse_access        { private header "__iterator/reverse_access.h" }
       module reverse_iterator      { private header "__iterator/reverse_iterator.h" }
       module size                  { private header "__iterator/size.h" }
+      module unreachable_sentinel  { private header "__iterator/unreachable_sentinel.h" }
       module wrap_iter             { private header "__iterator/wrap_iter.h" }
     }
   }
@@ -547,22 +661,25 @@ module std [system] {
     export *
 
     module __memory {
-      module addressof                { private header "__memory/addressof.h"                }
-      module allocation_guard         { private header "__memory/allocation_guard.h"         }
-      module allocator                { private header "__memory/allocator.h"                }
-      module allocator_arg_t          { private header "__memory/allocator_arg_t.h"          }
-      module allocator_traits         { private header "__memory/allocator_traits.h"         }
-      module auto_ptr                 { private header "__memory/auto_ptr.h"                 }
-      module compressed_pair          { private header "__memory/compressed_pair.h"          }
-      module construct_at             { private header "__memory/construct_at.h"             }
-      module pointer_safety           { private header "__memory/pointer_safety.h"           }
-      module pointer_traits           { private header "__memory/pointer_traits.h"           }
-      module raw_storage_iterator     { private header "__memory/raw_storage_iterator.h"     }
-      module shared_ptr               { private header "__memory/shared_ptr.h"               }
-      module temporary_buffer         { private header "__memory/temporary_buffer.h"         }
-      module uninitialized_algorithms { private header "__memory/uninitialized_algorithms.h" }
-      module unique_ptr               { private header "__memory/unique_ptr.h"               }
-      module uses_allocator           { private header "__memory/uses_allocator.h"           }
+      module addressof                       { private header "__memory/addressof.h" }
+      module allocation_guard                { private header "__memory/allocation_guard.h" }
+      module allocator                       { private header "__memory/allocator.h" }
+      module allocator_arg_t                 { private header "__memory/allocator_arg_t.h" }
+      module allocator_traits                { private header "__memory/allocator_traits.h" }
+      module auto_ptr                        { private header "__memory/auto_ptr.h" }
+      module compressed_pair                 { private header "__memory/compressed_pair.h" }
+      module concepts                        { private header "__memory/concepts.h" }
+      module construct_at                    { private header "__memory/construct_at.h" }
+      module pointer_traits                  { private header "__memory/pointer_traits.h" }
+      module ranges_construct_at             { private header "__memory/ranges_construct_at.h" }
+      module ranges_uninitialized_algorithms { private header "__memory/ranges_uninitialized_algorithms.h" }
+      module raw_storage_iterator            { private header "__memory/raw_storage_iterator.h" }
+      module shared_ptr                      { private header "__memory/shared_ptr.h" }
+      module temporary_buffer                { private header "__memory/temporary_buffer.h" }
+      module uninitialized_algorithms        { private header "__memory/uninitialized_algorithms.h" }
+      module unique_ptr                      { private header "__memory/unique_ptr.h" }
+      module uses_allocator                  { private header "__memory/uses_allocator.h" }
+      module voidify                         { private header "__memory/voidify.h" }
     }
   }
   module mutex {
@@ -580,6 +697,22 @@ module std [system] {
   module numeric {
     header "numeric"
     export *
+
+    module __numeric {
+      module accumulate               { private header "__numeric/accumulate.h" }
+      module adjacent_difference      { private header "__numeric/adjacent_difference.h" }
+      module exclusive_scan           { private header "__numeric/exclusive_scan.h" }
+      module gcd_lcm                  { private header "__numeric/gcd_lcm.h" }
+      module inclusive_scan           { private header "__numeric/inclusive_scan.h" }
+      module inner_product            { private header "__numeric/inner_product.h" }
+      module iota                     { private header "__numeric/iota.h" }
+      module midpoint                 { private header "__numeric/midpoint.h" }
+      module partial_sum              { private header "__numeric/partial_sum.h" }
+      module reduce                   { private header "__numeric/reduce.h" }
+      module transform_exclusive_scan { private header "__numeric/transform_exclusive_scan.h" }
+      module transform_inclusive_scan { private header "__numeric/transform_inclusive_scan.h" }
+      module transform_reduce         { private header "__numeric/transform_reduce.h" }
+    }
   }
   module optional {
     header "optional"
@@ -601,7 +734,42 @@ module std [system] {
     export *
 
     module __random {
-      module uniform_int_distribution { private header "__random/uniform_int_distribution.h" }
+      module bernoulli_distribution          { private header "__random/bernoulli_distribution.h" }
+      module binomial_distribution           { private header "__random/binomial_distribution.h" }
+      module cauchy_distribution             { private header "__random/cauchy_distribution.h" }
+      module chi_squared_distribution        { private header "__random/chi_squared_distribution.h" }
+      module clamp_to_integral               { private header "__random/clamp_to_integral.h" }
+      module default_random_engine           { private header "__random/default_random_engine.h" }
+      module discard_block_engine            { private header "__random/discard_block_engine.h" }
+      module discrete_distribution           { private header "__random/discrete_distribution.h" }
+      module exponential_distribution        { private header "__random/exponential_distribution.h" }
+      module extreme_value_distribution      { private header "__random/extreme_value_distribution.h" }
+      module fisher_f_distribution           { private header "__random/fisher_f_distribution.h" }
+      module gamma_distribution              { private header "__random/gamma_distribution.h" }
+      module generate_canonical              { private header "__random/generate_canonical.h" }
+      module geometric_distribution          { private header "__random/geometric_distribution.h" }
+      module independent_bits_engine         { private header "__random/independent_bits_engine.h" }
+      module is_seed_sequence                { private header "__random/is_seed_sequence.h" }
+      module knuth_b                         { private header "__random/knuth_b.h" }
+      module linear_congruential_engine      { private header "__random/linear_congruential_engine.h" }
+      module log2                            { private header "__random/log2.h" }
+      module lognormal_distribution          { private header "__random/lognormal_distribution.h" }
+      module mersenne_twister_engine         { private header "__random/mersenne_twister_engine.h" }
+      module negative_binomial_distribution  { private header "__random/negative_binomial_distribution.h" }
+      module normal_distribution             { private header "__random/normal_distribution.h" }
+      module piecewise_constant_distribution { private header "__random/piecewise_constant_distribution.h" }
+      module piecewise_linear_distribution   { private header "__random/piecewise_linear_distribution.h" }
+      module poisson_distribution            { private header "__random/poisson_distribution.h" }
+      module random_device                   { private header "__random/random_device.h" }
+      module ranlux                          { private header "__random/ranlux.h" }
+      module seed_seq                        { private header "__random/seed_seq.h" }
+      module shuffle_order_engine            { private header "__random/shuffle_order_engine.h" }
+      module student_t_distribution          { private header "__random/student_t_distribution.h" }
+      module subtract_with_carry_engine      { private header "__random/subtract_with_carry_engine.h" }
+      module uniform_int_distribution        { private header "__random/uniform_int_distribution.h" }
+      module uniform_random_bit_generator    { private header "__random/uniform_random_bit_generator.h" }
+      module uniform_real_distribution       { private header "__random/uniform_real_distribution.h" }
+      module weibull_distribution            { private header "__random/weibull_distribution.h" }
     }
   }
   module ranges {
@@ -612,24 +780,44 @@ module std [system] {
     export *
 
     module __ranges {
-      module access                 { private header "__ranges/access.h"                }
-      module all                    { private header "__ranges/all.h"                   }
-      module common_view            { private header "__ranges/common_view.h"           }
-      module concepts               { private header "__ranges/concepts.h"              }
-      module copyable_box           { private header "__ranges/copyable_box.h"          }
-      module dangling               { private header "__ranges/dangling.h"              }
-      module data                   { private header "__ranges/data.h"                  }
-      module drop_view              { private header "__ranges/drop_view.h"             }
-      module empty                  { private header "__ranges/empty.h"                 }
-      module empty_view             { private header "__ranges/empty_view.h"            }
+      module access                 { private header "__ranges/access.h" }
+      module all                    {
+        private header "__ranges/all.h"
+        export functional.__functional.compose
+        export functional.__functional.perfect_forward
+      }
+      module common_view            { private header "__ranges/common_view.h" }
+      module concepts               { private header "__ranges/concepts.h" }
+      module copyable_box           { private header "__ranges/copyable_box.h" }
+      module counted                {
+        private header "__ranges/counted.h"
+        export span
+      }
+      module dangling               { private header "__ranges/dangling.h" }
+      module data                   { private header "__ranges/data.h" }
+      module drop_view              { private header "__ranges/drop_view.h" }
+      module empty                  { private header "__ranges/empty.h" }
+      module empty_view             { private header "__ranges/empty_view.h" }
       module enable_borrowed_range  { private header "__ranges/enable_borrowed_range.h" }
-      module enable_view            { private header "__ranges/enable_view.h"           }
+      module enable_view            { private header "__ranges/enable_view.h" }
+      module iota_view              { private header "__ranges/iota_view.h" }
+      module join_view              { private header "__ranges/join_view.h" }
       module non_propagating_cache  { private header "__ranges/non_propagating_cache.h" }
-      module ref_view               { private header "__ranges/ref_view.h"              }
-      module size                   { private header "__ranges/size.h"                  }
-      module subrange               { private header "__ranges/subrange.h"              }
-      module transform_view         { private header "__ranges/transform_view.h"        }
-      module view_interface         { private header "__ranges/view_interface.h"        }
+      module owning_view            { private header "__ranges/owning_view.h" }
+      module range_adaptor          { private header "__ranges/range_adaptor.h" }
+      module ref_view               { private header "__ranges/ref_view.h" }
+      module reverse_view           { private header "__ranges/reverse_view.h" }
+      module single_view            { private header "__ranges/single_view.h" }
+      module size                   { private header "__ranges/size.h" }
+      module subrange               { private header "__ranges/subrange.h" }
+      module take_view              { private header "__ranges/take_view.h" }
+      module transform_view         {
+        private header "__ranges/transform_view.h"
+        export functional.__functional.bind_back
+        export functional.__functional.perfect_forward
+      }
+      module view_interface         { private header "__ranges/view_interface.h" }
+      module views                  { private header "__ranges/views.h" }
     }
   }
   module ratio {
@@ -706,6 +894,11 @@ module std [system] {
   module thread {
     header "thread"
     export *
+
+    module __thread {
+      module poll_with_backoff    { private header "__thread/poll_with_backoff.h" }
+      module timed_backoff_policy { private header "__thread/timed_backoff_policy.h" }
+    }
   }
   module tuple {
     header "tuple"
@@ -740,20 +933,22 @@ module std [system] {
     export *
 
     module __utility {
-      module __decay_copy        { private header "__utility/__decay_copy.h"        }
-      module as_const            { private header "__utility/as_const.h"            }
-      module cmp                 { private header "__utility/cmp.h"                 }
-      module declval             { private header "__utility/declval.h"             }
-      module exchange            { private header "__utility/exchange.h"            }
-      module forward             { private header "__utility/forward.h"             }
-      module in_place            { private header "__utility/in_place.h"            }
-      module integer_sequence    { private header "__utility/integer_sequence.h"    }
-      module move                { private header "__utility/move.h"                }
-      module pair                { private header "__utility/pair.h"                }
+      module as_const            { private header "__utility/as_const.h" }
+      module auto_cast           { private header "__utility/auto_cast.h" }
+      module cmp                 { private header "__utility/cmp.h" }
+      module declval             { private header "__utility/declval.h" }
+      module exchange            { private header "__utility/exchange.h" }
+      module forward             { private header "__utility/forward.h" }
+      module in_place            { private header "__utility/in_place.h" }
+      module integer_sequence    { private header "__utility/integer_sequence.h" }
+      module move                { private header "__utility/move.h" }
+      module pair                { private header "__utility/pair.h" }
       module piecewise_construct { private header "__utility/piecewise_construct.h" }
-      module rel_ops             { private header "__utility/rel_ops.h"             }
-      module swap                { private header "__utility/swap.h"                }
-      module to_underlying       { private header "__utility/to_underlying.h"       }
+      module priority_tag        { private header "__utility/priority_tag.h" }
+      module rel_ops             { private header "__utility/rel_ops.h" }
+      module swap                { private header "__utility/swap.h" }
+      module to_underlying       { private header "__utility/to_underlying.h" }
+      module transaction         { private header "__utility/transaction.h" }
     }
   }
   module valarray {
@@ -784,21 +979,21 @@ module std [system] {
   module __availability      { private header "__availability"      export * }
   module __bit_reference     { private header "__bit_reference"     export * }
   module __bits              { private header "__bits"              export * }
-  module __debug             { header "__debug"             export * }
+  module __debug             {         header "__debug"             export * }
   module __errc              { private header "__errc"              export * }
-  module __function_like     { private header "__function_like.h"   export * }
-  module __hash_table        { header "__hash_table"        export * }
+  module __hash_table        {         header "__hash_table"        export * }
   module __locale            { private header "__locale"            export * }
+  module __mbstate_t         { private header "__mbstate_t.h"       export * }
   module __mutex_base        { private header "__mutex_base"        export * }
   module __node_handle       { private header "__node_handle"       export * }
-  module __nullptr           { header "__nullptr"           export * }
+  module __nullptr           {         header "__nullptr"           export * }
   module __split_buffer      { private header "__split_buffer"      export * }
   module __std_stream        { private header "__std_stream"        export * }
   module __string            { private header "__string"            export * }
-  module __threading_support { header "__threading_support" export * }
-  module __tree              { header "__tree"              export * }
+  module __threading_support {         header "__threading_support" export * }
+  module __tree              {         header "__tree"              export * }
   module __tuple             { private header "__tuple"             export * }
-  module __undef_macros      { header "__undef_macros"      export * }
+  module __undef_macros      {         header "__undef_macros"      export * }
 
   module experimental {
     requires cplusplus11
lib/libcxx/include/mutex
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- mutex ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -112,7 +112,7 @@ template <class... MutexTypes>
 class scoped_lock // C++17
 {
 public:
-    using mutex_type = Mutex;  // If MutexTypes... consists of the single type Mutex
+    using mutex_type = Mutex;  // Only if sizeof...(MutexTypes) == 1
 
     explicit scoped_lock(MutexTypes&... m);
     scoped_lock(adopt_lock_t, MutexTypes&... m);
@@ -215,14 +215,12 @@ class _LIBCPP_TYPE_VIS recursive_mutex
     __libcpp_recursive_mutex_t __m_;
 
 public:
-     recursive_mutex();
-     ~recursive_mutex();
+    recursive_mutex();
+    ~recursive_mutex();
 
-private:
-    recursive_mutex(const recursive_mutex&); // = delete;
-    recursive_mutex& operator=(const recursive_mutex&); // = delete;
+    recursive_mutex(const recursive_mutex&) = delete;
+    recursive_mutex& operator=(const recursive_mutex&) = delete;
 
-public:
     void lock();
     bool try_lock() _NOEXCEPT;
     void unlock()  _NOEXCEPT;
@@ -242,9 +240,8 @@ public:
      timed_mutex();
      ~timed_mutex();
 
-private:
-    timed_mutex(const timed_mutex&); // = delete;
-    timed_mutex& operator=(const timed_mutex&); // = delete;
+    timed_mutex(const timed_mutex&) = delete;
+    timed_mutex& operator=(const timed_mutex&) = delete;
 
 public:
     void lock();
@@ -283,14 +280,12 @@ class _LIBCPP_TYPE_VIS recursive_timed_mutex
     size_t             __count_;
     __thread_id        __id_;
 public:
-     recursive_timed_mutex();
-     ~recursive_timed_mutex();
+    recursive_timed_mutex();
+    ~recursive_timed_mutex();
 
-private:
-    recursive_timed_mutex(const recursive_timed_mutex&); // = delete;
-    recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete;
+    recursive_timed_mutex(const recursive_timed_mutex&) = delete;
+    recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
 
-public:
     void lock();
     bool try_lock() _NOEXCEPT;
     template <class _Rep, class _Period>
@@ -576,6 +571,8 @@ struct _LIBCPP_TEMPLATE_VIS once_flag
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR
         once_flag() _NOEXCEPT : __state_(0) {}
+    once_flag(const once_flag&) = delete;
+    once_flag& operator=(const once_flag&) = delete;
 
 #if defined(_LIBCPP_ABI_MICROSOFT)
    typedef uintptr_t _State_type;
@@ -583,11 +580,7 @@ struct _LIBCPP_TEMPLATE_VIS once_flag
    typedef unsigned long _State_type;
 #endif
 
-
 private:
-    once_flag(const once_flag&); // = delete;
-    once_flag& operator=(const once_flag&); // = delete;
-
     _State_type __state_;
 
 #ifndef _LIBCPP_CXX03_LANG
lib/libcxx/include/new
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===----------------------------- new ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -149,6 +149,16 @@ _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
 
 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc();  // not in C++ spec
 
+_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
+void __throw_bad_array_new_length()
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw bad_array_new_length();
+#else
+    _VSTD::abort();
+#endif
+}
+
 #if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \
     !defined(_LIBCPP_ABI_VCRUNTIME)
 #ifndef _LIBCPP_CXX03_LANG
@@ -164,10 +174,10 @@ enum align_val_t { __zero = 0, __max = (size_t)-1 };
 struct destroying_delete_t {
   explicit destroying_delete_t() = default;
 };
-_LIBCPP_INLINE_VAR constexpr destroying_delete_t destroying_delete{};
+inline constexpr destroying_delete_t destroying_delete{};
 #endif // _LIBCPP_STD_VER > 17
 
-}  // std
+} // namespace std
 
 #if defined(_LIBCPP_CXX03_LANG)
 #define _THROW_BAD_ALLOC throw(std::bad_alloc)
@@ -332,22 +342,17 @@ void __libcpp_aligned_free(void* __ptr) {
 
 
 template <class _Tp>
-_LIBCPP_NODISCARD_AFTER_CXX17 inline
+_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_HIDE_FROM_ABI
 _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT
 {
     static_assert (!(is_function<_Tp>::value), "can't launder functions" );
     static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" );
-#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
     return __builtin_launder(__p);
-#else
-    return __p;
-#endif
 }
 
-
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_HIDE_FROM_ABI
 constexpr _Tp* launder(_Tp* __p) noexcept
 {
     return _VSTD::__launder(__p);
lib/libcxx/include/numbers
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- numbers ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -63,55 +63,52 @@ namespace std::numbers {
 #include <type_traits>
 #include <version>
 
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace numbers {
 
-template <class T>
+template <class _Tp>
 inline constexpr bool __false = false;
 
-template <class T>
+template <class _Tp>
 struct __illformed
 {
-  static_assert(__false<T>, "A program that instantiates a primary template of a mathematical constant variable template is ill-formed.");
+  static_assert(__false<_Tp>, "A program that instantiates a primary template of a mathematical constant variable template is ill-formed.");
 };
 
-template <class T> inline constexpr T e_v =          __illformed<T>{};
-template <class T> inline constexpr T log2e_v =      __illformed<T>{};
-template <class T> inline constexpr T log10e_v =     __illformed<T>{};
-template <class T> inline constexpr T pi_v =         __illformed<T>{};
-template <class T> inline constexpr T inv_pi_v =     __illformed<T>{};
-template <class T> inline constexpr T inv_sqrtpi_v = __illformed<T>{};
-template <class T> inline constexpr T ln2_v =        __illformed<T>{};
-template <class T> inline constexpr T ln10_v =       __illformed<T>{};
-template <class T> inline constexpr T sqrt2_v =      __illformed<T>{};
-template <class T> inline constexpr T sqrt3_v =      __illformed<T>{};
-template <class T> inline constexpr T inv_sqrt3_v =  __illformed<T>{};
-template <class T> inline constexpr T egamma_v =     __illformed<T>{};
-template <class T> inline constexpr T phi_v =        __illformed<T>{};
-
-template <floating_point T> inline constexpr T e_v<T>          = 2.718281828459045235360287471352662;
-template <floating_point T> inline constexpr T log2e_v<T>      = 1.442695040888963407359924681001892;
-template <floating_point T> inline constexpr T log10e_v<T>     = 0.434294481903251827651128918916605;
-template <floating_point T> inline constexpr T pi_v<T>         = 3.141592653589793238462643383279502;
-template <floating_point T> inline constexpr T inv_pi_v<T>     = 0.318309886183790671537767526745028;
-template <floating_point T> inline constexpr T inv_sqrtpi_v<T> = 0.564189583547756286948079451560772;
-template <floating_point T> inline constexpr T ln2_v<T>        = 0.693147180559945309417232121458176;
-template <floating_point T> inline constexpr T ln10_v<T>       = 2.302585092994045684017991454684364;
-template <floating_point T> inline constexpr T sqrt2_v<T>      = 1.414213562373095048801688724209698;
-template <floating_point T> inline constexpr T sqrt3_v<T>      = 1.732050807568877293527446341505872;
-template <floating_point T> inline constexpr T inv_sqrt3_v<T>  = 0.577350269189625764509148780501957;
-template <floating_point T> inline constexpr T egamma_v<T>     = 0.577215664901532860606512090082402;
-template <floating_point T> inline constexpr T phi_v<T>        = 1.618033988749894848204586834365638;
+template <class _Tp> inline constexpr _Tp e_v =          __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp log2e_v =      __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp log10e_v =     __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp pi_v =         __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp inv_pi_v =     __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp inv_sqrtpi_v = __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp ln2_v =        __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp ln10_v =       __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp sqrt2_v =      __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp sqrt3_v =      __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp inv_sqrt3_v =  __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp egamma_v =     __illformed<_Tp>{};
+template <class _Tp> inline constexpr _Tp phi_v =        __illformed<_Tp>{};
+
+template <floating_point _Tp> inline constexpr _Tp e_v<_Tp>          = 2.718281828459045235360287471352662;
+template <floating_point _Tp> inline constexpr _Tp log2e_v<_Tp>      = 1.442695040888963407359924681001892;
+template <floating_point _Tp> inline constexpr _Tp log10e_v<_Tp>     = 0.434294481903251827651128918916605;
+template <floating_point _Tp> inline constexpr _Tp pi_v<_Tp>         = 3.141592653589793238462643383279502;
+template <floating_point _Tp> inline constexpr _Tp inv_pi_v<_Tp>     = 0.318309886183790671537767526745028;
+template <floating_point _Tp> inline constexpr _Tp inv_sqrtpi_v<_Tp> = 0.564189583547756286948079451560772;
+template <floating_point _Tp> inline constexpr _Tp ln2_v<_Tp>        = 0.693147180559945309417232121458176;
+template <floating_point _Tp> inline constexpr _Tp ln10_v<_Tp>       = 2.302585092994045684017991454684364;
+template <floating_point _Tp> inline constexpr _Tp sqrt2_v<_Tp>      = 1.414213562373095048801688724209698;
+template <floating_point _Tp> inline constexpr _Tp sqrt3_v<_Tp>      = 1.732050807568877293527446341505872;
+template <floating_point _Tp> inline constexpr _Tp inv_sqrt3_v<_Tp>  = 0.577350269189625764509148780501957;
+template <floating_point _Tp> inline constexpr _Tp egamma_v<_Tp>     = 0.577215664901532860606512090082402;
+template <floating_point _Tp> inline constexpr _Tp phi_v<_Tp>        = 1.618033988749894848204586834365638;
 
 inline constexpr double e          = e_v<double>;
 inline constexpr double log2e      = log2e_v<double>;
@@ -131,8 +128,6 @@ inline constexpr double phi        = phi_v<double>;
 
 _LIBCPP_END_NAMESPACE_STD
 
-_LIBCPP_POP_MACROS
-
-#endif //_LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#endif //!defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 #endif // _LIBCPP_NUMBERS
lib/libcxx/include/numeric
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- numeric ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -145,490 +145,29 @@ template<class T>
 */
 
 #include <__config>
-#include <__debug>
 #include <cmath> // for isnormal
 #include <functional>
 #include <iterator>
-#include <limits> // for numeric_limits
 #include <version>
 
+#include <__numeric/accumulate.h>
+#include <__numeric/adjacent_difference.h>
+#include <__numeric/exclusive_scan.h>
+#include <__numeric/gcd_lcm.h>
+#include <__numeric/inclusive_scan.h>
+#include <__numeric/inner_product.h>
+#include <__numeric/iota.h>
+#include <__numeric/midpoint.h>
+#include <__numeric/partial_sum.h>
+#include <__numeric/reduce.h>
+#include <__numeric/transform_exclusive_scan.h>
+#include <__numeric/transform_inclusive_scan.h>
+#include <__numeric/transform_reduce.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 _InputIterator, class _Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
-{
-    for (; __first != __last; ++__first)
-#if _LIBCPP_STD_VER > 17
-        __init = _VSTD::move(__init) + *__first;
-#else
-        __init = __init + *__first;
-#endif
-    return __init;
-}
-
-template <class _InputIterator, class _Tp, class _BinaryOperation>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
-{
-    for (; __first != __last; ++__first)
-#if _LIBCPP_STD_VER > 17
-        __init = __binary_op(_VSTD::move(__init), *__first);
-#else
-        __init = __binary_op(__init, *__first);
-#endif
-    return __init;
-}
-
-#if _LIBCPP_STD_VER > 14
-template <class _InputIterator, class _Tp, class _BinaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b)
-{
-    for (; __first != __last; ++__first)
-        __init = __b(__init, *__first);
-    return __init;
-}
-
-template <class _InputIterator, class _Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
-{
-    return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
-}
-
-template <class _InputIterator>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-typename iterator_traits<_InputIterator>::value_type
-reduce(_InputIterator __first, _InputIterator __last)
-{
-    return _VSTD::reduce(__first, __last,
-       typename iterator_traits<_InputIterator>::value_type{});
-}
-#endif
-
-template <class _InputIterator1, class _InputIterator2, class _Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
-{
-    for (; __first1 != __last1; ++__first1, (void) ++__first2)
-#if _LIBCPP_STD_VER > 17
-        __init = _VSTD::move(__init) + *__first1 * *__first2;
-#else
-        __init = __init + *__first1 * *__first2;
-#endif
-    return __init;
-}
-
-template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
-              _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
-{
-    for (; __first1 != __last1; ++__first1, (void) ++__first2)
-#if _LIBCPP_STD_VER > 17
-        __init = __binary_op1(_VSTD::move(__init), __binary_op2(*__first1, *__first2));
-#else
-        __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
-#endif
-    return __init;
-}
-
-#if _LIBCPP_STD_VER > 14
-template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-transform_reduce(_InputIterator __first, _InputIterator __last,
-           _Tp __init,  _BinaryOp __b, _UnaryOp __u)
-{
-    for (; __first != __last; ++__first)
-        __init = __b(__init, __u(*__first));
-    return __init;
-}
-
-template <class _InputIterator1, class _InputIterator2,
-          class _Tp, class _BinaryOp1, class _BinaryOp2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
-                 _InputIterator2 __first2, _Tp __init,  _BinaryOp1 __b1, _BinaryOp2 __b2)
-{
-    for (; __first1 != __last1; ++__first1, (void) ++__first2)
-        __init = __b1(__init, __b2(*__first1, *__first2));
-    return __init;
-}
-
-template <class _InputIterator1, class _InputIterator2, class _Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_Tp
-transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
-                 _InputIterator2 __first2, _Tp __init)
-{
-    return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init),
-                                   _VSTD::plus<>(), _VSTD::multiplies<>());
-}
-#endif
-
-template <class _InputIterator, class _OutputIterator>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
-{
-    if (__first != __last)
-    {
-        typename iterator_traits<_InputIterator>::value_type __t(*__first);
-        *__result = __t;
-        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
-        {
-#if _LIBCPP_STD_VER > 17
-            __t = _VSTD::move(__t) + *__first;
-#else
-            __t = __t + *__first;
-#endif
-            *__result = __t;
-        }
-    }
-    return __result;
-}
-
-template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
-              _BinaryOperation __binary_op)
-{
-    if (__first != __last)
-    {
-        typename iterator_traits<_InputIterator>::value_type __t(*__first);
-        *__result = __t;
-        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
-        {
-#if _LIBCPP_STD_VER > 17
-            __t = __binary_op(_VSTD::move(__t), *__first);
-#else
-            __t = __binary_op(__t, *__first);
-#endif
-            *__result = __t;
-        }
-    }
-    return __result;
-}
-
-#if _LIBCPP_STD_VER > 14
-template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-exclusive_scan(_InputIterator __first, _InputIterator __last,
-               _OutputIterator __result, _Tp __init, _BinaryOp __b)
-{
-    if (__first != __last)
-    {
-        _Tp __tmp(__b(__init, *__first));
-        while (true)
-        {
-            *__result = _VSTD::move(__init);
-            ++__result;
-            ++__first;
-            if (__first == __last)
-                break;
-            __init = _VSTD::move(__tmp);
-            __tmp = __b(__init, *__first);
-        }
-    }
-    return __result;
-}
-
-template <class _InputIterator, class _OutputIterator, class _Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-exclusive_scan(_InputIterator __first, _InputIterator __last,
-               _OutputIterator __result, _Tp __init)
-{
-    return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
-}
-
-template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
-                               _OutputIterator __result, _BinaryOp __b,  _Tp __init)
-{
-    for (; __first != __last; ++__first, (void) ++__result) {
-        __init = __b(__init, *__first);
-        *__result = __init;
-    }
-    return __result;
-}
-
-template <class _InputIterator, class _OutputIterator, class _BinaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
-                               _OutputIterator __result, _BinaryOp __b)
-{
-    if (__first != __last) {
-        typename iterator_traits<_InputIterator>::value_type __init = *__first;
-        *__result++ = __init;
-        if (++__first != __last)
-            return _VSTD::inclusive_scan(__first, __last, __result, __b, __init);
-    }
-
-    return __result;
-}
-
-template <class _InputIterator, class _OutputIterator>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
-                               _OutputIterator __result)
-{
-    return _VSTD::inclusive_scan(__first, __last, __result, _VSTD::plus<>());
-}
-
-template <class _InputIterator, class _OutputIterator, class _Tp,
-          class _BinaryOp, class _UnaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
-                           _OutputIterator __result, _Tp __init,
-                           _BinaryOp __b, _UnaryOp __u)
-{
-    if (__first != __last)
-    {
-        _Tp __saved = __init;
-        do
-        {
-            __init = __b(__init, __u(*__first));
-            *__result = __saved;
-            __saved = __init;
-            ++__result;
-        } while (++__first != __last);
-    }
-    return __result;
-}
-
-template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
-                           _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init)
-{
-    for (; __first != __last; ++__first, (void) ++__result) {
-        __init = __b(__init, __u(*__first));
-        *__result = __init;
-        }
-
-    return __result;
-}
-
-template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
-                               _OutputIterator __result, _BinaryOp __b, _UnaryOp __u)
-{
-    if (__first != __last) {
-        typename iterator_traits<_InputIterator>::value_type __init = __u(*__first);
-        *__result++ = __init;
-        if (++__first != __last)
-            return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init);
-    }
-
-    return __result;
-}
-#endif
-
-template <class _InputIterator, class _OutputIterator>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
-{
-    if (__first != __last)
-    {
-        typename iterator_traits<_InputIterator>::value_type __acc(*__first);
-        *__result = __acc;
-        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
-        {
-            typename iterator_traits<_InputIterator>::value_type __val(*__first);
-#if _LIBCPP_STD_VER > 17
-            *__result = __val - _VSTD::move(__acc);
-#else
-            *__result = __val - __acc;
-#endif
-            __acc = _VSTD::move(__val);
-        }
-    }
-    return __result;
-}
-
-template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_OutputIterator
-adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
-                      _BinaryOperation __binary_op)
-{
-    if (__first != __last)
-    {
-        typename iterator_traits<_InputIterator>::value_type __acc(*__first);
-        *__result = __acc;
-        for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
-        {
-            typename iterator_traits<_InputIterator>::value_type __val(*__first);
-#if _LIBCPP_STD_VER > 17
-            *__result = __binary_op(__val, _VSTD::move(__acc));
-#else
-            *__result = __binary_op(__val, __acc);
-#endif
-            __acc = _VSTD::move(__val);
-        }
-    }
-    return __result;
-}
-
-template <class _ForwardIterator, class _Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-void
-iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
-{
-    for (; __first != __last; ++__first, (void) ++__value_)
-        *__first = __value_;
-}
-
-
-#if _LIBCPP_STD_VER > 14
-template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __ct_abs;
-
-template <typename _Result, typename _Source>
-struct __ct_abs<_Result, _Source, true> {
-    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-    _Result operator()(_Source __t) const noexcept
-    {
-        if (__t >= 0) return __t;
-        if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t);
-        return -__t;
-    }
-};
-
-template <typename _Result, typename _Source>
-struct __ct_abs<_Result, _Source, false> {
-    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-    _Result operator()(_Source __t) const noexcept { return __t; }
-};
-
-
-template<class _Tp>
-_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
-_Tp __gcd(_Tp __m, _Tp __n)
-{
-    static_assert((!is_signed<_Tp>::value), "");
-    return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n);
-}
-
-
-template<class _Tp, class _Up>
-_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-common_type_t<_Tp,_Up>
-gcd(_Tp __m, _Up __n)
-{
-    static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types");
-    static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" );
-    static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
-    using _Rp = common_type_t<_Tp,_Up>;
-    using _Wp = make_unsigned_t<_Rp>;
-    return static_cast<_Rp>(_VSTD::__gcd(
-        static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)),
-        static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n))));
-}
-
-template<class _Tp, class _Up>
-_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-common_type_t<_Tp,_Up>
-lcm(_Tp __m, _Up __n)
-{
-    static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types");
-    static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" );
-    static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" );
-    if (__m == 0 || __n == 0)
-        return 0;
-
-    using _Rp = common_type_t<_Tp,_Up>;
-    _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n);
-    _Rp __val2 = __ct_abs<_Rp, _Up>()(__n);
-    _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm");
-    return __val1 * __val2;
-}
-
-#endif /* _LIBCPP_STD_VER > 14 */
-
-#if _LIBCPP_STD_VER > 17
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY constexpr
-enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp>
-midpoint(_Tp __a, _Tp __b) noexcept
-_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
-{
-    using _Up = make_unsigned_t<_Tp>;
-    constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1;
-
-    _Up __diff = _Up(__b) - _Up(__a);
-    _Up __sign_bit = __b < __a;
-
-    _Up __half_diff = (__diff / 2) + (__sign_bit << __bitshift) + (__sign_bit & __diff);
-
-    return __a + __half_diff;
-}
-
-
-template <class _TPtr>
-_LIBCPP_INLINE_VISIBILITY constexpr
-enable_if_t<is_pointer_v<_TPtr>
-             && is_object_v<remove_pointer_t<_TPtr>>
-             && ! is_void_v<remove_pointer_t<_TPtr>>
-             && (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr>
-midpoint(_TPtr __a, _TPtr __b) noexcept
-{
-    return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a);
-}
-
-
-template <typename _Tp>
-constexpr int __sign(_Tp __val) {
-    return (_Tp(0) < __val) - (__val < _Tp(0));
-}
-
-template <typename _Fp>
-constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; }
-
-template <class _Fp>
-_LIBCPP_INLINE_VISIBILITY constexpr
-enable_if_t<is_floating_point_v<_Fp>, _Fp>
-midpoint(_Fp __a, _Fp __b) noexcept
-{
-    constexpr _Fp __lo = numeric_limits<_Fp>::min()*2;
-    constexpr _Fp __hi = numeric_limits<_Fp>::max()/2;
-    return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ?  // typical case: overflow is impossible
-      (__a + __b)/2 :                                        // always correctly rounded
-      __fp_abs(__a) < __lo ? __a + __b/2 :                   // not safe to halve a
-      __fp_abs(__b) < __lo ? __a/2 + __b :                   // not safe to halve b
-      __a/2 + __b/2;                                         // otherwise correctly rounded
-}
-
-#endif // _LIBCPP_STD_VER > 17
-
-_LIBCPP_END_NAMESPACE_STD
-
-_LIBCPP_POP_MACROS
-
 #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
 #   include <__pstl_numeric>
 #endif
lib/libcxx/include/optional
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- optional ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -132,6 +132,18 @@ namespace std {
     template <class U> constexpr T value_or(U &&) const &;
     template <class U> constexpr T value_or(U &&) &&;
 
+    // [optional.monadic], monadic operations
+    template<class F> constexpr auto and_then(F&& f) &;         // since C++23
+    template<class F> constexpr auto and_then(F&& f) &&;        // since C++23
+    template<class F> constexpr auto and_then(F&& f) const&;    // since C++23
+    template<class F> constexpr auto and_then(F&& f) const&&;   // since C++23
+    template<class F> constexpr auto transform(F&& f) &;        // since C++23
+    template<class F> constexpr auto transform(F&& f) &&;       // since C++23
+    template<class F> constexpr auto transform(F&& f) const&;   // since C++23
+    template<class F> constexpr auto transform(F&& f) const&&;  // since C++23
+    template<class F> constexpr optional or_else(F&& f) &&;     // since C++23
+    template<class F> constexpr optional or_else(F&& f) const&; // since C++23
+
     // 23.6.3.6, modifiers
     void reset() noexcept; // constexpr in C++20
 
@@ -147,6 +159,7 @@ template<class T>
 */
 
 #include <__availability>
+#include <__concepts/invocable.h>
 #include <__config>
 #include <__debug>
 #include <__functional_base>
@@ -163,10 +176,6 @@ template<class T>
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-
 namespace std  // purposefully not using versioning namespace
 {
 
@@ -179,7 +188,7 @@ public:
     virtual const char* what() const _NOEXCEPT;
 };
 
-}  // std
+} // namespace std
 
 #if _LIBCPP_STD_VER > 14
 
@@ -202,7 +211,9 @@ struct nullopt_t
     _LIBCPP_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {}
 };
 
-_LIBCPP_INLINE_VAR constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}};
+inline constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}};
+
+struct __optional_construct_from_invoke_tag {};
 
 template <class _Tp, bool = is_trivially_destructible<_Tp>::value>
 struct __optional_destruct_base;
@@ -238,6 +249,13 @@ struct __optional_destruct_base<_Tp, false>
         :  __val_(_VSTD::forward<_Args>(__args)...),
            __engaged_(true) {}
 
+#if _LIBCPP_STD_VER > 20
+  template <class _Fp, class... _Args>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
+      : __val_(_VSTD::invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...)), __engaged_(true) {}
+#endif
+
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR_AFTER_CXX17 void reset() noexcept
     {
@@ -273,6 +291,13 @@ struct __optional_destruct_base<_Tp, true>
         :  __val_(_VSTD::forward<_Args>(__args)...),
            __engaged_(true) {}
 
+#if _LIBCPP_STD_VER > 20
+  template <class _Fp, class... _Args>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
+      : __val_(_VSTD::invoke(_VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...)), __engaged_(true) {}
+#endif
+
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR_AFTER_CXX17 void reset() noexcept
     {
@@ -586,6 +611,12 @@ using __optional_sfinae_assign_base_t = __sfinae_assign_base<
     (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)
 >;
 
+template<class _Tp>
+class optional;
+template <class _Tp>
+struct __is_std_optional : false_type {};
+template <class _Tp> struct __is_std_optional<optional<_Tp>> : true_type {};
+
 template <class _Tp>
 class optional
     : private __optional_move_assign_base<_Tp>
@@ -688,6 +719,7 @@ private:
       _CheckOptionalLikeConstructor<_QualUp>,
       __check_tuple_constructor_fail
     >;
+
 public:
 
     _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {}
@@ -695,7 +727,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default;
     _LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {}
 
-    template <class _InPlaceT, class... _Args, class = _EnableIf<
+    template <class _InPlaceT, class... _Args, class = enable_if_t<
           _And<
               _IsSame<_InPlaceT, in_place_t>,
               is_constructible<value_type, _Args...>
@@ -706,21 +738,21 @@ public:
     constexpr explicit optional(_InPlaceT, _Args&&... __args)
         : __base(in_place, _VSTD::forward<_Args>(__args)...) {}
 
-    template <class _Up, class... _Args, class = _EnableIf<
+    template <class _Up, class... _Args, class = enable_if_t<
         is_constructible_v<value_type, initializer_list<_Up>&, _Args...>>
     >
     _LIBCPP_INLINE_VISIBILITY
     constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
         : __base(in_place, __il, _VSTD::forward<_Args>(__args)...) {}
 
-    template <class _Up = value_type, _EnableIf<
+    template <class _Up = value_type, enable_if_t<
         _CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     constexpr optional(_Up&& __v)
         : __base(in_place, _VSTD::forward<_Up>(__v)) {}
 
-    template <class _Up, _EnableIf<
+    template <class _Up, enable_if_t<
         _CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
@@ -728,7 +760,7 @@ public:
         : __base(in_place, _VSTD::forward<_Up>(__v)) {}
 
     // LWG2756: conditionally explicit conversion from const optional<_Up>&
-    template <class _Up, _EnableIf<
+    template <class _Up, enable_if_t<
         _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
@@ -736,7 +768,7 @@ public:
     {
         this->__construct_from(__v);
     }
-    template <class _Up, _EnableIf<
+    template <class _Up, enable_if_t<
         _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
@@ -746,7 +778,7 @@ public:
     }
 
     // LWG2756: conditionally explicit conversion from optional<_Up>&&
-    template <class _Up, _EnableIf<
+    template <class _Up, enable_if_t<
         _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_implicit<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
@@ -754,7 +786,7 @@ public:
     {
         this->__construct_from(_VSTD::move(__v));
     }
-    template <class _Up, _EnableIf<
+    template <class _Up, enable_if_t<
         _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_explicit<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
@@ -763,6 +795,14 @@ public:
         this->__construct_from(_VSTD::move(__v));
     }
 
+#if _LIBCPP_STD_VER > 20
+  template<class _Fp, class... _Args>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
+      : __base(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...) {
+  }
+#endif
+
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR_AFTER_CXX17 optional& operator=(nullopt_t) noexcept
     {
@@ -775,7 +815,7 @@ public:
 
     // LWG2756
     template <class _Up = value_type,
-              class = _EnableIf<
+              class = enable_if_t<
                       _And<
                           _IsNotSame<__uncvref_t<_Up>, optional>,
                           _Or<
@@ -798,7 +838,7 @@ public:
     }
 
     // LWG2756
-    template <class _Up, _EnableIf<
+    template <class _Up, enable_if_t<
         _CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
@@ -810,7 +850,7 @@ public:
     }
 
     // LWG2756
-    template <class _Up, _EnableIf<
+    template <class _Up, enable_if_t<
         _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_assign<_Up>()
     , int> = 0>
     _LIBCPP_INLINE_VISIBILITY
@@ -822,7 +862,7 @@ public:
     }
 
     template <class... _Args,
-              class = _EnableIf
+              class = enable_if_t
                       <
                           is_constructible_v<value_type, _Args...>
                       >
@@ -837,7 +877,7 @@ public:
     }
 
     template <class _Up, class... _Args,
-              class = _EnableIf
+              class = enable_if_t
                       <
                           is_constructible_v<value_type, initializer_list<_Up>&, _Args...>
                       >
@@ -883,11 +923,7 @@ public:
     operator->() const
     {
         _LIBCPP_ASSERT(this->has_value(), "optional operator-> called on a disengaged value");
-#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
         return _VSTD::addressof(this->__get());
-#else
-        return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
-#endif
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -896,11 +932,7 @@ public:
     operator->()
     {
         _LIBCPP_ASSERT(this->has_value(), "optional operator-> called on a disengaged value");
-#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
         return _VSTD::addressof(this->__get());
-#else
-        return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
-#endif
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1005,35 +1037,144 @@ public:
                                   static_cast<value_type>(_VSTD::forward<_Up>(__v));
     }
 
-    using __base::reset;
-
-private:
-    template <class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR_AFTER_CXX17 _Up*
-    __operator_arrow(true_type, _Up& __x)
-    {
-        return _VSTD::addressof(__x);
-    }
+#if _LIBCPP_STD_VER > 20
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto and_then(_Func&& __f) & {
+    using _Up = invoke_result_t<_Func, value_type&>;
+    static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
+                  "Result of f(value()) must be a specialization of std::optional");
+    if (*this)
+      return _VSTD::invoke(_VSTD::forward<_Func>(__f), value());
+    return remove_cvref_t<_Up>();
+  }
+
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto and_then(_Func&& __f) const& {
+    using _Up = invoke_result_t<_Func, const value_type&>;
+    static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
+                  "Result of f(value()) must be a specialization of std::optional");
+    if (*this)
+      return _VSTD::invoke(_VSTD::forward<_Func>(__f), value());
+    return remove_cvref_t<_Up>();
+  }
+
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto and_then(_Func&& __f) && {
+    using _Up = invoke_result_t<_Func, value_type&&>;
+    static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
+                  "Result of f(std::move(value())) must be a specialization of std::optional");
+    if (*this)
+      return _VSTD::invoke(_VSTD::forward<_Func>(__f), _VSTD::move(value()));
+    return remove_cvref_t<_Up>();
+  }
+
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto and_then(_Func&& __f) const&& {
+    using _Up = invoke_result_t<_Func, const value_type&&>;
+    static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
+                  "Result of f(std::move(value())) must be a specialization of std::optional");
+    if (*this)
+      return _VSTD::invoke(_VSTD::forward<_Func>(__f), _VSTD::move(value()));
+    return remove_cvref_t<_Up>();
+  }
+
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto transform(_Func&& __f) & {
+    using _Up = remove_cv_t<invoke_result_t<_Func, value_type&>>;
+    static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
+    static_assert(!is_same_v<_Up, in_place_t>,
+                  "Result of f(value()) should not be std::in_place_t");
+    static_assert(!is_same_v<_Up, nullopt_t>,
+                  "Result of f(value()) should not be std::nullopt_t");
+    static_assert(is_object_v<_Up>, "Result of f(value()) should be an object type");
+    if (*this)
+      return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), value());
+    return optional<_Up>();
+  }
+
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto transform(_Func&& __f) const& {
+    using _Up = remove_cv_t<invoke_result_t<_Func, const value_type&>>;
+    static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
+    static_assert(!is_same_v<_Up, in_place_t>,
+                  "Result of f(value()) should not be std::in_place_t");
+    static_assert(!is_same_v<_Up, nullopt_t>,
+                  "Result of f(value()) should not be std::nullopt_t");
+    static_assert(is_object_v<_Up>, "Result of f(value()) should be an object type");
+    if (*this)
+      return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), value());
+    return optional<_Up>();
+  }
+
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto transform(_Func&& __f) && {
+    using _Up = remove_cv_t<invoke_result_t<_Func, value_type&&>>;
+    static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
+    static_assert(!is_same_v<_Up, in_place_t>,
+                  "Result of f(std::move(value())) should not be std::in_place_t");
+    static_assert(!is_same_v<_Up, nullopt_t>,
+                  "Result of f(std::move(value())) should not be std::nullopt_t");
+    static_assert(is_object_v<_Up>, "Result of f(std::move(value())) should be an object type");
+    if (*this)
+      return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), _VSTD::move(value()));
+    return optional<_Up>();
+  }
+
+  template<class _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto transform(_Func&& __f) const&& {
+    using _Up = remove_cvref_t<invoke_result_t<_Func, const value_type&&>>;
+    static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
+    static_assert(!is_same_v<_Up, in_place_t>,
+                  "Result of f(std::move(value())) should not be std::in_place_t");
+    static_assert(!is_same_v<_Up, nullopt_t>,
+                  "Result of f(std::move(value())) should not be std::nullopt_t");
+    static_assert(is_object_v<_Up>, "Result of f(std::move(value())) should be an object type");
+    if (*this)
+      return optional<_Up>(__optional_construct_from_invoke_tag{}, _VSTD::forward<_Func>(__f), _VSTD::move(value()));
+    return optional<_Up>();
+  }
+
+  template<invocable _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr optional or_else(_Func&& __f) const& requires is_copy_constructible_v<value_type> {
+    static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
+                  "Result of f() should be the same type as this optional");
+    if (*this)
+      return *this;
+    return _VSTD::forward<_Func>(__f)();
+  }
+
+  template<invocable _Func>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr optional or_else(_Func&& __f) && requires is_move_constructible_v<value_type> {
+    static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
+                  "Result of f() should be the same type as this optional");
+    if (*this)
+      return _VSTD::move(*this);
+    return _VSTD::forward<_Func>(__f)();
+  }
+#endif // _LIBCPP_STD_VER > 20
 
-    template <class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    static constexpr _Up*
-    __operator_arrow(false_type, _Up& __x)
-    {
-        return &__x;
-    }
+    using __base::reset;
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
-template<class T>
-    optional(T) -> optional<T>;
+#if _LIBCPP_STD_VER >= 17
+template<class _Tp>
+    optional(_Tp) -> optional<_Tp>;
 #endif
 
 // Comparisons between optionals
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() ==
         declval<const _Up&>()), bool>,
     bool
@@ -1049,7 +1190,7 @@ operator==(const optional<_Tp>& __x, const optional<_Up>& __y)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() !=
         declval<const _Up&>()), bool>,
     bool
@@ -1065,7 +1206,7 @@ operator!=(const optional<_Tp>& __x, const optional<_Up>& __y)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() <
         declval<const _Up&>()), bool>,
     bool
@@ -1081,7 +1222,7 @@ operator<(const optional<_Tp>& __x, const optional<_Up>& __y)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() >
         declval<const _Up&>()), bool>,
     bool
@@ -1097,7 +1238,7 @@ operator>(const optional<_Tp>& __x, const optional<_Up>& __y)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() <=
         declval<const _Up&>()), bool>,
     bool
@@ -1113,7 +1254,7 @@ operator<=(const optional<_Tp>& __x, const optional<_Up>& __y)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() >=
         declval<const _Up&>()), bool>,
     bool
@@ -1227,7 +1368,7 @@ operator>=(nullopt_t, const optional<_Tp>& __x) noexcept
 // Comparisons with T
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() ==
         declval<const _Up&>()), bool>,
     bool
@@ -1239,7 +1380,7 @@ operator==(const optional<_Tp>& __x, const _Up& __v)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() ==
         declval<const _Up&>()), bool>,
     bool
@@ -1251,7 +1392,7 @@ operator==(const _Tp& __v, const optional<_Up>& __x)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() !=
         declval<const _Up&>()), bool>,
     bool
@@ -1263,7 +1404,7 @@ operator!=(const optional<_Tp>& __x, const _Up& __v)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() !=
         declval<const _Up&>()), bool>,
     bool
@@ -1275,7 +1416,7 @@ operator!=(const _Tp& __v, const optional<_Up>& __x)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() <
         declval<const _Up&>()), bool>,
     bool
@@ -1287,7 +1428,7 @@ operator<(const optional<_Tp>& __x, const _Up& __v)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() <
         declval<const _Up&>()), bool>,
     bool
@@ -1299,7 +1440,7 @@ operator<(const _Tp& __v, const optional<_Up>& __x)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() <=
         declval<const _Up&>()), bool>,
     bool
@@ -1311,7 +1452,7 @@ operator<=(const optional<_Tp>& __x, const _Up& __v)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() <=
         declval<const _Up&>()), bool>,
     bool
@@ -1323,7 +1464,7 @@ operator<=(const _Tp& __v, const optional<_Up>& __x)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() >
         declval<const _Up&>()), bool>,
     bool
@@ -1335,7 +1476,7 @@ operator>(const optional<_Tp>& __x, const _Up& __v)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() >
         declval<const _Up&>()), bool>,
     bool
@@ -1347,7 +1488,7 @@ operator>(const _Tp& __v, const optional<_Up>& __x)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() >=
         declval<const _Up&>()), bool>,
     bool
@@ -1359,7 +1500,7 @@ operator>=(const optional<_Tp>& __x, const _Up& __v)
 
 template <class _Tp, class _Up>
 _LIBCPP_INLINE_VISIBILITY constexpr
-_EnableIf<
+enable_if_t<
     is_convertible_v<decltype(declval<const _Tp&>() >=
         declval<const _Up&>()), bool>,
     bool
@@ -1372,7 +1513,7 @@ operator>=(const _Tp& __v, const optional<_Up>& __x)
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-_EnableIf<
+enable_if_t<
     is_move_constructible_v<_Tp> && is_swappable_v<_Tp>,
     void
 >
@@ -1423,6 +1564,4 @@ _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP_STD_VER > 14
 
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP_OPTIONAL
lib/libcxx/include/ostream
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- ostream -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -55,6 +55,7 @@ public:
     basic_ostream& operator<<(double f);
     basic_ostream& operator<<(long double f);
     basic_ostream& operator<<(const void* p);
+    basic_ostream& operator<<(const volatile void* val); // C++23
     basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
     basic_ostream& operator<<(nullptr_t);
 
@@ -210,6 +211,14 @@ public:
     basic_ostream& operator<<(double __f);
     basic_ostream& operator<<(long double __f);
     basic_ostream& operator<<(const void* __p);
+
+#if _LIBCPP_STD_VER > 20
+    _LIBCPP_HIDE_FROM_ABI
+    basic_ostream& operator<<(const volatile void* __p) {
+        return operator<<(const_cast<const void*>(__p));
+    }
+#endif
+
     basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
 
     _LIBCPP_INLINE_VISIBILITY
@@ -240,12 +249,11 @@ class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
     bool __ok_;
     basic_ostream<_CharT, _Traits>& __os_;
 
-    sentry(const sentry&); // = delete;
-    sentry& operator=(const sentry&); // = delete;
-
 public:
     explicit sentry(basic_ostream<_CharT, _Traits>& __os);
     ~sentry();
+    sentry(const sentry&) = delete;
+    sentry& operator=(const sentry&) = delete;
 
     _LIBCPP_INLINE_VISIBILITY
     explicit operator bool() const {return __ok_;}
@@ -1087,7 +1095,9 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
 }
 
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
+#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/queue
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- queue ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -41,6 +41,8 @@ public:
 
     explicit queue(const container_type& c);
     explicit queue(container_type&& c)
+    template<class InputIterator>
+        queue(InputIterator first, InputIterator last); // since C++23
     template <class Alloc>
         explicit queue(const Alloc& a);
     template <class Alloc>
@@ -51,6 +53,8 @@ public:
         queue(const queue& q, const Alloc& a);
     template <class Alloc>
         queue(queue&& q, const Alloc& a);
+    template <class InputIterator, class Alloc>
+        queue(InputIterator first, InputIterator last, const Alloc&); // since C++23
 
     bool      empty() const;
     size_type size() const;
@@ -71,9 +75,17 @@ public:
 template<class Container>
   queue(Container) -> queue<typename Container::value_type, Container>; // C++17
 
+template<class InputIterator>
+  queue(InputIterator, InputIterator) -> queue<iter-value-type<InputIterator>>; // since C++23
+
 template<class Container, class Allocator>
   queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
 
+template<class InputIterator, class Allocator>
+  queue(InputIterator, InputIterator, Allocator)
+  -> queue<iter-value-type<InputIterator>,
+           deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
+
 template <class T, class Container>
   bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
 
@@ -115,27 +127,39 @@ public:
     priority_queue() : priority_queue(Compare()) {} // C++20
     explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
     priority_queue(const Compare& x, const Container&);
-    explicit priority_queue(const Compare& x = Compare(), Container&&= Container()); // before C++20
+    explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20
     priority_queue(const Compare& x, Container&&); // C++20
     template <class InputIterator>
         priority_queue(InputIterator first, InputIterator last,
                        const Compare& comp = Compare());
     template <class InputIterator>
         priority_queue(InputIterator first, InputIterator last,
-                       const Compare& comp, const container_type& c);
+                       const Compare& comp, const Container& c);
     template <class InputIterator>
         priority_queue(InputIterator first, InputIterator last,
-                       const Compare& comp, container_type&& c);
+                       const Compare& comp, Container&& c);
     template <class Alloc>
         explicit priority_queue(const Alloc& a);
     template <class Alloc>
         priority_queue(const Compare& comp, const Alloc& a);
     template <class Alloc>
-        priority_queue(const Compare& comp, const container_type& c,
+        priority_queue(const Compare& comp, const Container& c,
                        const Alloc& a);
     template <class Alloc>
-        priority_queue(const Compare& comp, container_type&& c,
+        priority_queue(const Compare& comp, Container&& c,
                        const Alloc& a);
+    template <class InputIterator>
+        priority_queue(InputIterator first, InputIterator last,
+                       const Alloc& a);
+    template <class InputIterator>
+        priority_queue(InputIterator first, InputIterator last,
+                       const Compare& comp, const Alloc& a);
+    template <class InputIterator>
+        priority_queue(InputIterator first, InputIterator last,
+                       const Compare& comp, const Container& c, const Alloc& a);
+    template <class InputIterator>
+        priority_queue(InputIterator first, InputIterator last,
+                       const Compare& comp, Container&& c, const Alloc& a);
     template <class Alloc>
         priority_queue(const priority_queue& q, const Alloc& a);
     template <class Alloc>
@@ -160,15 +184,30 @@ priority_queue(Compare, Container)
     -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
 
 template<class InputIterator,
-         class Compare = less<typename iterator_traits<InputIterator>::value_type>,
-         class Container = vector<typename iterator_traits<InputIterator>::value_type>>
+         class Compare = less<iter-value-type<InputIterator>>,
+         class Container = vector<iter-value-type<InputIterator>>>
 priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
-    -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17
+    -> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17
 
 template<class Compare, class Container, class Allocator>
 priority_queue(Compare, Container, Allocator)
     -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
 
+template<class InputIterator, class Allocator>
+priority_queue(InputIterator, InputIterator, Allocator)
+    -> priority_queue<iter-value-type<InputIterator>,
+                      vector<iter-value-type<InputIterator>, Allocator>,
+                      less<iter-value-type<InputIterator>>>; // C++17
+
+template<class InputIterator, class Compare, class Allocator>
+priority_queue(InputIterator, InputIterator, Compare, Allocator)
+    -> priority_queue<iter-value-type<InputIterator>,
+                      vector<iter-value-type<InputIterator>, Allocator>, Compare>; // C++17
+
+template<class InputIterator, class Compare, class Container, class Allocator>
+priority_queue(InputIterator, InputIterator, Compare, Container, Allocator)
+    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
+
 template <class T, class Container, class Compare>
   void swap(priority_queue<T, Container, Compare>& x,
             priority_queue<T, Container, Compare>& y)
@@ -179,13 +218,16 @@ template <class T, class Container, class Compare>
 */
 
 #include <__config>
+#include <__iterator/iterator_traits.h>
 #include <__memory/uses_allocator.h>
 #include <__utility/forward.h>
 #include <algorithm>
 #include <compare>
 #include <deque>
 #include <functional>
+#include <type_traits>
 #include <vector>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -228,6 +270,20 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     queue(const queue& __q) : c(__q.c) {}
 
+#if _LIBCPP_STD_VER > 20
+    template <class _InputIterator,
+              class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
+    _LIBCPP_HIDE_FROM_ABI
+    queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
+
+    template <class _InputIterator,
+              class _Alloc,
+              class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+              class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>>
+    _LIBCPP_HIDE_FROM_ABI
+    queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc) : c(__first, __second, __alloc) {}
+#endif
+
     _LIBCPP_INLINE_VISIBILITY
     queue& operator=(const queue& __q) {c = __q.c; return *this;}
 
@@ -252,28 +308,28 @@ public:
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         explicit queue(const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(__a) {}
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         queue(const queue& __q, const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(__q.c, __a) {}
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         queue(const container_type& __c, const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(__c, __a) {}
 #ifndef _LIBCPP_CXX03_LANG
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         queue(container_type&& __c, const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(_VSTD::move(__c), __a) {}
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         queue(queue&& __q, const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(_VSTD::move(__q.c), __a) {}
 
 #endif // _LIBCPP_CXX03_LANG
@@ -331,22 +387,36 @@ public:
     operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER > 14
 template<class _Container,
-         class = _EnableIf<!__is_allocator<_Container>::value>
+         class = enable_if_t<!__is_allocator<_Container>::value>
 >
 queue(_Container)
     -> queue<typename _Container::value_type, _Container>;
 
 template<class _Container,
          class _Alloc,
-         class = _EnableIf<!__is_allocator<_Container>::value>,
-         class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
+         class = enable_if_t<!__is_allocator<_Container>::value>,
+         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
 >
 queue(_Container, _Alloc)
     -> queue<typename _Container::value_type, _Container>;
 #endif
 
+#if _LIBCPP_STD_VER > 20
+template <class _InputIterator,
+          class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
+queue(_InputIterator, _InputIterator)
+    -> queue<__iter_value_type<_InputIterator>>;
+
+template <class _InputIterator,
+          class _Alloc,
+          class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+          class = __enable_if_t<__is_allocator<_Alloc>::value>>
+queue(_InputIterator, _InputIterator, _Alloc)
+    -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
+#endif
+
 template <class _Tp, class _Container>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
@@ -397,7 +467,7 @@ operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
 
 template <class _Tp, class _Container>
 inline _LIBCPP_INLINE_VISIBILITY
-_EnableIf<__is_swappable<_Container>::value, void>
+__enable_if_t<__is_swappable<_Container>::value, void>
 swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
     _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
 {
@@ -464,16 +534,16 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     priority_queue(const value_compare& __comp, container_type&& __c);
 #endif
-    template <class _InputIter>
+    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(_InputIter __f, _InputIter __l,
                        const value_compare& __comp = value_compare());
-    template <class _InputIter>
+    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(_InputIter __f, _InputIter __l,
                        const value_compare& __comp, const container_type& __c);
 #ifndef _LIBCPP_CXX03_LANG
-    template <class _InputIter>
+    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(_InputIter __f, _InputIter __l,
                        const value_compare& __comp, container_type&& __c);
@@ -481,32 +551,57 @@ public:
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         explicit priority_queue(const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(const value_compare& __comp, const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(const value_compare& __comp, const container_type& __c,
                        const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(const priority_queue& __q, const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
 #ifndef _LIBCPP_CXX03_LANG
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(const value_compare& __comp, container_type&& __c,
                        const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         priority_queue(priority_queue&& __q, const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
 #endif // _LIBCPP_CXX03_LANG
 
+    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
+        _LIBCPP_INLINE_VISIBILITY
+        priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a,
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
+
+    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
+        _LIBCPP_INLINE_VISIBILITY
+        priority_queue(_InputIter __f, _InputIter __l,
+                       const value_compare& __comp, const _Alloc& __a,
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
+
+    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
+        _LIBCPP_INLINE_VISIBILITY
+        priority_queue(_InputIter __f, _InputIter __l,
+                       const value_compare& __comp, const container_type& __c, const _Alloc& __a,
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
+
+#ifndef _LIBCPP_CXX03_LANG
+    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
+        _LIBCPP_INLINE_VISIBILITY
+        priority_queue(_InputIter __f, _InputIter __l,
+                       const value_compare& __comp, container_type&& __c, const _Alloc& __a,
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
+#endif  // _LIBCPP_CXX03_LANG
+
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
     bool            empty() const {return c.empty();}
     _LIBCPP_INLINE_VISIBILITY
@@ -532,11 +627,11 @@ public:
                    __is_nothrow_swappable<value_compare>::value);
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template <class _Compare,
           class _Container,
-          class = _EnableIf<!__is_allocator<_Compare>::value>,
-          class = _EnableIf<!__is_allocator<_Container>::value>
+          class = enable_if_t<!__is_allocator<_Compare>::value>,
+          class = enable_if_t<!__is_allocator<_Container>::value>
 >
 priority_queue(_Compare, _Container)
     -> priority_queue<typename _Container::value_type, _Container, _Compare>;
@@ -544,9 +639,9 @@ priority_queue(_Compare, _Container)
 template<class _InputIterator,
          class _Compare = less<__iter_value_type<_InputIterator>>,
          class _Container = vector<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
-         class = _EnableIf<!__is_allocator<_Compare>::value>,
-         class = _EnableIf<!__is_allocator<_Container>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Compare>::value>,
+         class = enable_if_t<!__is_allocator<_Container>::value>
 >
 priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
     -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
@@ -554,12 +649,39 @@ priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container
 template<class _Compare,
          class _Container,
          class _Alloc,
-         class = _EnableIf<!__is_allocator<_Compare>::value>,
-         class = _EnableIf<!__is_allocator<_Container>::value>,
-         class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
+         class = enable_if_t<!__is_allocator<_Compare>::value>,
+         class = enable_if_t<!__is_allocator<_Container>::value>,
+         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
 >
 priority_queue(_Compare, _Container, _Alloc)
     -> priority_queue<typename _Container::value_type, _Container, _Compare>;
+
+template<class _InputIterator, class _Allocator,
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>
+>
+priority_queue(_InputIterator, _InputIterator, _Allocator)
+    -> priority_queue<__iter_value_type<_InputIterator>,
+                      vector<__iter_value_type<_InputIterator>, _Allocator>,
+                      less<__iter_value_type<_InputIterator>>>;
+
+template<class _InputIterator, class _Compare, class _Allocator,
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Compare>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>
+>
+priority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
+    -> priority_queue<__iter_value_type<_InputIterator>,
+                      vector<__iter_value_type<_InputIterator>, _Allocator>, _Compare>;
+
+template<class _InputIterator, class _Compare, class _Container, class _Alloc,
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Compare>::value>,
+         class = enable_if_t<!__is_allocator<_Container>::value>,
+         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
+>
+priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
+    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
 #endif
 
 template <class _Tp, class _Container, class _Compare>
@@ -587,7 +709,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& _
 #endif // _LIBCPP_CXX03_LANG
 
 template <class _Tp, class _Container, class _Compare>
-template <class _InputIter>
+template <class _InputIter, class>
 inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
                                                           const value_compare& __comp)
@@ -598,7 +720,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _Input
 }
 
 template <class _Tp, class _Container, class _Compare>
-template <class _InputIter>
+template <class _InputIter, class>
 inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
                                                           const value_compare& __comp,
@@ -613,7 +735,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _Input
 #ifndef _LIBCPP_CXX03_LANG
 
 template <class _Tp, class _Container, class _Compare>
-template <class _InputIter>
+template <class _InputIter, class>
 inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
                                                           const value_compare& __comp,
@@ -631,7 +753,7 @@ template <class _Tp, class _Container, class _Compare>
 template <class _Alloc>
 inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
     : c(__a)
 {
 }
@@ -641,7 +763,7 @@ template <class _Alloc>
 inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
                                                           const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
     : c(__a),
       comp(__comp)
 {
@@ -653,7 +775,7 @@ inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
                                                           const container_type& __c,
                                                           const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
     : c(__c, __a),
       comp(__comp)
 {
@@ -665,11 +787,10 @@ template <class _Alloc>
 inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
                                                           const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
     : c(__q.c, __a),
       comp(__q.comp)
 {
-    _VSTD::make_heap(c.begin(), c.end(), comp);
 }
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -680,7 +801,7 @@ inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
                                                           container_type&& __c,
                                                           const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
     : c(_VSTD::move(__c), __a),
       comp(__comp)
 {
@@ -692,14 +813,68 @@ template <class _Alloc>
 inline
 priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
                                                           const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
     : c(_VSTD::move(__q.c), __a),
       comp(_VSTD::move(__q.comp))
+{
+}
+
+#endif  // _LIBCPP_CXX03_LANG
+
+template <class _Tp, class _Container, class _Compare>
+template <class _InputIter, class _Alloc, class>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(
+        _InputIter __f, _InputIter __l, const _Alloc& __a,
+        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
+    : c(__f, __l, __a),
+      comp()
 {
     _VSTD::make_heap(c.begin(), c.end(), comp);
 }
 
-#endif // _LIBCPP_CXX03_LANG
+template <class _Tp, class _Container, class _Compare>
+template <class _InputIter, class _Alloc, class>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(
+        _InputIter __f, _InputIter __l,
+        const value_compare& __comp, const _Alloc& __a,
+        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
+    : c(__f, __l, __a),
+      comp(__comp)
+{
+    _VSTD::make_heap(c.begin(), c.end(), comp);
+}
+
+template <class _Tp, class _Container, class _Compare>
+template <class _InputIter, class _Alloc, class>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(
+        _InputIter __f, _InputIter __l,
+        const value_compare& __comp, const container_type& __c, const _Alloc& __a,
+        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
+    : c(__c, __a),
+      comp(__comp)
+{
+    c.insert(c.end(), __f, __l);
+    _VSTD::make_heap(c.begin(), c.end(), comp);
+}
+
+#ifndef _LIBCPP_CXX03_LANG
+template <class _Tp, class _Container, class _Compare>
+template <class _InputIter, class _Alloc, class>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(
+        _InputIter __f, _InputIter __l, const value_compare& __comp,
+        container_type&& __c, const _Alloc& __a,
+        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
+    : c(_VSTD::move(__c), __a),
+      comp(__comp)
+{
+    c.insert(c.end(), __f, __l);
+    _VSTD::make_heap(c.begin(), c.end(), comp);
+}
+#endif  // _LIBCPP_CXX03_LANG
 
 template <class _Tp, class _Container, class _Compare>
 inline
@@ -756,7 +931,7 @@ priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
 
 template <class _Tp, class _Container, class _Compare>
 inline _LIBCPP_INLINE_VISIBILITY
-_EnableIf<
+__enable_if_t<
     __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
     void
 >
lib/libcxx/include/random
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- random -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -1678,5330 +1678,58 @@ class piecewise_linear_distribution
 */
 
 #include <__config>
+#include <__random/bernoulli_distribution.h>
+#include <__random/binomial_distribution.h>
+#include <__random/cauchy_distribution.h>
+#include <__random/chi_squared_distribution.h>
+#include <__random/clamp_to_integral.h>
+#include <__random/default_random_engine.h>
+#include <__random/discard_block_engine.h>
+#include <__random/discrete_distribution.h>
+#include <__random/exponential_distribution.h>
+#include <__random/extreme_value_distribution.h>
+#include <__random/fisher_f_distribution.h>
+#include <__random/gamma_distribution.h>
+#include <__random/generate_canonical.h>
+#include <__random/geometric_distribution.h>
+#include <__random/independent_bits_engine.h>
+#include <__random/is_seed_sequence.h>
+#include <__random/knuth_b.h>
+#include <__random/linear_congruential_engine.h>
+#include <__random/log2.h>
+#include <__random/lognormal_distribution.h>
+#include <__random/mersenne_twister_engine.h>
+#include <__random/negative_binomial_distribution.h>
+#include <__random/normal_distribution.h>
+#include <__random/piecewise_constant_distribution.h>
+#include <__random/piecewise_linear_distribution.h>
+#include <__random/poisson_distribution.h>
+#include <__random/random_device.h>
+#include <__random/ranlux.h>
+#include <__random/seed_seq.h>
+#include <__random/shuffle_order_engine.h>
+#include <__random/student_t_distribution.h>
+#include <__random/subtract_with_carry_engine.h>
 #include <__random/uniform_int_distribution.h>
-#include <algorithm>
-#include <cmath>
-#include <concepts>
-#include <cstddef>
-#include <cstdint>
+#include <__random/uniform_random_bit_generator.h>
+#include <__random/uniform_real_distribution.h>
+#include <__random/weibull_distribution.h>
 #include <initializer_list>
-#include <iosfwd>
-#include <limits>
-#include <numeric>
-#include <string>
-#include <type_traits>
-#include <vector>
+#include <version>
+
+#include <algorithm>   // for backward compatibility; TODO remove it
+#include <cmath>       // for backward compatibility; TODO remove it
+#include <cstddef>     // for backward compatibility; TODO remove it
+#include <cstdint>     // for backward compatibility; TODO remove it
+#include <iosfwd>      // for backward compatibility; TODO remove it
+#include <limits>      // for backward compatibility; TODO remove it
+#include <numeric>     // for backward compatibility; TODO remove it
+#include <string>      // for backward compatibility; TODO remove it
+#include <type_traits> // for backward compatibility; TODO remove it
+#include <vector>      // for backward compatibility; TODO remove it
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
-
-// [rand.req.urng]
-template<class _Gen>
-concept uniform_random_bit_generator =
-  invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> &&
-  requires {
-    { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>;
-    { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>;
-    requires bool_constant<(_Gen::min() < _Gen::max())>::value;
-  };
-
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
-
-// __is_seed_sequence
-
-template <class _Sseq, class _Engine>
-struct __is_seed_sequence
-{
-    static _LIBCPP_CONSTEXPR const bool value =
-              !is_convertible<_Sseq, typename _Engine::result_type>::value &&
-              !is_same<typename remove_cv<_Sseq>::type, _Engine>::value;
-};
-
-// linear_congruential_engine
-
-template <unsigned long long __a, unsigned long long __c,
-          unsigned long long __m, unsigned long long _Mp,
-          bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a),
-          bool _OverflowOK = ((__m | (__m-1)) > __m), // m = 2^n
-          bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q
-struct __lce_alg_picker
-{
-    static_assert(__a != 0 || __m != 0 || !_MightOverflow || _OverflowOK || _SchrageOK,
-                  "The current values of a, c, and m cannot generate a number "
-                  "within bounds of linear_congruential_engine.");
-
-    static _LIBCPP_CONSTEXPR const bool __use_schrage = _MightOverflow &&
-                                                        !_OverflowOK &&
-                                                        _SchrageOK;
-};
-
-template <unsigned long long __a, unsigned long long __c,
-          unsigned long long __m, unsigned long long _Mp,
-          bool _UseSchrage = __lce_alg_picker<__a, __c, __m, _Mp>::__use_schrage>
-struct __lce_ta;
-
-// 64
-
-template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
-struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true>
-{
-    typedef unsigned long long result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        // Schrage's algorithm
-        const result_type __q = __m / __a;
-        const result_type __r = __m % __a;
-        const result_type __t0 = __a * (__x % __q);
-        const result_type __t1 = __r * (__x / __q);
-        __x = __t0 + (__t0 < __t1) * __m - __t1;
-        __x += __c - (__x >= __m - __c) * __m;
-        return __x;
-    }
-};
-
-template <unsigned long long __a, unsigned long long __m>
-struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true>
-{
-    typedef unsigned long long result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        // Schrage's algorithm
-        const result_type __q = __m / __a;
-        const result_type __r = __m % __a;
-        const result_type __t0 = __a * (__x % __q);
-        const result_type __t1 = __r * (__x / __q);
-        __x = __t0 + (__t0 < __t1) * __m - __t1;
-        return __x;
-    }
-};
-
-template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
-struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false>
-{
-    typedef unsigned long long result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        return (__a * __x + __c) % __m;
-    }
-};
-
-template <unsigned long long __a, unsigned long long __c>
-struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false>
-{
-    typedef unsigned long long result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        return __a * __x + __c;
-    }
-};
-
-// 32
-
-template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
-struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true>
-{
-    typedef unsigned result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        const result_type __a = static_cast<result_type>(_Ap);
-        const result_type __c = static_cast<result_type>(_Cp);
-        const result_type __m = static_cast<result_type>(_Mp);
-        // Schrage's algorithm
-        const result_type __q = __m / __a;
-        const result_type __r = __m % __a;
-        const result_type __t0 = __a * (__x % __q);
-        const result_type __t1 = __r * (__x / __q);
-        __x = __t0 + (__t0 < __t1) * __m - __t1;
-        __x += __c - (__x >= __m - __c) * __m;
-        return __x;
-    }
-};
-
-template <unsigned long long _Ap, unsigned long long _Mp>
-struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true>
-{
-    typedef unsigned result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        const result_type __a = static_cast<result_type>(_Ap);
-        const result_type __m = static_cast<result_type>(_Mp);
-        // Schrage's algorithm
-        const result_type __q = __m / __a;
-        const result_type __r = __m % __a;
-        const result_type __t0 = __a * (__x % __q);
-        const result_type __t1 = __r * (__x / __q);
-        __x = __t0 + (__t0 < __t1) * __m - __t1;
-        return __x;
-    }
-};
-
-template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
-struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false>
-{
-    typedef unsigned result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        const result_type __a = static_cast<result_type>(_Ap);
-        const result_type __c = static_cast<result_type>(_Cp);
-        const result_type __m = static_cast<result_type>(_Mp);
-        return (__a * __x + __c) % __m;
-    }
-};
-
-template <unsigned long long _Ap, unsigned long long _Cp>
-struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false>
-{
-    typedef unsigned result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        const result_type __a = static_cast<result_type>(_Ap);
-        const result_type __c = static_cast<result_type>(_Cp);
-        return __a * __x + __c;
-    }
-};
-
-// 16
-
-template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b>
-struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b>
-{
-    typedef unsigned short result_type;
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type next(result_type __x)
-    {
-        return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x));
-    }
-};
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-class _LIBCPP_TEMPLATE_VIS linear_congruential_engine;
-
-template <class _CharT, class _Traits,
-          class _Up, _Up _Ap, _Up _Cp, _Up _Np>
-_LIBCPP_INLINE_VISIBILITY
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
-
-template <class _CharT, class _Traits,
-          class _Up, _Up _Ap, _Up _Cp, _Up _Np>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-class _LIBCPP_TEMPLATE_VIS linear_congruential_engine
-{
-public:
-    // types
-    typedef _UIntType result_type;
-
-private:
-    result_type __x_;
-
-    static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
-
-    static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters");
-    static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
-    static_assert(is_unsigned<_UIntType>::value, "_UIntType must be unsigned type");
-public:
-    static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u;
-    static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u;
-    static_assert(_Min < _Max,           "linear_congruential_engine invalid parameters");
-
-    // engine characteristics
-    static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
-    static _LIBCPP_CONSTEXPR const result_type increment = __c;
-    static _LIBCPP_CONSTEXPR const result_type modulus = __m;
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type min() {return _Min;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type max() {return _Max;}
-    static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
-
-    // constructors and seeding functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    linear_congruential_engine() : linear_congruential_engine(default_seed) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit linear_congruential_engine(result_type __s) { seed(__s); }
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit linear_congruential_engine(result_type __s = default_seed) {
-      seed(__s);
-    }
-#endif
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        explicit linear_congruential_engine(_Sseq& __q,
-        typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
-        {seed(__q);}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(result_type __s = default_seed)
-        {seed(integral_constant<bool, __m == 0>(),
-              integral_constant<bool, __c == 0>(), __s);}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            __is_seed_sequence<_Sseq, linear_congruential_engine>::value,
-            void
-        >::type
-        seed(_Sseq& __q)
-            {__seed(__q, integral_constant<unsigned,
-                1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
-                             :  (__m > 0x100000000ull))>());}
-
-    // generating functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type operator()()
-        {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));}
-    _LIBCPP_INLINE_VISIBILITY
-    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-    bool operator==(const linear_congruential_engine& __x,
-                    const linear_congruential_engine& __y)
-        {return __x.__x_ == __y.__x_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-    bool operator!=(const linear_congruential_engine& __x,
-                    const linear_congruential_engine& __y)
-        {return !(__x == __y);}
-
-private:
-
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(true_type, false_type, result_type __s) {__x_ = __s;}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ?
-                                                                 1 : __s % __m;}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;}
-
-    template<class _Sseq>
-        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
-    template<class _Sseq>
-        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
-
-    template <class _CharT, class _Traits,
-              class _Up, _Up _Ap, _Up _Cp, _Up _Np>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
-
-    template <class _CharT, class _Traits,
-              class _Up, _Up _Ap, _Up _Cp, _Up _Np>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
-};
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
-    linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
-    linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
-    linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
-    linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-template<class _Sseq>
-void
-linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
-                                                 integral_constant<unsigned, 1>)
-{
-    const unsigned __k = 1;
-    uint32_t __ar[__k+3];
-    __q.generate(__ar, __ar + __k + 3);
-    result_type __s = static_cast<result_type>(__ar[3] % __m);
-    __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
-}
-
-template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-template<class _Sseq>
-void
-linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
-                                                 integral_constant<unsigned, 2>)
-{
-    const unsigned __k = 2;
-    uint32_t __ar[__k+3];
-    __q.generate(__ar, __ar + __k + 3);
-    result_type __s = static_cast<result_type>((__ar[3] +
-                                              ((uint64_t)__ar[4] << 32)) % __m);
-    __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
-}
-
-template <class _CharT, class _Traits,
-          class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-inline _LIBCPP_INLINE_VISIBILITY
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _Ostream;
-    __os.flags(_Ostream::dec | _Ostream::left);
-    __os.fill(__os.widen(' '));
-    return __os << __x.__x_;
-}
-
-template <class _CharT, class _Traits,
-          class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    _UIntType __t;
-    __is >> __t;
-    if (!__is.fail())
-        __x.__x_ = __t;
-    return __is;
-}
-
-typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
-                                                                   minstd_rand0;
-typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
-                                                                    minstd_rand;
-typedef minstd_rand                                       default_random_engine;
-// mersenne_twister_engine
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;
-
-template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-bool
-operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
-           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
-
-template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-_LIBCPP_INLINE_VISIBILITY
-bool
-operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
-           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                   _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine
-{
-public:
-    // types
-    typedef _UIntType result_type;
-
-private:
-    result_type __x_[__n];
-    size_t      __i_;
-
-    static_assert(  0 <  __m, "mersenne_twister_engine invalid parameters");
-    static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
-    static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
-    static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
-    static_assert(  2 <= __w, "mersenne_twister_engine invalid parameters");
-    static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
-    static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
-    static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
-    static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
-    static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
-public:
-    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
-    static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
-                                                      (result_type(1) << __w) - result_type(1);
-    static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
-    static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
-    static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
-    static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
-    static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
-    static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
-
-    // engine characteristics
-    static _LIBCPP_CONSTEXPR const size_t word_size = __w;
-    static _LIBCPP_CONSTEXPR const size_t state_size = __n;
-    static _LIBCPP_CONSTEXPR const size_t shift_size = __m;
-    static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
-    static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
-    static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
-    static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
-    static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
-    static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
-    static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
-    static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
-    static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
-    static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
-    static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
-
-    // constructors and seeding functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit mersenne_twister_engine(result_type __sd) { seed(__sd); }
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit mersenne_twister_engine(result_type __sd = default_seed) {
-      seed(__sd);
-    }
-#endif
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        explicit mersenne_twister_engine(_Sseq& __q,
-        typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
-        {seed(__q);}
-    void seed(result_type __sd = default_seed);
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            __is_seed_sequence<_Sseq, mersenne_twister_engine>::value,
-            void
-        >::type
-        seed(_Sseq& __q)
-            {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
-
-    // generating functions
-    result_type operator()();
-    _LIBCPP_INLINE_VISIBILITY
-    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
-
-    template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-    friend
-    bool
-    operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
-               const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
-
-    template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-    friend
-    bool
-    operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
-               const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __y);
-
-    template <class _CharT, class _Traits,
-              class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                             _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
-
-    template <class _CharT, class _Traits,
-              class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-              _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-              _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                       _Bp, _Tp, _Cp, _Lp, _Fp>& __x);
-private:
-
-    template<class _Sseq>
-        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
-    template<class _Sseq>
-        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
-
-    template <size_t __count>
-        _LIBCPP_INLINE_VISIBILITY
-        static
-        typename enable_if
-        <
-            __count < __w,
-            result_type
-        >::type
-        __lshift(result_type __x) {return (__x << __count) & _Max;}
-
-    template <size_t __count>
-        _LIBCPP_INLINE_VISIBILITY
-        static
-        typename enable_if
-        <
-            (__count >= __w),
-            result_type
-        >::type
-        __lshift(result_type) {return result_type(0);}
-
-    template <size_t __count>
-        _LIBCPP_INLINE_VISIBILITY
-        static
-        typename enable_if
-        <
-            __count < _Dt,
-            result_type
-        >::type
-        __rshift(result_type __x) {return __x >> __count;}
-
-    template <size_t __count>
-        _LIBCPP_INLINE_VISIBILITY
-        static
-        typename enable_if
-        <
-            (__count >= _Dt),
-            result_type
-        >::type
-        __rshift(result_type) {return result_type(0);}
-};
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const size_t
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
-    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-void
-mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
-    __t, __c, __l, __f>::seed(result_type __sd)
-    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
-{   // __w >= 2
-    __x_[0] = __sd & _Max;
-    for (size_t __i = 1; __i < __n; ++__i)
-        __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max;
-    __i_ = 0;
-}
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-template<class _Sseq>
-void
-mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
-    __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>)
-{
-    const unsigned __k = 1;
-    uint32_t __ar[__n * __k];
-    __q.generate(__ar, __ar + __n * __k);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
-    const result_type __mask = __r == _Dt ? result_type(~0) :
-                                       (result_type(1) << __r) - result_type(1);
-    __i_ = 0;
-    if ((__x_[0] & ~__mask) == 0)
-    {
-        for (size_t __i = 1; __i < __n; ++__i)
-            if (__x_[__i] != 0)
-                return;
-        __x_[0] = result_type(1) << (__w - 1);
-    }
-}
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-template<class _Sseq>
-void
-mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
-    __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>)
-{
-    const unsigned __k = 2;
-    uint32_t __ar[__n * __k];
-    __q.generate(__ar, __ar + __n * __k);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __x_[__i] = static_cast<result_type>(
-            (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
-    const result_type __mask = __r == _Dt ? result_type(~0) :
-                                       (result_type(1) << __r) - result_type(1);
-    __i_ = 0;
-    if ((__x_[0] & ~__mask) == 0)
-    {
-        for (size_t __i = 1; __i < __n; ++__i)
-            if (__x_[__i] != 0)
-                return;
-        __x_[0] = result_type(1) << (__w - 1);
-    }
-}
-
-template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
-          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
-          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-_UIntType
-mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
-    __t, __c, __l, __f>::operator()()
-{
-    const size_t __j = (__i_ + 1) % __n;
-    const result_type __mask = __r == _Dt ? result_type(~0) :
-                                       (result_type(1) << __r) - result_type(1);
-    const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
-    const size_t __k = (__i_ + __m) % __n;
-    __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1));
-    result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
-    __i_ = __j;
-    __z ^= __lshift<__s>(__z) & __b;
-    __z ^= __lshift<__t>(__z) & __c;
-    return __z ^ __rshift<__l>(__z);
-}
-
-template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-bool
-operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
-           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
-{
-    if (__x.__i_ == __y.__i_)
-        return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);
-    if (__x.__i_ == 0 || __y.__i_ == 0)
-    {
-        size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_);
-        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
-                         __y.__x_ + __y.__i_))
-            return false;
-        if (__x.__i_ == 0)
-            return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);
-        return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);
-    }
-    if (__x.__i_ < __y.__i_)
-    {
-        size_t __j = _Np - __y.__i_;
-        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
-                         __y.__x_ + __y.__i_))
-            return false;
-        if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np,
-                         __y.__x_))
-            return false;
-        return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
-                           __y.__x_ + (_Np - (__x.__i_ + __j)));
-    }
-    size_t __j = _Np - __x.__i_;
-    if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
-                     __x.__x_ + __x.__i_))
-        return false;
-    if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np,
-                     __x.__x_))
-        return false;
-    return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
-                       __x.__x_ + (_Np - (__y.__i_ + __j)));
-}
-
-template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-inline _LIBCPP_INLINE_VISIBILITY
-bool
-operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
-           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __y)
-{
-    return !(__x == __y);
-}
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                         _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _Ostream;
-    __os.flags(_Ostream::dec | _Ostream::left);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.__x_[__x.__i_];
-    for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)
-        __os << __sp << __x.__x_[__j];
-    for (size_t __j = 0; __j < __x.__i_; ++__j)
-        __os << __sp << __x.__x_[__j];
-    return __os;
-}
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
-          _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp,
-          _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
-                                   _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    _UInt __t[_Np];
-    for (size_t __i = 0; __i < _Np; ++__i)
-        __is >> __t[__i];
-    if (!__is.fail())
-    {
-        for (size_t __i = 0; __i < _Np; ++__i)
-            __x.__x_[__i] = __t[__i];
-        __x.__i_ = 0;
-    }
-    return __is;
-}
-
-typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
-                                0x9908b0df, 11, 0xffffffff,
-                                7,  0x9d2c5680,
-                                15, 0xefc60000,
-                                18, 1812433253>                         mt19937;
-typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
-                                0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL,
-                                17, 0x71d67fffeda60000ULL,
-                                37, 0xfff7eee000000000ULL,
-                                43, 6364136223846793005ULL>          mt19937_64;
-
-// subtract_with_carry_engine
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine;
-
-template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-bool
-operator==(
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
-
-template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-_LIBCPP_INLINE_VISIBILITY
-bool
-operator!=(
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine
-{
-public:
-    // types
-    typedef _UIntType result_type;
-
-private:
-    result_type __x_[__r];
-    result_type  __c_;
-    size_t      __i_;
-
-    static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
-    static_assert(  0 <  __w, "subtract_with_carry_engine invalid parameters");
-    static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters");
-    static_assert(  0 <  __s, "subtract_with_carry_engine invalid parameters");
-    static_assert(__s <  __r, "subtract_with_carry_engine invalid parameters");
-public:
-    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
-    static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
-                                                      (result_type(1) << __w) - result_type(1);
-    static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
-
-    // engine characteristics
-    static _LIBCPP_CONSTEXPR const size_t word_size = __w;
-    static _LIBCPP_CONSTEXPR const size_t short_lag = __s;
-    static _LIBCPP_CONSTEXPR const size_t long_lag = __r;
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
-    static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
-
-    // constructors and seeding functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit subtract_with_carry_engine(result_type __sd) { seed(__sd); }
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit subtract_with_carry_engine(result_type __sd = default_seed) {
-      seed(__sd);
-    }
-#endif
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        explicit subtract_with_carry_engine(_Sseq& __q,
-        typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
-        {seed(__q);}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(result_type __sd = default_seed)
-        {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value,
-            void
-        >::type
-        seed(_Sseq& __q)
-            {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
-
-    // generating functions
-    result_type operator()();
-    _LIBCPP_INLINE_VISIBILITY
-    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
-
-    template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-    friend
-    bool
-    operator==(
-        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
-        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
-
-    template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-    friend
-    bool
-    operator!=(
-        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
-        const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y);
-
-    template <class _CharT, class _Traits,
-              class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
-
-    template <class _CharT, class _Traits,
-              class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
-
-private:
-
-    void seed(result_type __sd, integral_constant<unsigned, 1>);
-    void seed(result_type __sd, integral_constant<unsigned, 2>);
-    template<class _Sseq>
-        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
-    template<class _Sseq>
-        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
-};
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-    _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type
-    subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-void
-subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
-        integral_constant<unsigned, 1>)
-{
-    linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
-        __e(__sd == 0u ? default_seed : __sd);
-    for (size_t __i = 0; __i < __r; ++__i)
-        __x_[__i] = static_cast<result_type>(__e() & _Max);
-    __c_ = __x_[__r-1] == 0;
-    __i_ = 0;
-}
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-void
-subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
-        integral_constant<unsigned, 2>)
-{
-    linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
-        __e(__sd == 0u ? default_seed : __sd);
-    for (size_t __i = 0; __i < __r; ++__i)
-    {
-        result_type __e0 = __e();
-        __x_[__i] = static_cast<result_type>(
-                                    (__e0 + ((uint64_t)__e() << 32)) & _Max);
-    }
-    __c_ = __x_[__r-1] == 0;
-    __i_ = 0;
-}
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-template<class _Sseq>
-void
-subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
-        integral_constant<unsigned, 1>)
-{
-    const unsigned __k = 1;
-    uint32_t __ar[__r * __k];
-    __q.generate(__ar, __ar + __r * __k);
-    for (size_t __i = 0; __i < __r; ++__i)
-        __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
-    __c_ = __x_[__r-1] == 0;
-    __i_ = 0;
-}
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-template<class _Sseq>
-void
-subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
-        integral_constant<unsigned, 2>)
-{
-    const unsigned __k = 2;
-    uint32_t __ar[__r * __k];
-    __q.generate(__ar, __ar + __r * __k);
-    for (size_t __i = 0; __i < __r; ++__i)
-        __x_[__i] = static_cast<result_type>(
-                  (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
-    __c_ = __x_[__r-1] == 0;
-    __i_ = 0;
-}
-
-template<class _UIntType, size_t __w, size_t __s, size_t __r>
-_UIntType
-subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()()
-{
-    const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r];
-    result_type& __xr = __x_[__i_];
-    result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1;
-    __xr = (__xs - __xr - __c_) & _Max;
-    __c_ = __new_c;
-    __i_ = (__i_ + 1) % __r;
-    return __xr;
-}
-
-template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-bool
-operator==(
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
-{
-    if (__x.__c_ != __y.__c_)
-        return false;
-    if (__x.__i_ == __y.__i_)
-        return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_);
-    if (__x.__i_ == 0 || __y.__i_ == 0)
-    {
-        size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_);
-        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
-                         __y.__x_ + __y.__i_))
-            return false;
-        if (__x.__i_ == 0)
-            return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_);
-        return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j);
-    }
-    if (__x.__i_ < __y.__i_)
-    {
-        size_t __j = _Rp - __y.__i_;
-        if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
-                         __y.__x_ + __y.__i_))
-            return false;
-        if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp,
-                         __y.__x_))
-            return false;
-        return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_,
-                           __y.__x_ + (_Rp - (__x.__i_ + __j)));
-    }
-    size_t __j = _Rp - __x.__i_;
-    if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
-                     __x.__x_ + __x.__i_))
-        return false;
-    if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp,
-                     __x.__x_))
-        return false;
-    return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_,
-                       __x.__x_ + (_Rp - (__y.__i_ + __j)));
-}
-
-template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-inline _LIBCPP_INLINE_VISIBILITY
-bool
-operator!=(
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
-    const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y)
-{
-    return !(__x == __y);
-}
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _Ostream;
-    __os.flags(_Ostream::dec | _Ostream::left);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.__x_[__x.__i_];
-    for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j)
-        __os << __sp << __x.__x_[__j];
-    for (size_t __j = 0; __j < __x.__i_; ++__j)
-        __os << __sp << __x.__x_[__j];
-    __os << __sp << __x.__c_;
-    return __os;
-}
-
-template <class _CharT, class _Traits,
-          class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    _UInt __t[_Rp+1];
-    for (size_t __i = 0; __i < _Rp+1; ++__i)
-        __is >> __t[__i];
-    if (!__is.fail())
-    {
-        for (size_t __i = 0; __i < _Rp; ++__i)
-            __x.__x_[__i] = __t[__i];
-        __x.__c_ = __t[_Rp];
-        __x.__i_ = 0;
-    }
-    return __is;
-}
-
-typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>     ranlux24_base;
-typedef subtract_with_carry_engine<uint_fast64_t, 48,  5, 12>     ranlux48_base;
-
-// discard_block_engine
-
-template<class _Engine, size_t __p, size_t __r>
-class _LIBCPP_TEMPLATE_VIS discard_block_engine
-{
-    _Engine __e_;
-    int     __n_;
-
-    static_assert(  0 <  __r, "discard_block_engine invalid parameters");
-    static_assert(__r <= __p, "discard_block_engine invalid parameters");
-    static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters");
-public:
-    // types
-    typedef typename _Engine::result_type result_type;
-
-    // engine characteristics
-    static _LIBCPP_CONSTEXPR const size_t block_size = __p;
-    static _LIBCPP_CONSTEXPR const size_t used_block = __r;
-
-#ifdef _LIBCPP_CXX03_LANG
-    static const result_type _Min = _Engine::_Min;
-    static const result_type _Max = _Engine::_Max;
-#else
-    static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
-    static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
-#endif
-
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); }
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); }
-
-    // constructors and seeding functions
-    _LIBCPP_INLINE_VISIBILITY
-    discard_block_engine() : __n_(0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit discard_block_engine(const _Engine& __e)
-        : __e_(__e), __n_(0) {}
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    explicit discard_block_engine(_Engine&& __e)
-        : __e_(_VSTD::move(__e)), __n_(0) {}
-#endif // _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        explicit discard_block_engine(_Sseq& __q,
-        typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
-                           !is_convertible<_Sseq, _Engine>::value>::type* = 0)
-        : __e_(__q), __n_(0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed() {__e_.seed(); __n_ = 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            __is_seed_sequence<_Sseq, discard_block_engine>::value,
-            void
-        >::type
-        seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
-
-    // generating functions
-    result_type operator()();
-    _LIBCPP_INLINE_VISIBILITY
-    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    const _Engine& base() const _NOEXCEPT {return __e_;}
-
-    template<class _Eng, size_t _Pp, size_t _Rp>
-    friend
-    bool
-    operator==(
-        const discard_block_engine<_Eng, _Pp, _Rp>& __x,
-        const discard_block_engine<_Eng, _Pp, _Rp>& __y);
-
-    template<class _Eng, size_t _Pp, size_t _Rp>
-    friend
-    bool
-    operator!=(
-        const discard_block_engine<_Eng, _Pp, _Rp>& __x,
-        const discard_block_engine<_Eng, _Pp, _Rp>& __y);
-
-    template <class _CharT, class _Traits,
-              class _Eng, size_t _Pp, size_t _Rp>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const discard_block_engine<_Eng, _Pp, _Rp>& __x);
-
-    template <class _CharT, class _Traits,
-              class _Eng, size_t _Pp, size_t _Rp>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               discard_block_engine<_Eng, _Pp, _Rp>& __x);
-};
-
-template<class _Engine, size_t __p, size_t __r>
-    _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
-
-template<class _Engine, size_t __p, size_t __r>
-    _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
-
-template<class _Engine, size_t __p, size_t __r>
-typename discard_block_engine<_Engine, __p, __r>::result_type
-discard_block_engine<_Engine, __p, __r>::operator()()
-{
-    if (__n_ >= static_cast<int>(__r))
-    {
-        __e_.discard(__p - __r);
-        __n_ = 0;
-    }
-    ++__n_;
-    return __e_();
-}
-
-template<class _Eng, size_t _Pp, size_t _Rp>
-inline _LIBCPP_INLINE_VISIBILITY
-bool
-operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
-           const discard_block_engine<_Eng, _Pp, _Rp>& __y)
-{
-    return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_;
-}
-
-template<class _Eng, size_t _Pp, size_t _Rp>
-inline _LIBCPP_INLINE_VISIBILITY
-bool
-operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x,
-           const discard_block_engine<_Eng, _Pp, _Rp>& __y)
-{
-    return !(__x == __y);
-}
-
-template <class _CharT, class _Traits,
-          class _Eng, size_t _Pp, size_t _Rp>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const discard_block_engine<_Eng, _Pp, _Rp>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _Ostream;
-    __os.flags(_Ostream::dec | _Ostream::left);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    return __os << __x.__e_ << __sp << __x.__n_;
-}
-
-template <class _CharT, class _Traits,
-          class _Eng, size_t _Pp, size_t _Rp>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           discard_block_engine<_Eng, _Pp, _Rp>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    _Eng __e;
-    int __n;
-    __is >> __e >> __n;
-    if (!__is.fail())
-    {
-        __x.__e_ = __e;
-        __x.__n_ = __n;
-    }
-    return __is;
-}
-
-typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
-typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
-
-// independent_bits_engine
-
-template<class _Engine, size_t __w, class _UIntType>
-class _LIBCPP_TEMPLATE_VIS independent_bits_engine
-{
-    template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp>
-    class __get_n
-    {
-        static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits;
-        static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0);
-        static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np;
-        static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0;
-    public:
-        static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np;
-    };
-public:
-    // types
-    typedef _UIntType result_type;
-
-private:
-    _Engine __e_;
-
-    static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits;
-    static_assert(  0 <  __w, "independent_bits_engine invalid parameters");
-    static_assert(__w <= _Dt, "independent_bits_engine invalid parameters");
-
-    typedef typename _Engine::result_type _Engine_result_type;
-    typedef typename conditional
-        <
-            sizeof(_Engine_result_type) <= sizeof(result_type),
-                result_type,
-                _Engine_result_type
-        >::type _Working_result_type;
-#ifdef _LIBCPP_CXX03_LANG
-    static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min
-                                          + _Working_result_type(1);
-#else
-    static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min()
-                                                            + _Working_result_type(1);
-#endif
-    static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value;
-    static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value;
-    static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n;
-    static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n;
-    static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits;
-    static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
-    static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 :
-                                                               (_Rp >> __w0) << __w0;
-    static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 :
-                                                               (_Rp >> (__w0+1)) << (__w0+1);
-    static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ?
-                                _Engine_result_type(~0) >> (_EDt - __w0) :
-                                _Engine_result_type(0);
-    static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ?
-                                _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) :
-                                _Engine_result_type(~0);
-public:
-    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
-    static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) :
-                                                      (result_type(1) << __w) - result_type(1);
-    static_assert(_Min < _Max, "independent_bits_engine invalid parameters");
-
-    // engine characteristics
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
-
-    // constructors and seeding functions
-    _LIBCPP_INLINE_VISIBILITY
-    independent_bits_engine() {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit independent_bits_engine(const _Engine& __e)
-        : __e_(__e) {}
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    explicit independent_bits_engine(_Engine&& __e)
-        : __e_(_VSTD::move(__e)) {}
-#endif // _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        explicit independent_bits_engine(_Sseq& __q,
-        typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
-                           !is_convertible<_Sseq, _Engine>::value>::type* = 0)
-         : __e_(__q) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed() {__e_.seed();}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(result_type __sd) {__e_.seed(__sd);}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            __is_seed_sequence<_Sseq, independent_bits_engine>::value,
-            void
-        >::type
-        seed(_Sseq& __q) {__e_.seed(__q);}
-
-    // generating functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
-    _LIBCPP_INLINE_VISIBILITY
-    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    const _Engine& base() const _NOEXCEPT {return __e_;}
-
-    template<class _Eng, size_t _Wp, class _UInt>
-    friend
-    bool
-    operator==(
-        const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
-        const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
-
-    template<class _Eng, size_t _Wp, class _UInt>
-    friend
-    bool
-    operator!=(
-        const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
-        const independent_bits_engine<_Eng, _Wp, _UInt>& __y);
-
-    template <class _CharT, class _Traits,
-              class _Eng, size_t _Wp, class _UInt>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const independent_bits_engine<_Eng, _Wp, _UInt>& __x);
-
-    template <class _CharT, class _Traits,
-              class _Eng, size_t _Wp, class _UInt>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               independent_bits_engine<_Eng, _Wp, _UInt>& __x);
-
-private:
-    _LIBCPP_INLINE_VISIBILITY
-    result_type __eval(false_type);
-    result_type __eval(true_type);
-
-    template <size_t __count>
-        _LIBCPP_INLINE_VISIBILITY
-        static
-        typename enable_if
-        <
-            __count < _Dt,
-            result_type
-        >::type
-        __lshift(result_type __x) {return __x << __count;}
-
-    template <size_t __count>
-        _LIBCPP_INLINE_VISIBILITY
-        static
-        typename enable_if
-        <
-            (__count >= _Dt),
-            result_type
-        >::type
-        __lshift(result_type) {return result_type(0);}
-};
-
-template<class _Engine, size_t __w, class _UIntType>
-inline
-_UIntType
-independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
-{
-    return static_cast<result_type>(__e_() & __mask0);
-}
-
-template<class _Engine, size_t __w, class _UIntType>
-_UIntType
-independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
-{
-    result_type _Sp = 0;
-    for (size_t __k = 0; __k < __n0; ++__k)
-    {
-        _Engine_result_type __u;
-        do
-        {
-            __u = __e_() - _Engine::min();
-        } while (__u >= __y0);
-        _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0));
-    }
-    for (size_t __k = __n0; __k < __n; ++__k)
-    {
-        _Engine_result_type __u;
-        do
-        {
-            __u = __e_() - _Engine::min();
-        } while (__u >= __y1);
-        _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1));
-    }
-    return _Sp;
-}
-
-template<class _Eng, size_t _Wp, class _UInt>
-inline _LIBCPP_INLINE_VISIBILITY
-bool
-operator==(
-    const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
-    const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
-{
-    return __x.base() == __y.base();
-}
-
-template<class _Eng, size_t _Wp, class _UInt>
-inline _LIBCPP_INLINE_VISIBILITY
-bool
-operator!=(
-    const independent_bits_engine<_Eng, _Wp, _UInt>& __x,
-    const independent_bits_engine<_Eng, _Wp, _UInt>& __y)
-{
-    return !(__x == __y);
-}
-
-template <class _CharT, class _Traits,
-          class _Eng, size_t _Wp, class _UInt>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const independent_bits_engine<_Eng, _Wp, _UInt>& __x)
-{
-    return __os << __x.base();
-}
-
-template <class _CharT, class _Traits,
-          class _Eng, size_t _Wp, class _UInt>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           independent_bits_engine<_Eng, _Wp, _UInt>& __x)
-{
-    _Eng __e;
-    __is >> __e;
-    if (!__is.fail())
-        __x.__e_ = __e;
-    return __is;
-}
-
-// shuffle_order_engine
-
-template <uint64_t _Xp, uint64_t _Yp>
-struct __ugcd
-{
-    static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value;
-};
-
-template <uint64_t _Xp>
-struct __ugcd<_Xp, 0>
-{
-    static _LIBCPP_CONSTEXPR const uint64_t value = _Xp;
-};
-
-template <uint64_t _Np, uint64_t _Dp>
-class __uratio
-{
-    static_assert(_Dp != 0, "__uratio divide by 0");
-    static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value;
-public:
-    static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd;
-    static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd;
-
-    typedef __uratio<num, den> type;
-};
-
-template<class _Engine, size_t __k>
-class _LIBCPP_TEMPLATE_VIS shuffle_order_engine
-{
-    static_assert(0 < __k, "shuffle_order_engine invalid parameters");
-public:
-    // types
-    typedef typename _Engine::result_type result_type;
-
-private:
-    _Engine __e_;
-    result_type _V_[__k];
-    result_type _Y_;
-
-public:
-    // engine characteristics
-    static _LIBCPP_CONSTEXPR const size_t table_size = __k;
-
-#ifdef _LIBCPP_CXX03_LANG
-    static const result_type _Min = _Engine::_Min;
-    static const result_type _Max = _Engine::_Max;
-#else
-    static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min();
-    static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max();
-#endif
-    static_assert(_Min < _Max, "shuffle_order_engine invalid parameters");
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
-
-    static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull;
-
-    // constructors and seeding functions
-    _LIBCPP_INLINE_VISIBILITY
-    shuffle_order_engine() {__init();}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit shuffle_order_engine(const _Engine& __e)
-        : __e_(__e) {__init();}
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    explicit shuffle_order_engine(_Engine&& __e)
-        : __e_(_VSTD::move(__e)) {__init();}
-#endif // _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        explicit shuffle_order_engine(_Sseq& __q,
-        typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
-                           !is_convertible<_Sseq, _Engine>::value>::type* = 0)
-         : __e_(__q) {__init();}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed() {__e_.seed(); __init();}
-    _LIBCPP_INLINE_VISIBILITY
-    void seed(result_type __sd) {__e_.seed(__sd); __init();}
-    template<class _Sseq>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            __is_seed_sequence<_Sseq, shuffle_order_engine>::value,
-            void
-        >::type
-        seed(_Sseq& __q) {__e_.seed(__q); __init();}
-
-    // generating functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
-    _LIBCPP_INLINE_VISIBILITY
-    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    const _Engine& base() const _NOEXCEPT {return __e_;}
-
-private:
-    template<class _Eng, size_t _Kp>
-    friend
-    bool
-    operator==(
-        const shuffle_order_engine<_Eng, _Kp>& __x,
-        const shuffle_order_engine<_Eng, _Kp>& __y);
-
-    template<class _Eng, size_t _Kp>
-    friend
-    bool
-    operator!=(
-        const shuffle_order_engine<_Eng, _Kp>& __x,
-        const shuffle_order_engine<_Eng, _Kp>& __y);
-
-    template <class _CharT, class _Traits,
-              class _Eng, size_t _Kp>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const shuffle_order_engine<_Eng, _Kp>& __x);
-
-    template <class _CharT, class _Traits,
-              class _Eng, size_t _Kp>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               shuffle_order_engine<_Eng, _Kp>& __x);
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __init()
-    {
-        for (size_t __i = 0; __i < __k; ++__i)
-            _V_[__i] = __e_();
-        _Y_ = __e_();
-    }
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type __eval2(true_type) {return __evalf<__k, 0>();}
-
-    template <uint64_t _Np, uint64_t _Dp>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)),
-            result_type
-        >::type
-        __eval(__uratio<_Np, _Dp>)
-            {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();}
-
-    template <uint64_t _Np, uint64_t _Dp>
-        _LIBCPP_INLINE_VISIBILITY
-        typename enable_if
-        <
-            __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min),
-            result_type
-        >::type
-        __eval(__uratio<_Np, _Dp>)
-        {
-            const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min)
-                                                   / __uratio<_Np, _Dp>::den);
-            _Y_ = _V_[__j];
-            _V_[__j] = __e_();
-            return _Y_;
-        }
-
-    template <uint64_t __n, uint64_t __d>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type __evalf()
-        {
-            const double _Fp = __d == 0 ?
-                __n / (2. * 0x8000000000000000ull) :
-                __n / (double)__d;
-            const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min));
-            _Y_ = _V_[__j];
-            _V_[__j] = __e_();
-            return _Y_;
-        }
-};
-
-template<class _Engine, size_t __k>
-    _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size;
-
-template<class _Eng, size_t _Kp>
-bool
-operator==(
-    const shuffle_order_engine<_Eng, _Kp>& __x,
-    const shuffle_order_engine<_Eng, _Kp>& __y)
-{
-    return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) &&
-           __x.__e_ == __y.__e_;
-}
-
-template<class _Eng, size_t _Kp>
-inline _LIBCPP_INLINE_VISIBILITY
-bool
-operator!=(
-    const shuffle_order_engine<_Eng, _Kp>& __x,
-    const shuffle_order_engine<_Eng, _Kp>& __y)
-{
-    return !(__x == __y);
-}
-
-template <class _CharT, class _Traits,
-          class _Eng, size_t _Kp>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const shuffle_order_engine<_Eng, _Kp>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _Ostream;
-    __os.flags(_Ostream::dec | _Ostream::left);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.__e_ << __sp << __x._V_[0];
-    for (size_t __i = 1; __i < _Kp; ++__i)
-        __os << __sp << __x._V_[__i];
-    return __os << __sp << __x._Y_;
-}
-
-template <class _CharT, class _Traits,
-          class _Eng, size_t _Kp>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           shuffle_order_engine<_Eng, _Kp>& __x)
-{
-    typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    _Eng __e;
-    result_type _Vp[_Kp+1];
-    __is >> __e;
-    for (size_t __i = 0; __i < _Kp+1; ++__i)
-        __is >> _Vp[__i];
-    if (!__is.fail())
-    {
-        __x.__e_ = __e;
-        for (size_t __i = 0; __i < _Kp; ++__i)
-            __x._V_[__i] = _Vp[__i];
-        __x._Y_ = _Vp[_Kp];
-    }
-    return __is;
-}
-
-typedef shuffle_order_engine<minstd_rand0, 256>                         knuth_b;
-
-// random_device
-
-#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)
-
-class _LIBCPP_TYPE_VIS random_device
-{
-#ifdef _LIBCPP_USING_DEV_RANDOM
-    int __f_;
-#endif // defined(_LIBCPP_USING_DEV_RANDOM)
-public:
-    // types
-    typedef unsigned result_type;
-
-    // generator characteristics
-    static _LIBCPP_CONSTEXPR const result_type _Min = 0;
-    static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu;
-
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type min() { return _Min;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR result_type max() { return _Max;}
-
-    // constructors
-#ifndef _LIBCPP_CXX03_LANG
-    random_device() : random_device("/dev/urandom") {}
-    explicit random_device(const string& __token);
-#else
-    explicit random_device(const string& __token = "/dev/urandom");
-#endif
-    ~random_device();
-
-    // generating functions
-    result_type operator()();
-
-    // property functions
-    double entropy() const _NOEXCEPT;
-
-private:
-    // no copy functions
-    random_device(const random_device&); // = delete;
-    random_device& operator=(const random_device&); // = delete;
-};
-
-#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE
-
-// seed_seq
-
-class _LIBCPP_TEMPLATE_VIS seed_seq
-{
-public:
-    // types
-    typedef uint32_t result_type;
-
-private:
-    vector<result_type> __v_;
-
-    template<class _InputIterator>
-        void init(_InputIterator __first, _InputIterator __last);
-public:
-    // constructors
-    _LIBCPP_INLINE_VISIBILITY
-    seed_seq() _NOEXCEPT {}
-#ifndef _LIBCPP_CXX03_LANG
-    template<class _Tp>
-        _LIBCPP_INLINE_VISIBILITY
-        seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());}
-#endif // _LIBCPP_CXX03_LANG
-
-    template<class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
-        seed_seq(_InputIterator __first, _InputIterator __last)
-             {init(__first, __last);}
-
-    // generating functions
-    template<class _RandomAccessIterator>
-        void generate(_RandomAccessIterator __first, _RandomAccessIterator __last);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    size_t size() const _NOEXCEPT {return __v_.size();}
-    template<class _OutputIterator>
-        _LIBCPP_INLINE_VISIBILITY
-        void param(_OutputIterator __dest) const
-            {_VSTD::copy(__v_.begin(), __v_.end(), __dest);}
-
-private:
-    // no copy functions
-    seed_seq(const seed_seq&); // = delete;
-    void operator=(const seed_seq&); // = delete;
-
-    _LIBCPP_INLINE_VISIBILITY
-    static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);}
-};
-
-template<class _InputIterator>
-void
-seed_seq::init(_InputIterator __first, _InputIterator __last)
-{
-    for (_InputIterator __s = __first; __s != __last; ++__s)
-        __v_.push_back(*__s & 0xFFFFFFFF);
-}
-
-template<class _RandomAccessIterator>
-void
-seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
-{
-    if (__first != __last)
-    {
-        _VSTD::fill(__first, __last, 0x8b8b8b8b);
-        const size_t __n = static_cast<size_t>(__last - __first);
-        const size_t __s = __v_.size();
-        const size_t __t = (__n >= 623) ? 11
-                         : (__n >= 68) ? 7
-                         : (__n >= 39) ? 5
-                         : (__n >= 7)  ? 3
-                         : (__n - 1) / 2;
-        const size_t __p = (__n - __t) / 2;
-        const size_t __q = __p + __t;
-        const size_t __m = _VSTD::max(__s + 1, __n);
-        // __k = 0;
-        {
-            result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p]
-                                                      ^  __first[__n - 1]);
-            __first[__p] += __r;
-            __r += __s;
-            __first[__q] += __r;
-            __first[0] = __r;
-        }
-        for (size_t __k = 1; __k <= __s; ++__k)
-        {
-            const size_t __kmodn = __k % __n;
-            const size_t __kpmodn = (__k + __p) % __n;
-            result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
-                                           ^ __first[(__k - 1) % __n]);
-            __first[__kpmodn] += __r;
-            __r +=  __kmodn + __v_[__k-1];
-            __first[(__k + __q) % __n] += __r;
-            __first[__kmodn] = __r;
-        }
-        for (size_t __k = __s + 1; __k < __m; ++__k)
-        {
-            const size_t __kmodn = __k % __n;
-            const size_t __kpmodn = (__k + __p) % __n;
-            result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn]
-                                           ^ __first[(__k - 1) % __n]);
-            __first[__kpmodn] += __r;
-            __r +=  __kmodn;
-            __first[(__k + __q) % __n] += __r;
-            __first[__kmodn] = __r;
-        }
-        for (size_t __k = __m; __k < __m + __n; ++__k)
-        {
-            const size_t __kmodn = __k % __n;
-            const size_t __kpmodn = (__k + __p) % __n;
-            result_type __r = 1566083941 * _Tp(__first[__kmodn] +
-                                              __first[__kpmodn] +
-                                              __first[(__k - 1) % __n]);
-            __first[__kpmodn] ^= __r;
-            __r -= __kmodn;
-            __first[(__k + __q) % __n] ^= __r;
-            __first[__kmodn] = __r;
-        }
-    }
-}
-
-// generate_canonical
-
-template<class _RealType, size_t __bits, class _URNG>
-_RealType
-generate_canonical(_URNG& __g)
-{
-    const size_t _Dt = numeric_limits<_RealType>::digits;
-    const size_t __b = _Dt < __bits ? _Dt : __bits;
-#ifdef _LIBCPP_CXX03_LANG
-    const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
-#else
-    const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value;
-#endif
-    const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
-    const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1);
-    _RealType __base = _Rp;
-    _RealType _Sp = __g() - _URNG::min();
-    for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp)
-        _Sp += (__g() - _URNG::min()) * __base;
-    return _Sp / __base;
-}
-
-// uniform_real_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS uniform_real_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __a_;
-        result_type __b_;
-    public:
-        typedef uniform_real_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __a = 0,
-                            result_type __b = 1)
-            : __a_(__a), __b_(__b) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type a() const {return __a_;}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type b() const {return __b_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    uniform_real_distribution() : uniform_real_distribution(0) {}
-    explicit uniform_real_distribution(result_type __a, result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type a() const {return __p_.a();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type b() const {return __p_.b();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return a();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return b();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const uniform_real_distribution& __x,
-                        const uniform_real_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const uniform_real_distribution& __x,
-                        const uniform_real_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template<class _RealType>
-template<class _URNG>
-inline
-typename uniform_real_distribution<_RealType>::result_type
-uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    return (__p.b() - __p.a())
-        * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
-        + __p.a();
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const uniform_real_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    return __os << __x.a() << __sp << __x.b();
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           uniform_real_distribution<_RT>& __x)
-{
-    typedef uniform_real_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __a;
-    result_type __b;
-    __is >> __a >> __b;
-    if (!__is.fail())
-        __x.param(param_type(__a, __b));
-    return __is;
-}
-
-// bernoulli_distribution
-
-class _LIBCPP_TEMPLATE_VIS bernoulli_distribution
-{
-public:
-    // types
-    typedef bool result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        double __p_;
-    public:
-        typedef bernoulli_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(double __p = 0.5) : __p_(__p) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        double p() const {return __p_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__p_ == __y.__p_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    bernoulli_distribution() : bernoulli_distribution(0.5) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit bernoulli_distribution(double __p) : __p_(param_type(__p)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit bernoulli_distribution(double __p = 0.5) : __p_(param_type(__p)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    double p() const {return __p_.p();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return false;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return true;}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const bernoulli_distribution& __x,
-                        const bernoulli_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const bernoulli_distribution& __x,
-                        const bernoulli_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template<class _URNG>
-inline
-bernoulli_distribution::result_type
-bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
-{
-    uniform_real_distribution<double> __gen;
-    return __gen(__g) < __p.p();
-}
-
-template <class _CharT, class _Traits>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    return __os << __x.p();
-}
-
-template <class _CharT, class _Traits>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x)
-{
-    typedef bernoulli_distribution _Eng;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    double __p;
-    __is >> __p;
-    if (!__is.fail())
-        __x.param(param_type(__p));
-    return __is;
-}
-
-// binomial_distribution
-
-template<class _IntType = int>
-class _LIBCPP_TEMPLATE_VIS binomial_distribution
-{
-public:
-    // types
-    typedef _IntType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __t_;
-        double __p_;
-        double __pr_;
-        double __odds_ratio_;
-        result_type __r0_;
-    public:
-        typedef binomial_distribution distribution_type;
-
-        explicit param_type(result_type __t = 1, double __p = 0.5);
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type t() const {return __t_;}
-        _LIBCPP_INLINE_VISIBILITY
-        double p() const {return __p_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-
-        friend class binomial_distribution;
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    binomial_distribution() : binomial_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit binomial_distribution(result_type __t, double __p = 0.5)
-        : __p_(param_type(__t, __p)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit binomial_distribution(result_type __t = 1, double __p = 0.5)
-        : __p_(param_type(__t, __p)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit binomial_distribution(const param_type& __p) : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type t() const {return __p_.t();}
-    _LIBCPP_INLINE_VISIBILITY
-    double p() const {return __p_.p();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return t();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const binomial_distribution& __x,
-                        const binomial_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const binomial_distribution& __x,
-                        const binomial_distribution& __y)
-        {return !(__x == __y);}
-};
-
-#ifndef _LIBCPP_MSVCRT_LIKE
-extern "C" double lgamma_r(double, int *);
-#endif
-
-inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) {
-#if defined(_LIBCPP_MSVCRT_LIKE)
-  return lgamma(__d);
-#else
-  int __sign;
-  return lgamma_r(__d, &__sign);
-#endif
-}
-
-template<class _IntType>
-binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p)
-    : __t_(__t), __p_(__p)
-{
-    if (0 < __p_ && __p_ < 1)
-    {
-        __r0_ = static_cast<result_type>((__t_ + 1) * __p_);
-        __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) -
-                           __libcpp_lgamma(__r0_ + 1.) -
-                           __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) +
-                           (__t_ - __r0_) * _VSTD::log(1 - __p_));
-        __odds_ratio_ = __p_ / (1 - __p_);
-    }
-}
-
-// Reference: Kemp, C.D. (1986). `A modal method for generating binomial
-//           variables', Commun. Statist. - Theor. Meth. 15(3), 805-813.
-template<class _IntType>
-template<class _URNG>
-_IntType
-binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
-{
-    if (__pr.__t_ == 0 || __pr.__p_ == 0)
-        return 0;
-    if (__pr.__p_ == 1)
-        return __pr.__t_;
-    uniform_real_distribution<double> __gen;
-    double __u = __gen(__g) - __pr.__pr_;
-    if (__u < 0)
-        return __pr.__r0_;
-    double __pu = __pr.__pr_;
-    double __pd = __pu;
-    result_type __ru = __pr.__r0_;
-    result_type __rd = __ru;
-    while (true)
-    {
-        bool __break = true;
-        if (__rd >= 1)
-        {
-            __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
-            __u -= __pd;
-            __break = false;
-            if (__u < 0)
-                return __rd - 1;
-        }
-        if ( __rd != 0 )
-            --__rd;
-        ++__ru;
-        if (__ru <= __pr.__t_)
-        {
-            __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
-            __u -= __pu;
-            __break = false;
-            if (__u < 0)
-                return __ru;
-        }
-        if (__break)
-            return 0;
-    }
-}
-
-template <class _CharT, class _Traits, class _IntType>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const binomial_distribution<_IntType>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    return __os << __x.t() << __sp << __x.p();
-}
-
-template <class _CharT, class _Traits, class _IntType>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           binomial_distribution<_IntType>& __x)
-{
-    typedef binomial_distribution<_IntType> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __t;
-    double __p;
-    __is >> __t >> __p;
-    if (!__is.fail())
-        __x.param(param_type(__t, __p));
-    return __is;
-}
-
-// exponential_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS exponential_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __lambda_;
-    public:
-        typedef exponential_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type lambda() const {return __lambda_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__lambda_ == __y.__lambda_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    exponential_distribution() : exponential_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit exponential_distribution(result_type __lambda)
-        : __p_(param_type(__lambda)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit exponential_distribution(result_type __lambda = 1)
-        : __p_(param_type(__lambda)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit exponential_distribution(const param_type& __p) : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type lambda() const {return __p_.lambda();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const exponential_distribution& __x,
-                        const exponential_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const exponential_distribution& __x,
-                        const exponential_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _RealType>
-template<class _URNG>
-_RealType
-exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    return -_VSTD::log
-                  (
-                      result_type(1) -
-                      _VSTD::generate_canonical<result_type,
-                                       numeric_limits<result_type>::digits>(__g)
-                  )
-                  / __p.lambda();
-}
-
-template <class _CharT, class _Traits, class _RealType>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const exponential_distribution<_RealType>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    return __os << __x.lambda();
-}
-
-template <class _CharT, class _Traits, class _RealType>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           exponential_distribution<_RealType>& __x)
-{
-    typedef exponential_distribution<_RealType> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __lambda;
-    __is >> __lambda;
-    if (!__is.fail())
-        __x.param(param_type(__lambda));
-    return __is;
-}
-
-// normal_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS normal_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __mean_;
-        result_type __stddev_;
-    public:
-        typedef normal_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __mean = 0, result_type __stddev = 1)
-            : __mean_(__mean), __stddev_(__stddev) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type mean() const {return __mean_;}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type stddev() const {return __stddev_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-    result_type _V_;
-    bool _V_hot_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    normal_distribution() : normal_distribution(0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit normal_distribution(result_type __mean, result_type __stddev = 1)
-        : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit normal_distribution(result_type __mean = 0,
-                                 result_type __stddev = 1)
-        : __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit normal_distribution(const param_type& __p)
-        : __p_(__p), _V_hot_(false) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {_V_hot_ = false;}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type mean() const {return __p_.mean();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type stddev() const {return __p_.stddev();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return -numeric_limits<result_type>::infinity();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const normal_distribution& __x,
-                        const normal_distribution& __y)
-        {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ &&
-                (!__x._V_hot_ || __x._V_ == __y._V_);}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const normal_distribution& __x,
-                        const normal_distribution& __y)
-        {return !(__x == __y);}
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const normal_distribution<_RT>& __x);
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               normal_distribution<_RT>& __x);
-};
-
-template <class _RealType>
-template<class _URNG>
-_RealType
-normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    result_type _Up;
-    if (_V_hot_)
-    {
-        _V_hot_ = false;
-        _Up = _V_;
-    }
-    else
-    {
-        uniform_real_distribution<result_type> _Uni(-1, 1);
-        result_type __u;
-        result_type __v;
-        result_type __s;
-        do
-        {
-            __u = _Uni(__g);
-            __v = _Uni(__g);
-            __s = __u * __u + __v * __v;
-        } while (__s > 1 || __s == 0);
-        result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s);
-        _V_ = __v * _Fp;
-        _V_hot_ = true;
-        _Up = __u * _Fp;
-    }
-    return _Up * __p.stddev() + __p.mean();
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const normal_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_;
-    if (__x._V_hot_)
-        __os << __sp << __x._V_;
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           normal_distribution<_RT>& __x)
-{
-    typedef normal_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __mean;
-    result_type __stddev;
-    result_type _Vp = 0;
-    bool _V_hot = false;
-    __is >> __mean >> __stddev >> _V_hot;
-    if (_V_hot)
-        __is >> _Vp;
-    if (!__is.fail())
-    {
-        __x.param(param_type(__mean, __stddev));
-        __x._V_hot_ = _V_hot;
-        __x._V_ = _Vp;
-    }
-    return __is;
-}
-
-// lognormal_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS lognormal_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        normal_distribution<result_type> __nd_;
-    public:
-        typedef lognormal_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __m = 0, result_type __s = 1)
-            : __nd_(__m, __s) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type m() const {return __nd_.mean();}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type s() const {return __nd_.stddev();}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__nd_ == __y.__nd_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-        friend class lognormal_distribution;
-
-        template <class _CharT, class _Traits, class _RT>
-        friend
-        basic_ostream<_CharT, _Traits>&
-        operator<<(basic_ostream<_CharT, _Traits>& __os,
-                   const lognormal_distribution<_RT>& __x);
-
-        template <class _CharT, class _Traits, class _RT>
-        friend
-        basic_istream<_CharT, _Traits>&
-        operator>>(basic_istream<_CharT, _Traits>& __is,
-                   lognormal_distribution<_RT>& __x);
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    lognormal_distribution() : lognormal_distribution(0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit lognormal_distribution(result_type __m, result_type __s = 1)
-        : __p_(param_type(__m, __s)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit lognormal_distribution(result_type __m = 0,
-                                    result_type __s = 1)
-        : __p_(param_type(__m, __s)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit lognormal_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {__p_.__nd_.reset();}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g, const param_type& __p)
-        {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));}
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type m() const {return __p_.m();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type s() const {return __p_.s();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const lognormal_distribution& __x,
-                        const lognormal_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const lognormal_distribution& __x,
-                        const lognormal_distribution& __y)
-        {return !(__x == __y);}
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const lognormal_distribution<_RT>& __x);
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               lognormal_distribution<_RT>& __x);
-};
-
-template <class _CharT, class _Traits, class _RT>
-inline _LIBCPP_INLINE_VISIBILITY
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const lognormal_distribution<_RT>& __x)
-{
-    return __os << __x.__p_.__nd_;
-}
-
-template <class _CharT, class _Traits, class _RT>
-inline _LIBCPP_INLINE_VISIBILITY
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           lognormal_distribution<_RT>& __x)
-{
-    return __is >> __x.__p_.__nd_;
-}
-
-// poisson_distribution
-
-template<class _IntType = int>
-class _LIBCPP_TEMPLATE_VIS poisson_distribution
-{
-public:
-    // types
-    typedef _IntType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        double __mean_;
-        double __s_;
-        double __d_;
-        double __l_;
-        double __omega_;
-        double __c0_;
-        double __c1_;
-        double __c2_;
-        double __c3_;
-        double __c_;
-
-    public:
-        typedef poisson_distribution distribution_type;
-
-        explicit param_type(double __mean = 1.0);
-
-        _LIBCPP_INLINE_VISIBILITY
-        double mean() const {return __mean_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__mean_ == __y.__mean_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-
-        friend class poisson_distribution;
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    poisson_distribution() : poisson_distribution(1.0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit poisson_distribution(double __mean)
-        : __p_(__mean) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit poisson_distribution(double __mean = 1.0)
-        : __p_(__mean) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit poisson_distribution(const param_type& __p) : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    double mean() const {return __p_.mean();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::max();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const poisson_distribution& __x,
-                        const poisson_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const poisson_distribution& __x,
-                        const poisson_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template<class _IntType>
-poisson_distribution<_IntType>::param_type::param_type(double __mean)
-    // According to the standard `inf` is a valid input, but it causes the
-    // distribution to hang, so we replace it with the maximum representable
-    // mean.
-    : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean)
-{
-    if (__mean_ < 10)
-    {
-        __s_ = 0;
-        __d_ = 0;
-        __l_ = _VSTD::exp(-__mean_);
-        __omega_ = 0;
-        __c3_ = 0;
-        __c2_ = 0;
-        __c1_ = 0;
-        __c0_ = 0;
-        __c_ = 0;
-    }
-    else
-    {
-        __s_ = _VSTD::sqrt(__mean_);
-        __d_ = 6 * __mean_ * __mean_;
-        __l_ = _VSTD::trunc(__mean_ - 1.1484);
-        __omega_ = .3989423 / __s_;
-        double __b1_ = .4166667E-1 / __mean_;
-        double __b2_ = .3 * __b1_ * __b1_;
-        __c3_ = .1428571 * __b1_ * __b2_;
-        __c2_ = __b2_ - 15. * __c3_;
-        __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_;
-        __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_;
-        __c_ = .1069 / __mean_;
-    }
-}
-
-template <class _IntType>
-template<class _URNG>
-_IntType
-poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
-{
-    double __tx;
-    uniform_real_distribution<double> __urd;
-    if (__pr.__mean_ < 10)
-    {
-         __tx = 0;
-        for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx)
-            __p *= __urd(__urng);
-    }
-    else
-    {
-        double __difmuk;
-        double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng);
-        double __u;
-        if (__g > 0)
-        {
-            __tx = _VSTD::trunc(__g);
-            if (__tx >= __pr.__l_)
-                return _VSTD::__clamp_to_integral<result_type>(__tx);
-            __difmuk = __pr.__mean_ - __tx;
-            __u = __urd(__urng);
-            if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk)
-                return _VSTD::__clamp_to_integral<result_type>(__tx);
-        }
-        exponential_distribution<double> __edist;
-        for (bool __using_exp_dist = false; true; __using_exp_dist = true)
-        {
-            double __e;
-            if (__using_exp_dist || __g <= 0)
-            {
-                double __t;
-                do
-                {
-                    __e = __edist(__urng);
-                    __u = __urd(__urng);
-                    __u += __u - 1;
-                    __t = 1.8 + (__u < 0 ? -__e : __e);
-                } while (__t <= -.6744);
-                __tx = _VSTD::trunc(__pr.__mean_ + __pr.__s_ * __t);
-                __difmuk = __pr.__mean_ - __tx;
-                __using_exp_dist = true;
-            }
-            double __px;
-            double __py;
-            if (__tx < 10 && __tx >= 0)
-            {
-                const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
-                                             40320, 362880};
-                __px = -__pr.__mean_;
-                __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)];
-            }
-            else
-            {
-                double __del = .8333333E-1 / __tx;
-                __del -= 4.8 * __del * __del * __del;
-                double __v = __difmuk / __tx;
-                if (_VSTD::abs(__v) > 0.25)
-                    __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del;
-                else
-                    __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) *
-                           __v + .1421878) * __v + -.1661269) * __v + .2000118) *
-                           __v + -.2500068) * __v + .3333333) * __v + -.5) - __del;
-                __py = .3989423 / _VSTD::sqrt(__tx);
-            }
-            double __r = (0.5 - __difmuk) / __pr.__s_;
-            double __r2 = __r * __r;
-            double __fx = -0.5 * __r2;
-            double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) *
-                                        __r2 + __pr.__c1_) * __r2 + __pr.__c0_);
-            if (__using_exp_dist)
-            {
-                if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) -
-                                                   __fy * _VSTD::exp(__fx + __e))
-                    break;
-            }
-            else
-            {
-                if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx))
-                    break;
-            }
-        }
-    }
-    return _VSTD::__clamp_to_integral<result_type>(__tx);
-}
-
-template <class _CharT, class _Traits, class _IntType>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const poisson_distribution<_IntType>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    return __os << __x.mean();
-}
-
-template <class _CharT, class _Traits, class _IntType>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           poisson_distribution<_IntType>& __x)
-{
-    typedef poisson_distribution<_IntType> _Eng;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    double __mean;
-    __is >> __mean;
-    if (!__is.fail())
-        __x.param(param_type(__mean));
-    return __is;
-}
-
-// weibull_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS weibull_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __a_;
-        result_type __b_;
-    public:
-        typedef weibull_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __a = 1, result_type __b = 1)
-            : __a_(__a), __b_(__b) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type a() const {return __a_;}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type b() const {return __b_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    weibull_distribution() : weibull_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit weibull_distribution(result_type __a, result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit weibull_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g, const param_type& __p)
-        {return __p.b() *
-            _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());}
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type a() const {return __p_.a();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type b() const {return __p_.b();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const weibull_distribution& __x,
-                        const weibull_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const weibull_distribution& __x,
-                        const weibull_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const weibull_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.a() << __sp << __x.b();
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           weibull_distribution<_RT>& __x)
-{
-    typedef weibull_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __a;
-    result_type __b;
-    __is >> __a >> __b;
-    if (!__is.fail())
-        __x.param(param_type(__a, __b));
-    return __is;
-}
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS extreme_value_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __a_;
-        result_type __b_;
-    public:
-        typedef extreme_value_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __a = 0, result_type __b = 1)
-            : __a_(__a), __b_(__b) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type a() const {return __a_;}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type b() const {return __b_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    extreme_value_distribution() : extreme_value_distribution(0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit extreme_value_distribution(result_type __a, result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit extreme_value_distribution(result_type __a = 0,
-                                        result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit extreme_value_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type a() const {return __p_.a();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type b() const {return __p_.b();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return -numeric_limits<result_type>::infinity();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const extreme_value_distribution& __x,
-                        const extreme_value_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const extreme_value_distribution& __x,
-                        const extreme_value_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template<class _RealType>
-template<class _URNG>
-_RealType
-extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    return __p.a() - __p.b() *
-         _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g)));
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const extreme_value_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.a() << __sp << __x.b();
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           extreme_value_distribution<_RT>& __x)
-{
-    typedef extreme_value_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __a;
-    result_type __b;
-    __is >> __a >> __b;
-    if (!__is.fail())
-        __x.param(param_type(__a, __b));
-    return __is;
-}
-
-// gamma_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS gamma_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __alpha_;
-        result_type __beta_;
-    public:
-        typedef gamma_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __alpha = 1, result_type __beta = 1)
-            : __alpha_(__alpha), __beta_(__beta) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type alpha() const {return __alpha_;}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type beta() const {return __beta_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    gamma_distribution() : gamma_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit gamma_distribution(result_type __alpha, result_type __beta = 1)
-        : __p_(param_type(__alpha, __beta)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit gamma_distribution(result_type __alpha = 1,
-                                result_type __beta = 1)
-        : __p_(param_type(__alpha, __beta)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit gamma_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type alpha() const {return __p_.alpha();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type beta() const {return __p_.beta();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const gamma_distribution& __x,
-                        const gamma_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const gamma_distribution& __x,
-                        const gamma_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _RealType>
-template<class _URNG>
-_RealType
-gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    result_type __a = __p.alpha();
-    uniform_real_distribution<result_type> __gen(0, 1);
-    exponential_distribution<result_type> __egen;
-    result_type __x;
-    if (__a == 1)
-        __x = __egen(__g);
-    else if (__a > 1)
-    {
-        const result_type __b = __a - 1;
-        const result_type __c = 3 * __a - result_type(0.75);
-        while (true)
-        {
-            const result_type __u = __gen(__g);
-            const result_type __v = __gen(__g);
-            const result_type __w = __u * (1 - __u);
-            if (__w != 0)
-            {
-                const result_type __y = _VSTD::sqrt(__c / __w) *
-                                        (__u - result_type(0.5));
-                __x = __b + __y;
-                if (__x >= 0)
-                {
-                    const result_type __z = 64 * __w * __w * __w * __v * __v;
-                    if (__z <= 1 - 2 * __y * __y / __x)
-                        break;
-                    if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y))
-                        break;
-                }
-            }
-        }
-    }
-    else  // __a < 1
-    {
-        while (true)
-        {
-            const result_type __u = __gen(__g);
-            const result_type __es = __egen(__g);
-            if (__u <= 1 - __a)
-            {
-                __x = _VSTD::pow(__u, 1 / __a);
-                if (__x <= __es)
-                    break;
-            }
-            else
-            {
-                const result_type __e = -_VSTD::log((1-__u)/__a);
-                __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a);
-                if (__x <= __e + __es)
-                    break;
-            }
-        }
-    }
-    return __x * __p.beta();
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const gamma_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.alpha() << __sp << __x.beta();
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           gamma_distribution<_RT>& __x)
-{
-    typedef gamma_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __alpha;
-    result_type __beta;
-    __is >> __alpha >> __beta;
-    if (!__is.fail())
-        __x.param(param_type(__alpha, __beta));
-    return __is;
-}
-
-// negative_binomial_distribution
-
-template<class _IntType = int>
-class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution
-{
-public:
-    // types
-    typedef _IntType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __k_;
-        double __p_;
-    public:
-        typedef negative_binomial_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __k = 1, double __p = 0.5)
-            : __k_(__k), __p_(__p) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type k() const {return __k_;}
-        _LIBCPP_INLINE_VISIBILITY
-        double p() const {return __p_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    negative_binomial_distribution() : negative_binomial_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit negative_binomial_distribution(result_type __k, double __p = 0.5)
-        : __p_(__k, __p) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit negative_binomial_distribution(result_type __k = 1,
-                                            double __p = 0.5)
-        : __p_(__k, __p) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type k() const {return __p_.k();}
-    _LIBCPP_INLINE_VISIBILITY
-    double p() const {return __p_.p();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::max();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const negative_binomial_distribution& __x,
-                        const negative_binomial_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const negative_binomial_distribution& __x,
-                        const negative_binomial_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _IntType>
-template<class _URNG>
-_IntType
-negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr)
-{
-    result_type __k = __pr.k();
-    double __p = __pr.p();
-    if (__k <= 21 * __p)
-    {
-        bernoulli_distribution __gen(__p);
-        result_type __f = 0;
-        result_type __s = 0;
-        while (__s < __k)
-        {
-            if (__gen(__urng))
-                ++__s;
-            else
-                ++__f;
-        }
-        return __f;
-    }
-    return poisson_distribution<result_type>(gamma_distribution<double>
-                                            (__k, (1-__p)/__p)(__urng))(__urng);
-}
-
-template <class _CharT, class _Traits, class _IntType>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const negative_binomial_distribution<_IntType>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    return __os << __x.k() << __sp << __x.p();
-}
-
-template <class _CharT, class _Traits, class _IntType>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           negative_binomial_distribution<_IntType>& __x)
-{
-    typedef negative_binomial_distribution<_IntType> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __k;
-    double __p;
-    __is >> __k >> __p;
-    if (!__is.fail())
-        __x.param(param_type(__k, __p));
-    return __is;
-}
-
-// geometric_distribution
-
-template<class _IntType = int>
-class _LIBCPP_TEMPLATE_VIS geometric_distribution
-{
-public:
-    // types
-    typedef _IntType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        double __p_;
-    public:
-        typedef geometric_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(double __p = 0.5) : __p_(__p) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        double p() const {return __p_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__p_ == __y.__p_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructors and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    geometric_distribution() : geometric_distribution(0.5) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit geometric_distribution(double __p)
-        : __p_(__p) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit geometric_distribution(double __p = 0.5)
-        : __p_(__p) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit geometric_distribution(const param_type& __p) : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g, const param_type& __p)
-        {return negative_binomial_distribution<result_type>(1, __p.p())(__g);}
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    double p() const {return __p_.p();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::max();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const geometric_distribution& __x,
-                        const geometric_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const geometric_distribution& __x,
-                        const geometric_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _CharT, class _Traits, class _IntType>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const geometric_distribution<_IntType>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    return __os << __x.p();
-}
-
-template <class _CharT, class _Traits, class _IntType>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           geometric_distribution<_IntType>& __x)
-{
-    typedef geometric_distribution<_IntType> _Eng;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    double __p;
-    __is >> __p;
-    if (!__is.fail())
-        __x.param(param_type(__p));
-    return __is;
-}
-
-// chi_squared_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS chi_squared_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __n_;
-    public:
-        typedef chi_squared_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __n = 1) : __n_(__n) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type n() const {return __n_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__n_ == __y.__n_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    chi_squared_distribution() : chi_squared_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit chi_squared_distribution(result_type __n)
-        : __p_(param_type(__n)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit chi_squared_distribution(result_type __n = 1)
-        : __p_(param_type(__n)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit chi_squared_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g, const param_type& __p)
-        {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);}
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type n() const {return __p_.n();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const chi_squared_distribution& __x,
-                        const chi_squared_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const chi_squared_distribution& __x,
-                        const chi_squared_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const chi_squared_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    __os << __x.n();
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           chi_squared_distribution<_RT>& __x)
-{
-    typedef chi_squared_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __n;
-    __is >> __n;
-    if (!__is.fail())
-        __x.param(param_type(__n));
-    return __is;
-}
-
-// cauchy_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS cauchy_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __a_;
-        result_type __b_;
-    public:
-        typedef cauchy_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __a = 0, result_type __b = 1)
-            : __a_(__a), __b_(__b) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type a() const {return __a_;}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type b() const {return __b_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    cauchy_distribution() : cauchy_distribution(0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit cauchy_distribution(result_type __a, result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit cauchy_distribution(result_type __a = 0, result_type __b = 1)
-        : __p_(param_type(__a, __b)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit cauchy_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type a() const {return __p_.a();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type b() const {return __p_.b();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return -numeric_limits<result_type>::infinity();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const cauchy_distribution& __x,
-                        const cauchy_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const cauchy_distribution& __x,
-                        const cauchy_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _RealType>
-template<class _URNG>
-inline
-_RealType
-cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    uniform_real_distribution<result_type> __gen;
-    // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
-    return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g));
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const cauchy_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.a() << __sp << __x.b();
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           cauchy_distribution<_RT>& __x)
-{
-    typedef cauchy_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __a;
-    result_type __b;
-    __is >> __a >> __b;
-    if (!__is.fail())
-        __x.param(param_type(__a, __b));
-    return __is;
-}
-
-// fisher_f_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS fisher_f_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __m_;
-        result_type __n_;
-    public:
-        typedef fisher_f_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __m = 1, result_type __n = 1)
-            : __m_(__m), __n_(__n) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type m() const {return __m_;}
-        _LIBCPP_INLINE_VISIBILITY
-        result_type n() const {return __n_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    fisher_f_distribution() : fisher_f_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit fisher_f_distribution(result_type __m, result_type __n = 1)
-        : __p_(param_type(__m, __n)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
-        : __p_(param_type(__m, __n)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit fisher_f_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type m() const {return __p_.m();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type n() const {return __p_.n();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const fisher_f_distribution& __x,
-                        const fisher_f_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const fisher_f_distribution& __x,
-                        const fisher_f_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _RealType>
-template<class _URNG>
-_RealType
-fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
-    gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
-    return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const fisher_f_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    __os << __x.m() << __sp << __x.n();
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           fisher_f_distribution<_RT>& __x)
-{
-    typedef fisher_f_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __m;
-    result_type __n;
-    __is >> __m >> __n;
-    if (!__is.fail())
-        __x.param(param_type(__m, __n));
-    return __is;
-}
-
-// student_t_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS student_t_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        result_type __n_;
-    public:
-        typedef student_t_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        explicit param_type(result_type __n = 1) : __n_(__n) {}
-
-        _LIBCPP_INLINE_VISIBILITY
-        result_type n() const {return __n_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__n_ == __y.__n_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-    };
-
-private:
-    param_type __p_;
-    normal_distribution<result_type> __nd_;
-
-public:
-    // constructor and reset functions
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    student_t_distribution() : student_t_distribution(1) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit student_t_distribution(result_type __n)
-        : __p_(param_type(__n)) {}
-#else
-    _LIBCPP_INLINE_VISIBILITY
-    explicit student_t_distribution(result_type __n = 1)
-        : __p_(param_type(__n)) {}
-#endif
-    _LIBCPP_INLINE_VISIBILITY
-    explicit student_t_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {__nd_.reset();}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    result_type n() const {return __p_.n();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return -numeric_limits<result_type>::infinity();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return numeric_limits<result_type>::infinity();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const student_t_distribution& __x,
-                        const student_t_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const student_t_distribution& __x,
-                        const student_t_distribution& __y)
-        {return !(__x == __y);}
-};
-
-template <class _RealType>
-template<class _URNG>
-_RealType
-student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    gamma_distribution<result_type> __gd(__p.n() * .5, 2);
-    return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g));
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const student_t_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    __os << __x.n();
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           student_t_distribution<_RT>& __x)
-{
-    typedef student_t_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    result_type __n;
-    __is >> __n;
-    if (!__is.fail())
-        __x.param(param_type(__n));
-    return __is;
-}
-
-// discrete_distribution
-
-template<class _IntType = int>
-class _LIBCPP_TEMPLATE_VIS discrete_distribution
-{
-public:
-    // types
-    typedef _IntType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        vector<double> __p_;
-    public:
-        typedef discrete_distribution distribution_type;
-
-        _LIBCPP_INLINE_VISIBILITY
-        param_type() {}
-        template<class _InputIterator>
-            _LIBCPP_INLINE_VISIBILITY
-            param_type(_InputIterator __f, _InputIterator __l)
-            : __p_(__f, __l) {__init();}
-#ifndef _LIBCPP_CXX03_LANG
-        _LIBCPP_INLINE_VISIBILITY
-        param_type(initializer_list<double> __wl)
-            : __p_(__wl.begin(), __wl.end()) {__init();}
-#endif // _LIBCPP_CXX03_LANG
-        template<class _UnaryOperation>
-            param_type(size_t __nw, double __xmin, double __xmax,
-                       _UnaryOperation __fw);
-
-        vector<double> probabilities() const;
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__p_ == __y.__p_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-
-    private:
-        void __init();
-
-        friend class discrete_distribution;
-
-        template <class _CharT, class _Traits, class _IT>
-        friend
-        basic_ostream<_CharT, _Traits>&
-        operator<<(basic_ostream<_CharT, _Traits>& __os,
-                   const discrete_distribution<_IT>& __x);
-
-        template <class _CharT, class _Traits, class _IT>
-        friend
-        basic_istream<_CharT, _Traits>&
-        operator>>(basic_istream<_CharT, _Traits>& __is,
-                   discrete_distribution<_IT>& __x);
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-    _LIBCPP_INLINE_VISIBILITY
-    discrete_distribution() {}
-    template<class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
-        discrete_distribution(_InputIterator __f, _InputIterator __l)
-            : __p_(__f, __l) {}
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    discrete_distribution(initializer_list<double> __wl)
-        : __p_(__wl) {}
-#endif // _LIBCPP_CXX03_LANG
-    template<class _UnaryOperation>
-        _LIBCPP_INLINE_VISIBILITY
-        discrete_distribution(size_t __nw, double __xmin, double __xmax,
-                              _UnaryOperation __fw)
-        : __p_(__nw, __xmin, __xmax, __fw) {}
-    _LIBCPP_INLINE_VISIBILITY
-    explicit discrete_distribution(const param_type& __p)
-        : __p_(__p) {}
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    vector<double> probabilities() const {return __p_.probabilities();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return 0;}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return __p_.__p_.size();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const discrete_distribution& __x,
-                        const discrete_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const discrete_distribution& __x,
-                        const discrete_distribution& __y)
-        {return !(__x == __y);}
-
-    template <class _CharT, class _Traits, class _IT>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const discrete_distribution<_IT>& __x);
-
-    template <class _CharT, class _Traits, class _IT>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               discrete_distribution<_IT>& __x);
-};
-
-template<class _IntType>
-template<class _UnaryOperation>
-discrete_distribution<_IntType>::param_type::param_type(size_t __nw,
-                                                        double __xmin,
-                                                        double __xmax,
-                                                        _UnaryOperation __fw)
-{
-    if (__nw > 1)
-    {
-        __p_.reserve(__nw - 1);
-        double __d = (__xmax - __xmin) / __nw;
-        double __d2 = __d / 2;
-        for (size_t __k = 0; __k < __nw; ++__k)
-            __p_.push_back(__fw(__xmin + __k * __d + __d2));
-        __init();
-    }
-}
-
-template<class _IntType>
-void
-discrete_distribution<_IntType>::param_type::__init()
-{
-    if (!__p_.empty())
-    {
-        if (__p_.size() > 1)
-        {
-            double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0);
-            for (vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); __i < __e; ++__i)
-                *__i /= __s;
-            vector<double> __t(__p_.size() - 1);
-            _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin());
-            swap(__p_, __t);
-        }
-        else
-        {
-            __p_.clear();
-            __p_.shrink_to_fit();
-        }
-    }
-}
-
-template<class _IntType>
-vector<double>
-discrete_distribution<_IntType>::param_type::probabilities() const
-{
-    size_t __n = __p_.size();
-    vector<double> __p(__n+1);
-    _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin());
-    if (__n > 0)
-        __p[__n] = 1 - __p_[__n-1];
-    else
-        __p[0] = 1;
-    return __p;
-}
-
-template<class _IntType>
-template<class _URNG>
-_IntType
-discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
-{
-    uniform_real_distribution<double> __gen;
-    return static_cast<_IntType>(
-           _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) -
-                                                              __p.__p_.begin());
-}
-
-template <class _CharT, class _Traits, class _IT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const discrete_distribution<_IT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    size_t __n = __x.__p_.__p_.size();
-    __os << __n;
-    for (size_t __i = 0; __i < __n; ++__i)
-        __os << __sp << __x.__p_.__p_[__i];
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _IT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           discrete_distribution<_IT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    size_t __n;
-    __is >> __n;
-    vector<double> __p(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __is >> __p[__i];
-    if (!__is.fail())
-        swap(__x.__p_.__p_, __p);
-    return __is;
-}
-
-// piecewise_constant_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        vector<result_type> __b_;
-        vector<result_type> __densities_;
-        vector<result_type> __areas_;
-    public:
-        typedef piecewise_constant_distribution distribution_type;
-
-        param_type();
-        template<class _InputIteratorB, class _InputIteratorW>
-            param_type(_InputIteratorB __fB, _InputIteratorB __lB,
-                       _InputIteratorW __fW);
-#ifndef _LIBCPP_CXX03_LANG
-        template<class _UnaryOperation>
-            param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
-#endif // _LIBCPP_CXX03_LANG
-        template<class _UnaryOperation>
-            param_type(size_t __nw, result_type __xmin, result_type __xmax,
-                       _UnaryOperation __fw);
-        param_type(param_type const&) = default;
-        param_type & operator=(const param_type& __rhs);
-
-        _LIBCPP_INLINE_VISIBILITY
-        vector<result_type> intervals() const {return __b_;}
-        _LIBCPP_INLINE_VISIBILITY
-        vector<result_type> densities() const {return __densities_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-
-    private:
-        void __init();
-
-        friend class piecewise_constant_distribution;
-
-        template <class _CharT, class _Traits, class _RT>
-        friend
-        basic_ostream<_CharT, _Traits>&
-        operator<<(basic_ostream<_CharT, _Traits>& __os,
-                   const piecewise_constant_distribution<_RT>& __x);
-
-        template <class _CharT, class _Traits, class _RT>
-        friend
-        basic_istream<_CharT, _Traits>&
-        operator>>(basic_istream<_CharT, _Traits>& __is,
-                   piecewise_constant_distribution<_RT>& __x);
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-    _LIBCPP_INLINE_VISIBILITY
-    piecewise_constant_distribution() {}
-    template<class _InputIteratorB, class _InputIteratorW>
-        _LIBCPP_INLINE_VISIBILITY
-        piecewise_constant_distribution(_InputIteratorB __fB,
-                                        _InputIteratorB __lB,
-                                        _InputIteratorW __fW)
-        : __p_(__fB, __lB, __fW) {}
-
-#ifndef _LIBCPP_CXX03_LANG
-    template<class _UnaryOperation>
-        _LIBCPP_INLINE_VISIBILITY
-        piecewise_constant_distribution(initializer_list<result_type> __bl,
-                                        _UnaryOperation __fw)
-        : __p_(__bl, __fw) {}
-#endif // _LIBCPP_CXX03_LANG
-
-    template<class _UnaryOperation>
-        _LIBCPP_INLINE_VISIBILITY
-        piecewise_constant_distribution(size_t __nw, result_type __xmin,
-                                        result_type __xmax, _UnaryOperation __fw)
-        : __p_(__nw, __xmin, __xmax, __fw) {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    explicit piecewise_constant_distribution(const param_type& __p)
-        : __p_(__p) {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    vector<result_type> intervals() const {return __p_.intervals();}
-    _LIBCPP_INLINE_VISIBILITY
-    vector<result_type> densities() const {return __p_.densities();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return __p_.__b_.front();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return __p_.__b_.back();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const piecewise_constant_distribution& __x,
-                        const piecewise_constant_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const piecewise_constant_distribution& __x,
-                           const piecewise_constant_distribution& __y)
-        {return !(__x == __y);}
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const piecewise_constant_distribution<_RT>& __x);
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               piecewise_constant_distribution<_RT>& __x);
-};
-
-template<class _RealType>
-typename piecewise_constant_distribution<_RealType>::param_type &
-piecewise_constant_distribution<_RealType>::param_type::operator=
-                                                       (const param_type& __rhs)
-{
-//  These can throw
-    __b_.reserve        (__rhs.__b_.size ());
-    __densities_.reserve(__rhs.__densities_.size());
-    __areas_.reserve    (__rhs.__areas_.size());
-
-//  These can not throw
-    __b_         = __rhs.__b_;
-    __densities_ = __rhs.__densities_;
-    __areas_     =  __rhs.__areas_;
-    return *this;
-}
-
-template<class _RealType>
-void
-piecewise_constant_distribution<_RealType>::param_type::__init()
-{
-    // __densities_ contains non-normalized areas
-    result_type __total_area = _VSTD::accumulate(__densities_.begin(),
-                                                __densities_.end(),
-                                                result_type());
-    for (size_t __i = 0; __i < __densities_.size(); ++__i)
-        __densities_[__i] /= __total_area;
-    // __densities_ contains normalized areas
-    __areas_.assign(__densities_.size(), result_type());
-    _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1,
-                                                          __areas_.begin() + 1);
-    // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
-    __densities_.back() = 1 - __areas_.back();  // correct round off error
-    for (size_t __i = 0; __i < __densities_.size(); ++__i)
-        __densities_[__i] /= (__b_[__i+1] - __b_[__i]);
-    // __densities_ now contains __densities_
-}
-
-template<class _RealType>
-piecewise_constant_distribution<_RealType>::param_type::param_type()
-    : __b_(2),
-      __densities_(1, 1.0),
-      __areas_(1, 0.0)
-{
-    __b_[1] = 1;
-}
-
-template<class _RealType>
-template<class _InputIteratorB, class _InputIteratorW>
-piecewise_constant_distribution<_RealType>::param_type::param_type(
-        _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
-    : __b_(__fB, __lB)
-{
-    if (__b_.size() < 2)
-    {
-        __b_.resize(2);
-        __b_[0] = 0;
-        __b_[1] = 1;
-        __densities_.assign(1, 1.0);
-        __areas_.assign(1, 0.0);
-    }
-    else
-    {
-        __densities_.reserve(__b_.size() - 1);
-        for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW)
-            __densities_.push_back(*__fW);
-        __init();
-    }
-}
-
-#ifndef _LIBCPP_CXX03_LANG
-
-template<class _RealType>
-template<class _UnaryOperation>
-piecewise_constant_distribution<_RealType>::param_type::param_type(
-        initializer_list<result_type> __bl, _UnaryOperation __fw)
-    : __b_(__bl.begin(), __bl.end())
-{
-    if (__b_.size() < 2)
-    {
-        __b_.resize(2);
-        __b_[0] = 0;
-        __b_[1] = 1;
-        __densities_.assign(1, 1.0);
-        __areas_.assign(1, 0.0);
-    }
-    else
-    {
-        __densities_.reserve(__b_.size() - 1);
-        for (size_t __i = 0; __i < __b_.size() - 1; ++__i)
-            __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5));
-        __init();
-    }
-}
-
-#endif // _LIBCPP_CXX03_LANG
-
-template<class _RealType>
-template<class _UnaryOperation>
-piecewise_constant_distribution<_RealType>::param_type::param_type(
-        size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
-    : __b_(__nw == 0 ? 2 : __nw + 1)
-{
-    size_t __n = __b_.size() - 1;
-    result_type __d = (__xmax - __xmin) / __n;
-    __densities_.reserve(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-    {
-        __b_[__i] = __xmin + __i * __d;
-        __densities_.push_back(__fw(__b_[__i] + __d*.5));
-    }
-    __b_[__n] = __xmax;
-    __init();
-}
-
-template<class _RealType>
-template<class _URNG>
-_RealType
-piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    typedef uniform_real_distribution<result_type> _Gen;
-    result_type __u = _Gen()(__g);
-    ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
-                                      __u) - __p.__areas_.begin() - 1;
-    return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k];
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const piecewise_constant_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    size_t __n = __x.__p_.__b_.size();
-    __os << __n;
-    for (size_t __i = 0; __i < __n; ++__i)
-        __os << __sp << __x.__p_.__b_[__i];
-    __n = __x.__p_.__densities_.size();
-    __os << __sp << __n;
-    for (size_t __i = 0; __i < __n; ++__i)
-        __os << __sp << __x.__p_.__densities_[__i];
-    __n = __x.__p_.__areas_.size();
-    __os << __sp << __n;
-    for (size_t __i = 0; __i < __n; ++__i)
-        __os << __sp << __x.__p_.__areas_[__i];
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           piecewise_constant_distribution<_RT>& __x)
-{
-    typedef piecewise_constant_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    size_t __n;
-    __is >> __n;
-    vector<result_type> __b(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __is >> __b[__i];
-    __is >> __n;
-    vector<result_type> __densities(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __is >> __densities[__i];
-    __is >> __n;
-    vector<result_type> __areas(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __is >> __areas[__i];
-    if (!__is.fail())
-    {
-        swap(__x.__p_.__b_, __b);
-        swap(__x.__p_.__densities_, __densities);
-        swap(__x.__p_.__areas_, __areas);
-    }
-    return __is;
-}
-
-// piecewise_linear_distribution
-
-template<class _RealType = double>
-class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution
-{
-public:
-    // types
-    typedef _RealType result_type;
-
-    class _LIBCPP_TEMPLATE_VIS param_type
-    {
-        vector<result_type> __b_;
-        vector<result_type> __densities_;
-        vector<result_type> __areas_;
-    public:
-        typedef piecewise_linear_distribution distribution_type;
-
-        param_type();
-        template<class _InputIteratorB, class _InputIteratorW>
-            param_type(_InputIteratorB __fB, _InputIteratorB __lB,
-                       _InputIteratorW __fW);
-#ifndef _LIBCPP_CXX03_LANG
-        template<class _UnaryOperation>
-            param_type(initializer_list<result_type> __bl, _UnaryOperation __fw);
-#endif // _LIBCPP_CXX03_LANG
-        template<class _UnaryOperation>
-            param_type(size_t __nw, result_type __xmin, result_type __xmax,
-                       _UnaryOperation __fw);
-        param_type(param_type const&) = default;
-        param_type & operator=(const param_type& __rhs);
-
-        _LIBCPP_INLINE_VISIBILITY
-        vector<result_type> intervals() const {return __b_;}
-        _LIBCPP_INLINE_VISIBILITY
-        vector<result_type> densities() const {return __densities_;}
-
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator==(const param_type& __x, const param_type& __y)
-            {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;}
-        friend _LIBCPP_INLINE_VISIBILITY
-            bool operator!=(const param_type& __x, const param_type& __y)
-            {return !(__x == __y);}
-
-    private:
-        void __init();
-
-        friend class piecewise_linear_distribution;
-
-        template <class _CharT, class _Traits, class _RT>
-        friend
-        basic_ostream<_CharT, _Traits>&
-        operator<<(basic_ostream<_CharT, _Traits>& __os,
-                   const piecewise_linear_distribution<_RT>& __x);
-
-        template <class _CharT, class _Traits, class _RT>
-        friend
-        basic_istream<_CharT, _Traits>&
-        operator>>(basic_istream<_CharT, _Traits>& __is,
-                   piecewise_linear_distribution<_RT>& __x);
-    };
-
-private:
-    param_type __p_;
-
-public:
-    // constructor and reset functions
-    _LIBCPP_INLINE_VISIBILITY
-    piecewise_linear_distribution() {}
-    template<class _InputIteratorB, class _InputIteratorW>
-        _LIBCPP_INLINE_VISIBILITY
-        piecewise_linear_distribution(_InputIteratorB __fB,
-                                      _InputIteratorB __lB,
-                                      _InputIteratorW __fW)
-        : __p_(__fB, __lB, __fW) {}
-
-#ifndef _LIBCPP_CXX03_LANG
-    template<class _UnaryOperation>
-        _LIBCPP_INLINE_VISIBILITY
-        piecewise_linear_distribution(initializer_list<result_type> __bl,
-                                      _UnaryOperation __fw)
-        : __p_(__bl, __fw) {}
-#endif // _LIBCPP_CXX03_LANG
-
-    template<class _UnaryOperation>
-        _LIBCPP_INLINE_VISIBILITY
-        piecewise_linear_distribution(size_t __nw, result_type __xmin,
-                                      result_type __xmax, _UnaryOperation __fw)
-        : __p_(__nw, __xmin, __xmax, __fw) {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    explicit piecewise_linear_distribution(const param_type& __p)
-        : __p_(__p) {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    void reset() {}
-
-    // generating functions
-    template<class _URNG>
-        _LIBCPP_INLINE_VISIBILITY
-        result_type operator()(_URNG& __g)
-        {return (*this)(__g, __p_);}
-    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
-
-    // property functions
-    _LIBCPP_INLINE_VISIBILITY
-    vector<result_type> intervals() const {return __p_.intervals();}
-    _LIBCPP_INLINE_VISIBILITY
-    vector<result_type> densities() const {return __p_.densities();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    param_type param() const {return __p_;}
-    _LIBCPP_INLINE_VISIBILITY
-    void param(const param_type& __p) {__p_ = __p;}
-
-    _LIBCPP_INLINE_VISIBILITY
-    result_type min() const {return __p_.__b_.front();}
-    _LIBCPP_INLINE_VISIBILITY
-    result_type max() const {return __p_.__b_.back();}
-
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(const piecewise_linear_distribution& __x,
-                        const piecewise_linear_distribution& __y)
-        {return __x.__p_ == __y.__p_;}
-    friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(const piecewise_linear_distribution& __x,
-                        const piecewise_linear_distribution& __y)
-        {return !(__x == __y);}
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_ostream<_CharT, _Traits>&
-    operator<<(basic_ostream<_CharT, _Traits>& __os,
-               const piecewise_linear_distribution<_RT>& __x);
-
-    template <class _CharT, class _Traits, class _RT>
-    friend
-    basic_istream<_CharT, _Traits>&
-    operator>>(basic_istream<_CharT, _Traits>& __is,
-               piecewise_linear_distribution<_RT>& __x);
-};
-
-template<class _RealType>
-typename piecewise_linear_distribution<_RealType>::param_type &
-piecewise_linear_distribution<_RealType>::param_type::operator=
-                                                       (const param_type& __rhs)
-{
-//  These can throw
-    __b_.reserve        (__rhs.__b_.size ());
-    __densities_.reserve(__rhs.__densities_.size());
-    __areas_.reserve    (__rhs.__areas_.size());
-
-//  These can not throw
-    __b_         = __rhs.__b_;
-    __densities_ = __rhs.__densities_;
-    __areas_     =  __rhs.__areas_;
-    return *this;
-}
-
-
-template<class _RealType>
-void
-piecewise_linear_distribution<_RealType>::param_type::__init()
-{
-    __areas_.assign(__densities_.size() - 1, result_type());
-    result_type _Sp = 0;
-    for (size_t __i = 0; __i < __areas_.size(); ++__i)
-    {
-        __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
-                        (__b_[__i+1] - __b_[__i]) * .5;
-        _Sp += __areas_[__i];
-    }
-    for (size_t __i = __areas_.size(); __i > 1;)
-    {
-        --__i;
-        __areas_[__i] = __areas_[__i-1] / _Sp;
-    }
-    __areas_[0] = 0;
-    for (size_t __i = 1; __i < __areas_.size(); ++__i)
-        __areas_[__i] += __areas_[__i-1];
-    for (size_t __i = 0; __i < __densities_.size(); ++__i)
-        __densities_[__i] /= _Sp;
-}
-
-template<class _RealType>
-piecewise_linear_distribution<_RealType>::param_type::param_type()
-    : __b_(2),
-      __densities_(2, 1.0),
-      __areas_(1, 0.0)
-{
-    __b_[1] = 1;
-}
-
-template<class _RealType>
-template<class _InputIteratorB, class _InputIteratorW>
-piecewise_linear_distribution<_RealType>::param_type::param_type(
-        _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW)
-    : __b_(__fB, __lB)
-{
-    if (__b_.size() < 2)
-    {
-        __b_.resize(2);
-        __b_[0] = 0;
-        __b_[1] = 1;
-        __densities_.assign(2, 1.0);
-        __areas_.assign(1, 0.0);
-    }
-    else
-    {
-        __densities_.reserve(__b_.size());
-        for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW)
-            __densities_.push_back(*__fW);
-        __init();
-    }
-}
-
-#ifndef _LIBCPP_CXX03_LANG
-
-template<class _RealType>
-template<class _UnaryOperation>
-piecewise_linear_distribution<_RealType>::param_type::param_type(
-        initializer_list<result_type> __bl, _UnaryOperation __fw)
-    : __b_(__bl.begin(), __bl.end())
-{
-    if (__b_.size() < 2)
-    {
-        __b_.resize(2);
-        __b_[0] = 0;
-        __b_[1] = 1;
-        __densities_.assign(2, 1.0);
-        __areas_.assign(1, 0.0);
-    }
-    else
-    {
-        __densities_.reserve(__b_.size());
-        for (size_t __i = 0; __i < __b_.size(); ++__i)
-            __densities_.push_back(__fw(__b_[__i]));
-        __init();
-    }
-}
-
-#endif // _LIBCPP_CXX03_LANG
-
-template<class _RealType>
-template<class _UnaryOperation>
-piecewise_linear_distribution<_RealType>::param_type::param_type(
-        size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw)
-    : __b_(__nw == 0 ? 2 : __nw + 1)
-{
-    size_t __n = __b_.size() - 1;
-    result_type __d = (__xmax - __xmin) / __n;
-    __densities_.reserve(__b_.size());
-    for (size_t __i = 0; __i < __n; ++__i)
-    {
-        __b_[__i] = __xmin + __i * __d;
-        __densities_.push_back(__fw(__b_[__i]));
-    }
-    __b_[__n] = __xmax;
-    __densities_.push_back(__fw(__b_[__n]));
-    __init();
-}
-
-template<class _RealType>
-template<class _URNG>
-_RealType
-piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
-{
-    typedef uniform_real_distribution<result_type> _Gen;
-    result_type __u = _Gen()(__g);
-    ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
-                                      __u) - __p.__areas_.begin() - 1;
-    __u -= __p.__areas_[__k];
-    const result_type __dk = __p.__densities_[__k];
-    const result_type __dk1 = __p.__densities_[__k+1];
-    const result_type __deltad = __dk1 - __dk;
-    const result_type __bk = __p.__b_[__k];
-    if (__deltad == 0)
-        return __u / __dk + __bk;
-    const result_type __bk1 = __p.__b_[__k+1];
-    const result_type __deltab = __bk1 - __bk;
-    return (__bk * __dk1 - __bk1 * __dk +
-        _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
-        __deltad;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os,
-           const piecewise_linear_distribution<_RT>& __x)
-{
-    __save_flags<_CharT, _Traits> __lx(__os);
-    typedef basic_ostream<_CharT, _Traits> _OStream;
-    __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
-               _OStream::scientific);
-    _CharT __sp = __os.widen(' ');
-    __os.fill(__sp);
-    size_t __n = __x.__p_.__b_.size();
-    __os << __n;
-    for (size_t __i = 0; __i < __n; ++__i)
-        __os << __sp << __x.__p_.__b_[__i];
-    __n = __x.__p_.__densities_.size();
-    __os << __sp << __n;
-    for (size_t __i = 0; __i < __n; ++__i)
-        __os << __sp << __x.__p_.__densities_[__i];
-    __n = __x.__p_.__areas_.size();
-    __os << __sp << __n;
-    for (size_t __i = 0; __i < __n; ++__i)
-        __os << __sp << __x.__p_.__areas_[__i];
-    return __os;
-}
-
-template <class _CharT, class _Traits, class _RT>
-basic_istream<_CharT, _Traits>&
-operator>>(basic_istream<_CharT, _Traits>& __is,
-           piecewise_linear_distribution<_RT>& __x)
-{
-    typedef piecewise_linear_distribution<_RT> _Eng;
-    typedef typename _Eng::result_type result_type;
-    __save_flags<_CharT, _Traits> __lx(__is);
-    typedef basic_istream<_CharT, _Traits> _Istream;
-    __is.flags(_Istream::dec | _Istream::skipws);
-    size_t __n;
-    __is >> __n;
-    vector<result_type> __b(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __is >> __b[__i];
-    __is >> __n;
-    vector<result_type> __densities(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __is >> __densities[__i];
-    __is >> __n;
-    vector<result_type> __areas(__n);
-    for (size_t __i = 0; __i < __n; ++__i)
-        __is >> __areas[__i];
-    if (!__is.fail())
-    {
-        swap(__x.__p_.__b_, __b);
-        swap(__x.__p_.__densities_, __densities);
-        swap(__x.__p_.__areas_, __areas);
-    }
-    return __is;
-}
-
-_LIBCPP_END_NAMESPACE_STD
-
-_LIBCPP_POP_MACROS
-
 #endif // _LIBCPP_RANDOM
lib/libcxx/include/ranges
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- ranges -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -36,7 +36,7 @@ namespace std::ranges {
     inline constexpr bool enable_borrowed_range = false;
 
   template<class T>
-    using iterator_t = decltype(ranges::begin(declval<R&>()));
+    using iterator_t = decltype(ranges::begin(declval<T&>()));
   template<range R>
     using sentinel_t = decltype(ranges::end(declval<R&>()));
   template<range R>
@@ -135,6 +135,13 @@ namespace std::ranges {
   template<class T>
     inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
 
+  template<range R>
+    requires see below
+  class owning_view;
+
+  template<class T>
+    inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
+
   // [range.drop], drop view
   template<view V>
     class drop_view;
@@ -149,27 +156,56 @@ namespace std::ranges {
              can-reference<invoke_result_t<F&, range_reference_t<V>>>
   class transform_view;
 
+  // [range.counted], counted view
+  namespace views { inline constexpr unspecified counted = unspecified; }
+
   // [range.common], common view
   template<view V>
     requires (!common_range<V> && copyable<iterator_t<V>>)
   class common_view;
 
+ // [range.reverse], reverse view
+  template<view V>
+    requires bidirectional_range<V>
+  class reverse_view;
+
+  template<class T>
+    inline constexpr bool enable_borrowed_range<reverse_view<T>> = enable_borrowed_range<T>;
+
   template<class T>
   inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
+
+   // [range.take], take view
+  template<view> class take_view;
+
+  template<class T>
+  inline constexpr bool enable_borrowed_range<take_view<T>> = enable_borrowed_range<T>;
+
+  template<copy_constructible T>
+    requires is_object_v<T>
+  class single_view;
+
+  template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
+    requires weakly-equality-comparable-with<W, Bound> && copyable<W>
+  class iota_view;
+
+  template<class W, class Bound>
+    inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
+
+  // [range.join], join view
+  template<input_range V>
+    requires view<V> && input_range<range_reference_t<V>>
+  class join_view;
 }
 
 */
 
-// Make sure all feature tests macros are always available.
-#include <version>
-// Only enable the contents of the header when libc++ was build with LIBCXX_ENABLE_INCOMPLETE_FEATURES enabled
-#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
-
 #include <__config>
 #include <__ranges/access.h>
 #include <__ranges/all.h>
 #include <__ranges/common_view.h>
 #include <__ranges/concepts.h>
+#include <__ranges/counted.h>
 #include <__ranges/dangling.h>
 #include <__ranges/data.h>
 #include <__ranges/drop_view.h>
@@ -177,33 +213,25 @@ namespace std::ranges {
 #include <__ranges/empty_view.h>
 #include <__ranges/enable_borrowed_range.h>
 #include <__ranges/enable_view.h>
+#include <__ranges/iota_view.h>
+#include <__ranges/join_view.h>
 #include <__ranges/ref_view.h>
+#include <__ranges/reverse_view.h>
+#include <__ranges/single_view.h>
 #include <__ranges/size.h>
 #include <__ranges/subrange.h>
+#include <__ranges/take_view.h>
 #include <__ranges/transform_view.h>
 #include <__ranges/view_interface.h>
+#include <__ranges/views.h>
 #include <compare>          // Required by the standard.
 #include <initializer_list> // Required by the standard.
 #include <iterator>         // Required by the standard.
 #include <type_traits>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
-
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
-
-_LIBCPP_END_NAMESPACE_STD
-
-_LIBCPP_POP_MACROS
-
-#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
-
 #endif // _LIBCPP_RANGES
lib/libcxx/include/ratio
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- ratio -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -81,6 +81,7 @@ typedef ratio<1000000000000000000000000, 1> yotta;  // not supported
 #include <climits>
 #include <cstdint>
 #include <type_traits>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -499,30 +500,24 @@ struct __ratio_gcd
                   __static_lcm<_R1::den, _R2::den>::value> type;
 };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _R1, class _R2>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_equal_v
-    = ratio_equal<_R1, _R2>::value;
+inline constexpr bool ratio_equal_v = ratio_equal<_R1, _R2>::value;
 
 template <class _R1, class _R2>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_not_equal_v
-    = ratio_not_equal<_R1, _R2>::value;
+inline constexpr bool ratio_not_equal_v = ratio_not_equal<_R1, _R2>::value;
 
 template <class _R1, class _R2>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_v
-    = ratio_less<_R1, _R2>::value;
+inline constexpr bool ratio_less_v = ratio_less<_R1, _R2>::value;
 
 template <class _R1, class _R2>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_equal_v
-    = ratio_less_equal<_R1, _R2>::value;
+inline constexpr bool ratio_less_equal_v = ratio_less_equal<_R1, _R2>::value;
 
 template <class _R1, class _R2>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_v
-    = ratio_greater<_R1, _R2>::value;
+inline constexpr bool ratio_greater_v = ratio_greater<_R1, _R2>::value;
 
 template <class _R1, class _R2>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_equal_v
-    = ratio_greater_equal<_R1, _R2>::value;
+inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<_R1, _R2>::value;
 #endif
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/regex
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- regex ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -978,7 +978,7 @@ enum error_type
     __re_err_parse
 };
 
-}  // regex_constants
+} // namespace regex_constants
 
 class _LIBCPP_EXCEPTION_ABI regex_error
     : public runtime_error
@@ -1072,32 +1072,38 @@ private:
     template <class _ForwardIterator>
         string_type
         __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     template <class _ForwardIterator>
         string_type
         __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
-
+#endif
     template <class _ForwardIterator>
         string_type
         __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     template <class _ForwardIterator>
         string_type
         __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
-
+#endif
     template <class _ForwardIterator>
         char_class_type
         __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
                            bool __icase, char) const;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     template <class _ForwardIterator>
         char_class_type
         __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
                            bool __icase, wchar_t) const;
+#endif
 
     static int __regex_traits_value(unsigned char __ch, int __radix);
     _LIBCPP_INLINE_VISIBILITY
     int __regex_traits_value(char __ch, int __radix) const
         {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     _LIBCPP_INLINE_VISIBILITY
     int __regex_traits_value(wchar_t __ch, int __radix) const;
+#endif
 };
 
 template <class _CharT>
@@ -1168,6 +1174,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
     return __d;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <class _CharT>
 template <class _ForwardIterator>
 typename regex_traits<_CharT>::string_type
@@ -1189,6 +1196,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
     }
     return __d;
 }
+#endif
 
 // lookup_collatename is very FreeBSD-specific
 
@@ -1217,6 +1225,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
     return __r;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <class _CharT>
 template <class _ForwardIterator>
 typename regex_traits<_CharT>::string_type
@@ -1250,6 +1259,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
     }
     return __r;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // lookup_classname
 
@@ -1268,6 +1278,7 @@ regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
     return __get_classname(__s.c_str(), __icase);
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <class _CharT>
 template <class _ForwardIterator>
 typename regex_traits<_CharT>::char_class_type
@@ -1288,6 +1299,7 @@ regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
     }
     return __get_classname(__n.c_str(), __icase);
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template <class _CharT>
 bool
@@ -1298,19 +1310,51 @@ regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
     return (__c == '_' && (__m & __regex_word));
 }
 
+inline _LIBCPP_INLINE_VISIBILITY
+bool __is_07(unsigned char c)
+{
+    return (c & 0xF8u) ==
+#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
+        0xF0;
+#else
+        0x30;
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool __is_89(unsigned char c)
+{
+    return (c & 0xFEu) ==
+#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
+        0xF8;
+#else
+        0x38;
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned char __to_lower(unsigned char c)
+{
+#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
+    return c & 0xBF;
+#else
+    return c | 0x20;
+#endif
+}
+
 template <class _CharT>
 int
 regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
 {
-    if ((__ch & 0xF8u) == 0x30)  // '0' <= __ch && __ch <= '7'
+    if (__is_07(__ch))  // '0' <= __ch && __ch <= '7'
         return __ch - '0';
     if (__radix != 8)
     {
-        if ((__ch & 0xFEu) == 0x38)  // '8' <= __ch && __ch <= '9'
+        if (__is_89(__ch))  // '8' <= __ch && __ch <= '9'
             return __ch - '0';
         if (__radix == 16)
         {
-            __ch |= 0x20;  // tolower
+            __ch = __to_lower(__ch);  // tolower
             if ('a' <= __ch && __ch <= 'f')
                 return __ch - ('a' - 10);
         }
@@ -1318,6 +1362,7 @@ regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
     return -1;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <class _CharT>
 inline
 int
@@ -1325,6 +1370,7 @@ regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
 {
     return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
 }
+#endif
 
 template <class _CharT> class __node;
 
@@ -2135,7 +2181,9 @@ public:
 };
 
 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
+#endif
 
 // __match_char
 
@@ -2542,13 +2590,15 @@ template <class _CharT, class _Traits = regex_traits<_CharT> >
     class _LIBCPP_TEMPLATE_VIS basic_regex;
 
 typedef basic_regex<char>    regex;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 typedef basic_regex<wchar_t> wregex;
+#endif
 
 template <class _CharT, class _Traits>
 class
     _LIBCPP_TEMPLATE_VIS
     _LIBCPP_PREFERRED_NAME(regex)
-    _LIBCPP_PREFERRED_NAME(wregex)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex))
     basic_regex
 {
 public:
@@ -3014,7 +3064,7 @@ private:
     template <class, class> friend class __lookahead;
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template <class _ForwardIterator,
           class = typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value, nullptr_t>::type
 >
@@ -4897,17 +4947,19 @@ basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
 // sub_match
 
 typedef sub_match<const char*>             csub_match;
-typedef sub_match<const wchar_t*>          wcsub_match;
 typedef sub_match<string::const_iterator>  ssub_match;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+typedef sub_match<const wchar_t*>          wcsub_match;
 typedef sub_match<wstring::const_iterator> wssub_match;
+#endif
 
 template <class _BidirectionalIterator>
 class
     _LIBCPP_TEMPLATE_VIS
     _LIBCPP_PREFERRED_NAME(csub_match)
-    _LIBCPP_PREFERRED_NAME(wcsub_match)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match))
     _LIBCPP_PREFERRED_NAME(ssub_match)
-    _LIBCPP_PREFERRED_NAME(wssub_match)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match))
     sub_match
     : public pair<_BidirectionalIterator, _BidirectionalIterator>
 {
@@ -5326,17 +5378,19 @@ operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
 }
 
 typedef match_results<const char*>             cmatch;
-typedef match_results<const wchar_t*>          wcmatch;
 typedef match_results<string::const_iterator>  smatch;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+typedef match_results<const wchar_t*>          wcmatch;
 typedef match_results<wstring::const_iterator> wsmatch;
+#endif
 
 template <class _BidirectionalIterator, class _Allocator>
 class
     _LIBCPP_TEMPLATE_VIS
     _LIBCPP_PREFERRED_NAME(cmatch)
-    _LIBCPP_PREFERRED_NAME(wcmatch)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
     _LIBCPP_PREFERRED_NAME(smatch)
-    _LIBCPP_PREFERRED_NAME(wsmatch)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch))
     match_results
 {
 public:
@@ -6244,17 +6298,19 @@ template <class _BidirectionalIterator,
     class _LIBCPP_TEMPLATE_VIS regex_iterator;
 
 typedef regex_iterator<const char*>             cregex_iterator;
-typedef regex_iterator<const wchar_t*>          wcregex_iterator;
 typedef regex_iterator<string::const_iterator>  sregex_iterator;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+typedef regex_iterator<const wchar_t*>          wcregex_iterator;
 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
+#endif
 
 template <class _BidirectionalIterator, class _CharT, class _Traits>
 class
     _LIBCPP_TEMPLATE_VIS
     _LIBCPP_PREFERRED_NAME(cregex_iterator)
-    _LIBCPP_PREFERRED_NAME(wcregex_iterator)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator))
     _LIBCPP_PREFERRED_NAME(sregex_iterator)
-    _LIBCPP_PREFERRED_NAME(wsregex_iterator)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator))
     regex_iterator
 {
 public:
@@ -6372,17 +6428,19 @@ template <class _BidirectionalIterator,
     class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
 
 typedef regex_token_iterator<const char*>             cregex_token_iterator;
-typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
 typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
+#endif
 
 template <class _BidirectionalIterator, class _CharT, class _Traits>
 class
     _LIBCPP_TEMPLATE_VIS
     _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
-    _LIBCPP_PREFERRED_NAME(wcregex_token_iterator)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
     _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
-    _LIBCPP_PREFERRED_NAME(wsregex_token_iterator)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator))
     regex_token_iterator
 {
 public:
lib/libcxx/include/scoped_allocator
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- scoped_allocator --------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -91,6 +91,10 @@ public:
     scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
 };
 
+template<class OuterAlloc, class... InnerAllocs>
+    scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)
+        -> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;
+
 template <class OuterA1, class OuterA2, class... InnerAllocs>
     bool
     operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
@@ -649,6 +653,12 @@ private:
     template <class...> friend class __scoped_allocator_storage;
 };
 
+#if _LIBCPP_STD_VER > 14
+template<class _OuterAlloc, class... _InnerAllocs>
+    scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...)
+        -> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>;
+#endif
+
 template <class _OuterA1, class _OuterA2>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
lib/libcxx/include/semaphore
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- semaphore --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -47,8 +47,10 @@ using binary_semaphore = counting_semaphore<1>;
 
 #include <__availability>
 #include <__config>
+#include <__thread/timed_backoff_policy.h>
 #include <__threading_support>
 #include <atomic>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -67,10 +69,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 /*
 
-__atomic_semaphore_base is the general-case implementation, to be used for
-user-requested least-max values that exceed the OS implementation support
-(incl. when the OS has no support of its own) and for binary semaphores.
-
+__atomic_semaphore_base is the general-case implementation.
 It is a typical Dijkstra semaphore algorithm over atomics, wait and notify
 functions. It avoids contention against users' own use of those facilities.
 
@@ -82,7 +81,7 @@ class __atomic_semaphore_base
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    __atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
+    constexpr explicit __atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
     {
     }
     _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
@@ -108,81 +107,30 @@ public:
     _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
     bool try_acquire_for(chrono::duration<Rep, Period> const& __rel_time)
     {
-        auto const __test_fn = [this]() -> bool {
-            auto __old = __a.load(memory_order_acquire);
-            while(1) {
-                if (__old == 0)
-                    return false;
-                if(__a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed))
-                    return true;
-            }
-        };
+        if (__rel_time == chrono::duration<Rep, Period>::zero())
+            return try_acquire();
+        auto const __test_fn = [this]() { return try_acquire(); };
         return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy(), __rel_time);
     }
-};
-
-#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
-
-/*
-
-__platform_semaphore_base a simple wrapper for the OS semaphore type. That
-is, every call is routed to the OS in the most direct manner possible.
-
-*/
-
-class __platform_semaphore_base
-{
-    __libcpp_semaphore_t __semaphore;
-
-public:
-    _LIBCPP_INLINE_VISIBILITY
-    __platform_semaphore_base(ptrdiff_t __count) :
-        __semaphore()
-    {
-        __libcpp_semaphore_init(&__semaphore, __count);
-    }
-    _LIBCPP_INLINE_VISIBILITY
-    ~__platform_semaphore_base() {
-        __libcpp_semaphore_destroy(&__semaphore);
-    }
-    _LIBCPP_INLINE_VISIBILITY
-    void release(ptrdiff_t __update)
-    {
-        for(; __update; --__update)
-            __libcpp_semaphore_post(&__semaphore);
-    }
-    _LIBCPP_INLINE_VISIBILITY
-    void acquire()
-    {
-        __libcpp_semaphore_wait(&__semaphore);
-    }
-    _LIBCPP_INLINE_VISIBILITY
-    bool try_acquire_for(chrono::nanoseconds __rel_time)
+    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
+    bool try_acquire()
     {
-        return __libcpp_semaphore_wait_timed(&__semaphore, __rel_time);
+        auto __old = __a.load(memory_order_acquire);
+        while (true) {
+            if (__old == 0)
+                return false;
+            if (__a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed))
+                return true;
+        }
     }
 };
 
-template<ptrdiff_t __least_max_value>
-using __semaphore_base =
-    typename conditional<(__least_max_value > 1 && __least_max_value <= _LIBCPP_SEMAPHORE_MAX),
-                         __platform_semaphore_base,
-                         __atomic_semaphore_base>::type;
-
-#else
-
-template<ptrdiff_t __least_max_value>
-using __semaphore_base =
-    __atomic_semaphore_base;
-
 #define _LIBCPP_SEMAPHORE_MAX (numeric_limits<ptrdiff_t>::max())
 
-#endif //_LIBCPP_NO_NATIVE_SEMAPHORES
-
 template<ptrdiff_t __least_max_value = _LIBCPP_SEMAPHORE_MAX>
 class counting_semaphore
 {
-    __semaphore_base<__least_max_value> __semaphore;
+    __atomic_semaphore_base __semaphore;
 
 public:
     static constexpr ptrdiff_t max() noexcept {
@@ -190,7 +138,7 @@ public:
     }
 
     _LIBCPP_INLINE_VISIBILITY
-    counting_semaphore(ptrdiff_t __count = 0) : __semaphore(__count) { }
+    constexpr explicit counting_semaphore(ptrdiff_t __count) : __semaphore(__count) { }
     ~counting_semaphore() = default;
 
     counting_semaphore(const counting_semaphore&) = delete;
@@ -215,14 +163,14 @@ public:
     _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
     bool try_acquire()
     {
-        return try_acquire_for(chrono::nanoseconds::zero());
+        return __semaphore.try_acquire();
     }
     template <class Clock, class Duration>
     _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
     bool try_acquire_until(chrono::time_point<Clock, Duration> const& __abs_time)
     {
         auto const current = Clock::now();
-        if(current >= __abs_time)
+        if (current >= __abs_time)
             return try_acquire();
         else
             return try_acquire_for(__abs_time - current);
lib/libcxx/include/set
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- set -------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -183,6 +183,25 @@ public:
         pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
 };
 
+template <class InputIterator,
+      class Compare = less<typename iterator_traits<InputIterator>::value_type>,
+      class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
+set(InputIterator, InputIterator,
+    Compare = Compare(), Allocator = Allocator())
+  -> set<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
+
+template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
+set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
+  -> set<Key, Compare, Allocator>; // C++17
+
+template<class InputIterator, class Allocator>
+set(InputIterator, InputIterator, Allocator)
+  -> set<typename iterator_traits<InputIterator>::value_type,
+          less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
+
+template<class Key, class Allocator>
+set(initializer_list<Key>, Allocator) -> set<Key, less<Key>, Allocator>; // C++17
+
 template <class Key, class Compare, class Allocator>
 bool
 operator==(const set<Key, Compare, Allocator>& x,
@@ -389,6 +408,25 @@ public:
         pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
 };
 
+template <class InputIterator,
+      class Compare = less<typename iterator_traits<InputIterator>::value_type>,
+      class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
+multiset(InputIterator, InputIterator,
+    Compare = Compare(), Allocator = Allocator())
+  -> multiset<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
+
+template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
+multiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
+  -> multiset<Key, Compare, Allocator>; // C++17
+
+template<class InputIterator, class Allocator>
+multiset(InputIterator, InputIterator, Allocator)
+  -> multiset<typename iterator_traits<InputIterator>::value_type,
+          less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
+
+template<class Key, class Allocator>
+multiset(initializer_list<Key>, Allocator) -> multiset<Key, less<Key>, Allocator>; // C++17
+
 template <class Key, class Compare, class Allocator>
 bool
 operator==(const multiset<Key, Compare, Allocator>& x,
@@ -436,6 +474,7 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred);  // C++20
 #include <__config>
 #include <__debug>
 #include <__functional/is_transparent.h>
+#include <__iterator/iterator_traits.h>
 #include <__node_handle>
 #include <__tree>
 #include <__utility/forward.h>
@@ -462,7 +501,7 @@ public:
     // types:
     typedef _Key                                     key_type;
     typedef key_type                                 value_type;
-    typedef _Compare                                 key_compare;
+    typedef __identity_t<_Compare>                   key_compare;
     typedef key_compare                              value_compare;
     typedef __identity_t<_Allocator>                 allocator_type;
     typedef value_type&                              reference;
@@ -474,7 +513,6 @@ public:
 private:
     typedef __tree<value_type, value_compare, allocator_type> __base;
     typedef allocator_traits<allocator_type>                  __alloc_traits;
-    typedef typename __base::__node_holder                    __node_holder;
 
     __base __tree_;
 
@@ -868,30 +906,32 @@ public:
 #endif
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Compare = less<__iter_value_type<_InputIterator>>,
          class _Allocator = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>,
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>>
 set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
   -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
 
 template<class _Key, class _Compare = less<_Key>,
          class _Allocator = allocator<_Key>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>>
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
   -> set<_Key, _Compare, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 set(_InputIterator, _InputIterator, _Allocator)
   -> set<__iter_value_type<_InputIterator>,
          less<__iter_value_type<_InputIterator>>, _Allocator>;
 
 template<class _Key, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 set(initializer_list<_Key>, _Allocator)
   -> set<_Key, less<_Key>, _Allocator>;
 #endif
@@ -994,7 +1034,7 @@ public:
     // types:
     typedef _Key                                     key_type;
     typedef key_type                                 value_type;
-    typedef _Compare                                 key_compare;
+    typedef __identity_t<_Compare>                   key_compare;
     typedef key_compare                              value_compare;
     typedef __identity_t<_Allocator>                 allocator_type;
     typedef value_type&                              reference;
@@ -1006,7 +1046,6 @@ public:
 private:
     typedef __tree<value_type, value_compare, allocator_type> __base;
     typedef allocator_traits<allocator_type>                  __alloc_traits;
-    typedef typename __base::__node_holder                    __node_holder;
 
     __base __tree_;
 
@@ -1399,30 +1438,32 @@ public:
 #endif
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Compare = less<__iter_value_type<_InputIterator>>,
          class _Allocator = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>,
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>>
 multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
   -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
 
 template<class _Key, class _Compare = less<_Key>,
          class _Allocator = allocator<_Key>,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>,
-         class = _EnableIf<!__is_allocator<_Compare>::value, void>>
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>,
+         class = enable_if_t<!__is_allocator<_Compare>::value, void>>
 multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
   -> multiset<_Key, _Compare, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 multiset(_InputIterator, _InputIterator, _Allocator)
   -> multiset<__iter_value_type<_InputIterator>,
          less<__iter_value_type<_InputIterator>>, _Allocator>;
 
 template<class _Key, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value, void>>
+         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
 multiset(initializer_list<_Key>, _Allocator)
   -> multiset<_Key, less<_Key>, _Allocator>;
 #endif
lib/libcxx/include/setjmp.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- setjmp.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/shared_mutex
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ shared_mutex --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/span
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------------ span ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -56,18 +56,18 @@ public:
 
     // [span.cons], span constructors, copy, assignment, and destructor
     constexpr span() noexcept;
-    constexpr explicit(Extent != dynamic_extent) span(pointer ptr, size_type count);
-    constexpr explicit(Extent != dynamic_extent) span(pointer firstElem, pointer lastElem);
+    template <class It>
+    constexpr explicit(Extent != dynamic_extent) span(It first, size_type count);
+    template <class It, class End>
+    constexpr explicit(Extent != dynamic_extent) span(It first, End last);
     template <size_t N>
-        constexpr span(element_type (&arr)[N]) noexcept;
+        constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
     template <size_t N>
         constexpr span(array<value_type, N>& arr) noexcept;
     template <size_t N>
         constexpr span(const array<value_type, N>& arr) noexcept;
-    template <class Container>
-        constexpr explicit(Extent != dynamic_extent) span(Container& cont);
-    template <class Container>
-        constexpr explicit(Extent != dynamic_extent) span(const Container& cont);
+    template<class R>
+      constexpr explicit(Extent != dynamic_extent) span(R&& r);
     constexpr span(const span& other) noexcept = default;
     template <class OtherElementType, size_t OtherExtent>
         constexpr explicit(Extent != dynamic_extent) span(const span<OtherElementType, OtherExtent>& s) noexcept;
@@ -89,7 +89,7 @@ public:
     // [span.obs], span observers
     constexpr size_type size() const noexcept;
     constexpr size_type size_bytes() const noexcept;
-    constexpr bool empty() const noexcept;
+    [[nodiscard]] constexpr bool empty() const noexcept;
 
     // [span.elem], span element access
     constexpr reference operator[](size_type idx) const;
@@ -108,6 +108,9 @@ private:
     size_type size_;  // exposition only
 };
 
+template<class It, class EndOrSize>
+    span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
+
 template<class T, size_t N>
     span(T (&)[N]) -> span<T, N>;
 
@@ -117,11 +120,8 @@ template<class T, size_t N>
 template<class T, size_t N>
     span(const array<T, N>&) -> span<const T, N>;
 
-template<class Container>
-    span(Container&) -> span<typename Container::value_type>;
-
-template<class Container>
-    span(const Container&) -> span<const typename Container::value_type>;
+template<class R>
+    span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
 
 } // namespace std
 
@@ -129,9 +129,13 @@ template<class Container>
 
 #include <__config>
 #include <__debug>
+#include <__iterator/concepts.h>
 #include <__iterator/wrap_iter.h>
+#include <__ranges/concepts.h>
+#include <__ranges/data.h>
 #include <__ranges/enable_borrowed_range.h>
 #include <__ranges/enable_view.h>
+#include <__ranges/size.h>
 #include <array>        // for array
 #include <cstddef>      // for byte
 #include <iterator>     // for iterators
@@ -155,46 +159,46 @@ template <typename _Tp, size_t _Extent = dynamic_extent> class span;
 
 
 template <class _Tp>
-struct __is_span_impl : public false_type {};
-
-template <class _Tp, size_t _Extent>
-struct __is_span_impl<span<_Tp, _Extent>> : public true_type {};
-
-template <class _Tp>
-struct __is_span : public __is_span_impl<remove_cv_t<_Tp>> {};
-
-template <class _Tp>
-struct __is_std_array_impl : public false_type {};
+struct __is_std_array : false_type {};
 
 template <class _Tp, size_t _Sz>
-struct __is_std_array_impl<array<_Tp, _Sz>> : public true_type {};
+struct __is_std_array<array<_Tp, _Sz>> : true_type {};
 
 template <class _Tp>
-struct __is_std_array : public __is_std_array_impl<remove_cv_t<_Tp>> {};
-
-template <class _Tp, class _ElementType, class = void>
-struct __is_span_compatible_container : public false_type {};
-
-template <class _Tp, class _ElementType>
-struct __is_span_compatible_container<_Tp, _ElementType,
-        void_t<
-        // is not a specialization of span
-            typename enable_if<!__is_span<_Tp>::value, nullptr_t>::type,
-        // is not a specialization of array
-            typename enable_if<!__is_std_array<_Tp>::value, nullptr_t>::type,
-        // is_array_v<Container> is false,
-            typename enable_if<!is_array_v<_Tp>, nullptr_t>::type,
-        // data(cont) and size(cont) are well formed
-            decltype(data(declval<_Tp>())),
-            decltype(size(declval<_Tp>())),
-        // remove_pointer_t<decltype(data(cont))>(*)[] is convertible to ElementType(*)[]
-            typename enable_if<
-                is_convertible_v<remove_pointer_t<decltype(data(declval<_Tp &>()))>(*)[],
-                                 _ElementType(*)[]>,
-                nullptr_t>::type
-        >>
-    : public true_type {};
+struct __is_std_span : false_type {};
 
+template <class _Tp, size_t _Sz>
+struct __is_std_span<span<_Tp, _Sz>> : true_type {};
+
+#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+// This is a temporary workaround until we ship <ranges> -- we've unfortunately been
+// shipping <span> before its API was finalized, and we used to provide a constructor
+// from container types that had the requirements below. To avoid breaking code that
+// has started relying on the range-based constructor until we ship all of <ranges>,
+// we emulate the constructor requirements like this.
+template <class _Range, class _ElementType, class = void>
+struct __span_compatible_range : false_type { };
+
+template <class _Range, class _ElementType>
+struct __span_compatible_range<_Range, _ElementType, void_t<
+    enable_if_t<!__is_std_span<remove_cvref_t<_Range>>::value>,
+    enable_if_t<!__is_std_array<remove_cvref_t<_Range>>::value>,
+    enable_if_t<!is_array_v<remove_cvref_t<_Range>>>,
+    decltype(data(declval<_Range>())),
+    decltype(size(declval<_Range>())),
+    enable_if_t<is_convertible_v<remove_pointer_t<decltype(data(declval<_Range&>()))>(*)[], _ElementType(*)[]>>
+>> : true_type { };
+#else
+template <class _Range, class _ElementType>
+concept __span_compatible_range =
+  ranges::contiguous_range<_Range> &&
+  ranges::sized_range<_Range> &&
+  (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) &&
+  !__is_std_span<remove_cvref_t<_Range>>::value  &&
+  !__is_std_array<remove_cvref_t<_Range>>::value &&
+  !is_array_v<remove_cvref_t<_Range>> &&
+  is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
+#endif
 
 template <typename _Tp, size_t _Extent>
 class _LIBCPP_TEMPLATE_VIS span {
@@ -224,12 +228,33 @@ public:
     constexpr span           (const span&) noexcept = default;
     constexpr span& operator=(const span&) noexcept = default;
 
-    _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __ptr, size_type __count) : __data{__ptr}
-        { (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); }
-    _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __f, pointer __l) : __data{__f}
-        { (void)__l;     _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); }
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+    template <class _It,
+              enable_if_t<contiguous_iterator<_It> &&
+                              is_convertible_v<remove_reference_t<iter_reference_t<_It>>(*)[], element_type (*)[]>,
+                          nullptr_t> = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    constexpr explicit span(_It __first, size_type __count)
+        : __data{_VSTD::to_address(__first)} {
+      (void)__count;
+      _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (iterator, len)");
+    }
+
+    template <
+        class _It, class _End,
+        enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
+                        contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
+                    nullptr_t> = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    constexpr explicit span(_It __first, _End __last) : __data{_VSTD::to_address(__first)} {
+      (void)__last;
+      _LIBCPP_ASSERT((__last - __first >= 0), "invalid range in span's constructor (iterator, sentinel)");
+      _LIBCPP_ASSERT(__last - __first == _Extent,
+                     "invalid range in span's constructor (iterator, sentinel): last - first != extent");
+    }
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
-    _LIBCPP_INLINE_VISIBILITY constexpr span(element_type (&__arr)[_Extent])          noexcept : __data{__arr} {}
+    _LIBCPP_INLINE_VISIBILITY constexpr span(type_identity_t<element_type> (&__arr)[_Extent]) noexcept : __data{__arr} {}
 
     template <class _OtherElementType,
               enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
@@ -241,21 +266,28 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
 
-    template <class _Container>
+#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+    template <class _Container, class = enable_if_t<
+        __span_compatible_range<_Container, element_type>::value
+    >>
     _LIBCPP_INLINE_VISIBILITY
-        constexpr explicit span(      _Container& __c,
-            enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr)
-        : __data{_VSTD::data(__c)} {
-            _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)");
-        }
-
-    template <class _Container>
+    constexpr explicit span(_Container& __c) : __data{std::data(__c)} {
+      _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
+    }
+    template <class _Container, class = enable_if_t<
+        __span_compatible_range<const _Container, element_type>::value
+    >>
+    _LIBCPP_INLINE_VISIBILITY
+    constexpr explicit span(const _Container& __c) : __data{std::data(__c)} {
+      _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
+    }
+#else
+    template <__span_compatible_range<element_type> _Range>
     _LIBCPP_INLINE_VISIBILITY
-        constexpr explicit span(const _Container& __c,
-            enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr)
-        : __data{_VSTD::data(__c)} {
-            _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)");
-        }
+    constexpr explicit span(_Range&& __r) : __data{ranges::data(__r)} {
+      _LIBCPP_ASSERT(ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)");
+    }
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
     template <class _OtherElementType>
     _LIBCPP_INLINE_VISIBILITY
@@ -331,9 +363,9 @@ public:
         return {data() + __offset, __count};
     }
 
-    _LIBCPP_INLINE_VISIBILITY constexpr size_type size()       const noexcept { return _Extent; }
-    _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); }
-    _LIBCPP_INLINE_VISIBILITY constexpr bool empty()           const noexcept { return _Extent == 0; }
+    _LIBCPP_INLINE_VISIBILITY constexpr size_type size()           const noexcept { return _Extent; }
+    _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes()     const noexcept { return _Extent * sizeof(element_type); }
+    [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; }
 
     _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
     {
@@ -402,12 +434,28 @@ public:
     constexpr span           (const span&) noexcept = default;
     constexpr span& operator=(const span&) noexcept = default;
 
-    _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr}, __size{__count} {}
-    _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {}
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+    template <class _It,
+              enable_if_t<contiguous_iterator<_It> &&
+                              is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]>,
+                          nullptr_t> = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    constexpr span(_It __first, size_type __count)
+        : __data{_VSTD::to_address(__first)}, __size{__count} {}
+
+    template <
+        class _It, class _End,
+        enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
+                        contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
+                    nullptr_t> = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    constexpr span(_It __first, _End __last)
+        : __data(_VSTD::to_address(__first)), __size(__last - __first) {}
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
     template <size_t _Sz>
     _LIBCPP_INLINE_VISIBILITY
-    constexpr span(element_type (&__arr)[_Sz])          noexcept : __data{__arr}, __size{_Sz} {}
+    constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
 
     template <class _OtherElementType, size_t _Sz,
               enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
@@ -419,18 +467,22 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
 
-    template <class _Container>
+#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+    template <class _Container, class = enable_if_t<
+        __span_compatible_range<_Container, element_type>::value
+    >>
     _LIBCPP_INLINE_VISIBILITY
-        constexpr span(      _Container& __c,
-            enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr)
-        : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {}
-
-    template <class _Container>
+    constexpr span(_Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
+    template <class _Container, class = enable_if_t<
+        __span_compatible_range<const _Container, element_type>::value
+    >>
     _LIBCPP_INLINE_VISIBILITY
-        constexpr span(const _Container& __c,
-            enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr)
-        : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {}
-
+    constexpr span(const _Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
+#else
+    template <__span_compatible_range<element_type> _Range>
+    _LIBCPP_INLINE_VISIBILITY
+    constexpr span(_Range&& __r) : __data(ranges::data(__r)), __size{ranges::size(__r)} {}
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 
     template <class _OtherElementType, size_t _OtherExtent>
     _LIBCPP_INLINE_VISIBILITY
@@ -493,9 +545,9 @@ public:
         return {data() + __offset, __count};
     }
 
-    _LIBCPP_INLINE_VISIBILITY constexpr size_type size()       const noexcept { return __size; }
-    _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); }
-    _LIBCPP_INLINE_VISIBILITY constexpr bool empty()           const noexcept { return __size == 0; }
+    _LIBCPP_INLINE_VISIBILITY constexpr size_type size()           const noexcept { return __size; }
+    _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes()     const noexcept { return __size * sizeof(element_type); }
+    [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; }
 
     _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
     {
@@ -535,13 +587,13 @@ private:
     size_type __size;
 };
 
-#if !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 template <class _Tp, size_t _Extent>
 inline constexpr bool ranges::enable_borrowed_range<span<_Tp, _Extent> > = true;
 
 template <class _ElementType, size_t _Extent>
 inline constexpr bool ranges::enable_view<span<_ElementType, _Extent>> = true;
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 //  as_bytes & as_writable_bytes
 template <class _Tp, size_t _Extent>
@@ -556,7 +608,11 @@ auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept
 -> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())>
 { return __s.__as_writable_bytes(); }
 
-//  Deduction guides
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+template<contiguous_iterator _It, class _EndOrSize>
+    span(_It, _EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
 template<class _Tp, size_t _Sz>
     span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
 
@@ -566,11 +622,16 @@ template<class _Tp, size_t _Sz>
 template<class _Tp, size_t _Sz>
     span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>;
 
+#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
 template<class _Container>
     span(_Container&) -> span<typename _Container::value_type>;
 
 template<class _Container>
     span(const _Container&) -> span<const typename _Container::value_type>;
+#else
+template<ranges::contiguous_range _Range>
+    span(_Range&&) -> span<remove_reference_t<ranges::range_reference_t<_Range>>>;
+#endif
 
 #endif // _LIBCPP_STD_VER > 17
 
lib/libcxx/include/sstream
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- sstream ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -184,6 +184,7 @@ typedef basic_stringstream<wchar_t> wstringstream;
 #include <istream>
 #include <ostream>
 #include <string>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/stack
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- stack -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -41,11 +41,14 @@ public:
 
     explicit stack(const container_type& c);
     explicit stack(container_type&& c);
+    template <class InputIterator> stack(InputIterator first, InputIterator last); // since C++23
     template <class Alloc> explicit stack(const Alloc& a);
     template <class Alloc> stack(const container_type& c, const Alloc& a);
     template <class Alloc> stack(container_type&& c, const Alloc& a);
     template <class Alloc> stack(const stack& c, const Alloc& a);
     template <class Alloc> stack(stack&& c, const Alloc& a);
+    template<class InputIterator, class Alloc>
+    stack(InputIterator first, InputIterator last, const Alloc&); // since C++23
 
     bool empty() const;
     size_type size() const;
@@ -63,9 +66,17 @@ public:
 template<class Container>
   stack(Container) -> stack<typename Container::value_type, Container>;  // C++17
 
+template<class InputIterator>
+  stack(InputIterator, InputIterator) -> stack<iter-value-type<InputIterator>>; // since C++23
+
 template<class Container, class Allocator>
   stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17
 
+template<class InputIterator, class Allocator>
+  stack(InputIterator, InputIterator, Allocator)
+    -> stack<iter-value-type<InputIterator>,
+             deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
+
 template <class T, class Container>
   bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
 template <class T, class Container>
@@ -88,9 +99,12 @@ template <class T, class Container>
 */
 
 #include <__config>
+#include <__iterator/iterator_traits.h>
 #include <__memory/uses_allocator.h>
 #include <__utility/forward.h>
 #include <deque>
+#include <type_traits>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -158,31 +172,45 @@ public:
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         explicit stack(const _Alloc& __a,
-                       _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(__a) {}
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         stack(const container_type& __c, const _Alloc& __a,
-              _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+              __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(__c, __a) {}
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         stack(const stack& __s, const _Alloc& __a,
-              _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+              __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(__s.c, __a) {}
 #ifndef _LIBCPP_CXX03_LANG
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         stack(container_type&& __c, const _Alloc& __a,
-              _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+              __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(_VSTD::move(__c), __a) {}
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
         stack(stack&& __s, const _Alloc& __a,
-              _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
+              __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
             : c(_VSTD::move(__s.c), __a) {}
 #endif // _LIBCPP_CXX03_LANG
 
+#if _LIBCPP_STD_VER > 20
+    template <class _InputIterator,
+              class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
+    _LIBCPP_HIDE_FROM_ABI
+    stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
+
+    template <class _InputIterator,
+              class _Alloc,
+              class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+              class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>>
+    _LIBCPP_HIDE_FROM_ABI
+    stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc) : c(__first, __last, __alloc) {}
+#endif
+
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
     bool empty()     const      {return c.empty();}
     _LIBCPP_INLINE_VISIBILITY
@@ -231,22 +259,36 @@ public:
     operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER > 14
 template<class _Container,
-         class = _EnableIf<!__is_allocator<_Container>::value>
+         class = enable_if_t<!__is_allocator<_Container>::value>
 >
 stack(_Container)
     -> stack<typename _Container::value_type, _Container>;
 
 template<class _Container,
          class _Alloc,
-         class = _EnableIf<!__is_allocator<_Container>::value>,
-         class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
+         class = enable_if_t<!__is_allocator<_Container>::value>,
+         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
          >
 stack(_Container, _Alloc)
     -> stack<typename _Container::value_type, _Container>;
 #endif
 
+#if _LIBCPP_STD_VER > 20
+template<class _InputIterator,
+         class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
+stack(_InputIterator, _InputIterator)
+    -> stack<__iter_value_type<_InputIterator>>;
+
+template<class _InputIterator,
+         class _Alloc,
+         class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = __enable_if_t<__is_allocator<_Alloc>::value>>
+stack(_InputIterator, _InputIterator, _Alloc)
+    -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
+#endif
+
 template <class _Tp, class _Container>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
@@ -297,7 +339,7 @@ operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
 
 template <class _Tp, class _Container>
 inline _LIBCPP_INLINE_VISIBILITY
-_EnableIf<__is_swappable<_Container>::value, void>
+__enable_if_t<__is_swappable<_Container>::value, void>
 swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
     _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
 {
lib/libcxx/include/stdbool.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- stdbool.h --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stddef.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- stddef.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stdexcept
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- stdexcept --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -42,9 +42,9 @@ public:
 */
 
 #include <__config>
+#include <cstdlib>
 #include <exception>
 #include <iosfwd>  // for string forward decl
-#include <cstdlib>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -209,7 +209,7 @@ public:
 #endif
 };
 
-}  // std
+} // namespace std
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
lib/libcxx/include/stdint.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- stdint.h --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stdio.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- stdio.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/stdlib.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- stdlib.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -96,10 +96,14 @@ void *aligned_alloc(size_t alignment, size_t size);                       // C11
 extern "C++" {
 // abs
 
-#undef abs
-#undef labs
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-#undef llabs
+#ifdef abs
+# undef abs
+#endif
+#ifdef labs
+# undef labs
+#endif
+#ifdef llabs
+# undef llabs
 #endif
 
 // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
@@ -107,11 +111,9 @@ extern "C++" {
 inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
   return __builtin_labs(__x);
 }
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
 inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
   return __builtin_llabs(__x);
 }
-#endif // _LIBCPP_HAS_NO_LONG_LONG
 #endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
 
 #if !defined(__sun__)
@@ -131,10 +133,14 @@ abs(long double __lcpp_x) _NOEXCEPT {
 
 // div
 
-#undef div
-#undef ldiv
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-#undef lldiv
+#ifdef div
+# undef div
+#endif
+#ifdef ldiv
+# undef ldiv
+#endif
+#ifdef lldiv
+# undef lldiv
 #endif
 
 // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
@@ -142,12 +148,12 @@ abs(long double __lcpp_x) _NOEXCEPT {
 inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
   return ::ldiv(__x, __y);
 }
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
+#if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
 inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
                                              long long __y) _NOEXCEPT {
   return ::lldiv(__x, __y);
 }
-#endif // _LIBCPP_HAS_NO_LONG_LONG
+#endif
 #endif // _LIBCPP_MSVCRT / __sun__
 } // extern "C++"
 #endif // __cplusplus
lib/libcxx/include/streambuf
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------- streambuf ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -108,8 +108,10 @@ protected:
 */
 
 #include <__config>
+#include <cstdint>
 #include <ios>
 #include <iosfwd>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/string
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- string -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -158,6 +158,9 @@ public:
     void resize(size_type n, value_type c);
     void resize(size_type n);
 
+    template<class Operation>
+    constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23
+
     void reserve(size_type res_arg);
     void reserve(); // deprecated in C++20
     void shrink_to_fit();
@@ -524,7 +527,6 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
 #include <cstdio>  // EOF
 #include <cstdlib>
 #include <cstring>
-#include <cwchar>
 #include <initializer_list>
 #include <iosfwd>
 #include <iterator>
@@ -535,6 +537,10 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
 #include <utility>
 #include <version>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#   include <cwchar>
+#endif
+
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
 # include <cstdint>
 #endif
@@ -612,30 +618,6 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
 
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
 
-template <bool>
-class _LIBCPP_TEMPLATE_VIS __basic_string_common
-{
-protected:
-    _LIBCPP_NORETURN void __throw_length_error() const;
-    _LIBCPP_NORETURN void __throw_out_of_range() const;
-};
-
-template <bool __b>
-void
-__basic_string_common<__b>::__throw_length_error() const
-{
-    _VSTD::__throw_length_error("basic_string");
-}
-
-template <bool __b>
-void
-__basic_string_common<__b>::__throw_out_of_range() const
-{
-    _VSTD::__throw_out_of_range("basic_string");
-}
-
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
-
 template <class _Iter>
 struct __string_is_trivial_iterator : public false_type {};
 
@@ -675,7 +657,7 @@ typedef basic_string<char8_t> u8string;
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
 typedef basic_string<char16_t> u16string;
 typedef basic_string<char32_t> u32string;
-#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
+#endif
 
 template<class _CharT, class _Traits, class _Allocator>
 class
@@ -688,7 +670,6 @@ class
     _LIBCPP_PREFERRED_NAME(u32string)
 #endif
     basic_string
-    : private __basic_string_common<true>
 {
 public:
     typedef basic_string                                 __self;
@@ -832,17 +813,15 @@ public:
     basic_string(basic_string&& __str, const allocator_type& __a);
 #endif // _LIBCPP_CXX03_LANG
 
-    template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
+    template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
     _LIBCPP_INLINE_VISIBILITY
     basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
       _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
       __init(__s, traits_type::length(__s));
-#   if _LIBCPP_DEBUG_LEVEL == 2
-      __get_db()->__insert_c(this);
-#   endif
+      _VSTD::__debug_db_insert_c(this);
     }
 
-    template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
+    template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
         _LIBCPP_INLINE_VISIBILITY
         basic_string(const _CharT* __s, const _Allocator& __a);
 
@@ -857,7 +836,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     basic_string(size_type __n, _CharT __c);
 
-    template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
+    template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
         _LIBCPP_INLINE_VISIBILITY
         basic_string(size_type __n, _CharT __c, const _Allocator& __a);
 
@@ -867,24 +846,24 @@ public:
     basic_string(const basic_string& __str, size_type __pos,
                  const _Allocator& __a = _Allocator());
 
-    template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
+    template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
         _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
         basic_string(const _Tp& __t, size_type __pos, size_type __n,
                      const allocator_type& __a = allocator_type());
 
-    template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
+    template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
                                           !__is_same_uncvref<_Tp, basic_string>::value> >
         _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
         explicit basic_string(const _Tp& __t);
 
-    template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
+    template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
         _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
         explicit basic_string(const _Tp& __t, const allocator_type& __a);
 
-    template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
+    template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
         _LIBCPP_INLINE_VISIBILITY
         basic_string(_InputIterator __first, _InputIterator __last);
-    template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
+    template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
         _LIBCPP_INLINE_VISIBILITY
         basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
 #ifndef _LIBCPP_CXX03_LANG
@@ -901,7 +880,7 @@ public:
 
     basic_string& operator=(const basic_string& __str);
 
-    template <class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
+    template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
     basic_string& operator=(const _Tp& __t)
         {__self_view __sv = __t; return assign(__sv);}
 
@@ -983,6 +962,16 @@ public:
     _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
 
     void reserve(size_type __requested_capacity);
+
+#if _LIBCPP_STD_VER > 20
+    template <class _Op>
+    _LIBCPP_HIDE_FROM_ABI constexpr
+    void resize_and_overwrite(size_type __n, _Op __op) {
+      __resize_default_init(__n);
+      __erase_to_end(_VSTD::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
+    }
+#endif
+
     _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
 
     _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY
@@ -1004,7 +993,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
             && !__is_same_uncvref<_Tp, basic_string >::value,
@@ -1022,7 +1011,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf<
+    __enable_if_t<
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
             && !__is_same_uncvref<_Tp, basic_string>::value,
             basic_string&
@@ -1032,7 +1021,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
             && !__is_same_uncvref<_Tp, basic_string>::value,
@@ -1048,7 +1037,7 @@ public:
 
     template<class _InputIterator>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __is_exactly_cpp17_input_iterator<_InputIterator>::value,
             basic_string&
@@ -1061,7 +1050,7 @@ public:
     }
     template<class _ForwardIterator>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __is_cpp17_forward_iterator<_ForwardIterator>::value,
             basic_string&
@@ -1084,7 +1073,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             basic_string&
@@ -1101,7 +1090,7 @@ public:
     basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
             && !__is_same_uncvref<_Tp, basic_string>::value,
@@ -1113,7 +1102,7 @@ public:
     basic_string& assign(size_type __n, value_type __c);
     template<class _InputIterator>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __is_exactly_cpp17_input_iterator<_InputIterator>::value,
             basic_string&
@@ -1121,7 +1110,7 @@ public:
         assign(_InputIterator __first, _InputIterator __last);
     template<class _ForwardIterator>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __is_cpp17_forward_iterator<_ForwardIterator>::value,
             basic_string&
@@ -1137,7 +1126,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             basic_string&
@@ -1147,7 +1136,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
             basic_string&
@@ -1162,7 +1151,7 @@ public:
     iterator      insert(const_iterator __pos, size_type __n, value_type __c);
     template<class _InputIterator>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __is_exactly_cpp17_input_iterator<_InputIterator>::value,
             iterator
@@ -1170,7 +1159,7 @@ public:
         insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
     template<class _ForwardIterator>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __is_cpp17_forward_iterator<_ForwardIterator>::value,
             iterator
@@ -1193,7 +1182,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             basic_string&
@@ -1202,7 +1191,7 @@ public:
     basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string>::value,
             basic_string&
@@ -1216,7 +1205,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             basic_string&
@@ -1231,7 +1220,7 @@ public:
     basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
     template<class _InputIterator>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __is_cpp17_input_iterator<_InputIterator>::value,
             basic_string&
@@ -1273,7 +1262,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             size_type
@@ -1289,7 +1278,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             size_type
@@ -1305,7 +1294,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             size_type
@@ -1322,7 +1311,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             size_type
@@ -1339,7 +1328,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             size_type
@@ -1356,7 +1345,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             size_type
@@ -1373,7 +1362,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             int
@@ -1382,7 +1371,7 @@ public:
 
     template <class _Tp>
     _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-    _EnableIf
+    __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
             int
@@ -1395,7 +1384,7 @@ public:
 
     template <class _Tp>
     inline _LIBCPP_INLINE_VISIBILITY
-        _EnableIf
+        __enable_if_t
         <
             __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string>::value,
             int
@@ -1406,28 +1395,28 @@ public:
     int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
 
 #if _LIBCPP_STD_VER > 17
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool starts_with(__self_view __sv) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool starts_with(__self_view __sv) const noexcept
     { return __self_view(data(), size()).starts_with(__sv); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool starts_with(value_type __c) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool starts_with(value_type __c) const noexcept
     { return !empty() && _Traits::eq(front(), __c); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool starts_with(const value_type* __s) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool starts_with(const value_type* __s) const noexcept
     { return starts_with(__self_view(__s)); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool ends_with(__self_view __sv) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool ends_with(__self_view __sv) const noexcept
     { return __self_view(data(), size()).ends_with( __sv); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool ends_with(value_type __c) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool ends_with(value_type __c) const noexcept
     { return !empty() && _Traits::eq(back(), __c); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool ends_with(const value_type* __s) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool ends_with(const value_type* __s) const noexcept
     { return ends_with(__self_view(__s)); }
 #endif
 
@@ -1465,6 +1454,11 @@ public:
 #endif // _LIBCPP_DEBUG_LEVEL == 2
 
 private:
+    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
+        // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
+        return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
+    }
+
     _LIBCPP_INLINE_VISIBILITY
     allocator_type& __alloc() _NOEXCEPT
         {return __r_.second();}
@@ -1591,7 +1585,7 @@ private:
 
     template <class _InputIterator>
     inline
-    _EnableIf
+    __enable_if_t
     <
         __is_exactly_cpp17_input_iterator<_InputIterator>::value
     >
@@ -1599,7 +1593,7 @@ private:
 
     template <class _ForwardIterator>
     inline
-    _EnableIf
+    __enable_if_t
     <
         __is_cpp17_forward_iterator<_ForwardIterator>::value
     >
@@ -1705,6 +1699,13 @@ private:
       return *this;
     }
 
+    _LIBCPP_HIDE_FROM_ABI basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
+      __set_size(__newsz);
+      __invalidate_iterators_past(__newsz);
+      traits_type::assign(__p[__newsz], value_type());
+      return *this;
+    }
+
     _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
     _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
 
@@ -1717,20 +1718,12 @@ private:
 
     _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
     void __throw_length_error() const {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        __basic_string_common<true>::__throw_length_error();
-#else
-        _VSTD::abort();
-#endif
+        _VSTD::__throw_length_error("basic_string");
     }
 
     _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
     void __throw_out_of_range() const {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        __basic_string_common<true>::__throw_out_of_range();
-#else
-        _VSTD::abort();
-#endif
+        _VSTD::__throw_out_of_range("basic_string");
     }
 
     friend basic_string operator+<>(const basic_string&, const basic_string&);
@@ -1743,20 +1736,24 @@ private:
 // These declarations must appear before any functions are implicitly used
 // so that they have the correct visibility specifier.
 #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
-_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
-_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
+    _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
+#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+        _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
+#   endif
 #else
-_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
-_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
+    _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
+#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+        _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
+#   endif
 #endif
 
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _CharT = __iter_value_type<_InputIterator>,
          class _Allocator = allocator<_CharT>,
-         class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>
          >
 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
   -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
@@ -1764,7 +1761,7 @@ basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
 template<class _CharT,
          class _Traits,
          class _Allocator = allocator<_CharT>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>
+         class = enable_if_t<__is_allocator<_Allocator>::value>
          >
 explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
   -> basic_string<_CharT, _Traits, _Allocator>;
@@ -1772,7 +1769,7 @@ explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _A
 template<class _CharT,
          class _Traits,
          class _Allocator = allocator<_CharT>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>,
          class _Sz = typename allocator_traits<_Allocator>::size_type
          >
 basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
@@ -1785,7 +1782,8 @@ void
 basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
 {
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__invalidate_all(this);
+    if (!__libcpp_is_constant_evaluated())
+        __get_db()->__invalidate_all(this);
 #endif
 }
 
@@ -1795,22 +1793,24 @@ void
 basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
 {
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __c_node* __c = __get_db()->__find_c_and_lock(this);
-    if (__c)
-    {
-        const_pointer __new_last = __get_pointer() + __pos;
-        for (__i_node** __p = __c->end_; __p != __c->beg_; )
+    if (!__libcpp_is_constant_evaluated()) {
+        __c_node* __c = __get_db()->__find_c_and_lock(this);
+        if (__c)
         {
-            --__p;
-            const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
-            if (__i->base() > __new_last)
+            const_pointer __new_last = __get_pointer() + __pos;
+            for (__i_node** __p = __c->end_; __p != __c->beg_; )
             {
-                (*__p)->__c_ = nullptr;
-                if (--__c->end_ != __p)
-                    _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
+                --__p;
+                const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
+                if (__i->base() > __new_last)
+                {
+                    (*__p)->__c_ = nullptr;
+                    if (--__c->end_ != __p)
+                        _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
+                }
             }
+            __get_db()->unlock();
         }
-        __get_db()->unlock();
     }
 #else
     (void)__pos;
@@ -1823,9 +1823,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string()
     _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
      : __r_(__default_init_tag(), __default_init_tag())
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __zero();
 }
 
@@ -1839,9 +1837,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __
 #endif
 : __r_(__default_init_tag(), __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __zero();
 }
 
@@ -1851,9 +1847,9 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
                                                        size_type __reserve)
 {
     if (__reserve > max_size())
-        this->__throw_length_error();
+        __throw_length_error();
     pointer __p;
-    if (__reserve < __min_cap)
+    if (__fits_in_sso(__reserve))
     {
         __set_short_size(__sz);
         __p = __get_short_pointer();
@@ -1875,9 +1871,9 @@ void
 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
 {
     if (__sz > max_size())
-        this->__throw_length_error();
+        __throw_length_error();
     pointer __p;
-    if (__sz < __min_cap)
+    if (__fits_in_sso(__sz))
     {
         __set_short_size(__sz);
         __p = __get_short_pointer();
@@ -1901,9 +1897,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const
 {
     _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
     __init(__s, traits_type::length(__s));
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -1913,9 +1907,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_
 {
     _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
     __init(__s, __n);
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -1925,9 +1917,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_
 {
     _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
     __init(__s, __n);
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -1939,10 +1929,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
     else
         __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
                                   __str.__get_long_size());
-
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -1955,21 +1942,19 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
     else
         __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
                                   __str.__get_long_size());
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
     const value_type* __s, size_type __sz) {
   pointer __p;
-  if (__sz < __min_cap) {
+  if (__fits_in_sso(__sz)) {
     __p = __get_short_pointer();
     __set_short_size(__sz);
   } else {
     if (__sz > max_size())
-      this->__throw_length_error();
+      __throw_length_error();
     size_t __cap = __recommend(__sz);
     __p = __alloc_traits::allocate(__alloc(), __cap + 1);
     __set_long_pointer(__p);
@@ -1992,9 +1977,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
     : __r_(_VSTD::move(__str.__r_))
 {
     __str.__zero();
+    _VSTD::__debug_db_insert_c(this);
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    if (__is_long())
+    if (!__libcpp_is_constant_evaluated() && __is_long())
         __get_db()->swap(this, &__str);
 #endif
 }
@@ -2011,9 +1996,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co
         __r_.first().__r = __str.__r_.first().__r;
         __str.__zero();
     }
+    _VSTD::__debug_db_insert_c(this);
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    if (__is_long())
+    if (!__libcpp_is_constant_evaluated() && __is_long())
         __get_db()->swap(this, &__str);
 #endif
 }
@@ -2025,9 +2010,9 @@ void
 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
 {
     if (__n > max_size())
-        this->__throw_length_error();
+        __throw_length_error();
     pointer __p;
-    if (__n < __min_cap)
+    if (__fits_in_sso(__n))
     {
         __set_short_size(__n);
         __p = __get_short_pointer();
@@ -2050,9 +2035,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __
      : __r_(__default_init_tag(), __default_init_tag())
 {
     __init(__n, __c);
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2061,9 +2044,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __
     : __r_(__default_init_tag(), __a)
 {
     __init(__n, __c);
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2074,11 +2055,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
 {
     size_type __str_sz = __str.size();
     if (__pos > __str_sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2089,11 +2068,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
 {
     size_type __str_sz = __str.size();
     if (__pos > __str_sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     __init(__str.data() + __pos, __str_sz - __pos);
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2105,9 +2082,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
     __self_view __sv0 = __t;
     __self_view __sv = __sv0.substr(__pos, __n);
     __init(__sv.data(), __sv.size());
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2117,9 +2092,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
 {
     __self_view __sv = __t;
     __init(__sv.data(), __sv.size());
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2129,14 +2102,12 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _
 {
     __self_view __sv = __t;
     __init(__sv.data(), __sv.size());
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _InputIterator>
-_EnableIf
+__enable_if_t
 <
     __is_exactly_cpp17_input_iterator<_InputIterator>::value
 >
@@ -2162,7 +2133,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _Input
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _ForwardIterator>
-_EnableIf
+__enable_if_t
 <
     __is_cpp17_forward_iterator<_ForwardIterator>::value
 >
@@ -2170,9 +2141,9 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For
 {
     size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
     if (__sz > max_size())
-        this->__throw_length_error();
+        __throw_length_error();
     pointer __p;
-    if (__sz < __min_cap)
+    if (__fits_in_sso(__sz))
     {
         __set_short_size(__sz);
         __p = __get_short_pointer();
@@ -2211,9 +2182,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first,
      : __r_(__default_init_tag(), __default_init_tag())
 {
     __init(__first, __last);
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2224,9 +2193,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first,
     : __r_(__default_init_tag(), __a)
 {
     __init(__first, __last);
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -2238,9 +2205,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
      : __r_(__default_init_tag(), __default_init_tag())
 {
     __init(__il.begin(), __il.end());
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2251,9 +2216,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
     : __r_(__default_init_tag(), __a)
 {
     __init(__il.begin(), __il.end());
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 #endif // _LIBCPP_CXX03_LANG
@@ -2262,7 +2225,8 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
 {
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__erase_c(this);
+    if (!__libcpp_is_constant_evaluated())
+        __get_db()->__erase_c(this);
 #endif
     if (__is_long())
         __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
@@ -2276,7 +2240,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
 {
     size_type __ms = max_size();
     if (__delta_cap > __ms - __old_cap - 1)
-        this->__throw_length_error();
+        __throw_length_error();
     pointer __old_p = __get_pointer();
     size_type __cap = __old_cap < __ms / 2 - __alignment ?
                           __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
@@ -2308,7 +2272,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
 {
     size_type __ms = max_size();
     if (__delta_cap > __ms - __old_cap)
-        this->__throw_length_error();
+        __throw_length_error();
     pointer __old_p = __get_pointer();
     size_type __cap = __old_cap < __ms / 2 - __alignment ?
                           __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
@@ -2358,14 +2322,12 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_external(
   if (__cap >= __n) {
     value_type* __p = _VSTD::__to_address(__get_pointer());
     traits_type::move(__p, __s, __n);
-    traits_type::assign(__p[__n], value_type());
-    __set_size(__n);
-    __invalidate_iterators_past(__n);
+    return __null_terminate_at(__p, __n);
   } else {
     size_type __sz = size();
     __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
+    return *this;
   }
-  return *this;
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2373,7 +2335,7 @@ basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
 {
     _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
-    return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
+    return (__builtin_constant_p(__n) && __fits_in_sso(__n))
                ? __assign_short(__s, __n)
                : __assign_external(__s, __n);
 }
@@ -2390,10 +2352,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
     }
     value_type* __p = _VSTD::__to_address(__get_pointer());
     traits_type::assign(__p, __n, __c);
-    traits_type::assign(__p[__n], value_type());
-    __set_size(__n);
-    __invalidate_iterators_past(__n);
-    return *this;
+    return __null_terminate_at(__p, __n);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2491,7 +2450,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _InputIterator>
-_EnableIf
+__enable_if_t
 <
      __is_exactly_cpp17_input_iterator<_InputIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
@@ -2505,7 +2464,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _Input
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _ForwardIterator>
-_EnableIf
+__enable_if_t
 <
     __is_cpp17_forward_iterator<_ForwardIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
@@ -2525,7 +2484,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _For
             __grow_by(__cap, __n - __cap, __sz, 0, __sz);
         }
         pointer __p = __get_pointer();
-        for (; __first != __last; ++__first, ++__p)
+        for (; __first != __last; ++__p, (void) ++__first)
             traits_type::assign(*__p, *__first);
         traits_type::assign(*__p, value_type());
         __set_size(__n);
@@ -2545,13 +2504,13 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, siz
 {
     size_type __sz = __str.size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
     && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
@@ -2562,7 +2521,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __p
     __self_view __sv = __t;
     size_type __sz = __sv.size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
 }
 
@@ -2578,8 +2537,8 @@ basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
 {
     _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
-    return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
-               ? (traits_type::length(__s) < __min_cap
+    return __builtin_constant_p(*__s)
+               ? (__fits_in_sso(traits_type::length(__s))
                       ? __assign_short(__s, traits_type::length(__s))
                       : __assign_external(__s, traits_type::length(__s)))
                : __assign_external(__s);
@@ -2665,7 +2624,7 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
     if (__sz == __cap)
     {
         __grow_by(__cap, 1, __sz, __sz, 0);
-        __is_short = !__is_long();
+        __is_short = false; // the string is always long after __grow_by
     }
     pointer __p;
     if (__is_short)
@@ -2684,7 +2643,7 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _ForwardIterator>
-_EnableIf
+__enable_if_t
 <
     __is_cpp17_forward_iterator<_ForwardIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
@@ -2703,7 +2662,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(
             if (__cap - __sz < __n)
                 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
             pointer __p = __get_pointer() + __sz;
-            for (; __first != __last; ++__p, ++__first)
+            for (; __first != __last; ++__p, (void) ++__first)
                 traits_type::assign(*__p, *__first);
             traits_type::assign(*__p, value_type());
             __set_size(__sz + __n);
@@ -2731,13 +2690,13 @@ basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, siz
 {
     size_type __sz = __str.size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-    _EnableIf
+    __enable_if_t
     <
         __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
         basic_string<_CharT, _Traits, _Allocator>&
@@ -2747,7 +2706,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __p
     __self_view __sv = __t;
     size_type __sz = __sv.size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
 }
 
@@ -2768,7 +2727,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
     _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
     size_type __sz = size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     size_type __cap = capacity();
     if (__cap - __sz >= __n)
     {
@@ -2799,7 +2758,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
 {
     size_type __sz = size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     if (__n)
     {
         size_type __cap = capacity();
@@ -2826,36 +2785,33 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _InputIterator>
-_EnableIf
+__enable_if_t
 <
    __is_exactly_cpp17_input_iterator<_InputIterator>::value,
    typename basic_string<_CharT, _Traits, _Allocator>::iterator
 >
 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
-        "string::insert(iterator, range) called with an iterator not"
-        " referring to this string");
-#endif
-    const basic_string __temp(__first, __last, __alloc());
-    return insert(__pos, __temp.data(), __temp.data() + __temp.size());
+  _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
+                       "string::insert(iterator, range) called with an iterator not"
+                       " referring to this string");
+  const basic_string __temp(__first, __last, __alloc());
+  return insert(__pos, __temp.data(), __temp.data() + __temp.size());
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _ForwardIterator>
-_EnableIf
+__enable_if_t
 <
     __is_cpp17_forward_iterator<_ForwardIterator>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::iterator
 >
 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
-        "string::insert(iterator, range) called with an iterator not"
-        " referring to this string");
-#endif
+  _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
+                       "string::insert(iterator, range) called with an iterator not"
+                       " referring to this string");
+
     size_type __ip = static_cast<size_type>(__pos - begin());
     size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
     if (__n)
@@ -2881,7 +2837,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _Forward
             __sz += __n;
             __set_size(__sz);
             traits_type::assign(__p[__sz], value_type());
-            for (__p += __ip; __first != __last; ++__p, ++__first)
+            for (__p += __ip; __first != __last; ++__p, (void) ++__first)
                 traits_type::assign(*__p, *__first);
         }
         else
@@ -2908,13 +2864,13 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_
 {
     size_type __str_sz = __str.size();
     if (__pos2 > __str_sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
     basic_string<_CharT, _Traits, _Allocator>&
@@ -2925,7 +2881,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& _
     __self_view __sv = __t;
     size_type __str_sz = __sv.size();
     if (__pos2 > __str_sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
 }
 
@@ -2941,6 +2897,10 @@ template <class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::iterator
 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
 {
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
+                         "string::insert(iterator, character) called with an iterator not"
+                         " referring to this string");
+
     size_type __ip = static_cast<size_type>(__pos - begin());
     size_type __sz = size();
     size_type __cap = capacity();
@@ -2968,14 +2928,12 @@ inline
 typename basic_string<_CharT, _Traits, _Allocator>::iterator
 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
-        "string::insert(iterator, n, value) called with an iterator not"
-        " referring to this string");
-#endif
-    difference_type __p = __pos - begin();
-    insert(static_cast<size_type>(__p), __n, __c);
-    return begin() + __p;
+  _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
+                       "string::insert(iterator, n, value) called with an iterator not"
+                       " referring to this string");
+  difference_type __p = __pos - begin();
+  insert(static_cast<size_type>(__p), __n, __c);
+  return begin() + __p;
 }
 
 // replace
@@ -2988,7 +2946,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
     _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
     size_type __sz = size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     __n1 = _VSTD::min(__n1, __sz - __pos);
     size_type __cap = capacity();
     if (__cap - __sz + __n1 >= __n2)
@@ -3003,7 +2961,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
                 {
                     traits_type::move(__p + __pos, __s, __n2);
                     traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
-                    goto __finish;
+                    return __null_terminate_at(__p, __sz + (__n2 - __n1));
                 }
                 if (__p + __pos < __s && __s < __p + __sz)
                 {
@@ -3022,13 +2980,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
             }
         }
         traits_type::move(__p + __pos, __s, __n2);
-__finish:
-// __sz += __n2 - __n1; in this and the below function below can cause unsigned
-// integer overflow, but this is a safe operation, so we disable the check.
-        __sz += __n2 - __n1;
-        __set_size(__sz);
-        __invalidate_iterators_past(__sz);
-        traits_type::assign(__p[__sz], value_type());
+        return __null_terminate_at(__p, __sz + (__n2 - __n1));
     }
     else
         __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
@@ -3038,11 +2990,10 @@ __finish:
 template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
-    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
 {
     size_type __sz = size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     __n1 = _VSTD::min(__n1, __sz - __pos);
     size_type __cap = capacity();
     value_type* __p;
@@ -3062,16 +3013,12 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
         __p = _VSTD::__to_address(__get_long_pointer());
     }
     traits_type::assign(__p + __pos, __n2, __c);
-    __sz += __n2 - __n1;
-    __set_size(__sz);
-    __invalidate_iterators_past(__sz);
-    traits_type::assign(__p[__sz], value_type());
-    return *this;
+    return __null_terminate_at(__p, __sz - (__n1 - __n2));
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _InputIterator>
-_EnableIf
+__enable_if_t
 <
     __is_cpp17_input_iterator<_InputIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
@@ -3080,7 +3027,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
                                                    _InputIterator __j1, _InputIterator __j2)
 {
     const basic_string __temp(__j1, __j2, __alloc());
-    return this->replace(__i1, __i2, __temp);
+    return replace(__i1, __i2, __temp);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -3098,13 +3045,13 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
 {
     size_type __str_sz = __str.size();
     if (__pos2 > __str_sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
     basic_string<_CharT, _Traits, _Allocator>&
@@ -3115,7 +3062,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
     __self_view __sv = __t;
     size_type __str_sz = __sv.size();
     if (__pos2 > __str_sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
 }
 
@@ -3177,10 +3124,7 @@ basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
         size_type __n_move = __sz - __pos - __n;
         if (__n_move != 0)
             traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
-        __sz -= __n;
-        __set_size(__sz);
-        __invalidate_iterators_past(__sz);
-        traits_type::assign(__p[__sz], value_type());
+        __null_terminate_at(__p, __sz - __n);
     }
 }
 
@@ -3188,7 +3132,8 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
                                                  size_type __n) {
-  if (__pos > size()) this->__throw_out_of_range();
+  if (__pos > size())
+    __throw_out_of_range();
   if (__n == npos) {
     __erase_to_end(__pos);
   } else {
@@ -3202,17 +3147,15 @@ inline
 typename basic_string<_CharT, _Traits, _Allocator>::iterator
 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
-        "string::erase(iterator) called with an iterator not"
-        " referring to this string");
-#endif
-    _LIBCPP_ASSERT(__pos != end(),
-        "string::erase(iterator) called with a non-dereferenceable iterator");
-    iterator __b = begin();
-    size_type __r = static_cast<size_type>(__pos - __b);
-    erase(__r, 1);
-    return __b + static_cast<difference_type>(__r);
+  _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
+                       "string::erase(iterator) called with an iterator not"
+                       " referring to this string");
+
+  _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator");
+  iterator __b = begin();
+  size_type __r = static_cast<size_type>(__pos - __b);
+  erase(__r, 1);
+  return __b + static_cast<difference_type>(__r);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -3220,16 +3163,15 @@ inline
 typename basic_string<_CharT, _Traits, _Allocator>::iterator
 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
-        "string::erase(iterator,  iterator) called with an iterator not"
-        " referring to this string");
-#endif
-    _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
-    iterator __b = begin();
-    size_type __r = static_cast<size_type>(__first - __b);
-    erase(__r, static_cast<size_type>(__last - __first));
-    return __b + static_cast<difference_type>(__r);
+  _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
+                       "string::erase(iterator,  iterator) called with an iterator not"
+                       " referring to this string");
+
+  _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
+  iterator __b = begin();
+  size_type __r = static_cast<size_type>(__first - __b);
+  erase(__r, static_cast<size_type>(__last - __first));
+  return __b + static_cast<difference_type>(__r);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -3238,20 +3180,7 @@ void
 basic_string<_CharT, _Traits, _Allocator>::pop_back()
 {
     _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
-    size_type __sz;
-    if (__is_long())
-    {
-        __sz = __get_long_size() - 1;
-        __set_long_size(__sz);
-        traits_type::assign(*(__get_long_pointer() + __sz), value_type());
-    }
-    else
-    {
-        __sz = __get_short_size() - 1;
-        __set_short_size(__sz);
-        traits_type::assign(*(__get_short_pointer() + __sz), value_type());
-    }
-    __invalidate_iterators_past(__sz);
+    __erase_to_end(size() - 1);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -3277,17 +3206,7 @@ inline
 void
 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
 {
-    if (__is_long())
-    {
-        traits_type::assign(*(__get_long_pointer() + __pos), value_type());
-        __set_long_size(__pos);
-    }
-    else
-    {
-        traits_type::assign(*(__get_short_pointer() + __pos), value_type());
-        __set_short_size(__pos);
-    }
-    __invalidate_iterators_past(__pos);
+  __null_terminate_at(_VSTD::__to_address(__get_pointer()), __pos);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -3330,12 +3249,13 @@ void
 basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
 {
     if (__requested_capacity > max_size())
-        this->__throw_length_error();
+        __throw_length_error();
 
-#if _LIBCPP_STD_VER > 17
-    // Reserve never shrinks as of C++20.
-    if (__requested_capacity <= capacity()) return;
-#endif
+    // Make sure reserve(n) never shrinks. This is technically only required in C++20
+    // and later (since P0966R1), however we provide consistent behavior in all Standard
+    // modes because this function is instantiated in the shared library.
+    if (__requested_capacity <= capacity())
+        return;
 
     size_type __target_capacity = _VSTD::max(__requested_capacity, size());
     __target_capacity = __recommend(__target_capacity);
@@ -3345,6 +3265,7 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacit
 }
 
 template <class _CharT, class _Traits, class _Allocator>
+inline
 void
 basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
 {
@@ -3355,6 +3276,7 @@ basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
 }
 
 template <class _CharT, class _Traits, class _Allocator>
+inline
 void
 basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
 {
@@ -3434,7 +3356,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::const_reference
 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
 {
     if (__n >= size())
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return (*this)[__n];
 }
 
@@ -3443,7 +3365,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::reference
 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
 {
     if (__n >= size())
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     return (*this)[__n];
 }
 
@@ -3489,7 +3411,7 @@ basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n,
 {
     size_type __sz = size();
     if (__pos > __sz)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     size_type __rlen = _VSTD::min(__n, __sz - __pos);
     traits_type::copy(__s, data() + __pos, __rlen);
     return __rlen;
@@ -3515,11 +3437,13 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
 #endif
 {
 #if _LIBCPP_DEBUG_LEVEL == 2
-    if (!__is_long())
-        __get_db()->__invalidate_all(this);
-    if (!__str.__is_long())
-        __get_db()->__invalidate_all(&__str);
-    __get_db()->swap(this, &__str);
+    if (!__libcpp_is_constant_evaluated()) {
+        if (!__is_long())
+            __get_db()->__invalidate_all(this);
+        if (!__str.__is_long())
+            __get_db()->__invalidate_all(&__str);
+        __get_db()->swap(this, &__str);
+    }
 #endif
     _LIBCPP_ASSERT(
         __alloc_traits::propagate_on_container_swap::value ||
@@ -3563,7 +3487,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
 
 template<class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::size_type
@@ -3621,7 +3545,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
 
 template<class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::size_type
@@ -3679,7 +3603,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __s
 
 template<class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::size_type
@@ -3737,7 +3661,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __st
 
 template<class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::size_type
@@ -3795,7 +3719,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string&
 
 template<class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::size_type
@@ -3854,7 +3778,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string&
 
 template<class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::size_type
@@ -3892,7 +3816,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     int
@@ -3931,7 +3855,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
     _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
     size_type __sz = size();
     if (__pos1 > __sz || __n2 == npos)
-        this->__throw_out_of_range();
+        __throw_out_of_range();
     size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
     int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
     if (__r == 0)
@@ -3946,7 +3870,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
     int
@@ -3971,7 +3895,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
 
 template <class _CharT, class _Traits, class _Allocator>
 template <class _Tp>
-_EnableIf
+__enable_if_t
 <
     __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
     && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
@@ -3995,7 +3919,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
                                                    size_type __pos2,
                                                    size_type __n2) const
 {
-        return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
+    return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -4409,6 +4333,7 @@ _LIBCPP_FUNC_VIS string to_string(float __val);
 _LIBCPP_FUNC_VIS string to_string(double __val);
 _LIBCPP_FUNC_VIS string to_string(long double __val);
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _LIBCPP_FUNC_VIS int                stoi  (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
 _LIBCPP_FUNC_VIS long               stol  (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
 _LIBCPP_FUNC_VIS unsigned long      stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
@@ -4428,6 +4353,7 @@ _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
 _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
 _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
 _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_TEMPLATE_DATA_VIS
@@ -4507,16 +4433,16 @@ template<class _CharT, class _Traits, class _Allocator>
 bool
 basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
 {
-    return this->data() <= _VSTD::__to_address(__i->base()) &&
-           _VSTD::__to_address(__i->base()) < this->data() + this->size();
+    return data() <= _VSTD::__to_address(__i->base()) &&
+           _VSTD::__to_address(__i->base()) < data() + size();
 }
 
 template<class _CharT, class _Traits, class _Allocator>
 bool
 basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
 {
-    return this->data() < _VSTD::__to_address(__i->base()) &&
-           _VSTD::__to_address(__i->base()) <= this->data() + this->size();
+    return data() < _VSTD::__to_address(__i->base()) &&
+           _VSTD::__to_address(__i->base()) <= data() + size();
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -4524,7 +4450,7 @@ bool
 basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
 {
     const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
-    return this->data() <= __p && __p <= this->data() + this->size();
+    return data() <= __p && __p <= data() + size();
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -4532,7 +4458,7 @@ bool
 basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
 {
     const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
-    return this->data() <= __p && __p < this->data() + this->size();
+    return data() <= __p && __p < data() + size();
 }
 
 #endif // _LIBCPP_DEBUG_LEVEL == 2
@@ -4549,11 +4475,13 @@ inline namespace literals
         return basic_string<char> (__str, __len);
     }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     inline _LIBCPP_INLINE_VISIBILITY
     basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
     {
         return basic_string<wchar_t> (__str, __len);
     }
+#endif
 
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
     inline _LIBCPP_INLINE_VISIBILITY
@@ -4574,8 +4502,8 @@ inline namespace literals
     {
         return basic_string<char32_t> (__str, __len);
     }
-  }
-}
+  } // namespace string_literals
+} // namespace literals
 #endif
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/string.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- string.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/string_view
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ string_view ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -85,6 +85,10 @@ namespace std {
       constexpr basic_string_view(const charT* str);
       basic_string_view(nullptr_t) = delete; // C++2b
       constexpr basic_string_view(const charT* str, size_type len);
+      template <class It, class End>
+      constexpr basic_string_view(It begin, End end); // C++20
+      template <class Range>
+      constexpr basic_string_view(Range&& r); // C++23
 
       // 7.4, basic_string_view iterator support
       constexpr const_iterator begin() const noexcept;
@@ -166,6 +170,12 @@ namespace std {
       size_type     size_;  // exposition only
     };
 
+  // basic_string_view deduction guides
+  template<class It, class End>
+    basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
+  template<class Range>
+    basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
+
   // 7.11, Hash support
   template <class T> struct hash;
   template <> struct hash<string_view>;
@@ -187,8 +197,11 @@ namespace std {
 
 #include <__config>
 #include <__debug>
+#include <__ranges/concepts.h>
+#include <__ranges/data.h>
 #include <__ranges/enable_borrowed_range.h>
 #include <__ranges/enable_view.h>
+#include <__ranges/size.h>
 #include <__string>
 #include <algorithm>
 #include <compare>
@@ -196,6 +209,7 @@ namespace std {
 #include <iterator>
 #include <limits>
 #include <stdexcept>
+#include <type_traits>
 #include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -217,7 +231,9 @@ typedef basic_string_view<char8_t>  u8string_view;
 #endif
 typedef basic_string_view<char16_t> u16string_view;
 typedef basic_string_view<char32_t> u32string_view;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 typedef basic_string_view<wchar_t>  wstring_view;
+#endif
 
 template<class _CharT, class _Traits>
 class
@@ -227,7 +243,7 @@ class
 #endif
     _LIBCPP_PREFERRED_NAME(u16string_view)
     _LIBCPP_PREFERRED_NAME(u32string_view)
-    _LIBCPP_PREFERRED_NAME(wstring_view)
+    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring_view))
     basic_string_view {
 public:
     // types
@@ -255,10 +271,10 @@ public:
     _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
     basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
 
-    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY
     basic_string_view(const basic_string_view&) _NOEXCEPT = default;
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY
     basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
 
     _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
@@ -270,6 +286,35 @@ public:
 #endif
     }
 
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+    template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
+      requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
+    constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
+       : __data(_VSTD::to_address(__begin)), __size(__end - __begin)
+    {
+      _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
+    }
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+    template <class _Range>
+      requires (
+        !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
+        ranges::contiguous_range<_Range> &&
+        ranges::sized_range<_Range> &&
+        is_same_v<ranges::range_value_t<_Range>, _CharT> &&
+        !is_convertible_v<_Range, const _CharT*> &&
+        (!requires(remove_cvref_t<_Range>& d) {
+          d.operator _VSTD::basic_string_view<_CharT, _Traits>();
+        }) &&
+        (!requires {
+         typename remove_reference_t<_Range>::traits_type;
+        } || is_same_v<typename remove_reference_t<_Range>::traits_type, _Traits>)
+      )
+    constexpr _LIBCPP_HIDE_FROM_ABI
+    basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {}
+#endif
+
     _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
     basic_string_view(const _CharT* __s)
         : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
@@ -311,7 +356,7 @@ public:
     size_type length()   const _NOEXCEPT { return __size; }
 
     _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
+    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); }
 
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     bool empty()         const _NOEXCEPT { return __size == 0; }
@@ -618,28 +663,28 @@ public:
     }
 
 #if _LIBCPP_STD_VER > 17
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool starts_with(basic_string_view __s) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool starts_with(basic_string_view __s) const noexcept
     { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool starts_with(value_type __c) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool starts_with(value_type __c) const noexcept
     { return !empty() && _Traits::eq(front(), __c); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool starts_with(const value_type* __s) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool starts_with(const value_type* __s) const noexcept
     { return starts_with(basic_string_view(__s)); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool ends_with(basic_string_view __s) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool ends_with(basic_string_view __s) const noexcept
     { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool ends_with(value_type __c) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool ends_with(value_type __c) const noexcept
     { return !empty() && _Traits::eq(back(), __c); }
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-    bool ends_with(const value_type* __s) const _NOEXCEPT
+    constexpr _LIBCPP_INLINE_VISIBILITY
+    bool ends_with(const value_type* __s) const noexcept
     { return ends_with(basic_string_view(__s)); }
 #endif
 
@@ -662,13 +707,26 @@ private:
     size_type           __size;
 };
 
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 template <class _CharT, class _Traits>
 inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
 
 template <class _CharT, class _Traits>
 inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// [string.view.deduct]
+
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
+  basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+
+#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+template <ranges::contiguous_range _Range>
+  basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
+#endif
 
 // [string.view.comparison]
 // operator ==
@@ -681,7 +739,9 @@ bool operator==(basic_string_view<_CharT, _Traits> __lhs,
     return __lhs.compare(__rhs) == 0;
 }
 
-template<class _CharT, class _Traits>
+// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
+// This applies to the other sufficient overloads below for the other comparison operators.
+template<class _CharT, class _Traits, int = 1>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator==(basic_string_view<_CharT, _Traits> __lhs,
                 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -690,7 +750,7 @@ bool operator==(basic_string_view<_CharT, _Traits> __lhs,
     return __lhs.compare(__rhs) == 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
                 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -710,7 +770,7 @@ bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
     return __lhs.compare(__rhs) != 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
                 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -720,7 +780,7 @@ bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
     return __lhs.compare(__rhs) != 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
                 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -739,7 +799,7 @@ bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Char
     return __lhs.compare(__rhs) < 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator<(basic_string_view<_CharT, _Traits> __lhs,
                 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -747,7 +807,7 @@ bool operator<(basic_string_view<_CharT, _Traits> __lhs,
     return __lhs.compare(__rhs) < 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
                 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -764,7 +824,7 @@ bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
     return __lhs.compare(__rhs) > 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator>(basic_string_view<_CharT, _Traits> __lhs,
                 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -772,7 +832,7 @@ bool operator>(basic_string_view<_CharT, _Traits> __lhs,
     return __lhs.compare(__rhs) > 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
                 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -789,7 +849,7 @@ bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
     return __lhs.compare(__rhs) <= 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
                 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -797,7 +857,7 @@ bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
     return __lhs.compare(__rhs) <= 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
                 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -815,7 +875,7 @@ bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
 }
 
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
                 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -823,7 +883,7 @@ bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
     return __lhs.compare(__rhs) >= 0;
 }
 
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
                 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -860,11 +920,13 @@ inline namespace literals
         return basic_string_view<char> (__str, __len);
     }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT
     {
         return basic_string_view<wchar_t> (__str, __len);
     }
+#endif
 
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
     inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
@@ -885,8 +947,8 @@ inline namespace literals
     {
         return basic_string_view<char32_t> (__str, __len);
     }
-  }
-}
+  } // namespace string_view_literals
+} // namespace literals
 #endif
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/strstream
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- strstream --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -132,6 +132,7 @@ private:
 #include <__config>
 #include <istream>
 #include <ostream>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/system_error
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- system_error ----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -46,10 +46,10 @@ template <class T> struct is_error_condition_enum
     : public false_type {};
 
 template <class _Tp>
-inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
+inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
 
 template <class _Tp>
-inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
+inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
 
 class error_code
 {
@@ -150,6 +150,7 @@ template <> struct hash<std::error_condition>;
 #include <stdexcept>
 #include <string>
 #include <type_traits>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -165,7 +166,7 @@ struct _LIBCPP_TEMPLATE_VIS is_error_code_enum
 
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
+inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value;
 #endif
 
 // is_error_condition_enum
@@ -176,7 +177,7 @@ struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
 
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
+inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
 #endif
 
 template <>
@@ -206,13 +207,11 @@ public:
     error_category() _NOEXCEPT;
 #else
     _LIBCPP_INLINE_VISIBILITY
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
 #endif
-private:
-    error_category(const error_category&);// = delete;
-    error_category& operator=(const error_category&);// = delete;
+    error_category(const error_category&) = delete;
+    error_category& operator=(const error_category&) = delete;
 
-public:
     virtual const char* name() const _NOEXCEPT = 0;
     virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
     virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
lib/libcxx/include/tgmath.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- tgmath.h ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/include/thread
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- thread -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -86,8 +86,9 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
 #include <__debug>
 #include <__functional_base>
 #include <__mutex_base>
+#include <__thread/poll_with_backoff.h>
+#include <__thread/timed_backoff_policy.h>
 #include <__threading_support>
-#include <__utility/__decay_copy.h>
 #include <__utility/forward.h>
 #include <chrono>
 #include <cstddef>
@@ -97,6 +98,7 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
 #include <system_error>
 #include <tuple>
 #include <type_traits>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -302,8 +304,8 @@ thread::thread(_Fp&& __f, _Args&&... __args)
     typedef tuple<_TSPtr, typename decay<_Fp>::type, typename decay<_Args>::type...> _Gp;
     unique_ptr<_Gp> __p(
             new _Gp(_VSTD::move(__tsp),
-                    _VSTD::__decay_copy(_VSTD::forward<_Fp>(__f)),
-                    _VSTD::__decay_copy(_VSTD::forward<_Args>(__args))...));
+                    _VSTD::forward<_Fp>(__f),
+                    _VSTD::forward<_Args>(__args)...));
     int __ec = _VSTD::__libcpp_thread_create(&__t_, &__thread_proxy<_Gp>, __p.get());
     if (__ec == 0)
         __p.release();
@@ -402,7 +404,7 @@ sleep_until(const chrono::time_point<chrono::steady_clock, _Duration>& __t)
 inline _LIBCPP_INLINE_VISIBILITY
 void yield() _NOEXCEPT {__libcpp_thread_yield();}
 
-}  // this_thread
+} // namespace this_thread
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/include/tuple
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- tuple ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -73,6 +73,19 @@ public:
     void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));               // constexpr in C++20
 };
 
+
+template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
+  requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
+struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
+  using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
+};
+
+template<class... TTypes, class... UTypes>                                // since C++23
+  requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
+struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
+  using type = tuple<common_type_t<TTypes, UTypes>...>;
+};
+
 template <class ...T>
 tuple(T...) -> tuple<T...>;                                         // since C++17
 template <class T1, class T2>
@@ -132,11 +145,14 @@ template <class T1, class... T>
 
 // 20.4.1.6, relational operators:
 template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
-template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
-template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
-template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14
-template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
-template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
+template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20
+template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
+template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);  // constexpr in C++14, removed in C++20
+template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
+template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
+template<class... T, class... U>
+  constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
+    operator<=>(const tuple<T...>&, const tuple<U...>&);                                  // since C++20
 
 template <class... Types, class Alloc>
   struct uses_allocator<tuple<Types...>, Alloc>;
@@ -149,6 +165,8 @@ template <class... Types>
 
 */
 
+#include <__compare/common_comparison_category.h>
+#include <__compare/synth_three_way.h>
 #include <__config>
 #include <__functional/unwrap_ref.h>
 #include <__functional_base>
@@ -156,6 +174,7 @@ template <class... Types>
 #include <__memory/uses_allocator.h>
 #include <__tuple>
 #include <__utility/forward.h>
+#include <__utility/integer_sequence.h>
 #include <__utility/move.h>
 #include <compare>
 #include <cstddef>
@@ -231,7 +250,7 @@ public:
               "Attempted to default construct a reference element in a tuple");}
 
     template <class _Tp,
-              class = _EnableIf<
+              class = __enable_if_t<
                   _And<
                       _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
                       is_constructible<_Hp, _Tp>
@@ -304,7 +323,7 @@ public:
             : _Hp(__a) {}
 
     template <class _Tp,
-              class = _EnableIf<
+              class = __enable_if_t<
                   _And<
                     _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
                     is_constructible<_Hp, _Tp>
@@ -466,7 +485,7 @@ public:
     // [tuple.cnstr]
 
     // tuple() constructors (including allocator_arg_t variants)
-    template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
+    template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
         _And<
             _IsImpDefault<_Tp>... // explicit check
         >::value
@@ -477,7 +496,7 @@ public:
     { }
 
     template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
-              template<class...> class _IsDefault = is_default_constructible, _EnableIf<
+              template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
         _And<
             _IsDefault<_Tp>...,
             _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
@@ -488,7 +507,7 @@ public:
         _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
     { }
 
-    template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
+    template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
         _And<
             _IsImpDefault<_Tp>... // explicit check
         >::value
@@ -502,7 +521,7 @@ public:
 
     template <class _Alloc,
               template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
-              template<class...> class _IsDefault = is_default_constructible, _EnableIf<
+              template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
         _And<
             _IsDefault<_Tp>...,
             _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
@@ -516,7 +535,7 @@ public:
                     __tuple_types<_Tp...>()) {}
 
     // tuple(const T&...) constructors (including allocator_arg_t variants)
-    template <template<class...> class _And = _And, _EnableIf<
+    template <template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) >= 1>,
             is_copy_constructible<_Tp>...,
@@ -533,7 +552,7 @@ public:
                 __t...
                ) {}
 
-    template <template<class...> class _And = _And, _EnableIf<
+    template <template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) >= 1>,
             is_copy_constructible<_Tp>...,
@@ -550,7 +569,7 @@ public:
                 __t...
                ) {}
 
-    template <class _Alloc, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) >= 1>,
             is_copy_constructible<_Tp>...,
@@ -567,7 +586,7 @@ public:
                 __t...
                ) {}
 
-    template <class _Alloc, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) >= 1>,
             is_copy_constructible<_Tp>...,
@@ -595,7 +614,7 @@ public:
         is_constructible<_Tp, _Up>...
     > { };
 
-    template <class ..._Up, _EnableIf<
+    template <class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableUTypesCtor<_Up...>,
@@ -611,7 +630,7 @@ public:
                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
                     _VSTD::forward<_Up>(__u)...) {}
 
-    template <class ..._Up, _EnableIf<
+    template <class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableUTypesCtor<_Up...>,
@@ -627,7 +646,7 @@ public:
                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
                     _VSTD::forward<_Up>(__u)...) {}
 
-    template <class _Alloc, class ..._Up, _EnableIf<
+    template <class _Alloc, class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableUTypesCtor<_Up...>,
@@ -643,7 +662,7 @@ public:
                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
                     _VSTD::forward<_Up>(__u)...) {}
 
-    template <class _Alloc, class ..._Up, _EnableIf<
+    template <class _Alloc, class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableUTypesCtor<_Up...>,
@@ -663,14 +682,14 @@ public:
     tuple(const tuple&) = default;
     tuple(tuple&&) = default;
 
-    template <class _Alloc, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
         _And<is_copy_constructible<_Tp>...>::value
     , int> = 0>
     tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
         : __base_(allocator_arg_t(), __alloc, __t)
     { }
 
-    template <class _Alloc, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
         _And<is_move_constructible<_Tp>...>::value
     , int> = 0>
     tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
@@ -693,7 +712,7 @@ public:
         is_constructible<_Tp, const _Up&>...
     > { };
 
-    template <class ..._Up, _EnableIf<
+    template <class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableCopyFromOtherTuple<_Up...>,
@@ -706,7 +725,7 @@ public:
         : __base_(__t)
     { }
 
-    template <class ..._Up, _EnableIf<
+    template <class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableCopyFromOtherTuple<_Up...>,
@@ -719,7 +738,7 @@ public:
         : __base_(__t)
     { }
 
-    template <class ..._Up, class _Alloc, _EnableIf<
+    template <class ..._Up, class _Alloc, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableCopyFromOtherTuple<_Up...>,
@@ -731,7 +750,7 @@ public:
         : __base_(allocator_arg_t(), __a, __t)
     { }
 
-    template <class ..._Up, class _Alloc, _EnableIf<
+    template <class ..._Up, class _Alloc, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableCopyFromOtherTuple<_Up...>,
@@ -759,7 +778,7 @@ public:
         is_constructible<_Tp, _Up>...
     > { };
 
-    template <class ..._Up, _EnableIf<
+    template <class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableMoveFromOtherTuple<_Up...>,
@@ -772,7 +791,7 @@ public:
         : __base_(_VSTD::move(__t))
     { }
 
-    template <class ..._Up, _EnableIf<
+    template <class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableMoveFromOtherTuple<_Up...>,
@@ -785,7 +804,7 @@ public:
         : __base_(_VSTD::move(__t))
     { }
 
-    template <class _Alloc, class ..._Up, _EnableIf<
+    template <class _Alloc, class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableMoveFromOtherTuple<_Up...>,
@@ -797,7 +816,7 @@ public:
         : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
     { }
 
-    template <class _Alloc, class ..._Up, _EnableIf<
+    template <class _Alloc, class ..._Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
             _EnableMoveFromOtherTuple<_Up...>,
@@ -826,7 +845,7 @@ public:
         _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
     > { };
 
-    template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
@@ -841,7 +860,7 @@ public:
         : __base_(__p)
     { }
 
-    template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
@@ -856,7 +875,7 @@ public:
         : __base_(__p)
     { }
 
-    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
@@ -867,7 +886,7 @@ public:
         : __base_(allocator_arg_t(), __a, __p)
     { }
 
-    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
@@ -895,7 +914,7 @@ public:
         _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
     > { };
 
-    template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
@@ -910,7 +929,7 @@ public:
         : __base_(_VSTD::move(__p))
     { }
 
-    template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
@@ -925,7 +944,7 @@ public:
         : __base_(_VSTD::move(__p))
     { }
 
-    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
@@ -936,7 +955,7 @@ public:
         : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
     { }
 
-    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
+    template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == 2>,
             _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
@@ -967,7 +986,7 @@ public:
         return *this;
     }
 
-    template<class... _Up, _EnableIf<
+    template<class... _Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
             is_assignable<_Tp&, _Up const&>...
@@ -982,7 +1001,7 @@ public:
         return *this;
     }
 
-    template<class... _Up, _EnableIf<
+    template<class... _Up, __enable_if_t<
         _And<
             _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
             is_assignable<_Tp&, _Up>...
@@ -998,7 +1017,7 @@ public:
         return *this;
     }
 
-    template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
+    template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
         _And<_Dep,
             _BoolConstant<sizeof...(_Tp) == 2>,
             is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
@@ -1017,7 +1036,7 @@ public:
         return *this;
     }
 
-    template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
+    template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
         _And<_Dep,
             _BoolConstant<sizeof...(_Tp) == 2>,
             is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
@@ -1037,7 +1056,7 @@ public:
     }
 
     // EXTENSION
-    template<class _Up, size_t _Np, class = _EnableIf<
+    template<class _Up, size_t _Np, class = __enable_if_t<
         _And<
             _BoolConstant<_Np == sizeof...(_Tp)>,
             is_assignable<_Tp&, _Up const&>...
@@ -1053,7 +1072,7 @@ public:
     }
 
     // EXTENSION
-    template<class _Up, size_t _Np, class = void, class = _EnableIf<
+    template<class _Up, size_t _Np, class = void, class = __enable_if_t<
         _And<
             _BoolConstant<_Np == sizeof...(_Tp)>,
             is_assignable<_Tp&, _Up>...
@@ -1097,7 +1116,21 @@ public:
     void swap(tuple&) _NOEXCEPT {}
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER > 20
+template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
+    requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
+struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
+    using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
+};
+
+template <class... _TTypes, class... _UTypes>
+    requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
+struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
+    using type = tuple<common_type_t<_TTypes, _UTypes>...>;
+};
+#endif
+
+#if _LIBCPP_STD_VER > 14
 template <class ..._Tp>
 tuple(_Tp...) -> tuple<_Tp...>;
 template <class _Tp1, class _Tp2>
@@ -1128,7 +1161,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 typename tuple_element<_Ip, tuple<_Tp...> >::type&
 get(tuple<_Tp...>& __t) _NOEXCEPT
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
+    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
     return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
 }
 
@@ -1137,7 +1170,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
 get(const tuple<_Tp...>& __t) _NOEXCEPT
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
+    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
     return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
 }
 
@@ -1146,7 +1179,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
 get(tuple<_Tp...>&& __t) _NOEXCEPT
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
+    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
     return static_cast<type&&>(
              static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
 }
@@ -1156,7 +1189,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
 get(const tuple<_Tp...>&& __t) _NOEXCEPT
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
+    typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
     return static_cast<const type&&>(
              static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
 }
@@ -1194,7 +1227,7 @@ struct __find_exactly_one_checked<_T1> {
     static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
 };
 
-} // namespace __find_detail;
+} // namespace __find_detail
 
 template <typename _T1, typename... _Args>
 struct __find_exactly_one_t
@@ -1250,8 +1283,8 @@ struct __ignore_t
 };
 
 namespace {
-  _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
-}
+  constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
+} // namespace
 
 template <class... _Tp>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
@@ -1300,6 +1333,30 @@ operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
     return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
 }
 
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
+// operator<=>
+
+template <class ..._Tp, class ..._Up, size_t ..._Is>
+_LIBCPP_HIDE_FROM_ABI constexpr
+auto
+__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
+    common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
+    static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
+    return __result;
+}
+
+template <class ..._Tp, class ..._Up>
+requires (sizeof...(_Tp) == sizeof...(_Up))
+_LIBCPP_HIDE_FROM_ABI constexpr
+common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
+operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
+}
+
+#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
 template <class ..._Tp, class ..._Up>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 bool
@@ -1368,6 +1425,8 @@ operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
     return !(__y < __x);
 }
 
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+
 // tuple_cat
 
 template <class _Tp, class _Up> struct __tuple_cat_type;
@@ -1375,7 +1434,7 @@ template <class _Tp, class _Up> struct __tuple_cat_type;
 template <class ..._Ttypes, class ..._Utypes>
 struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
 {
-    typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
+    typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
 };
 
 template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
@@ -1386,7 +1445,7 @@ struct __tuple_cat_return_1
 template <class ..._Types, class _Tuple0>
 struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
+    typedef _LIBCPP_NODEBUG typename __tuple_cat_type<tuple<_Types...>,
             typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
                                                                            type;
 };
@@ -1416,7 +1475,7 @@ struct __tuple_cat_return<_Tuple0, _Tuples...>
 template <>
 struct __tuple_cat_return<>
 {
-    typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
+    typedef _LIBCPP_NODEBUG tuple<> type;
 };
 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
@@ -1432,7 +1491,7 @@ struct __tuple_cat_return_ref_imp;
 template <class ..._Types, size_t ..._I0, class _Tuple0>
 struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
+    typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
     typedef tuple<_Types..., typename __apply_cv<_Tuple0,
                           typename tuple_element<_I0, _T0>::type>::type&&...> type;
 };
@@ -1480,8 +1539,8 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
     typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
     operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
     {
-        typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
-        typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
+        typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
+        typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
         return __tuple_cat<
             tuple<_Types...,
                   typename __apply_cv<_Tuple0, typename tuple_element<
@@ -1501,7 +1560,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 typename __tuple_cat_return<_Tuple0, _Tuples...>::type
 tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
+    typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
     return __tuple_cat<tuple<>, __tuple_indices<>,
                   typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
                   (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
@@ -1525,7 +1584,7 @@ pair<_T1, _T2>::pair(piecewise_construct_t,
 
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
+inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
 
 #define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
 
lib/libcxx/include/type_traits
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------ type_traits ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -455,58 +455,63 @@ using bool_constant = integral_constant<bool, __b>;
 #define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
 #endif
 
+template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
+
+template <bool _Bp, class _Tp = void> using __enable_if_t _LIBCPP_NODEBUG = typename enable_if<_Bp, _Tp>::type;
+
+#if _LIBCPP_STD_VER > 11
+template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
+#endif
+
 typedef _LIBCPP_BOOL_CONSTANT(true)  true_type;
 typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
 
 template <bool _Val>
-using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>;
+using _BoolConstant _LIBCPP_NODEBUG = integral_constant<bool, _Val>;
 
 template <bool> struct _MetaBase;
 template <>
 struct _MetaBase<true> {
   template <class _Tp, class _Up>
-  using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Tp;
+  using _SelectImpl _LIBCPP_NODEBUG = _Tp;
   template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
-  using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _FirstFn<_Args...>;
+  using _SelectApplyImpl _LIBCPP_NODEBUG = _FirstFn<_Args...>;
   template <class _First, class...>
-  using _FirstImpl _LIBCPP_NODEBUG_TYPE = _First;
+  using _FirstImpl _LIBCPP_NODEBUG = _First;
   template <class, class _Second, class...>
-  using _SecondImpl _LIBCPP_NODEBUG_TYPE = _Second;
-  template <class _Tp = void>
-  using _EnableIfImpl _LIBCPP_NODEBUG_TYPE = _Tp;
+  using _SecondImpl _LIBCPP_NODEBUG = _Second;
   template <class _Result, class _First, class ..._Rest>
-  using _OrImpl _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
+  using _OrImpl _LIBCPP_NODEBUG = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
 };
 
 template <>
 struct _MetaBase<false> {
   template <class _Tp, class _Up>
-  using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Up;
+  using _SelectImpl _LIBCPP_NODEBUG = _Up;
   template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
-  using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _SecondFn<_Args...>;
+  using _SelectApplyImpl _LIBCPP_NODEBUG = _SecondFn<_Args...>;
   template <class _Result, class ...>
-  using _OrImpl _LIBCPP_NODEBUG_TYPE = _Result;
+  using _OrImpl _LIBCPP_NODEBUG = _Result;
 };
-template <bool _Cond, class _Ret = void>
-using _EnableIf _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _EnableIfImpl<_Ret>;
 template <bool _Cond, class _IfRes, class _ElseRes>
-using _If _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
+using _If _LIBCPP_NODEBUG = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
 template <class ..._Rest>
-using _Or _LIBCPP_NODEBUG_TYPE = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
+using _Or _LIBCPP_NODEBUG = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
 template <class _Pred>
 struct _Not : _BoolConstant<!_Pred::value> {};
 template <class ..._Args>
-using _FirstType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
+using _FirstType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
 template <class ..._Args>
-using _SecondType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
+using _SecondType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
 
 template <class ...> using __expand_to_true = true_type;
 template <class ..._Pred>
-__expand_to_true<_EnableIf<_Pred::value>...> __and_helper(int);
+__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
 template <class ...>
 false_type __and_helper(...);
 template <class ..._Pred>
-using _And _LIBCPP_NODEBUG_TYPE = decltype(__and_helper<_Pred...>(0));
+using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0));
 
 template <template <class...> class _Func, class ..._Args>
 struct _Lazy : _Func<_Args...> {};
@@ -519,7 +524,7 @@ template <template <class...> class, class ...>
 false_type __sfinae_test_impl(...);
 
 template <template <class ...> class _Templ, class ..._Args>
-using _IsValidExpansion _LIBCPP_NODEBUG_TYPE = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
+using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
 
 template <class>
 struct __void_t { typedef void type; };
@@ -528,7 +533,7 @@ template <class _Tp>
 struct __identity { typedef _Tp type; };
 
 template <class _Tp>
-using __identity_t _LIBCPP_NODEBUG_TYPE = typename __identity<_Tp>::type;
+using __identity_t _LIBCPP_NODEBUG = typename __identity<_Tp>::type;
 
 template <class _Tp, bool>
 struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
@@ -543,59 +548,31 @@ template <class _If, class _Then>
 template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
 #endif
 
-template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
-
-#if _LIBCPP_STD_VER > 11
-template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
-#endif
-
 // is_same
 
-#if __has_keyword(__is_same)
-
 template <class _Tp, class _Up>
 struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class _Up>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v = __is_same(_Tp, _Up);
+inline constexpr bool is_same_v = __is_same(_Tp, _Up);
 #endif
 
-#else
-
-template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same           : public false_type {};
-template <class _Tp>            struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
+// _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types:
+// is_same<A,B> and is_same<C,D> are guaranteed to be different types, but
+// _IsSame<A,B> and _IsSame<C,D> are the same type (namely, false_type).
+// Neither GCC nor Clang can mangle the __is_same builtin, so _IsSame
+// mustn't be directly used anywhere that contributes to name-mangling
+// (such as in a dependent return type).
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
 template <class _Tp, class _Up>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v
-    = is_same<_Tp, _Up>::value;
-#endif
-
-#endif // __is_same
+using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
 
 template <class _Tp, class _Up>
-using _IsSame = _BoolConstant<
-#ifdef __clang__
-    __is_same(_Tp, _Up)
-#else
-    is_same<_Tp, _Up>::value
-#endif
->;
-
-template <class _Tp, class _Up>
-using _IsNotSame = _BoolConstant<
-#ifdef __clang__
-    !__is_same(_Tp, _Up)
-#else
-    !is_same<_Tp, _Up>::value
-#endif
->;
-
+using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
 
 template <class _Tp>
-using __test_for_primary_template = _EnableIf<
+using __test_for_primary_template = __enable_if_t<
     _IsSame<_Tp, typename _Tp::__primary_template>::value
   >;
 template <class _Tp>
@@ -603,9 +580,9 @@ using __is_primary_template = _IsValidExpansion<
     __test_for_primary_template, _Tp
   >;
 
-struct __two {char __lx[2];};
+// helper class
 
-// helper class:
+struct __two {char __lx[2];};
 
 // is_const
 
@@ -614,9 +591,9 @@ struct __two {char __lx[2];};
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v = __is_const(_Tp);
+inline constexpr bool is_const_v = __is_const(_Tp);
 #endif
 
 #else
@@ -624,10 +601,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v = __is_const(_Tp);
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const            : public false_type {};
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v
-    = is_const<_Tp>::value;
+inline constexpr bool is_const_v = is_const<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_const)
@@ -639,9 +615,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_volatile : _BoolConstant<__is_volatile(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v = __is_volatile(_Tp);
+inline constexpr bool is_volatile_v = __is_volatile(_Tp);
 #endif
 
 #else
@@ -649,10 +625,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v = __is_volatile(_Tp);
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile               : public false_type {};
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v
-    = is_volatile<_Tp>::value;
+inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_volatile)
@@ -727,9 +702,9 @@ template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_void : _BoolConstant<__is_void(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v = __is_void(_Tp);
+inline constexpr bool is_void_v = __is_void(_Tp);
 #endif
 
 #else
@@ -737,10 +712,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v = __is_void(_Tp);
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
     : public is_same<typename remove_cv<_Tp>::type, void> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v
-    = is_void<_Tp>::value;
+inline constexpr bool is_void_v = is_void<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_void)
@@ -757,10 +731,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer
     : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_null_pointer_v
-    = is_null_pointer<_Tp>::value;
+inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
 #endif
 #endif // _LIBCPP_STD_VER > 11
 
@@ -773,7 +746,7 @@ struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
 
 #if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v = __is_integral(_Tp);
+inline constexpr bool is_integral_v = __is_integral(_Tp);
 #endif
 
 #else
@@ -781,16 +754,13 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v = __is_integral(_Tp);
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
     : public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v
-    = is_integral<_Tp>::value;
+inline constexpr bool is_integral_v = is_integral<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_integral)
 
-// __libcpp_is_signed_integer, __libcpp_is_unsigned_integer
-
 // [basic.fundamental] defines five standard signed integer types;
 // __int128_t is an extended signed integer type.
 // The signed and unsigned integer types, plus bool and the
@@ -817,6 +787,7 @@ template <> struct __libcpp_is_unsigned_integer<__uint128_t>        : public tru
 #endif
 
 // is_floating_point
+// <concepts> implements __libcpp_floating_point
 
 template <class _Tp> struct __libcpp_is_floating_point              : public false_type {};
 template <>          struct __libcpp_is_floating_point<float>       : public true_type {};
@@ -826,10 +797,9 @@ template <>          struct __libcpp_is_floating_point<long double> : public tru
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point
     : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v
-    = is_floating_point<_Tp>::value;
+inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
 #endif
 
 // is_array
@@ -839,9 +809,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v = __is_array(_Tp);
+inline constexpr bool is_array_v = __is_array(_Tp);
 #endif
 
 #else
@@ -853,27 +823,25 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]>
     : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v
-    = is_array<_Tp>::value;
+inline constexpr bool is_array_v = is_array<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_array)
 
 // is_pointer
 
-// Before Clang 11 / AppleClang 12.0.5, __is_pointer didn't work for Objective-C types.
+// Before AppleClang 12.0.5, __is_pointer didn't work for Objective-C types.
 #if __has_keyword(__is_pointer) &&                                             \
-    !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1100) &&               \
     !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205)
 
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v = __is_pointer(_Tp);
+inline constexpr bool is_pointer_v = __is_pointer(_Tp);
 #endif
 
 #else // __has_keyword(__is_pointer)
@@ -892,10 +860,9 @@ template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretai
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
     : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v
-    = is_pointer<_Tp>::value;
+inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_pointer)
@@ -915,15 +882,13 @@ struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : _BoolConstant<__is_rvalue_refe
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_reference : _BoolConstant<__is_reference(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v = __is_reference(_Tp);
-
+inline constexpr bool is_reference_v = __is_reference(_Tp);
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
-
+inline constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
+inline constexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
 #endif
 
 #else // __has_keyword(__is_lvalue_reference) && etc...
@@ -938,18 +903,15 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference        : public fa
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&>  : public true_type {};
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v
-    = is_reference<_Tp>::value;
+inline constexpr bool is_reference_v = is_reference<_Tp>::value;
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v
-    = is_lvalue_reference<_Tp>::value;
+inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value;
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v
-    = is_rvalue_reference<_Tp>::value;
+inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_lvalue_reference) && etc...
@@ -969,10 +931,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_union_v
-    = is_union<_Tp>::value;
+inline constexpr bool is_union_v = is_union<_Tp>::value;
 #endif
 
 // is_class
@@ -995,10 +956,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_class_v
-    = is_class<_Tp>::value;
+inline constexpr bool is_class_v = is_class<_Tp>::value;
 #endif
 
 // is_function
@@ -1013,10 +973,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function
     > {};
 
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_function_v
-    = is_function<_Tp>::value;
+inline constexpr bool is_function_v = is_function<_Tp>::value;
 #endif
 
 template <class _Tp> struct __libcpp_is_member_pointer {
@@ -1040,10 +999,9 @@ template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
     : _BoolConstant<__is_member_function_pointer(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
-    = __is_member_function_pointer(_Tp);
+inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
 #endif
 
 #else // __has_keyword(__is_member_function_pointer)
@@ -1051,10 +1009,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
     : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
-    = is_member_function_pointer<_Tp>::value;
+inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_member_function_pointer)
@@ -1066,9 +1023,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v = __is_member_pointer(_Tp);
+inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
 #endif
 
 #else // __has_keyword(__is_member_pointer)
@@ -1076,10 +1033,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v = __is_member_poin
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
  : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v
-    = is_member_pointer<_Tp>::value;
+inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_member_pointer)
@@ -1092,10 +1048,9 @@ template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
     : _BoolConstant<__is_member_object_pointer(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
-    = __is_member_object_pointer(_Tp);
+inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
 #endif
 
 #else // __has_keyword(__is_member_object_pointer)
@@ -1103,10 +1058,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
     : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj >  {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
-    = is_member_object_pointer<_Tp>::value;
+inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_member_object_pointer)
@@ -1118,9 +1072,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
     : public integral_constant<bool, __is_enum(_Tp)> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v = __is_enum(_Tp);
+inline constexpr bool is_enum_v = __is_enum(_Tp);
 #endif
 
 #else
@@ -1137,10 +1091,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
                                      !is_class<_Tp>::value            &&
                                      !is_function<_Tp>::value         > {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v
-    = is_enum<_Tp>::value;
+inline constexpr bool is_enum_v = is_enum<_Tp>::value;
 #endif
 
 #endif // __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
@@ -1152,10 +1105,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
     : public integral_constant<bool, is_integral<_Tp>::value      ||
                                      is_floating_point<_Tp>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v
-    = is_arithmetic<_Tp>::value;
+inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
 #endif
 
 // is_fundamental
@@ -1169,9 +1121,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v = __is_fundamental(_Tp);
+inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
 #endif
 
 #else // __has_keyword(__is_fundamental)
@@ -1181,10 +1133,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
                                      __is_nullptr_t<_Tp>::value ||
                                      is_arithmetic<_Tp>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v
-    = is_fundamental<_Tp>::value;
+inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_fundamental)
@@ -1197,9 +1148,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v = __is_scalar(_Tp);
+inline constexpr bool is_scalar_v = __is_scalar(_Tp);
 #endif
 
 #else // __has_keyword(__is_scalar)
@@ -1219,10 +1170,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
 
 template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v
-    = is_scalar<_Tp>::value;
+inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_scalar)
@@ -1234,9 +1184,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v = __is_object(_Tp);
+inline constexpr bool is_object_v = __is_object(_Tp);
 #endif
 
 #else // __has_keyword(__is_object)
@@ -1247,10 +1197,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
                                      is_union<_Tp>::value  ||
                                      is_class<_Tp>::value  > {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v
-    = is_object<_Tp>::value;
+inline constexpr bool is_object_v = is_object<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_object)
@@ -1263,9 +1212,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v = __is_compound(_Tp);
+inline constexpr bool is_compound_v = __is_compound(_Tp);
 #endif
 
 #else // __has_keyword(__is_compound)
@@ -1273,10 +1222,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v = __is_compound(_Tp);
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
     : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v
-    = is_compound<_Tp>::value;
+inline constexpr bool is_compound_v = is_compound<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_compound)
@@ -1296,7 +1244,7 @@ struct __is_referenceable : integral_constant<bool,
 // add_const
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {
-  typedef _LIBCPP_NODEBUG_TYPE const _Tp type;
+  typedef _LIBCPP_NODEBUG const _Tp type;
 };
 
 #if _LIBCPP_STD_VER > 11
@@ -1306,7 +1254,7 @@ template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
 // add_volatile
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {
-  typedef _LIBCPP_NODEBUG_TYPE volatile _Tp type;
+  typedef _LIBCPP_NODEBUG volatile _Tp type;
 };
 
 #if _LIBCPP_STD_VER > 11
@@ -1315,7 +1263,7 @@ template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
 
 // add_cv
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {
-  typedef _LIBCPP_NODEBUG_TYPE const volatile _Tp type;
+  typedef _LIBCPP_NODEBUG const volatile _Tp type;
 };
 
 #if _LIBCPP_STD_VER > 11
@@ -1331,9 +1279,9 @@ struct _LIBCPP_TEMPLATE_VIS remove_reference { typedef __remove_reference(_Tp) t
 
 #else // __has_keyword(__remove_reference)
 
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference        {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&>  {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference        {typedef _LIBCPP_NODEBUG _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&>  {typedef _LIBCPP_NODEBUG _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
@@ -1343,21 +1291,21 @@ template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::
 
 // add_lvalue_reference
 
-template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl            { typedef _LIBCPP_NODEBUG_TYPE _Tp  type; };
-template <class _Tp                                       > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; };
+template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl            { typedef _LIBCPP_NODEBUG _Tp  type; };
+template <class _Tp                                       > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp& type; };
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference
-{typedef _LIBCPP_NODEBUG_TYPE typename  __add_lvalue_reference_impl<_Tp>::type type;};
+{typedef _LIBCPP_NODEBUG typename  __add_lvalue_reference_impl<_Tp>::type type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
 #endif
 
-template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl            { typedef _LIBCPP_NODEBUG_TYPE  _Tp   type; };
-template <class _Tp                                       > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE  _Tp&& type; };
+template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl            { typedef _LIBCPP_NODEBUG _Tp   type; };
+template <class _Tp                                       > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp&& type; };
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
-{typedef _LIBCPP_NODEBUG_TYPE  typename __add_rvalue_reference_impl<_Tp>::type type;};
+{typedef _LIBCPP_NODEBUG typename __add_rvalue_reference_impl<_Tp>::type type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
@@ -1378,17 +1326,17 @@ declval() _NOEXCEPT;
 
 template <class _Tp>
 struct __uncvref  {
-    typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<typename remove_reference<_Tp>::type>::type type;
+    typedef _LIBCPP_NODEBUG typename remove_cv<typename remove_reference<_Tp>::type>::type type;
 };
 
 template <class _Tp>
 struct __unconstref {
-    typedef _LIBCPP_NODEBUG_TYPE typename remove_const<typename remove_reference<_Tp>::type>::type type;
+    typedef _LIBCPP_NODEBUG typename remove_const<typename remove_reference<_Tp>::type>::type type;
 };
 
 #ifndef _LIBCPP_CXX03_LANG
 template <class _Tp>
-using __uncvref_t _LIBCPP_NODEBUG_TYPE = typename __uncvref<_Tp>::type;
+using __uncvref_t _LIBCPP_NODEBUG = typename __uncvref<_Tp>::type;
 #endif
 
 // __is_same_uncvref
@@ -1413,11 +1361,11 @@ struct __any
 
 // remove_pointer
 
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer                      {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*>                {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const>          {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile>       {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer                      {typedef _LIBCPP_NODEBUG _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*>                {typedef _LIBCPP_NODEBUG _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const>          {typedef _LIBCPP_NODEBUG _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile>       {typedef _LIBCPP_NODEBUG _Tp type;};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
@@ -1429,12 +1377,12 @@ template <class _Tp,
         bool = __is_referenceable<_Tp>::value ||
                 _IsSame<typename remove_cv<_Tp>::type, void>::value>
 struct __add_pointer_impl
-    {typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type* type;};
+    {typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type* type;};
 template <class _Tp> struct __add_pointer_impl<_Tp, false>
-    {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
+    {typedef _LIBCPP_NODEBUG _Tp type;};
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer
-    {typedef _LIBCPP_NODEBUG_TYPE typename __add_pointer_impl<_Tp>::type type;};
+    {typedef _LIBCPP_NODEBUG typename __add_pointer_impl<_Tp>::type type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
@@ -1448,16 +1396,14 @@ template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
 
 // is_signed
 
-// Before Clang 10, __is_signed didn't work for floating-point types or enums.
-#if __has_keyword(__is_signed) &&                                              \
-    !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1000)
+#if __has_keyword(__is_signed)
 
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v = __is_signed(_Tp);
+inline constexpr bool is_signed_v = __is_signed(_Tp);
 #endif
 
 #else // __has_keyword(__is_signed)
@@ -1475,10 +1421,9 @@ template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v
-    = is_signed<_Tp>::value;
+inline constexpr bool is_signed_v = is_signed<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_signed)
@@ -1494,9 +1439,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v = __is_unsigned(_Tp);
+inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
 #endif
 
 #else // __has_keyword(__is_unsigned)
@@ -1514,10 +1459,9 @@ template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v
-    = is_unsigned<_Tp>::value;
+inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_unsigned)
@@ -1531,10 +1475,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]>
 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]>
     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t rank_v
-    = rank<_Tp>::value;
+inline constexpr size_t rank_v = rank<_Tp>::value;
 #endif
 
 // extent
@@ -1545,9 +1488,9 @@ template<class _Tp, size_t _Dim = 0>
 struct _LIBCPP_TEMPLATE_VIS extent
     : integral_constant<size_t, __array_extent(_Tp, _Dim)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, unsigned _Ip = 0>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v = __array_extent(_Tp, _Ip);
+inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
 #endif
 
 #else // __has_keyword(__array_extent)
@@ -1563,10 +1506,9 @@ template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0>
 template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip>
     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, unsigned _Ip = 0>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v
-    = extent<_Tp, _Ip>::value;
+inline constexpr size_t extent_v = extent<_Tp, _Ip>::value;
 #endif
 
 #endif // __has_keyword(__array_extent)
@@ -1604,7 +1546,7 @@ template <class>                 struct _LIBCPP_TEMPLATE_VIS is_bounded_array
 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR
+inline constexpr
 bool is_bounded_array_v  = is_bounded_array<_Tp>::value;
 
 // is_unbounded_array
@@ -1613,7 +1555,7 @@ template <class>     struct _LIBCPP_TEMPLATE_VIS is_unbounded_array        : fal
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR
+inline constexpr
 bool is_unbounded_array_v  = is_unbounded_array<_Tp>::value;
 #endif
 
@@ -1621,13 +1563,13 @@ bool is_unbounded_array_v  = is_unbounded_array<_Tp>::value;
 
 template <class _Up, bool>
 struct __decay {
-    typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<_Up>::type type;
+    typedef _LIBCPP_NODEBUG typename remove_cv<_Up>::type type;
 };
 
 template <class _Up>
 struct __decay<_Up, true> {
 public:
-    typedef _LIBCPP_NODEBUG_TYPE typename conditional
+    typedef _LIBCPP_NODEBUG typename conditional
                      <
                          is_array<_Up>::value,
                          typename remove_extent<_Up>::type*,
@@ -1644,9 +1586,9 @@ template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS decay
 {
 private:
-    typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
+    typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
 public:
-    typedef _LIBCPP_NODEBUG_TYPE typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
+    typedef _LIBCPP_NODEBUG typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
 };
 
 #if _LIBCPP_STD_VER > 11
@@ -1658,10 +1600,9 @@ template <class _Tp> using decay_t = typename decay<_Tp>::type;
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract
     : public integral_constant<bool, __is_abstract(_Tp)> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_abstract_v
-    = is_abstract<_Tp>::value;
+inline constexpr bool is_abstract_v = is_abstract<_Tp>::value;
 #endif
 
 // is_final
@@ -1674,25 +1615,21 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
 is_final : public integral_constant<bool, __is_final(_Tp)> {};
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_final_v
-    = is_final<_Tp>::value;
+inline constexpr bool is_final_v = is_final<_Tp>::value;
 #endif
 
 // is_aggregate
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
+#if _LIBCPP_STD_VER > 14
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
 is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
 
-#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool is_aggregate_v
-    = is_aggregate<_Tp>::value;
-#endif
+inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
 
-#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
+#endif // _LIBCPP_STD_VER > 14
 
 // is_base_of
 
@@ -1700,10 +1637,9 @@ template <class _Bp, class _Dp>
 struct _LIBCPP_TEMPLATE_VIS is_base_of
     : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Bp, class _Dp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_base_of_v
-    = is_base_of<_Bp, _Dp>::value;
+inline constexpr bool is_base_of_v = is_base_of<_Bp, _Dp>::value;
 #endif
 
 // __is_core_convertible
@@ -1797,10 +1733,9 @@ template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
 
 #endif // __has_feature(is_convertible_to)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _From, class _To>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_convertible_v
-    = is_convertible<_From, _To>::value;
+inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
 #endif
 
 // is_nothrow_convertible
@@ -1860,10 +1795,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empt
 
 #endif // __has_feature(is_empty)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_empty_v
-    = is_empty<_Tp>::value;
+inline constexpr bool is_empty_v = is_empty<_Tp>::value;
 #endif
 
 // is_polymorphic
@@ -1886,10 +1820,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic
 
 #endif // __has_feature(is_polymorphic)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_polymorphic_v
-    = is_polymorphic<_Tp>::value;
+inline constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
 #endif
 
 // has_virtual_destructor
@@ -1906,25 +1839,21 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_virtual_destructor_v
-    = has_virtual_destructor<_Tp>::value;
+inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<_Tp>::value;
 #endif
 
 // has_unique_object_representations
 
-#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
+#if _LIBCPP_STD_VER > 14
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
     : public integral_constant<bool,
        __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
 
-#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v
-    = has_unique_object_representations<_Tp>::value;
-#endif
+inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<_Tp>::value;
 
 #endif
 
@@ -1933,10 +1862,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
     : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t alignment_of_v
-    = alignment_of<_Tp>::value;
+inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
 #endif
 
 // aligned_storage
@@ -2214,26 +2142,26 @@ template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeLi
 template <class _Hp, class _Tp, size_t _Size>
 struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
 {
-    typedef _LIBCPP_NODEBUG_TYPE _Hp type;
+    typedef _LIBCPP_NODEBUG _Hp type;
 };
 
 template <class _Hp, class _Tp, size_t _Size>
 struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
 {
-    typedef _LIBCPP_NODEBUG_TYPE typename __find_first<_Tp, _Size>::type type;
+    typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
 };
 
 template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
                              bool = is_volatile<typename remove_reference<_Tp>::type>::value>
 struct __apply_cv
 {
-    typedef _LIBCPP_NODEBUG_TYPE _Up type;
+    typedef _LIBCPP_NODEBUG _Up type;
 };
 
 template <class _Tp, class _Up>
 struct __apply_cv<_Tp, _Up, true, false>
 {
-    typedef _LIBCPP_NODEBUG_TYPE const _Up type;
+    typedef _LIBCPP_NODEBUG const _Up type;
 };
 
 template <class _Tp, class _Up>
@@ -2340,7 +2268,7 @@ template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
 
 #ifndef _LIBCPP_CXX03_LANG
 template <class _Tp>
-_LIBCPP_NODISCARD_ATTRIBUTE _LIBCPP_INLINE_VISIBILITY constexpr
+_LIBCPP_HIDE_FROM_ABI constexpr
 typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
     return static_cast<typename make_unsigned<_Tp>::type>(__x);
 }
@@ -2379,7 +2307,7 @@ struct __common_type2_imp<_Tp, _Up,
                                             true ? declval<_Tp>() : declval<_Up>()
                                             )>::type>
 {
-  typedef _LIBCPP_NODEBUG_TYPE typename decay<decltype(
+  typedef _LIBCPP_NODEBUG typename decay<decltype(
                          true ? declval<_Tp>() : declval<_Up>()
                          )>::type type;
 };
@@ -2390,7 +2318,7 @@ struct __common_type_impl {};
 // Clang provides variadic templates in C++03 as an extension.
 #if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
 # define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
-template <class... Tp>
+template <class... _Tp>
 struct __common_types;
 template <class... _Tp>
 struct _LIBCPP_TEMPLATE_VIS common_type;
@@ -2514,7 +2442,7 @@ using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
 #endif // _LIBCPP_STD_VER > 11
 
 // common_reference
-#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
 // Let COND_RES(X, Y) be:
 template <class _Xp, class _Yp>
 using __cond_res =
@@ -2668,20 +2596,20 @@ struct common_reference<_Tp, _Up, _Vp, _Rest...>
 // bullet 5 - Otherwise, there shall be no member `type`.
 template <class...> struct common_reference {};
 
-#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // is_assignable
 
-template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
+template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG _Tp type; };
 
 #if __has_keyword(__is_assignable)
 
 template<class _Tp, class _Up>
 struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class _Arg>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v = __is_assignable(_Tp, _Arg);
+inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
 #endif
 
 #else // __has_keyword(__is_assignable)
@@ -2708,10 +2636,9 @@ template <class _Tp, class _Arg>
 struct is_assignable
     : public __is_assignable_imp<_Tp, _Arg> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class _Arg>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v
-    = is_assignable<_Tp, _Arg>::value;
+inline constexpr bool is_assignable_v = is_assignable<_Tp, _Arg>::value;
 #endif
 
 #endif // __has_keyword(__is_assignable)
@@ -2722,10 +2649,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_assignable_v
-    = is_copy_assignable<_Tp>::value;
+inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
 #endif
 
 // is_move_assignable
@@ -2734,10 +2660,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
                            typename add_rvalue_reference<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v
-    = is_move_assignable<_Tp>::value;
+inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
 #endif
 
 // is_destructible
@@ -2747,9 +2672,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v
 template<class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v = __is_destructible(_Tp);
+inline constexpr bool is_destructible_v = __is_destructible(_Tp);
 #endif
 
 #else // __has_keyword(__is_destructible)
@@ -2810,10 +2735,9 @@ template <>
 struct is_destructible<void>
     : public false_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v
-    = is_destructible<_Tp>::value;
+inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
 #endif
 
 #endif // __has_keyword(__is_destructible)
@@ -3049,140 +2973,14 @@ struct __member_pointer_class_type<_Ret _ClassType::*> {
 
 // template <class T, class... Args> struct is_constructible;
 
-#if defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW >= 10000
-# define _LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE
-#endif
-
-#if !defined(_LIBCPP_CXX03_LANG) && !__has_feature(is_constructible) && !defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
-
-template <class _Tp, class... _Args>
-struct __libcpp_is_constructible;
-
-template <class _To, class _From>
-struct __is_invalid_base_to_derived_cast {
-  static_assert(is_reference<_To>::value, "Wrong specialization");
-  using _RawFrom = __uncvref_t<_From>;
-  using _RawTo = __uncvref_t<_To>;
-  static const bool value = _And<
-        _IsNotSame<_RawFrom, _RawTo>,
-        is_base_of<_RawFrom, _RawTo>,
-        _Not<__libcpp_is_constructible<_RawTo, _From>>
-  >::value;
-};
-
-template <class _To, class _From>
-struct __is_invalid_lvalue_to_rvalue_cast : false_type {
-  static_assert(is_reference<_To>::value, "Wrong specialization");
-};
-
-template <class _ToRef, class _FromRef>
-struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> {
-  using _RawFrom = __uncvref_t<_FromRef>;
-  using _RawTo = __uncvref_t<_ToRef>;
-  static const bool value = _And<
-      _Not<is_function<_RawTo>>,
-      _Or<
-        _IsSame<_RawFrom, _RawTo>,
-        is_base_of<_RawTo, _RawFrom>>
-    >::value;
-};
-
-struct __is_constructible_helper
-{
-    template <class _To>
-    static void __eat(_To);
-
-    // This overload is needed to work around a Clang bug that disallows
-    // static_cast<T&&>(e) for non-reference-compatible types.
-    // Example: static_cast<int&&>(declval<double>());
-    // NOTE: The static_cast implementation below is required to support
-    //  classes with explicit conversion operators.
-    template <class _To, class _From,
-              class = decltype(__eat<_To>(declval<_From>()))>
-    static true_type __test_cast(int);
-
-    template <class _To, class _From,
-              class = decltype(static_cast<_To>(declval<_From>()))>
-    static integral_constant<bool,
-        !__is_invalid_base_to_derived_cast<_To, _From>::value &&
-        !__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value
-    > __test_cast(long);
-
-    template <class, class>
-    static false_type __test_cast(...);
-
-    template <class _Tp, class ..._Args,
-        class = decltype(_Tp(declval<_Args>()...))>
-    static true_type __test_nary(int);
-    template <class _Tp, class...>
-    static false_type __test_nary(...);
-
-    template <class _Tp, class _A0, class = decltype(::new _Tp(declval<_A0>()))>
-    static is_destructible<_Tp> __test_unary(int);
-    template <class, class>
-    static false_type __test_unary(...);
-};
-
-template <class _Tp, bool = is_void<_Tp>::value>
-struct __is_default_constructible
-    : decltype(__is_constructible_helper::__test_nary<_Tp>(0))
-{};
-
-template <class _Tp>
-struct __is_default_constructible<_Tp, true> : false_type {};
-
-template <class _Tp>
-struct __is_default_constructible<_Tp[], false> : false_type {};
-
-template <class _Tp, size_t _Nx>
-struct __is_default_constructible<_Tp[_Nx], false>
-    : __is_default_constructible<typename remove_all_extents<_Tp>::type>  {};
-
-template <class _Tp, class... _Args>
-struct __libcpp_is_constructible
-{
-  static_assert(sizeof...(_Args) > 1, "Wrong specialization");
-  typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0))
-      type;
-};
-
-template <class _Tp>
-struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {};
-
-template <class _Tp, class _A0>
-struct __libcpp_is_constructible<_Tp, _A0>
-    : public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0))
-{};
-
-template <class _Tp, class _A0>
-struct __libcpp_is_constructible<_Tp&, _A0>
-    : public decltype(__is_constructible_helper::
-    __test_cast<_Tp&, _A0>(0))
-{};
-
-template <class _Tp, class _A0>
-struct __libcpp_is_constructible<_Tp&&, _A0>
-    : public decltype(__is_constructible_helper::
-    __test_cast<_Tp&&, _A0>(0))
-{};
-
-#endif
-
-#if __has_feature(is_constructible) || defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
 template <class _Tp, class ..._Args>
 struct _LIBCPP_TEMPLATE_VIS is_constructible
     : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
-    {};
-#else
-template <class _Tp, class... _Args>
-struct _LIBCPP_TEMPLATE_VIS is_constructible
-    : public __libcpp_is_constructible<_Tp, _Args...>::type {};
-#endif
+{ };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class ..._Args>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_constructible_v
-    = is_constructible<_Tp, _Args...>::value;
+inline constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
 #endif
 
 // is_default_constructible
@@ -3192,10 +2990,9 @@ struct _LIBCPP_TEMPLATE_VIS is_default_constructible
     : public is_constructible<_Tp>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_default_constructible_v
-    = is_default_constructible<_Tp>::value;
+inline constexpr bool is_default_constructible_v = is_default_constructible<_Tp>::value;
 #endif
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -3229,10 +3026,9 @@ struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
     : public is_constructible<_Tp,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_constructible_v
-    = is_copy_constructible<_Tp>::value;
+inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
 #endif
 
 // is_move_constructible
@@ -3242,65 +3038,22 @@ struct _LIBCPP_TEMPLATE_VIS is_move_constructible
     : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v
-    = is_move_constructible<_Tp>::value;
+inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
 #endif
 
 // is_trivially_constructible
 
-#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501
-
 template <class _Tp, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
     : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
 {
 };
 
-#else  // !__has_feature(is_trivially_constructible)
-
-template <class _Tp, class... _Args>
-struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
-    : false_type
-{
-};
-
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp>
-#if __has_feature(has_trivial_constructor) || defined(_LIBCPP_COMPILER_GCC)
-    : integral_constant<bool, __has_trivial_constructor(_Tp)>
-#else
-    : integral_constant<bool, is_scalar<_Tp>::value>
-#endif
-{
-};
-
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&>
-    : integral_constant<bool, is_scalar<_Tp>::value>
-{
-};
-
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&>
-    : integral_constant<bool, is_scalar<_Tp>::value>
-{
-};
-
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&>
-    : integral_constant<bool, is_scalar<_Tp>::value>
-{
-};
-
-#endif // !__has_feature(is_trivially_constructible)
-
-
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class... _Args>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v
-    = is_trivially_constructible<_Tp, _Args...>::value;
+inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value;
 #endif
 
 // is_trivially_default_constructible
@@ -3309,10 +3062,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructi
     : public is_trivially_constructible<_Tp>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v
-    = is_trivially_default_constructible<_Tp>::value;
+inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value;
 #endif
 
 // is_trivially_copy_constructible
@@ -3321,10 +3073,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
     : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v
-    = is_trivially_copy_constructible<_Tp>::value;
+inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
 #endif
 
 // is_trivially_move_constructible
@@ -3333,50 +3084,21 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
     : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v
-    = is_trivially_move_constructible<_Tp>::value;
+inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
 #endif
 
 // is_trivially_assignable
 
-#if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501
-
 template <class _Tp, class _Arg>
 struct is_trivially_assignable
     : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
-{
-};
-
-#else  // !__has_feature(is_trivially_assignable)
-
-template <class _Tp, class _Arg>
-struct is_trivially_assignable
-    : public false_type {};
-
-template <class _Tp>
-struct is_trivially_assignable<_Tp&, _Tp>
-    : integral_constant<bool, is_scalar<_Tp>::value> {};
-
-template <class _Tp>
-struct is_trivially_assignable<_Tp&, _Tp&>
-    : integral_constant<bool, is_scalar<_Tp>::value> {};
-
-template <class _Tp>
-struct is_trivially_assignable<_Tp&, const _Tp&>
-    : integral_constant<bool, is_scalar<_Tp>::value> {};
-
-template <class _Tp>
-struct is_trivially_assignable<_Tp&, _Tp&&>
-    : integral_constant<bool, is_scalar<_Tp>::value> {};
-
-#endif // !__has_feature(is_trivially_assignable)
+{ };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class _Arg>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_assignable_v
-    = is_trivially_assignable<_Tp, _Arg>::value;
+inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value;
 #endif
 
 // is_trivially_copy_assignable
@@ -3385,10 +3107,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v
-    = is_trivially_copy_assignable<_Tp>::value;
+inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
 #endif
 
 // is_trivially_move_assignable
@@ -3398,10 +3119,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
                                      typename add_rvalue_reference<_Tp>::type>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v
-    = is_trivially_move_assignable<_Tp>::value;
+inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
 #endif
 
 // is_trivially_destructible
@@ -3430,10 +3150,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_destructible_v
-    = is_trivially_destructible<_Tp>::value;
+inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
 #endif
 
 // is_nothrow_constructible
@@ -3484,10 +3203,9 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
 #endif // _LIBCPP_HAS_NO_NOEXCEPT
 
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class ..._Args>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v
-    = is_nothrow_constructible<_Tp, _Args...>::value;
+inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
 #endif
 
 // is_nothrow_default_constructible
@@ -3496,10 +3214,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructibl
     : public is_nothrow_constructible<_Tp>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v
-    = is_nothrow_default_constructible<_Tp>::value;
+inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
 #endif
 
 // is_nothrow_copy_constructible
@@ -3508,10 +3225,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
     : public is_nothrow_constructible<_Tp,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v
-    = is_nothrow_copy_constructible<_Tp>::value;
+inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
 #endif
 
 // is_nothrow_move_constructible
@@ -3520,10 +3236,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
     : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v
-    = is_nothrow_move_constructible<_Tp>::value;
+inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
 #endif
 
 // is_nothrow_assignable
@@ -3558,10 +3273,9 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
 
 #endif // _LIBCPP_HAS_NO_NOEXCEPT
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp, class _Arg>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v
-    = is_nothrow_assignable<_Tp, _Arg>::value;
+inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
 #endif
 
 // is_nothrow_copy_assignable
@@ -3570,10 +3284,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v
-    = is_nothrow_copy_assignable<_Tp>::value;
+inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
 #endif
 
 // is_nothrow_move_assignable
@@ -3583,10 +3296,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
                                      typename add_rvalue_reference<_Tp>::type>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v
-    = is_nothrow_move_assignable<_Tp>::value;
+inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
 #endif
 
 // is_nothrow_destructible
@@ -3646,10 +3358,9 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v
-    = is_nothrow_destructible<_Tp>::value;
+inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
 #endif
 
 // is_pod
@@ -3669,10 +3380,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pod_v
-    = is_pod<_Tp>::value;
+inline constexpr bool is_pod_v = is_pod<_Tp>::value;
 #endif
 
 // is_literal_type;
@@ -3682,11 +3392,10 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 is_
     : public integral_constant<bool, __is_literal_type(_Tp)>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v
-    = is_literal_type<_Tp>::value;
-#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+_LIBCPP_DEPRECATED_IN_CXX17 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
+#endif // _LIBCPP_STD_VER > 14
 #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
 
 // is_standard_layout;
@@ -3699,28 +3408,20 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_standard_layout_v
-    = is_standard_layout<_Tp>::value;
+inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
 #endif
 
 // is_trivially_copyable;
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
-#if __has_feature(is_trivially_copyable)
     : public integral_constant<bool, __is_trivially_copyable(_Tp)>
-#elif _GNUC_VER >= 501
-    : public integral_constant<bool, !is_volatile<_Tp>::value && __is_trivially_copyable(_Tp)>
-#else
-    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
-#endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copyable_v
-    = is_trivially_copyable<_Tp>::value;
+inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
 #endif
 
 // is_trivial;
@@ -3734,10 +3435,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+#if _LIBCPP_STD_VER > 14
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivial_v
-    = is_trivial<_Tp>::value;
+inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
 #endif
 
 template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
@@ -3811,10 +3511,6 @@ using __enable_if_bullet6 = typename enable_if
 
 // fall back - none of the bullets
 
-#define _LIBCPP_INVOKE_RETURN(...) \
-    noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
-    { return __VA_ARGS__; }
-
 template <class ..._Args>
 auto __invoke(__any, _Args&& ...__args) -> __nat;
 
@@ -3828,42 +3524,54 @@ template <class _Fp, class _A0, class ..._Args,
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
+    noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
+    { return          (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
 
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet1<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR auto
 __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
+    noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
+    { return          (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
 
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet2<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_Args&&>(__args)...))
+    noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
+    { return          (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
 
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet2<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR auto
 __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_Args&&>(__args)...))
+    noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
+    { return          (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
 
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet3<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
+    noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
+    { return          ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
 
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet3<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR auto
 __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
+    noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
+    { return          ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
 
 // bullets 4, 5 and 6
 
@@ -3872,42 +3580,54 @@ template <class _Fp, class _A0,
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto
 __invoke(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f)
+    noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
+    -> decltype(      static_cast<_A0&&>(__a0).*__f)
+    { return          static_cast<_A0&&>(__a0).*__f; }
 
 template <class _Fp, class _A0,
           class = __enable_if_bullet4<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR auto
 __invoke_constexpr(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f)
+    noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
+    -> decltype(      static_cast<_A0&&>(__a0).*__f)
+    { return          static_cast<_A0&&>(__a0).*__f; }
 
 template <class _Fp, class _A0,
           class = __enable_if_bullet5<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto
 __invoke(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
+    noexcept(noexcept(__a0.get().*__f))
+    -> decltype(      __a0.get().*__f)
+    { return          __a0.get().*__f; }
 
 template <class _Fp, class _A0,
           class = __enable_if_bullet5<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR auto
 __invoke_constexpr(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
+    noexcept(noexcept(__a0.get().*__f))
+    -> decltype(      __a0.get().*__f)
+    { return          __a0.get().*__f; }
 
 template <class _Fp, class _A0,
           class = __enable_if_bullet6<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto
 __invoke(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f)
+    noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
+    -> decltype(      (*static_cast<_A0&&>(__a0)).*__f)
+    { return          (*static_cast<_A0&&>(__a0)).*__f; }
 
 template <class _Fp, class _A0,
           class = __enable_if_bullet6<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR auto
 __invoke_constexpr(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f)
+    noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
+    -> decltype(      (*static_cast<_A0&&>(__a0)).*__f)
+    { return          (*static_cast<_A0&&>(__a0)).*__f; }
 
 // bullet 7
 
@@ -3915,15 +3635,17 @@ template <class _Fp, class ..._Args>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR_AFTER_CXX17 auto
 __invoke(_Fp&& __f, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
+    noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
+    { return          static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
 
 template <class _Fp, class ..._Args>
 inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR auto
 __invoke_constexpr(_Fp&& __f, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
-
-#undef _LIBCPP_INVOKE_RETURN
+    noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
+    -> decltype(      static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
+    { return          static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
 
 // __invokable
 template <class _Ret, class _Fp, class ..._Args>
@@ -4122,12 +3844,10 @@ struct _LIBCPP_TEMPLATE_VIS is_invocable_r
     : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
 
 template <class _Fn, class ..._Args>
-_LIBCPP_INLINE_VAR constexpr bool is_invocable_v
-    = is_invocable<_Fn, _Args...>::value;
+inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
 
 template <class _Ret, class _Fn, class ..._Args>
-_LIBCPP_INLINE_VAR constexpr bool is_invocable_r_v
-    = is_invocable_r<_Ret, _Fn, _Args...>::value;
+inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
 
 // is_nothrow_invocable
 
@@ -4140,12 +3860,10 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
     : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
 
 template <class _Fn, class ..._Args>
-_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v
-    = is_nothrow_invocable<_Fn, _Args...>::value;
+inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
 
 template <class _Ret, class _Fn, class ..._Args>
-_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
-    = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
+inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
 
 #endif // _LIBCPP_STD_VER > 14
 
@@ -4215,7 +3933,7 @@ struct __nothrow_swappable_with {
 template <class _Tp, class _Up>
 struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
 
-}  // __detail
+} // namespace __detail
 
 template <class _Tp>
 struct __is_swappable
@@ -4268,20 +3986,16 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
 };
 
 template <class _Tp, class _Up>
-_LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v
-    = is_swappable_with<_Tp, _Up>::value;
+inline constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value;
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool is_swappable_v
-    = is_swappable<_Tp>::value;
+inline constexpr bool is_swappable_v = is_swappable<_Tp>::value;
 
 template <class _Tp, class _Up>
-_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v
-    = is_nothrow_swappable_with<_Tp, _Up>::value;
+inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value;
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v
-    = is_nothrow_swappable<_Tp>::value;
+inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
 
 #endif // _LIBCPP_STD_VER > 14
 
@@ -4349,40 +4063,6 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 typename __sfinae_underlying_type<_Tp>::__promoted_type
 __convert_to_integral(_Tp __val) { return __val; }
 
-#ifndef _LIBCPP_CXX03_LANG
-
-template <class _Tp>
-struct __has_operator_addressof_member_imp
-{
-    template <class _Up>
-        static auto __test(int)
-            -> typename __select_2nd<decltype(declval<_Up>().operator&()), true_type>::type;
-    template <class>
-        static auto __test(long) -> false_type;
-
-    static const bool value = decltype(__test<_Tp>(0))::value;
-};
-
-template <class _Tp>
-struct __has_operator_addressof_free_imp
-{
-    template <class _Up>
-        static auto __test(int)
-            -> typename __select_2nd<decltype(operator&(declval<_Up>())), true_type>::type;
-    template <class>
-        static auto __test(long) -> false_type;
-
-    static const bool value = decltype(__test<_Tp>(0))::value;
-};
-
-template <class _Tp>
-struct __has_operator_addressof
-    : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
-                                  || __has_operator_addressof_free_imp<_Tp>::value>
-{};
-
-#endif // _LIBCPP_CXX03_LANG
-
 // is_scoped_enum [meta.unary.prop]
 
 #if _LIBCPP_STD_VER > 20
@@ -4398,8 +4078,7 @@ struct _LIBCPP_TEMPLATE_VIS is_scoped_enum
     : public __is_scoped_enum_helper<_Tp> {};
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scoped_enum_v =
-    is_scoped_enum<_Tp>::value;
+inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
 #endif
 
 #if _LIBCPP_STD_VER > 14
@@ -4407,20 +4086,17 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scoped_enum_v =
 template <class... _Args>
 struct conjunction : _And<_Args...> {};
 template<class... _Args>
-_LIBCPP_INLINE_VAR constexpr bool conjunction_v
-    = conjunction<_Args...>::value;
+inline constexpr bool conjunction_v = conjunction<_Args...>::value;
 
 template <class... _Args>
 struct disjunction : _Or<_Args...> {};
 template<class... _Args>
-_LIBCPP_INLINE_VAR constexpr bool disjunction_v
-    = disjunction<_Args...>::value;
+inline constexpr bool disjunction_v = disjunction<_Args...>::value;
 
 template <class _Tp>
 struct negation : _Not<_Tp> {};
 template<class _Tp>
-_LIBCPP_INLINE_VAR constexpr bool negation_v
-    = negation<_Tp>::value;
+inline constexpr bool negation_v = negation<_Tp>::value;
 #endif // _LIBCPP_STD_VER > 14
 
 // These traits are used in __tree and __hash_table
@@ -4453,7 +4129,6 @@ template <class _ValTy, class _Key, class _RawValTy>
 struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
     : false_type {};
 
-#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
 #if _LIBCPP_STD_VER > 17
 _LIBCPP_INLINE_VISIBILITY
 inline constexpr bool is_constant_evaluated() noexcept {
@@ -4463,10 +4138,6 @@ inline constexpr bool is_constant_evaluated() noexcept {
 
 inline _LIBCPP_CONSTEXPR
 bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
-#else
-inline _LIBCPP_CONSTEXPR
-bool __libcpp_is_constant_evaluated() _NOEXCEPT { return false; }
-#endif
 
 template <class _CharT>
 using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
@@ -4481,13 +4152,4 @@ using __maybe_const = conditional_t<_Const, const _Tp, _Tp>;
 
 _LIBCPP_END_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER > 14
-// std::byte
-namespace std  // purposefully not versioned
-{
-
-
-}
-#endif
-
 #endif // _LIBCPP_TYPE_TRAITS
lib/libcxx/include/typeindex
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- typeindex ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -49,6 +49,7 @@ struct hash<type_index>
 #include <__functional_base>
 #include <compare>
 #include <typeinfo>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
lib/libcxx/include/typeinfo
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- typeinfo ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -361,7 +361,7 @@ class _LIBCPP_EXCEPTION_ABI bad_typeid
   virtual const char* what() const _NOEXCEPT;
 };
 
-}  // std
+} // namespace std
 
 #endif // defined(_LIBCPP_ABI_VCRUNTIME)
 
lib/libcxx/include/unordered_map
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- unordered_map -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -216,6 +216,47 @@ public:
     void reserve(size_type n);
 };
 
+template<class InputIterator,
+    class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
+    class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
+unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_map<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
+    Allocator>; // C++17
+
+template<class Key, class T, class Hash = hash<Key>,
+    class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
+unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_map<Key, T, Hash, Pred, Allocator>; // C++17
+
+template<class InputIterator, class Allocator>
+unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
+  -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
+        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
+
+template<class InputIterator, class Allocator>
+unordered_map(InputIterator, InputIterator, Allocator)
+  -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
+        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
+
+template<class InputIterator, class Hash, class Allocator>
+unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
+  -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
+          equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
+
+template<class Key, class T, typename Allocator>
+unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
+  -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
+
+template<class Key, class T, typename Allocator>
+unordered_map(initializer_list<pair<const Key, T>>, Allocator)
+  -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
+
+template<class Key, class T, class Hash, class Allocator>
+unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash, Allocator)
+  -> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
+
 template <class Key, class T, class Hash, class Pred, class Alloc>
     void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
               unordered_map<Key, T, Hash, Pred, Alloc>& y)
@@ -404,6 +445,48 @@ public:
     void reserve(size_type n);
 };
 
+template<class InputIterator,
+    class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
+    class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
+unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_multimap<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
+    Allocator>; // C++17
+
+template<class Key, class T, class Hash = hash<Key>,
+    class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
+unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_multimap<Key, T, Hash, Pred, Allocator>; // C++17
+
+template<class InputIterator, class Allocator>
+unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator)
+  -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
+        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
+
+template<class InputIterator, class Allocator>
+unordered_multimap(InputIterator, InputIterator, Allocator)
+  -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
+        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
+
+template<class InputIterator, class Hash, class Allocator>
+unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
+  -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
+          equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
+
+template<class Key, class T, typename Allocator>
+unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
+  -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
+
+template<class Key, class T, typename Allocator>
+unordered_multimap(initializer_list<pair<const Key, T>>, Allocator)
+  -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
+
+template<class Key, class T, class Hash, class Allocator>
+unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash,
+    Allocator)
+  -> unordered_multimap<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
+
 template <class Key, class T, class Hash, class Pred, class Alloc>
     void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
               unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
@@ -435,6 +518,8 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
 #include <__debug>
 #include <__functional/is_transparent.h>
 #include <__hash_table>
+#include <__iterator/iterator_traits.h>
+#include <__memory/addressof.h>
 #include <__node_handle>
 #include <__utility/forward.h>
 #include <compare>
@@ -473,12 +558,13 @@ public:
     size_t operator()(const _Key& __x) const
         {return static_cast<const _Hash&>(*this)(__x);}
 #if _LIBCPP_STD_VER > 17
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _K2& __x) const
         {return static_cast<const _Hash&>(*this)(__x);}
 #endif
-    void swap(__unordered_map_hasher&__y)
+    _LIBCPP_INLINE_VISIBILITY
+    void swap(__unordered_map_hasher& __y)
         _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
     {
         using _VSTD::swap;
@@ -508,12 +594,13 @@ public:
     size_t operator()(const _Key& __x) const
         {return __hash_(__x);}
 #if _LIBCPP_STD_VER > 17
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _K2& __x) const
         {return __hash_(__x);}
 #endif
-    void swap(__unordered_map_hasher&__y)
+    _LIBCPP_INLINE_VISIBILITY
+    void swap(__unordered_map_hasher& __y)
         _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
     {
         using _VSTD::swap;
@@ -557,24 +644,25 @@ public:
     bool operator()(const _Key& __x, const _Cp& __y) const
         {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
 #if _LIBCPP_STD_VER > 17
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _K2& __y) const
         {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _K2& __x, const _Cp& __y) const
         {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _K2& __y) const
         {return static_cast<const _Pred&>(*this)(__x, __y);}
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _K2& __x, const _Key& __y) const
         {return static_cast<const _Pred&>(*this)(__x, __y);}
 #endif
-    void swap(__unordered_map_equal&__y)
+    _LIBCPP_INLINE_VISIBILITY
+    void swap(__unordered_map_equal& __y)
         _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
     {
         using _VSTD::swap;
@@ -607,24 +695,25 @@ public:
     bool operator()(const _Key& __x, const _Cp& __y) const
         {return __pred_(__x, __y.__get_value().first);}
 #if _LIBCPP_STD_VER > 17
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _K2& __y) const
         {return __pred_(__x.__get_value().first, __y);}
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _K2& __x, const _Cp& __y) const
         {return __pred_(__x, __y.__get_value().first);}
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _K2& __y) const
         {return __pred_(__x, __y);}
-    template <typename _K2, typename = _EnableIf<__is_transparent<_Hash, _K2>::value && __is_transparent<_Pred, _K2>::value>>
+    template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _K2& __x, const _Key& __y) const
         {return __pred_(__x, __y);}
 #endif
-    void swap(__unordered_map_equal&__y)
+    _LIBCPP_INLINE_VISIBILITY
+    void swap(__unordered_map_equal& __y)
         _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
     {
         using _VSTD::swap;
@@ -980,11 +1069,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     unordered_map()
         _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
-        {
-#if _LIBCPP_DEBUG_LEVEL == 2
-            __get_db()->__insert_c(this);
-#endif
-        }
+    {
+        _VSTD::__debug_db_insert_c(this);
+    }
     explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
                            const key_equal& __eql = key_equal());
     unordered_map(size_type __n, const hasher& __hf,
@@ -1052,7 +1139,7 @@ public:
 #ifndef _LIBCPP_CXX03_LANG
         __table_ = __u.__table_;
 #else
-        if (this != &__u) {
+        if (this != _VSTD::addressof(__u)) {
             __table_.clear();
             __table_.hash_function() = __u.__table_.hash_function();
             __table_.key_eq() = __u.__table_.key_eq();
@@ -1100,13 +1187,10 @@ public:
         {return __table_.__insert_unique(__x);}
 
     iterator insert(const_iterator __p, const value_type& __x) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
-            " referring to this unordered_map");
-#else
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                             "unordered_map::insert(const_iterator, const value_type&) called with an iterator not "
+                             "referring to this unordered_map");
         ((void)__p);
-#endif
         return insert(__x).first;
     }
 
@@ -1124,13 +1208,10 @@ public:
         {return __table_.__insert_unique(_VSTD::move(__x));}
 
     iterator insert(const_iterator __p, value_type&& __x) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
-            " referring to this unordered_map");
-#else
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                             "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
+                             " referring to this unordered_map");
         ((void)__p);
-#endif
         return __table_.__insert_unique(_VSTD::move(__x)).first;
     }
 
@@ -1145,13 +1226,10 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         iterator insert(const_iterator __p, _Pp&& __x)
         {
-#if _LIBCPP_DEBUG_LEVEL == 2
-            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-                "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
-                " referring to this unordered_map");
-#else
+            _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                                 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
+                                 " referring to this unordered_map");
           ((void)__p);
-#endif
             return insert(_VSTD::forward<_Pp>(__x)).first;
         }
 
@@ -1164,13 +1242,10 @@ public:
     template <class... _Args>
     _LIBCPP_INLINE_VISIBILITY
     iterator emplace_hint(const_iterator __p, _Args&&... __args) {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
-            " referring to this unordered_map");
-#else
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
+                             "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
+                             " referring to this unordered_map");
           ((void)__p);
-#endif
         return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
     }
 
@@ -1199,13 +1274,10 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
-            "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
-            " referring to this unordered_map");
-#else
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__h)) == this,
+                             "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
+                             " referring to this unordered_map");
         ((void)__h);
-#endif
         return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
     }
 
@@ -1213,13 +1285,10 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
-            "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
-            " referring to this unordered_map");
-#else
+        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__h)) == this,
+                             "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
+                             " referring to this unordered_map");
         ((void)__h);
-#endif
         return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
     }
 
@@ -1355,51 +1424,48 @@ public:
     iterator       find(const key_type& __k)       {return __table_.find(__k);}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const key_type& __k) const {return __table_.find(__k);}
-
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
-        find(const _K2& __k)       {return __table_.find(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
-        find(const _K2& __k) const {return __table_.find(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    iterator       find(const _K2& __k)            {return __table_.find(__k);}
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
+#endif // _LIBCPP_STD_VER > 17
 
     _LIBCPP_INLINE_VISIBILITY
     size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
-        count(const _K2& __k) const {return __table_.__count_unique(__k);}
-    #endif // _LIBCPP_STD_VER > 17
-    #if _LIBCPP_STD_VER > 17
-        _LIBCPP_INLINE_VISIBILITY
-        bool contains(const key_type& __k) const {return find(__k) != end();}
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    size_type count(const _K2& __k) const      {return __table_.__count_unique(__k);}
+#endif // _LIBCPP_STD_VER > 17
+
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const key_type& __k) const {return find(__k) != end();}
+
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const _K2& __k) const      {return find(__k) != end();}
+#endif // _LIBCPP_STD_VER > 17
 
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
-        contains(const _K2& __k) const {return find(__k) != end();}
-    #endif // _LIBCPP_STD_VER > 17
     _LIBCPP_INLINE_VISIBILITY
     pair<iterator, iterator>             equal_range(const key_type& __k)
         {return __table_.__equal_range_unique(__k);}
     _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
         {return __table_.__equal_range_unique(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
-        equal_range(const _K2& __k)       {return __table_.__equal_range_unique(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
-        equal_range(const _K2& __k) const {return __table_.__equal_range_unique(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<iterator, iterator>             equal_range(const _K2& __k)
+        {return __table_.__equal_range_unique(__k);}
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
+        {return __table_.__equal_range_unique(__k);}
+#endif // _LIBCPP_STD_VER > 17
 
     mapped_type& operator[](const key_type& __k);
 #ifndef _LIBCPP_CXX03_LANG
@@ -1447,13 +1513,13 @@ public:
 #if _LIBCPP_DEBUG_LEVEL == 2
 
     bool __dereferenceable(const const_iterator* __i) const
-        {return __table_.__dereferenceable(&__i->__i_);}
+        {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
     bool __decrementable(const const_iterator* __i) const
-        {return __table_.__decrementable(&__i->__i_);}
+        {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
     bool __addable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
     bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
 
 #endif // _LIBCPP_DEBUG_LEVEL == 2
 
@@ -1464,15 +1530,16 @@ private:
 #endif
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Hash = hash<__iter_key_type<_InputIterator>>,
          class _Pred = equal_to<__iter_key_type<_InputIterator>>,
          class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
               _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
@@ -1480,52 +1547,55 @@ unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocat
 template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
          class _Pred = equal_to<remove_const_t<_Key>>,
          class _Allocator = allocator<pair<const _Key, _Tp>>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
               _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
                    hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(_InputIterator, _InputIterator, _Allocator)
   -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
                    hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _InputIterator, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
   -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
                    _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_map<remove_const_t<_Key>, _Tp,
                    hash<remove_const_t<_Key>>,
                    equal_to<remove_const_t<_Key>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator)
   -> unordered_map<remove_const_t<_Key>, _Tp,
                    hash<remove_const_t<_Key>>,
                    equal_to<remove_const_t<_Key>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
   -> unordered_map<remove_const_t<_Key>, _Tp, _Hash,
                    equal_to<remove_const_t<_Key>>, _Allocator>;
@@ -1536,9 +1606,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         size_type __n, const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -1548,9 +1616,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const allocator_type& __a)
     : __table_(__hf, __eql, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -1560,9 +1626,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const allocator_type& __a)
     : __table_(typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
@@ -1570,9 +1634,7 @@ template <class _InputIterator>
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         _InputIterator __first, _InputIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__first, __last);
 }
 
@@ -1583,9 +1645,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -1597,9 +1657,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -1609,9 +1667,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const unordered_map& __u)
     : __table_(__u.__table_)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -1621,9 +1677,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const unordered_map& __u, const allocator_type& __a)
     : __table_(__u.__table_, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -1637,9 +1691,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
     : __table_(_VSTD::move(__u.__table_))
 {
+    _VSTD::__debug_db_insert_c(this);
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    __get_db()->swap(this, &__u);
+    __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -1648,9 +1702,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         unordered_map&& __u, const allocator_type& __a)
     : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__a != __u.get_allocator())
     {
         iterator __i = __u.begin();
@@ -1661,7 +1713,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
     }
 #if _LIBCPP_DEBUG_LEVEL == 2
     else
-        __get_db()->swap(this, &__u);
+        __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -1669,9 +1721,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         initializer_list<value_type> __il)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__il.begin(), __il.end());
 }
 
@@ -1681,9 +1731,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
@@ -1694,9 +1742,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
@@ -1914,11 +1960,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     unordered_multimap()
         _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
-        {
-#if _LIBCPP_DEBUG_LEVEL == 2
-            __get_db()->__insert_c(this);
-#endif
-        }
+    {
+        _VSTD::__debug_db_insert_c(this);
+    }
     explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
                                 const key_equal& __eql = key_equal());
     unordered_multimap(size_type __n, const hasher& __hf,
@@ -1987,7 +2031,7 @@ public:
 #ifndef _LIBCPP_CXX03_LANG
         __table_ = __u.__table_;
 #else
-        if (this != &__u) {
+        if (this != _VSTD::addressof(__u)) {
             __table_.clear();
             __table_.hash_function() = __u.__table_.hash_function();
             __table_.key_eq() = __u.__table_.key_eq();
@@ -2167,49 +2211,48 @@ public:
     iterator       find(const key_type& __k)       {return __table_.find(__k);}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const key_type& __k) const {return __table_.find(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
-        find(const _K2& __k)       {return __table_.find(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
-        find(const _K2& __k) const {return __table_.find(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    iterator       find(const _K2& __k)            {return __table_.find(__k);}
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
+#endif // _LIBCPP_STD_VER > 17
+
     _LIBCPP_INLINE_VISIBILITY
     size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
-        count(const _K2& __k) const {return __table_.__count_multi(__k);}
-    #endif // _LIBCPP_STD_VER > 17
-    #if _LIBCPP_STD_VER > 17
-        _LIBCPP_INLINE_VISIBILITY
-        bool contains(const key_type& __k) const {return find(__k) != end();}
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    size_type count(const _K2& __k) const      {return __table_.__count_multi(__k);}
+#endif // _LIBCPP_STD_VER > 17
+
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const key_type& __k) const {return find(__k) != end();}
+
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const _K2& __k) const      {return find(__k) != end();}
+#endif // _LIBCPP_STD_VER > 17
 
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
-        contains(const _K2& __k) const {return find(__k) != end();}
-    #endif // _LIBCPP_STD_VER > 17
     _LIBCPP_INLINE_VISIBILITY
     pair<iterator, iterator>             equal_range(const key_type& __k)
         {return __table_.__equal_range_multi(__k);}
     _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
         {return __table_.__equal_range_multi(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
-        equal_range(const _K2& __k)       {return __table_.__equal_range_multi(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
-        equal_range(const _K2& __k) const {return __table_.__equal_range_multi(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<iterator, iterator>             equal_range(const _K2& __k)
+        {return __table_.__equal_range_multi(__k);}
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
+        {return __table_.__equal_range_multi(__k);}
+#endif // _LIBCPP_STD_VER > 17
 
     _LIBCPP_INLINE_VISIBILITY
     size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
@@ -2250,28 +2293,29 @@ public:
 #if _LIBCPP_DEBUG_LEVEL == 2
 
     bool __dereferenceable(const const_iterator* __i) const
-        {return __table_.__dereferenceable(&__i->__i_);}
+        {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
     bool __decrementable(const const_iterator* __i) const
-        {return __table_.__decrementable(&__i->__i_);}
+        {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
     bool __addable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
     bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
 
 #endif // _LIBCPP_DEBUG_LEVEL == 2
 
 
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Hash = hash<__iter_key_type<_InputIterator>>,
          class _Pred = equal_to<__iter_key_type<_InputIterator>>,
          class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
                    _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
@@ -2279,52 +2323,55 @@ unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Al
 template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
          class _Pred = equal_to<remove_const_t<_Key>>,
          class _Allocator = allocator<pair<const _Key, _Tp>>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
                    _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
                         hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(_InputIterator, _InputIterator, _Allocator)
   -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
                         hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _InputIterator, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
   -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
                         _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_multimap<remove_const_t<_Key>, _Tp,
                         hash<remove_const_t<_Key>>,
                         equal_to<remove_const_t<_Key>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
   -> unordered_multimap<remove_const_t<_Key>, _Tp,
                         hash<remove_const_t<_Key>>,
                         equal_to<remove_const_t<_Key>>, _Allocator>;
 
 template<class _Key, class _Tp, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
   -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash,
                         equal_to<remove_const_t<_Key>>, _Allocator>;
@@ -2335,9 +2382,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         size_type __n, const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -2347,9 +2392,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const allocator_type& __a)
     : __table_(__hf, __eql, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -2358,9 +2401,7 @@ template <class _InputIterator>
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         _InputIterator __first, _InputIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__first, __last);
 }
 
@@ -2371,9 +2412,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -2385,9 +2424,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -2398,9 +2435,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const allocator_type& __a)
     : __table_(typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
@@ -2408,9 +2443,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const unordered_multimap& __u)
     : __table_(__u.__table_)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -2420,9 +2453,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const unordered_multimap& __u, const allocator_type& __a)
     : __table_(__u.__table_, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -2436,9 +2467,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
     : __table_(_VSTD::move(__u.__table_))
 {
+    _VSTD::__debug_db_insert_c(this);
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    __get_db()->swap(this, &__u);
+    __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -2447,9 +2478,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         unordered_multimap&& __u, const allocator_type& __a)
     : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__a != __u.get_allocator())
     {
         iterator __i = __u.begin();
@@ -2461,7 +2490,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
     }
 #if _LIBCPP_DEBUG_LEVEL == 2
     else
-        __get_db()->swap(this, &__u);
+        __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -2469,9 +2498,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         initializer_list<value_type> __il)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__il.begin(), __il.end());
 }
 
@@ -2481,9 +2508,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
@@ -2494,9 +2519,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, typename __table::allocator_type(__a))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
lib/libcxx/include/unordered_set
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- unordered_set -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -182,6 +182,43 @@ public:
     void reserve(size_type n);
 };
 
+template<class InputIterator,
+    class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
+    class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
+    class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
+unordered_set(InputIterator, InputIterator, typename see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_set<typename iterator_traits<InputIterator>::value_type,
+        Hash, Pred, Allocator>; // C++17
+
+template<class T, class Hash = hash<T>,
+          class Pred = equal_to<T>, class Allocator = allocator<T>>
+unordered_set(initializer_list<T>, typename see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_set<T, Hash, Pred, Allocator>; // C++17
+
+template<class InputIterator,  class Allocator>
+unordered_set(InputIterator, InputIterator, typename see below::size_type, Allocator)
+  -> unordered_set<typename iterator_traits<InputIterator>::value_type,
+        hash<typename iterator_traits<InputIterator>::value_type>,
+        equal_to<typename iterator_traits<InputIterator>::value_type>,
+        Allocator>; // C++17
+
+template<class InputIterator, class Hash, class Allocator>
+unordered_set(InputIterator, InputIterator, typename see below::size_type,
+    Hash, Allocator)
+  -> unordered_set<typename iterator_traits<InputIterator>::value_type, Hash,
+        equal_to<typename iterator_traits<InputIterator>::value_type>,
+        Allocator>; // C++17
+
+template<class T, class Allocator>
+unordered_set(initializer_list<T>, typename see below::size_type, Allocator)
+  -> unordered_set<T, hash<T>, equal_to<T>, Allocator>; // C++17
+
+template<class T, class Hash, class Allocator>
+unordered_set(initializer_list<T>, typename see below::size_type, Hash, Allocator)
+  -> unordered_set<T, Hash, equal_to<T>, Allocator>; // C++17
+
 template <class Value, class Hash, class Pred, class Alloc>
     void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
               unordered_set<Value, Hash, Pred, Alloc>& y)
@@ -359,6 +396,42 @@ public:
     void reserve(size_type n);
 };
 
+template<class InputIterator,
+    class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
+    class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
+    class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
+unordered_multiset(InputIterator, InputIterator, see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
+        Hash, Pred, Allocator>; // C++17
+
+template<class T, class Hash = hash<T>,
+          class Pred = equal_to<T>, class Allocator = allocator<T>>
+unordered_multiset(initializer_list<T>, typename see below::size_type = see below,
+    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
+  -> unordered_multiset<T, Hash, Pred, Allocator>; // C++17
+
+template<class InputIterator,  class Allocator>
+unordered_multiset(InputIterator, InputIterator, typename see below::size_type, Allocator)
+  -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
+        hash<typename iterator_traits<InputIterator>::value_type>,
+        equal_to<typename iterator_traits<InputIterator>::value_type>,
+        Allocator>; // C++17
+
+template<class InputIterator,  class Hash, class Allocator>
+unordered_multiset(InputIterator, InputIterator, typename see below::size_type,
+    Hash, Allocator)
+  -> unordered_multiset<typename iterator_traits<InputIterator>::value_type, Hash,
+        equal_to<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
+
+template<class T, class Allocator>
+unordered_multiset(initializer_list<T>, typename see below::size_type, Allocator)
+  -> unordered_multiset<T, hash<T>, equal_to<T>, Allocator>; // C++17
+
+template<class T, class Hash, class Allocator>
+unordered_multiset(initializer_list<T>, typename see below::size_type, Hash, Allocator)
+  -> unordered_multiset<T, Hash, equal_to<T>, Allocator>; // C++17
+
 template <class Value, class Hash, class Pred, class Alloc>
     void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
               unordered_multiset<Value, Hash, Pred, Alloc>& y)
@@ -390,6 +463,7 @@ template <class Value, class Hash, class Pred, class Alloc>
 #include <__debug>
 #include <__functional/is_transparent.h>
 #include <__hash_table>
+#include <__memory/addressof.h>
 #include <__node_handle>
 #include <__utility/forward.h>
 #include <compare>
@@ -451,11 +525,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     unordered_set()
         _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
-        {
-#if _LIBCPP_DEBUG_LEVEL == 2
-            __get_db()->__insert_c(this);
-#endif
-        }
+    {
+        _VSTD::__debug_db_insert_c(this);
+    }
     explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
                            const key_equal& __eql = key_equal());
 #if _LIBCPP_STD_VER > 11
@@ -569,7 +641,7 @@ public:
 #if _LIBCPP_DEBUG_LEVEL == 2
         iterator emplace_hint(const_iterator __p, _Args&&... __args)
         {
-            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
                 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
                 " referring to this unordered_set");
             return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
@@ -586,7 +658,7 @@ public:
 #if _LIBCPP_DEBUG_LEVEL == 2
     iterator insert(const_iterator __p, value_type&& __x)
         {
-            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
                 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
                 " referring to this unordered_set");
             return insert(_VSTD::move(__x)).first;
@@ -607,7 +679,7 @@ public:
 #if _LIBCPP_DEBUG_LEVEL == 2
     iterator insert(const_iterator __p, const value_type& __x)
         {
-            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
                 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
                 " referring to this unordered_set");
             return insert(__x).first;
@@ -706,49 +778,48 @@ public:
     iterator       find(const key_type& __k)       {return __table_.find(__k);}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const key_type& __k) const {return __table_.find(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
-        find(const _K2& __k)       {return __table_.find(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
-        find(const _K2& __k) const {return __table_.find(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    iterator       find(const _K2& __k)            {return __table_.find(__k);}
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
+#endif // _LIBCPP_STD_VER > 17
+
     _LIBCPP_INLINE_VISIBILITY
     size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
-        count(const _K2& __k) const {return __table_.__count_unique(__k);}
-    #endif // _LIBCPP_STD_VER > 17
-    #if _LIBCPP_STD_VER > 17
-        _LIBCPP_INLINE_VISIBILITY
-        bool contains(const key_type& __k) const {return find(__k) != end();}
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    size_type count(const _K2& __k) const      {return __table_.__count_unique(__k);}
+#endif // _LIBCPP_STD_VER > 17
+
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const key_type& __k) const {return find(__k) != end();}
+
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const _K2& __k) const      {return find(__k) != end();}
+#endif // _LIBCPP_STD_VER > 17
 
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
-        contains(const _K2& __k) const {return find(__k) != end();}
-    #endif // _LIBCPP_STD_VER > 17
     _LIBCPP_INLINE_VISIBILITY
     pair<iterator, iterator>             equal_range(const key_type& __k)
         {return __table_.__equal_range_unique(__k);}
     _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
         {return __table_.__equal_range_unique(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
-        equal_range(const _K2& __k)       {return __table_.__equal_range_unique(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
-        equal_range(const _K2& __k) const {return __table_.__equal_range_unique(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<iterator, iterator>             equal_range(const _K2& __k)
+        {return __table_.__equal_range_unique(__k);}
+    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
+        {return __table_.__equal_range_unique(__k);}
+#endif // _LIBCPP_STD_VER > 17
 
     _LIBCPP_INLINE_VISIBILITY
     size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
@@ -799,15 +870,16 @@ public:
 
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Hash = hash<__iter_value_type<_InputIterator>>,
          class _Pred = equal_to<__iter_value_type<_InputIterator>>,
          class _Allocator = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
               _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
@@ -815,16 +887,17 @@ unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocat
 template<class _Tp, class _Hash = hash<_Tp>,
          class _Pred = equal_to<_Tp>,
          class _Allocator = allocator<_Tp>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
               _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_set(_InputIterator, _InputIterator,
               typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_set<__iter_value_type<_InputIterator>,
@@ -833,9 +906,10 @@ unordered_set(_InputIterator, _InputIterator,
                    _Allocator>;
 
 template<class _InputIterator, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_set(_InputIterator, _InputIterator,
               typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
   -> unordered_set<__iter_value_type<_InputIterator>, _Hash,
@@ -843,14 +917,14 @@ unordered_set(_InputIterator, _InputIterator,
                    _Allocator>;
 
 template<class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
 
 template<class _Tp, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
   -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
 #endif
@@ -860,9 +934,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
         const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -871,9 +943,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
         const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -882,9 +952,7 @@ template <class _InputIterator>
 unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         _InputIterator __first, _InputIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__first, __last);
 }
 
@@ -895,9 +963,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -909,9 +975,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -922,9 +986,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const allocator_type& __a)
     : __table_(__a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
@@ -932,9 +994,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const unordered_set& __u)
     : __table_(__u.__table_)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -944,9 +1004,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const unordered_set& __u, const allocator_type& __a)
     : __table_(__u.__table_, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -960,9 +1018,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
     : __table_(_VSTD::move(__u.__table_))
 {
+    _VSTD::__debug_db_insert_c(this);
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    __get_db()->swap(this, &__u);
+    __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -971,9 +1029,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         unordered_set&& __u, const allocator_type& __a)
     : __table_(_VSTD::move(__u.__table_), __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__a != __u.get_allocator())
     {
         iterator __i = __u.begin();
@@ -982,7 +1038,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
     }
 #if _LIBCPP_DEBUG_LEVEL == 2
     else
-        __get_db()->swap(this, &__u);
+        __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -990,9 +1046,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
 unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         initializer_list<value_type> __il)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__il.begin(), __il.end());
 }
 
@@ -1002,9 +1056,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
@@ -1015,9 +1067,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
@@ -1148,11 +1198,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     unordered_multiset()
         _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
-        {
-#if _LIBCPP_DEBUG_LEVEL == 2
-            __get_db()->__insert_c(this);
-#endif
-        }
+    {
+        _VSTD::__debug_db_insert_c(this);
+    }
     explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
                                 const key_equal& __eql = key_equal());
     unordered_multiset(size_type __n, const hasher& __hf,
@@ -1372,49 +1420,48 @@ public:
     iterator       find(const key_type& __k)       {return __table_.find(__k);}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const key_type& __k) const {return __table_.find(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
-        find(const _K2& __k)       {return __table_.find(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
-        find(const _K2& __k) const {return __table_.find(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    iterator       find(const _K2& __k)            {return __table_.find(__k);}
+    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
+#endif // _LIBCPP_STD_VER > 17
+
     _LIBCPP_INLINE_VISIBILITY
     size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
-        count(const _K2& __k) const {return __table_.__count_multi(__k);}
-    #endif // _LIBCPP_STD_VER > 17
-    #if _LIBCPP_STD_VER > 17
-        _LIBCPP_INLINE_VISIBILITY
-        bool contains(const key_type& __k) const {return find(__k) != end();}
+#if _LIBCPP_STD_VER > 17
+    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    size_type count(const _K2& __k) const      {return __table_.__count_multi(__k);}
+#endif // _LIBCPP_STD_VER > 17
+
+#if _LIBCPP_STD_VER > 17
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const key_type& __k) const {return find(__k) != end();}
+
+    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    bool contains(const _K2& __k) const      {return find(__k) != end();}
+#endif // _LIBCPP_STD_VER > 17
 
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
-        contains(const _K2& __k) const {return find(__k) != end();}
-    #endif // _LIBCPP_STD_VER > 17
     _LIBCPP_INLINE_VISIBILITY
     pair<iterator, iterator>             equal_range(const key_type& __k)
         {return __table_.__equal_range_multi(__k);}
     _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
         {return __table_.__equal_range_multi(__k);}
-    #if _LIBCPP_STD_VER > 17
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
-        equal_range(const _K2& __k)       {return __table_.__equal_range_multi(__k);}
-        template <typename _K2>
-        _LIBCPP_INLINE_VISIBILITY
-        _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
-        equal_range(const _K2& __k) const {return __table_.__equal_range_multi(__k);}
-    #endif // _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 17
+    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<iterator, iterator>             equal_range(const _K2& __k)
+        {return __table_.__equal_range_multi(__k);}
+    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
+    _LIBCPP_INLINE_VISIBILITY
+    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
+        {return __table_.__equal_range_multi(__k);}
+#endif // _LIBCPP_STD_VER > 17
 
     _LIBCPP_INLINE_VISIBILITY
     size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
@@ -1465,31 +1512,33 @@ public:
 
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Hash = hash<__iter_value_type<_InputIterator>>,
          class _Pred = equal_to<__iter_value_type<_InputIterator>>,
          class _Allocator = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
               _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
 
 template<class _Tp, class _Hash = hash<_Tp>,
          class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<!__is_allocator<_Pred>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<!__is_allocator<_Pred>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
               _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
   -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
 
 template<class _InputIterator, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_multiset<__iter_value_type<_InputIterator>,
                    hash<__iter_value_type<_InputIterator>>,
@@ -1497,9 +1546,10 @@ unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Al
                    _Allocator>;
 
 template<class _InputIterator, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
               _Hash, _Allocator)
   -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
@@ -1507,14 +1557,14 @@ unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Al
                    _Allocator>;
 
 template<class _Tp, class _Allocator,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
   -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
 
 template<class _Tp, class _Hash, class _Allocator,
-         class = _EnableIf<!__is_allocator<_Hash>::value>,
-         class = _EnableIf<!is_integral<_Hash>::value>,
-         class = _EnableIf<__is_allocator<_Allocator>::value>>
+         class = enable_if_t<!__is_allocator<_Hash>::value>,
+         class = enable_if_t<!is_integral<_Hash>::value>,
+         class = enable_if_t<__is_allocator<_Allocator>::value>>
 unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
   -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
 #endif
@@ -1524,9 +1574,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         size_type __n, const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -1536,9 +1584,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const allocator_type& __a)
     : __table_(__hf, __eql, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
 }
 
@@ -1547,9 +1593,7 @@ template <class _InputIterator>
 unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         _InputIterator __first, _InputIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__first, __last);
 }
 
@@ -1560,9 +1604,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const hasher& __hf, const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -1574,9 +1616,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__first, __last);
 }
@@ -1587,9 +1627,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const allocator_type& __a)
     : __table_(__a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
 }
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
@@ -1597,9 +1635,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const unordered_multiset& __u)
     : __table_(__u.__table_)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -1609,9 +1645,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const unordered_multiset& __u, const allocator_type& __a)
     : __table_(__u.__table_, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__u.bucket_count());
     insert(__u.begin(), __u.end());
 }
@@ -1625,9 +1659,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
     : __table_(_VSTD::move(__u.__table_))
 {
+    _VSTD::__debug_db_insert_c(this);
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    __get_db()->swap(this, &__u);
+    __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -1636,9 +1670,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         unordered_multiset&& __u, const allocator_type& __a)
     : __table_(_VSTD::move(__u.__table_), __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__a != __u.get_allocator())
     {
         iterator __i = __u.begin();
@@ -1647,7 +1679,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
     }
 #if _LIBCPP_DEBUG_LEVEL == 2
     else
-        __get_db()->swap(this, &__u);
+        __get_db()->swap(this, _VSTD::addressof(__u));
 #endif
 }
 
@@ -1655,9 +1687,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
 unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         initializer_list<value_type> __il)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     insert(__il.begin(), __il.end());
 }
 
@@ -1667,9 +1697,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const key_equal& __eql)
     : __table_(__hf, __eql)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
@@ -1680,9 +1708,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const key_equal& __eql, const allocator_type& __a)
     : __table_(__hf, __eql, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     __table_.rehash(__n);
     insert(__il.begin(), __il.end());
 }
lib/libcxx/include/utility
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- utility -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -79,7 +79,7 @@ struct pair
     pair(pair&&) = default;
     explicit(see-below) constexpr pair();
     explicit(see-below) pair(const T1& x, const T2& y);                          // constexpr in C++14
-    template <class U, class V> explicit(see-below) pair(U&& x, V&& y);          // constexpr in C++14
+    template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&);    // constexpr in C++14
     template <class U, class V> explicit(see-below) pair(const pair<U, V>& p);   // constexpr in C++14
     template <class U, class V> explicit(see-below) pair(pair<U, V>&& p);        // constexpr in C++14
     template <class... Args1, class... Args2>
@@ -95,12 +95,18 @@ struct pair
                                 is_nothrow_swappable_v<T2>);                     // constexpr in C++20
 };
 
+template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
+
 template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
-template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
-template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
-template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
-template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
-template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
+template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
+template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
+template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
+template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
+template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
+template <class T1, class T2>
+  constexpr common_comparison_type_t<synth-three-way-result<T1>,
+                                     synth-three-way-result<T2>>
+    operator<=>(const pair<T1,T2>&, const pair<T1,T2>&);                               // C++20
 
 template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);                // constexpr in C++14
 template <class T1, class T2>
@@ -179,7 +185,8 @@ template<class... T>
   using index_sequence_for = make_index_sequence<sizeof...(T)>;
 
 template<class T, class U=T>
-    T exchange(T& obj, U&& new_value);
+    constexpr T exchange(T& obj, U&& new_value)
+      noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23
 
 // 20.2.7, in-place construction // C++17
 struct in_place_t {
@@ -211,6 +218,7 @@ template <class T>
 #include <__debug>
 #include <__tuple>
 #include <__utility/as_const.h>
+#include <__utility/auto_cast.h>
 #include <__utility/cmp.h>
 #include <__utility/declval.h>
 #include <__utility/exchange.h>
@@ -220,11 +228,17 @@ template <class T>
 #include <__utility/move.h>
 #include <__utility/pair.h>
 #include <__utility/piecewise_construct.h>
+#include <__utility/priority_tag.h>
 #include <__utility/rel_ops.h>
 #include <__utility/swap.h>
 #include <__utility/to_underlying.h>
+#include <__utility/transaction.h>
 #include <compare>
 #include <initializer_list>
 #include <version>
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
 #endif // _LIBCPP_UTILITY
lib/libcxx/include/valarray
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===-------------------------- valarray ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -105,6 +105,8 @@ public:
     void resize(size_t n, value_type x = value_type());
 };
 
+template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
+
 class slice
 {
 public:
@@ -346,6 +348,7 @@ template <class T> unspecified2 end(const valarray<T>& v);
 #include <functional>
 #include <initializer_list>
 #include <new>
+#include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -1081,6 +1084,11 @@ private:
     valarray& __assign_range(const value_type* __f, const value_type* __l);
 };
 
+#if _LIBCPP_STD_VER > 14
+template<class _Tp, size_t _Size>
+valarray(const _Tp(&)[_Size], size_t) -> valarray<_Tp>;
+#endif
+
 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
 
 template <class _Op, class _Tp>
@@ -3048,7 +3056,7 @@ template <class _Tp>
 valarray<_Tp>&
 valarray<_Tp>::operator=(const valarray& __v)
 {
-    if (this != &__v)
+    if (this != _VSTD::addressof(__v))
         return __assign_range(__v.__begin_, __v.__end_);
     return *this;
 }
lib/libcxx/include/variant
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------------ variant -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -233,10 +233,7 @@ public:
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-// TODO: GCC 5 lies about its support for C++17 (it says it supports it but it
-//       really doesn't). That breaks variant, which uses some C++17 features.
-//       Remove this once we drop support for GCC 5.
-#if _LIBCPP_STD_VER > 14 && !(defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW < 6000)
+#if _LIBCPP_STD_VER > 14
 
 // Light N-dimensional array of function pointers. Used in place of std::array to avoid
 // adding a dependency.
@@ -269,7 +266,7 @@ template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS variant_size;
 
 template <class _Tp>
-_LIBCPP_INLINE_VAR constexpr size_t variant_size_v = variant_size<_Tp>::value;
+inline constexpr size_t variant_size_v = variant_size<_Tp>::value;
 
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {};
@@ -309,7 +306,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
   using type = __type_pack_element<_Ip, _Types...>;
 };
 
-_LIBCPP_INLINE_VAR constexpr size_t variant_npos = static_cast<size_t>(-1);
+inline constexpr size_t variant_npos = static_cast<size_t>(-1);
 
 constexpr int __choose_index_type(unsigned int __num_elem) {
   if (__num_elem < numeric_limits<unsigned char>::max())
@@ -552,7 +549,7 @@ private:
   inline _LIBCPP_INLINE_VISIBILITY
   static constexpr auto __make_fdiagonal_impl() {
     return __make_dispatch<_Fp, _Vs...>(
-        index_sequence<(__identity<_Vs>{}, _Ip)...>{});
+        index_sequence<((void)__identity<_Vs>{}, _Ip)...>{});
   }
 
   template <class _Fp, class... _Vs, size_t... _Is>
@@ -1196,11 +1193,11 @@ struct __narrowing_check {
   template <class _Dest>
   static auto __test_impl(_Dest (&&)[1]) -> __identity<_Dest>;
   template <class _Dest, class _Source>
-  using _Apply _LIBCPP_NODEBUG_TYPE = decltype(__test_impl<_Dest>({declval<_Source>()}));
+  using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({declval<_Source>()}));
 };
 
 template <class _Dest, class _Source>
-using __check_for_narrowing _LIBCPP_NODEBUG_TYPE =
+using __check_for_narrowing _LIBCPP_NODEBUG =
   typename _If<
 #ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
     false &&
@@ -1244,18 +1241,18 @@ struct __make_overloads_imp;
 template <size_t ..._Idx>
 struct __make_overloads_imp<__tuple_indices<_Idx...> > {
   template <class ..._Types>
-  using _Apply _LIBCPP_NODEBUG_TYPE = __all_overloads<__overload<_Types, _Idx>...>;
+  using _Apply _LIBCPP_NODEBUG = __all_overloads<__overload<_Types, _Idx>...>;
 };
 
 template <class ..._Types>
-using _MakeOverloads _LIBCPP_NODEBUG_TYPE = typename __make_overloads_imp<
+using _MakeOverloads _LIBCPP_NODEBUG = typename __make_overloads_imp<
     __make_indices_imp<sizeof...(_Types), 0> >::template _Apply<_Types...>;
 
 template <class _Tp, class... _Types>
 using __best_match_t =
     typename invoke_result_t<_MakeOverloads<_Types...>, _Tp, _Tp>::type;
 
-} // __variant_detail
+} // namespace __variant_detail
 
 template <class... _Types>
 class _LIBCPP_TEMPLATE_VIS variant
@@ -1718,11 +1715,10 @@ inline _LIBCPP_INLINE_VISIBILITY
 
 template <class... _Types>
 inline _LIBCPP_INLINE_VISIBILITY
-auto swap(variant<_Types...>& __lhs,
-          variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs)))
-    -> decltype(__lhs.swap(__rhs)) {
-  __lhs.swap(__rhs);
-}
+auto swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs)
+  noexcept(noexcept(__lhs.swap(__rhs)))
+  -> decltype(      __lhs.swap(__rhs))
+  { return          __lhs.swap(__rhs); }
 
 template <class... _Types>
 struct _LIBCPP_TEMPLATE_VIS hash<
lib/libcxx/include/vector
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===------------------------------ vector --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -245,7 +245,7 @@ public:
 
 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
    vector(InputIterator, InputIterator, Allocator = Allocator())
-   -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
+   -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
 
 template <class Allocator> struct hash<std::vector<bool, Allocator>>;
 
@@ -271,10 +271,11 @@ erase_if(vector<T, Allocator>& c, Predicate pred);    // C++20
 
 */
 
-#include <__config>
 #include <__bit_reference>
+#include <__config>
 #include <__debug>
 #include <__functional_base>
+#include <__iterator/iterator_traits.h>
 #include <__iterator/wrap_iter.h>
 #include <__split_buffer>
 #include <__utility/forward.h>
@@ -301,245 +302,63 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <bool>
-class _LIBCPP_TEMPLATE_VIS __vector_base_common
-{
-protected:
-    _LIBCPP_INLINE_VISIBILITY __vector_base_common() {}
-    _LIBCPP_NORETURN void __throw_length_error() const;
-    _LIBCPP_NORETURN void __throw_out_of_range() const;
-};
-
-template <bool __b>
-void
-__vector_base_common<__b>::__throw_length_error() const
-{
-    _VSTD::__throw_length_error("vector");
-}
-
-template <bool __b>
-void
-__vector_base_common<__b>::__throw_out_of_range() const
-{
-    _VSTD::__throw_out_of_range("vector");
-}
-
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
-
-template <class _Tp, class _Allocator>
-class __vector_base
-    : protected __vector_base_common<true>
-{
-public:
-    typedef _Allocator                               allocator_type;
-    typedef allocator_traits<allocator_type>         __alloc_traits;
-    typedef typename __alloc_traits::size_type       size_type;
-protected:
-    typedef _Tp                                      value_type;
-    typedef value_type&                              reference;
-    typedef const value_type&                        const_reference;
-    typedef typename __alloc_traits::difference_type difference_type;
-    typedef typename __alloc_traits::pointer         pointer;
-    typedef typename __alloc_traits::const_pointer   const_pointer;
-    typedef pointer                                  iterator;
-    typedef const_pointer                            const_iterator;
-
-    pointer                                         __begin_;
-    pointer                                         __end_;
-    __compressed_pair<pointer, allocator_type> __end_cap_;
-
-    _LIBCPP_INLINE_VISIBILITY
-    allocator_type& __alloc() _NOEXCEPT
-        {return __end_cap_.second();}
-    _LIBCPP_INLINE_VISIBILITY
-    const allocator_type& __alloc() const _NOEXCEPT
-        {return __end_cap_.second();}
-    _LIBCPP_INLINE_VISIBILITY
-    pointer& __end_cap() _NOEXCEPT
-        {return __end_cap_.first();}
-    _LIBCPP_INLINE_VISIBILITY
-    const pointer& __end_cap() const _NOEXCEPT
-        {return __end_cap_.first();}
-
-    _LIBCPP_INLINE_VISIBILITY
-    __vector_base()
-        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
-    _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT;
-#endif
-    ~__vector_base();
-
-    _LIBCPP_INLINE_VISIBILITY
-    void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
-    _LIBCPP_INLINE_VISIBILITY
-    size_type capacity() const _NOEXCEPT
-        {return static_cast<size_type>(__end_cap() - __begin_);}
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __destruct_at_end(pointer __new_last) _NOEXCEPT;
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __copy_assign_alloc(const __vector_base& __c)
-        {__copy_assign_alloc(__c, integral_constant<bool,
-                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(__vector_base& __c)
-        _NOEXCEPT_(
-            !__alloc_traits::propagate_on_container_move_assignment::value ||
-            is_nothrow_move_assignable<allocator_type>::value)
-        {__move_assign_alloc(__c, integral_constant<bool,
-                      __alloc_traits::propagate_on_container_move_assignment::value>());}
-
-    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
-    void __throw_length_error() const {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        __vector_base_common<true>::__throw_length_error();
-#else
-        _VSTD::abort();
-#endif
-    }
-
-    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
-    void __throw_out_of_range() const {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        __vector_base_common<true>::__throw_out_of_range();
-#else
-        _VSTD::abort();
-#endif
-    }
-
-private:
-    _LIBCPP_INLINE_VISIBILITY
-    void __copy_assign_alloc(const __vector_base& __c, true_type)
-        {
-            if (__alloc() != __c.__alloc())
-            {
-                clear();
-                __alloc_traits::deallocate(__alloc(), __begin_, capacity());
-                __begin_ = __end_ = __end_cap() = nullptr;
-            }
-            __alloc() = __c.__alloc();
-        }
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __copy_assign_alloc(const __vector_base&, false_type)
-        {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(__vector_base& __c, true_type)
-        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
-        {
-            __alloc() = _VSTD::move(__c.__alloc());
-        }
-
-    _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(__vector_base&, false_type)
-        _NOEXCEPT
-        {}
-};
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-void
-__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
-{
-    pointer __soon_to_be_end = __end_;
-    while (__new_last != __soon_to_be_end)
-        __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
-    __end_ = __new_last;
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-__vector_base<_Tp, _Allocator>::__vector_base()
-        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
-    : __begin_(nullptr),
-      __end_(nullptr),
-      __end_cap_(nullptr, __default_init_tag())
-{
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
-    : __begin_(nullptr),
-      __end_(nullptr),
-      __end_cap_(nullptr, __a)
-{
-}
-
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT
-    : __begin_(nullptr),
-      __end_(nullptr),
-      __end_cap_(nullptr, _VSTD::move(__a)) {}
-#endif
-
-template <class _Tp, class _Allocator>
-__vector_base<_Tp, _Allocator>::~__vector_base()
-{
-    if (__begin_ != nullptr)
-    {
-        clear();
-        __alloc_traits::deallocate(__alloc(), __begin_, capacity());
-    }
-}
-
 template <class _Tp, class _Allocator /* = allocator<_Tp> */>
 class _LIBCPP_TEMPLATE_VIS vector
-    : private __vector_base<_Tp, _Allocator>
 {
 private:
-    typedef __vector_base<_Tp, _Allocator>           __base;
-    typedef allocator<_Tp>                           __default_allocator_type;
+    typedef allocator<_Tp>                                  __default_allocator_type;
 public:
-    typedef vector                                   __self;
-    typedef _Tp                                      value_type;
-    typedef _Allocator                               allocator_type;
-    typedef typename __base::__alloc_traits          __alloc_traits;
-    typedef typename __base::reference               reference;
-    typedef typename __base::const_reference         const_reference;
-    typedef typename __base::size_type               size_type;
-    typedef typename __base::difference_type         difference_type;
-    typedef typename __base::pointer                 pointer;
-    typedef typename __base::const_pointer           const_pointer;
-    typedef __wrap_iter<pointer>                     iterator;
-    typedef __wrap_iter<const_pointer>               const_iterator;
-    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
-    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
+    typedef vector                                          __self;
+    typedef _Tp                                             value_type;
+    typedef _Allocator                                      allocator_type;
+    typedef allocator_traits<allocator_type>                __alloc_traits;
+    typedef value_type&                                     reference;
+    typedef const value_type&                               const_reference;
+    typedef typename __alloc_traits::size_type              size_type;
+    typedef typename __alloc_traits::difference_type        difference_type;
+    typedef typename __alloc_traits::pointer                pointer;
+    typedef typename __alloc_traits::const_pointer          const_pointer;
+    typedef __wrap_iter<pointer>                            iterator;
+    typedef __wrap_iter<const_pointer>                      const_iterator;
+    typedef _VSTD::reverse_iterator<iterator>               reverse_iterator;
+    typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
 
     static_assert((is_same<typename allocator_type::value_type, value_type>::value),
                   "Allocator::value_type must be same type as value_type");
 
     _LIBCPP_INLINE_VISIBILITY
     vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
-        {
-#if _LIBCPP_DEBUG_LEVEL == 2
-            __get_db()->__insert_c(this);
-#endif
-        }
+    {
+        _VSTD::__debug_db_insert_c(this);
+    }
     _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
 #if _LIBCPP_STD_VER <= 14
         _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
 #else
         _NOEXCEPT
 #endif
-        : __base(__a)
+        : __end_cap_(nullptr, __a)
     {
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__insert_c(this);
-#endif
+        _VSTD::__debug_db_insert_c(this);
     }
     explicit vector(size_type __n);
 #if _LIBCPP_STD_VER > 11
     explicit vector(size_type __n, const allocator_type& __a);
 #endif
     vector(size_type __n, const value_type& __x);
-    vector(size_type __n, const value_type& __x, const allocator_type& __a);
+
+    template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
+    vector(size_type __n, const value_type& __x, const allocator_type& __a)
+        : __end_cap_(nullptr, __a)
+    {
+      _VSTD::__debug_db_insert_c(this);
+      if (__n > 0)
+      {
+          __vallocate(__n);
+          __construct_at_end(__n, __x);
+      }
+    }
+
     template <class _InputIterator>
         vector(_InputIterator __first,
                typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
@@ -572,10 +391,16 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     ~vector()
     {
-        __annotate_delete();
+      __annotate_delete();
 #if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__erase_c(this);
+      __get_db()->__erase_c(this);
 #endif
+
+      if (this->__begin_ != nullptr)
+      {
+        __clear();
+        __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
+      }
     }
 
     vector(const vector& __x);
@@ -680,7 +505,7 @@ public:
         {return static_cast<size_type>(this->__end_ - this->__begin_);}
     _LIBCPP_INLINE_VISIBILITY
     size_type capacity() const _NOEXCEPT
-        {return __base::capacity();}
+        {return static_cast<size_type>(__end_cap() - this->__begin_);}
     _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
     bool empty() const _NOEXCEPT
         {return this->__begin_ == this->__end_;}
@@ -793,7 +618,7 @@ public:
     void clear() _NOEXCEPT
     {
         size_type __old_size = size();
-        __base::clear();
+        __clear();
         __annotate_shrink(__old_size);
         __invalidate_all_iterators();
     }
@@ -821,6 +646,11 @@ public:
 #endif // _LIBCPP_DEBUG_LEVEL == 2
 
 private:
+    pointer __begin_ = nullptr;
+    pointer __end_ = nullptr;
+    __compressed_pair<pointer, allocator_type> __end_cap_ =
+        __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
+
     _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
     _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
     void __vallocate(size_type __n);
@@ -854,7 +684,7 @@ private:
     {
         __invalidate_iterators_past(__new_last);
         size_type __old_size = size();
-        __base::__destruct_at_end(__new_last);
+        __base_destruct_at_end(__new_last);
         __annotate_shrink(__old_size);
     }
 
@@ -918,7 +748,7 @@ private:
 
   struct _ConstructTransaction {
     explicit _ConstructTransaction(vector &__v, size_type __n)
-      : __v_(__v),  __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
+      : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
 #ifndef _LIBCPP_HAS_NO_ASAN
       __v_.__annotate_increase(__n);
 #endif
@@ -949,19 +779,96 @@ private:
         _VSTD::forward<_Args>(__args)...);
     ++__tx.__pos_;
   }
+
+  _LIBCPP_INLINE_VISIBILITY
+  allocator_type& __alloc() _NOEXCEPT
+      {return this->__end_cap_.second();}
+  _LIBCPP_INLINE_VISIBILITY
+  const allocator_type& __alloc() const _NOEXCEPT
+      {return this->__end_cap_.second();}
+  _LIBCPP_INLINE_VISIBILITY
+  pointer& __end_cap() _NOEXCEPT
+      {return this->__end_cap_.first();}
+  _LIBCPP_INLINE_VISIBILITY
+  const pointer& __end_cap() const _NOEXCEPT
+      {return this->__end_cap_.first();}
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
+    pointer __soon_to_be_end = this->__end_;
+    while (__new_last != __soon_to_be_end)
+        __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
+    this->__end_ = __new_last;
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __copy_assign_alloc(const vector& __c)
+      {__copy_assign_alloc(__c, integral_constant<bool,
+                    __alloc_traits::propagate_on_container_copy_assignment::value>());}
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __move_assign_alloc(vector& __c)
+      _NOEXCEPT_(
+          !__alloc_traits::propagate_on_container_move_assignment::value ||
+          is_nothrow_move_assignable<allocator_type>::value)
+      {__move_assign_alloc(__c, integral_constant<bool,
+                    __alloc_traits::propagate_on_container_move_assignment::value>());}
+
+  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+  void __throw_length_error() const {
+      _VSTD::__throw_length_error("vector");
+  }
+
+  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+  void __throw_out_of_range() const {
+      _VSTD::__throw_out_of_range("vector");
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __copy_assign_alloc(const vector& __c, true_type)
+  {
+    if (__alloc() != __c.__alloc())
+    {
+      __clear();
+      __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
+      this->__begin_ = this->__end_ = __end_cap() = nullptr;
+    }
+    __alloc() = __c.__alloc();
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __copy_assign_alloc(const vector&, false_type)
+  {}
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __move_assign_alloc(vector& __c, true_type)
+      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
+  {
+    __alloc() = _VSTD::move(__c.__alloc());
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  void __move_assign_alloc(vector&, false_type)
+      _NOEXCEPT
+  {}
 };
 
-#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+#if _LIBCPP_STD_VER >= 17
 template<class _InputIterator,
          class _Alloc = allocator<__iter_value_type<_InputIterator>>,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 vector(_InputIterator, _InputIterator)
   -> vector<__iter_value_type<_InputIterator>, _Alloc>;
 
 template<class _InputIterator,
          class _Alloc,
-         class = _EnableIf<__is_allocator<_Alloc>::value>
+         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
+         class = enable_if_t<__is_allocator<_Alloc>::value>
          >
 vector(_InputIterator, _InputIterator, _Alloc)
   -> vector<__iter_value_type<_InputIterator>, _Alloc>;
@@ -1063,7 +970,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
 {
     _ConstructTransaction __tx(*this, __n);
     const_pointer __new_end = __tx.__new_end_;
-    for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
+    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
         __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
     }
 }
@@ -1081,7 +988,7 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
 {
     _ConstructTransaction __tx(*this, __n);
     const_pointer __new_end = __tx.__new_end_;
-    for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
+    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
         __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
     }
 }
@@ -1140,9 +1047,7 @@ vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
 template <class _Tp, class _Allocator>
 vector<_Tp, _Allocator>::vector(size_type __n)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1153,11 +1058,9 @@ vector<_Tp, _Allocator>::vector(size_type __n)
 #if _LIBCPP_STD_VER > 11
 template <class _Tp, class _Allocator>
 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
-    : __base(__a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1169,23 +1072,7 @@ vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
 template <class _Tp, class _Allocator>
 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
-    if (__n > 0)
-    {
-        __vallocate(__n);
-        __construct_at_end(__n, __x);
-    }
-}
-
-template <class _Tp, class _Allocator>
-vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
-    : __base(__a)
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1203,9 +1090,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first,
                             typename iterator_traits<_InputIterator>::reference>::value,
                           _InputIterator>::type __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (; __first != __last; ++__first)
         __emplace_back(*__first);
 }
@@ -1218,11 +1103,9 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
                          is_constructible<
                             value_type,
                             typename iterator_traits<_InputIterator>::reference>::value>::type*)
-    : __base(__a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     for (; __first != __last; ++__first)
         __emplace_back(*__first);
 }
@@ -1236,9 +1119,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
                                    typename iterator_traits<_ForwardIterator>::reference>::value,
                                                    _ForwardIterator>::type __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
     if (__n > 0)
     {
@@ -1254,11 +1135,9 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
                                 is_constructible<
                                    value_type,
                                    typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
-    : __base(__a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
     if (__n > 0)
     {
@@ -1269,11 +1148,9 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
 
 template <class _Tp, class _Allocator>
 vector<_Tp, _Allocator>::vector(const vector& __x)
-    : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
+    : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     size_type __n = __x.size();
     if (__n > 0)
     {
@@ -1284,11 +1161,9 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
 
 template <class _Tp, class _Allocator>
 vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
-    : __base(__a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     size_type __n = __x.size();
     if (__n > 0)
     {
@@ -1307,11 +1182,11 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
 #else
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
 #endif
-    : __base(_VSTD::move(__x.__alloc()))
+    : __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
 {
+    _VSTD::__debug_db_insert_c(this);
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    __get_db()->swap(this, &__x);
+    __get_db()->swap(this, _VSTD::addressof(__x));
 #endif
     this->__begin_ = __x.__begin_;
     this->__end_ = __x.__end_;
@@ -1322,11 +1197,9 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
-    : __base(__a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__a == __x.__alloc())
     {
         this->__begin_ = __x.__begin_;
@@ -1334,7 +1207,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>
         this->__end_cap() = __x.__end_cap();
         __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
 #if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->swap(this, &__x);
+        __get_db()->swap(this, _VSTD::addressof(__x));
 #endif
     }
     else
@@ -1348,9 +1221,7 @@ template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__il.size() > 0)
     {
         __vallocate(__il.size());
@@ -1361,11 +1232,9 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
-    : __base(__a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    _VSTD::__debug_db_insert_c(this);
     if (__il.size() > 0)
     {
         __vallocate(__il.size());
@@ -1389,7 +1258,7 @@ void
 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
     _NOEXCEPT_(__alloc_traits::is_always_equal::value)
 {
-    if (__base::__alloc() != __c.__alloc())
+    if (__alloc() != __c.__alloc())
     {
         typedef move_iterator<iterator> _Ip;
         assign(_Ip(__c.begin()), _Ip(__c.end()));
@@ -1404,13 +1273,13 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
     _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
 {
     __vdeallocate();
-    __base::__move_assign_alloc(__c); // this can throw
+    __move_assign_alloc(__c); // this can throw
     this->__begin_ = __c.__begin_;
     this->__end_ = __c.__end_;
     this->__end_cap() = __c.__end_cap();
     __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->swap(this, &__c);
+    __get_db()->swap(this, _VSTD::addressof(__c));
 #endif
 }
 
@@ -1421,9 +1290,9 @@ inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>&
 vector<_Tp, _Allocator>::operator=(const vector& __x)
 {
-    if (this != &__x)
+    if (this != _VSTD::addressof(__x))
     {
-        __base::__copy_assign_alloc(__x);
+        __copy_assign_alloc(__x);
         assign(__x.__begin_, __x.__end_);
     }
     return *this;
@@ -1605,6 +1474,8 @@ vector<_Tp, _Allocator>::reserve(size_type __n)
 {
     if (__n > capacity())
     {
+        if (__n > max_size())
+            this->__throw_length_error();
         allocator_type& __a = this->__alloc();
         __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
         __swap_out_circular_buffer(__v);
@@ -1728,11 +1599,8 @@ inline _LIBCPP_INLINE_VISIBILITY
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::erase(const_iterator __position)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
-        "vector::erase(iterator) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
+                         "vector::erase(iterator) called with an iterator not referring to this vector");
     _LIBCPP_ASSERT(__position != end(),
         "vector::erase(iterator) called with a non-dereferenceable iterator");
     difference_type __ps = __position - cbegin();
@@ -1747,14 +1615,11 @@ template <class _Tp, class _Allocator>
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
-        "vector::erase(iterator,  iterator) called with an iterator not"
-        " referring to this vector");
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
-        "vector::erase(iterator,  iterator) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
+                         "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
+                         "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
+
     _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
     pointer __p = this->__begin_ + (__first - begin());
     if (__first != __last) {
@@ -1775,7 +1640,7 @@ vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointe
       pointer __i = __from_s + __n;
       _ConstructTransaction __tx(*this, __from_e - __i);
       for (pointer __pos = __tx.__pos_; __i < __from_e;
-           ++__i, ++__pos, __tx.__pos_ = __pos) {
+           ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
           __alloc_traits::construct(this->__alloc(),
                                     _VSTD::__to_address(__pos),
                                     _VSTD::move(*__i));
@@ -1788,11 +1653,8 @@ template <class _Tp, class _Allocator>
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
-        "vector::insert(iterator, x) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
+                         "vector::insert(iterator, x) called with an iterator not referring to this vector");
     pointer __p = this->__begin_ + (__position - begin());
     if (this->__end_ < this->__end_cap())
     {
@@ -1825,11 +1687,8 @@ template <class _Tp, class _Allocator>
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
-        "vector::insert(iterator, x) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
+                         "vector::insert(iterator, x) called with an iterator not referring to this vector");
     pointer __p = this->__begin_ + (__position - begin());
     if (this->__end_ < this->__end_cap())
     {
@@ -1858,11 +1717,8 @@ template <class... _Args>
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
-        "vector::emplace(iterator, x) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
+                         "vector::emplace(iterator, x) called with an iterator not referring to this vector");
     pointer __p = this->__begin_ + (__position - begin());
     if (this->__end_ < this->__end_cap())
     {
@@ -1893,11 +1749,8 @@ template <class _Tp, class _Allocator>
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
-        "vector::insert(iterator, n, x) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
+                         "vector::insert(iterator, n, x) called with an iterator not referring to this vector");
     pointer __p = this->__begin_ + (__position - begin());
     if (__n > 0)
     {
@@ -1944,11 +1797,8 @@ typename enable_if
 >::type
 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
-        "vector::insert(iterator, range) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
+                         "vector::insert(iterator, range) called with an iterator not referring to this vector");
     difference_type __off = __position - begin();
     pointer __p = this->__begin_ + __off;
     allocator_type& __a = this->__alloc();
@@ -1997,11 +1847,8 @@ typename enable_if
 >::type
 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
-        "vector::insert(iterator, range) called with an iterator not"
-        " referring to this vector");
-#endif
+    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
+                         "vector::insert(iterator, range) called with an iterator not referring to this vector");
     pointer __p = this->__begin_ + (__position - begin());
     difference_type __n = _VSTD::distance(__first, __last);
     if (__n > 0)
@@ -2079,7 +1926,7 @@ vector<_Tp, _Allocator>::swap(vector& __x)
     _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
         integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
 #if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->swap(this, &__x);
+    __get_db()->swap(this, _VSTD::addressof(__x));
 #endif
 }
 
@@ -2184,7 +2031,6 @@ struct __has_storage_type<vector<bool, _Allocator> >
 
 template <class _Allocator>
 class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
-    : private __vector_base_common<true>
 {
 public:
     typedef vector                                   __self;
@@ -2453,6 +2299,16 @@ public:
     bool __invariants() const;
 
 private:
+    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+    void __throw_length_error() const {
+        _VSTD::__throw_length_error("vector");
+    }
+
+    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+    void __throw_out_of_range() const {
+        _VSTD::__throw_out_of_range("vector");
+    }
+
     _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
     void __vallocate(size_type __n);
     void __vdeallocate() _NOEXCEPT;
@@ -2874,7 +2730,7 @@ template <class _Allocator>
 vector<bool, _Allocator>&
 vector<bool, _Allocator>::operator=(const vector& __v)
 {
-    if (this != &__v)
+    if (this != _VSTD::addressof(__v))
     {
         __copy_assign_alloc(__v);
         if (__v.__size_)
@@ -2978,7 +2834,7 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
             __size_ = __n;
         else
         {
-            vector __v(__alloc());
+            vector __v(get_allocator());
             __v.reserve(__recommend(__n));
             __v.__size_ = __n;
             swap(__v);
@@ -3033,7 +2889,9 @@ vector<bool, _Allocator>::reserve(size_type __n)
 {
     if (__n > capacity())
     {
-        vector __v(this->__alloc());
+        if (__n > max_size())
+            this->__throw_length_error();
+        vector __v(this->get_allocator());
         __v.__vallocate(__n);
         __v.__construct_at_end(this->begin(), this->end());
         swap(__v);
@@ -3103,7 +2961,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __
     }
     else
     {
-        vector __v(__alloc());
+        vector __v(get_allocator());
         __v.reserve(__recommend(__size_ + 1));
         __v.__size_ = __size_ + 1;
         __r = _VSTD::copy(cbegin(), __position, __v.begin());
@@ -3129,7 +2987,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const
     }
     else
     {
-        vector __v(__alloc());
+        vector __v(get_allocator());
         __v.reserve(__recommend(__size_ + __n));
         __v.__size_ = __size_ + __n;
         __r = _VSTD::copy(cbegin(), __position, __v.begin());
@@ -3158,7 +3016,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __fir
         ++this->__size_;
         back() = *__first;
     }
-    vector __v(__alloc());
+    vector __v(get_allocator());
     if (__first != __last)
     {
 #ifndef _LIBCPP_NO_EXCEPTIONS
@@ -3208,7 +3066,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __f
     }
     else
     {
-        vector __v(__alloc());
+        vector __v(get_allocator());
         __v.reserve(__recommend(__size_ + __n));
         __v.__size_ = __size_ + __n;
         __r = _VSTD::copy(cbegin(), __position, __v.begin());
@@ -3275,7 +3133,7 @@ vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
         }
         else
         {
-            vector __v(__alloc());
+            vector __v(get_allocator());
             __v.reserve(__recommend(__size_ + __n));
             __v.__size_ = __size_ + __n;
             __r = _VSTD::copy(cbegin(), cend(), __v.begin());
lib/libcxx/include/version
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- version ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -14,7 +14,9 @@
   version synopsis
 
 Macro name                                              Value   Headers
+__cpp_lib_adaptor_iterator_pair_constructor             202106L <queue> <stack>
 __cpp_lib_addressof_constexpr                           201603L <memory>
+__cpp_lib_allocate_at_least                             202106L <memory>
 __cpp_lib_allocator_traits_is_always_equal              201411L <deque> <forward_list> <list>
                                                                 <map> <memory> <scoped_allocator>
                                                                 <set> <string> <unordered_map>
@@ -24,6 +26,8 @@ __cpp_lib_apply                                         201603L <tuple>
 __cpp_lib_array_constexpr                               201811L <array> <iterator>
                                                         201603L // C++17
 __cpp_lib_as_const                                      201510L <utility>
+__cpp_lib_associative_heterogeneous_erasure             202110L <map> <set> <unordered_map>
+                                                                <unordered_set>
 __cpp_lib_assume_aligned                                201811L <memory>
 __cpp_lib_atomic_flag_test                              201907L <atomic>
 __cpp_lib_atomic_float                                  201711L <atomic>
@@ -41,6 +45,7 @@ __cpp_lib_bool_constant                                 201505L <type_traits>
 __cpp_lib_bounded_array_traits                          201902L <type_traits>
 __cpp_lib_boyer_moore_searcher                          201603L <functional>
 __cpp_lib_byte                                          201603L <cstddef>
+__cpp_lib_byteswap                                      202110L <bit>
 __cpp_lib_char8_t                                       201811L <atomic> <filesystem> <istream>
                                                                 <limits> <locale> <ostream>
                                                                 <string> <string_view>
@@ -59,6 +64,7 @@ __cpp_lib_constexpr_numeric                             201911L <numeric>
 __cpp_lib_constexpr_string                              201811L <string>
 __cpp_lib_constexpr_string_view                         201811L <string_view>
 __cpp_lib_constexpr_tuple                               201811L <tuple>
+__cpp_lib_constexpr_typeinfo                            202106L <typeinfo>
 __cpp_lib_constexpr_utility                             201811L <utility>
 __cpp_lib_constexpr_vector                              201907L <vector>
 __cpp_lib_coroutine                                     201902L <coroutine>
@@ -72,7 +78,7 @@ __cpp_lib_exchange_function                             201304L <utility>
 __cpp_lib_execution                                     201902L <execution>
                                                         201603L // C++17
 __cpp_lib_filesystem                                    201703L <filesystem>
-__cpp_lib_format                                        201907L <format>
+__cpp_lib_format                                        202106L <format>
 __cpp_lib_gcd_lcm                                       201606L <numeric>
 __cpp_lib_generic_associative_lookup                    201304L <map> <set>
 __cpp_lib_generic_unordered_lookup                      201811L <unordered_map> <unordered_set>
@@ -86,6 +92,7 @@ __cpp_lib_integer_sequence                              201304L <utility>
 __cpp_lib_integral_constant_callable                    201304L <type_traits>
 __cpp_lib_interpolate                                   201902L <cmath> <numeric>
 __cpp_lib_invoke                                        201411L <functional>
+__cpp_lib_invoke_r                                      202106L <functional>
 __cpp_lib_is_aggregate                                  201703L <type_traits>
 __cpp_lib_is_constant_evaluated                         201811L <type_traits>
 __cpp_lib_is_final                                      201402L <type_traits>
@@ -108,6 +115,8 @@ __cpp_lib_map_try_emplace                               201411L <map>
 __cpp_lib_math_constants                                201907L <numbers>
 __cpp_lib_math_special_functions                        201603L <cmath>
 __cpp_lib_memory_resource                               201603L <memory_resource>
+__cpp_lib_monadic_optional                              202110L <optional>
+__cpp_lib_move_only_function                            202110L <functional>
 __cpp_lib_node_extract                                  201606L <map> <set> <unordered_map>
                                                                 <unordered_set>
 __cpp_lib_nonmember_container_access                    201411L <array> <deque> <forward_list>
@@ -117,11 +126,14 @@ __cpp_lib_nonmember_container_access                    201411L <array> <deque>
 __cpp_lib_not_fn                                        201603L <functional>
 __cpp_lib_null_iterators                                201304L <iterator>
 __cpp_lib_optional                                      201606L <optional>
+__cpp_lib_out_ptr                                       202106L <memory>
 __cpp_lib_parallel_algorithm                            201603L <algorithm> <numeric>
-__cpp_lib_polymorphic_allocator                         201902L <memory>
+__cpp_lib_polymorphic_allocator                         201902L <memory_resource>
 __cpp_lib_quoted_string_io                              201304L <iomanip>
 __cpp_lib_ranges                                        201811L <algorithm> <functional> <iterator>
                                                                 <memory> <ranges>
+__cpp_lib_ranges_starts_ends_with                       202106L <algorithm>
+__cpp_lib_ranges_zip                                    202110L <ranges> <tuple> <utility>
 __cpp_lib_raw_memory_algorithms                         201606L <memory>
 __cpp_lib_remove_cvref                                  201711L <type_traits>
 __cpp_lib_result_of_sfinae                              201210L <functional> <type_traits>
@@ -137,11 +149,13 @@ __cpp_lib_shift                                         201806L <algorithm>
 __cpp_lib_smart_ptr_for_overwrite                       202002L <memory>
 __cpp_lib_source_location                               201907L <source_location>
 __cpp_lib_span                                          202002L <span>
+__cpp_lib_spanstream                                    202106L <spanstream>
 __cpp_lib_ssize                                         201902L <iterator>
 __cpp_lib_stacktrace                                    202011L <stacktrace>
 __cpp_lib_starts_ends_with                              201711L <string> <string_view>
 __cpp_lib_stdatomic_h                                   202011L <stdatomic.h>
 __cpp_lib_string_contains                               202011L <string> <string_view>
+__cpp_lib_string_resize_and_overwrite                   202110L <string>
 __cpp_lib_string_udls                                   201304L <string>
 __cpp_lib_string_view                                   201803L <string> <string_view>
                                                         201606L // C++17
@@ -149,13 +163,14 @@ __cpp_lib_syncbuf                                       201803L <syncstream>
 __cpp_lib_three_way_comparison                          201907L <compare>
 __cpp_lib_to_address                                    201711L <memory>
 __cpp_lib_to_array                                      201907L <array>
-__cpp_lib_to_chars                                      201611L <utility>
+__cpp_lib_to_chars                                      201611L <charconv>
 __cpp_lib_to_underlying                                 202102L <utility>
 __cpp_lib_transformation_trait_aliases                  201304L <type_traits>
 __cpp_lib_transparent_operators                         201510L <functional> <memory>
                                                         201210L // C++14
 __cpp_lib_tuple_element_t                               201402L <tuple>
 __cpp_lib_tuples_by_type                                201304L <tuple> <utility>
+__cpp_lib_type_identity                                 201806L <type_traits>
 __cpp_lib_type_trait_variable_templates                 201510L <type_traits>
 __cpp_lib_uncaught_exceptions                           201411L <exception>
 __cpp_lib_unordered_map_try_emplace                     201411L <unordered_map>
@@ -199,17 +214,13 @@ __cpp_lib_void_t                                        201411L <type_traits>
 #endif
 
 #if _LIBCPP_STD_VER > 14
-# if !defined(_LIBCPP_HAS_NO_BUILTIN_ADDRESSOF)
-#   define __cpp_lib_addressof_constexpr                201603L
-# endif
+# define __cpp_lib_addressof_constexpr                  201603L
 # define __cpp_lib_allocator_traits_is_always_equal     201411L
 # define __cpp_lib_any                                  201606L
 # define __cpp_lib_apply                                201603L
 # define __cpp_lib_array_constexpr                      201603L
 # define __cpp_lib_as_const                             201510L
-# if !defined(_LIBCPP_HAS_NO_THREADS)
-#   define __cpp_lib_atomic_is_always_lock_free         201603L
-# endif
+# define __cpp_lib_atomic_is_always_lock_free           201603L
 # define __cpp_lib_bool_constant                        201505L
 // # define __cpp_lib_boyer_moore_searcher                 201603L
 # define __cpp_lib_byte                                 201603L
@@ -222,15 +233,11 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # endif
 # define __cpp_lib_gcd_lcm                              201606L
 // # define __cpp_lib_hardware_interference_size           201703L
-# if defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
-#   define __cpp_lib_has_unique_object_representations  201606L
-# endif
+# define __cpp_lib_has_unique_object_representations    201606L
 # define __cpp_lib_hypot                                201603L
 # define __cpp_lib_incomplete_container_elements        201505L
 # define __cpp_lib_invoke                               201411L
-# if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
-#   define __cpp_lib_is_aggregate                       201703L
-# endif
+# define __cpp_lib_is_aggregate                         201703L
 # define __cpp_lib_is_invocable                         201703L
 # define __cpp_lib_is_swappable                         201603L
 # define __cpp_lib_launder                              201606L
@@ -267,32 +274,20 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # undef  __cpp_lib_array_constexpr
 # define __cpp_lib_array_constexpr                      201811L
 // # define __cpp_lib_assume_aligned                       201811L
-# if !defined(_LIBCPP_HAS_NO_THREADS)
-#   define __cpp_lib_atomic_flag_test                   201907L
-# endif
-# if !defined(_LIBCPP_HAS_NO_THREADS)
-// #   define __cpp_lib_atomic_float                       201711L
-# endif
-# if !defined(_LIBCPP_HAS_NO_THREADS)
-#   define __cpp_lib_atomic_lock_free_type_aliases      201907L
-# endif
-# if !defined(_LIBCPP_HAS_NO_THREADS)
-// #   define __cpp_lib_atomic_ref                         201806L
-# endif
-# if !defined(_LIBCPP_HAS_NO_THREADS)
-// #   define __cpp_lib_atomic_shared_ptr                  201711L
-# endif
-# if !defined(_LIBCPP_HAS_NO_THREADS)
-#   define __cpp_lib_atomic_value_initialization        201911L
-# endif
-# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)
+# define __cpp_lib_atomic_flag_test                     201907L
+// # define __cpp_lib_atomic_float                         201711L
+# define __cpp_lib_atomic_lock_free_type_aliases        201907L
+// # define __cpp_lib_atomic_ref                           201806L
+// # define __cpp_lib_atomic_shared_ptr                    201711L
+# define __cpp_lib_atomic_value_initialization          201911L
+# if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)
 #   define __cpp_lib_atomic_wait                        201907L
 # endif
 # if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)
 #   define __cpp_lib_barrier                            201907L
 # endif
 # define __cpp_lib_bind_front                           201907L
-// # define __cpp_lib_bit_cast                             201806L
+# define __cpp_lib_bit_cast                             201806L
 // # define __cpp_lib_bitops                               201907L
 # define __cpp_lib_bounded_array_traits                 201902L
 # if !defined(_LIBCPP_HAS_NO_CHAR8_T)
@@ -311,7 +306,7 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # define __cpp_lib_constexpr_tuple                      201811L
 # define __cpp_lib_constexpr_utility                    201811L
 // # define __cpp_lib_constexpr_vector                     201907L
-// # define __cpp_lib_coroutine                            201902L
+# define __cpp_lib_coroutine                            201902L
 # if _LIBCPP_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L
 #   define __cpp_lib_destroying_delete                  201806L
 # endif
@@ -320,7 +315,7 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # undef  __cpp_lib_execution
 // # define __cpp_lib_execution                            201902L
 # if !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format)
-// #   define __cpp_lib_format                             201907L
+// #   define __cpp_lib_format                             202106L
 # endif
 # define __cpp_lib_generic_unordered_lookup             201811L
 # define __cpp_lib_int_pow2                             202002L
@@ -328,9 +323,7 @@ __cpp_lib_void_t                                        201411L <type_traits>
 #   define __cpp_lib_integer_comparison_functions       202002L
 # endif
 # define __cpp_lib_interpolate                          201902L
-# if !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
-#   define __cpp_lib_is_constant_evaluated              201811L
-# endif
+# define __cpp_lib_is_constant_evaluated                201811L
 // # define __cpp_lib_is_layout_compatible                 201907L
 # define __cpp_lib_is_nothrow_convertible               201806L
 // # define __cpp_lib_is_pointer_interconvertible          201907L
@@ -362,14 +355,28 @@ __cpp_lib_void_t                                        201411L <type_traits>
 // # define __cpp_lib_three_way_comparison                 201907L
 # define __cpp_lib_to_address                           201711L
 # define __cpp_lib_to_array                             201907L
+# define __cpp_lib_type_identity                        201806L
 # define __cpp_lib_unwrap_ref                           201811L
 #endif
 
 #if _LIBCPP_STD_VER > 20
+# define __cpp_lib_adaptor_iterator_pair_constructor    202106L
+// # define __cpp_lib_allocate_at_least                    202106L
+// # define __cpp_lib_associative_heterogeneous_erasure    202110L
+# define __cpp_lib_byteswap                             202110L
+// # define __cpp_lib_constexpr_typeinfo                   202106L
+// # define __cpp_lib_invoke_r                             202106L
 # define __cpp_lib_is_scoped_enum                       202011L
+# define __cpp_lib_monadic_optional                     202110L
+// # define __cpp_lib_move_only_function                   202110L
+// # define __cpp_lib_out_ptr                              202106L
+// # define __cpp_lib_ranges_starts_ends_with              202106L
+// # define __cpp_lib_ranges_zip                           202110L
+// # define __cpp_lib_spanstream                           202106L
 // # define __cpp_lib_stacktrace                           202011L
 // # define __cpp_lib_stdatomic_h                          202011L
 # define __cpp_lib_string_contains                      202011L
+# define __cpp_lib_string_resize_and_overwrite          202110L
 # define __cpp_lib_to_underlying                        202102L
 #endif
 
lib/libcxx/include/wchar.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- wchar.h ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -108,6 +108,10 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
 #include <__config>
 #include <stddef.h>
 
+#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
+#   error "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
+#endif
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
@@ -170,13 +174,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
 }
 #endif
 
-#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT_LIKE)
+#if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
 extern "C" {
 size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
                   size_t nmc, size_t len, mbstate_t *__restrict ps);
 size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
                   size_t nwc, size_t len, mbstate_t *__restrict ps);
-}  // extern "C++"
-#endif // __cplusplus && _LIBCPP_MSVCRT
+}  // extern "C"
+#endif  // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
 
 #endif // _LIBCPP_WCHAR_H
lib/libcxx/include/wctype.h
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- wctype.h ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -46,6 +46,10 @@ wctrans_t wctrans(const char* property);
 
 #include <__config>
 
+#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
+#   error "The <wctype.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
+#endif
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
lib/libcxx/src/experimental/memory_resource.cpp
@@ -1,4 +1,4 @@
-//===------------------------ memory_resource.cpp -------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -76,7 +76,9 @@ union ResourceInitHelper {
   ~ResourceInitHelper() {}
 };
 
-_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "memory_resource_init_helper.h"
 
 } // end namespace
 
@@ -95,8 +97,7 @@ static memory_resource *
 __default_memory_resource(bool set = false, memory_resource * new_res = nullptr) noexcept
 {
 #ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
-    _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res =
-        ATOMIC_VAR_INIT(&res_init.resources.new_delete_res);
+    _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
     if (set) {
         new_res = new_res ? new_res : new_delete_resource();
         // TODO: Can a weaker ordering be used?
lib/libcxx/src/experimental/memory_resource_init_helper.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
lib/libcxx/src/filesystem/directory_iterator.cpp
@@ -1,4 +1,4 @@
-//===------------------ directory_iterator.cpp ----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,99 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "filesystem"
 #include "__config"
-#if defined(_LIBCPP_WIN32API)
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <windows.h>
-#else
-#include <dirent.h>
-#endif
+#include "filesystem"
+#include "stack"
 #include <errno.h>
 
 #include "filesystem_common.h"
 
 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
 
-namespace detail {
-namespace {
-
-#if !defined(_LIBCPP_WIN32API)
-
-#if defined(DT_BLK)
-template <class DirEntT, class = decltype(DirEntT::d_type)>
-static file_type get_file_type(DirEntT* ent, int) {
-  switch (ent->d_type) {
-  case DT_BLK:
-    return file_type::block;
-  case DT_CHR:
-    return file_type::character;
-  case DT_DIR:
-    return file_type::directory;
-  case DT_FIFO:
-    return file_type::fifo;
-  case DT_LNK:
-    return file_type::symlink;
-  case DT_REG:
-    return file_type::regular;
-  case DT_SOCK:
-    return file_type::socket;
-  // Unlike in lstat, hitting "unknown" here simply means that the underlying
-  // filesystem doesn't support d_type. Report is as 'none' so we correctly
-  // set the cache to empty.
-  case DT_UNKNOWN:
-    break;
-  }
-  return file_type::none;
-}
-#endif // defined(DT_BLK)
-
-template <class DirEntT>
-static file_type get_file_type(DirEntT* ent, long) {
-  return file_type::none;
-}
-
-static pair<string_view, file_type> posix_readdir(DIR* dir_stream,
-                                                  error_code& ec) {
-  struct dirent* dir_entry_ptr = nullptr;
-  errno = 0; // zero errno in order to detect errors
-  ec.clear();
-  if ((dir_entry_ptr = ::readdir(dir_stream)) == nullptr) {
-    if (errno)
-      ec = capture_errno();
-    return {};
-  } else {
-    return {dir_entry_ptr->d_name, get_file_type(dir_entry_ptr, 0)};
-  }
-}
-#else
-// defined(_LIBCPP_WIN32API)
-
-static file_type get_file_type(const WIN32_FIND_DATAW& data) {
-  if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
-      data.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
-    return file_type::symlink;
-  if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-    return file_type::directory;
-  return file_type::regular;
-}
-static uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
-  return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
-}
-static file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
-  ULARGE_INTEGER tmp;
-  const FILETIME& time = data.ftLastWriteTime;
-  tmp.u.LowPart = time.dwLowDateTime;
-  tmp.u.HighPart = time.dwHighDateTime;
-  return file_time_type(file_time_type::duration(tmp.QuadPart));
-}
-
-#endif
-
-} // namespace
-} // namespace detail
-
 using detail::ErrorHandler;
 
 #if defined(_LIBCPP_WIN32API)
@@ -196,9 +112,9 @@ public:
       : __stream_(nullptr), __root_(root) {
     if ((__stream_ = ::opendir(root.c_str())) == nullptr) {
       ec = detail::capture_errno();
-      const bool allow_eacess =
+      const bool allow_eacces =
           bool(opts & directory_options::skip_permission_denied);
-      if (allow_eacess && ec.value() == EACCES)
+      if (allow_eacces && ec.value() == EACCES)
         ec.clear();
       return;
     }
lib/libcxx/src/filesystem/filesystem_common.h
@@ -10,19 +10,29 @@
 #define FILESYSTEM_COMMON_H
 
 #include "__config"
-#include "filesystem"
 #include "array"
 #include "chrono"
 #include "climits"
+#include "cstdarg"
 #include "cstdlib"
 #include "ctime"
+#include "filesystem"
+#include "ratio"
+#include "system_error"
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <windows.h>
+#endif
 
 #if !defined(_LIBCPP_WIN32API)
-# include <unistd.h>
+# include <dirent.h>   // for DIR & friends
+# include <fcntl.h>    /* values for fchmodat */
 # include <sys/stat.h>
 # include <sys/statvfs.h>
 # include <sys/time.h> // for ::utimes as used in __last_write_time
-# include <fcntl.h>    /* values for fchmodat */
+# include <unistd.h>
 #endif
 
 #include "../include/apple_availability.h"
@@ -59,7 +69,7 @@ errc __win_err_to_errc(int err);
 
 namespace {
 
-static _LIBCPP_FORMAT_PRINTF(1, 0) string
+static _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 0) string
 format_string_impl(const char* msg, va_list ap) {
   array<char, 256> buf;
 
@@ -83,7 +93,7 @@ format_string_impl(const char* msg, va_list ap) {
   return result;
 }
 
-static _LIBCPP_FORMAT_PRINTF(1, 2) string
+static _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) string
 format_string(const char* msg, ...) {
   string ret;
   va_list ap;
@@ -171,7 +181,7 @@ struct ErrorHandler {
     _LIBCPP_UNREACHABLE();
   }
 
-  _LIBCPP_FORMAT_PRINTF(3, 0)
+  _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 0)
   void report_impl(const error_code& ec, const char* msg, va_list ap) const {
     if (ec_) {
       *ec_ = ec;
@@ -190,7 +200,7 @@ struct ErrorHandler {
     _LIBCPP_UNREACHABLE();
   }
 
-  _LIBCPP_FORMAT_PRINTF(3, 4)
+  _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
   T report(const error_code& ec, const char* msg, ...) const {
     va_list ap;
     va_start(ap, msg);
@@ -212,7 +222,7 @@ struct ErrorHandler {
     return report(make_error_code(err));
   }
 
-  _LIBCPP_FORMAT_PRINTF(3, 4)
+  _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
   T report(errc const& err, const char* msg, ...) const {
     va_list ap;
     va_start(ap, msg);
@@ -524,7 +534,76 @@ bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,
   return posix_utimensat(p, TS, ec);
 #endif
 }
-#endif /* !_LIBCPP_WIN32API */
+
+#if defined(DT_BLK)
+template <class DirEntT, class = decltype(DirEntT::d_type)>
+static file_type get_file_type(DirEntT* ent, int) {
+  switch (ent->d_type) {
+  case DT_BLK:
+    return file_type::block;
+  case DT_CHR:
+    return file_type::character;
+  case DT_DIR:
+    return file_type::directory;
+  case DT_FIFO:
+    return file_type::fifo;
+  case DT_LNK:
+    return file_type::symlink;
+  case DT_REG:
+    return file_type::regular;
+  case DT_SOCK:
+    return file_type::socket;
+  // Unlike in lstat, hitting "unknown" here simply means that the underlying
+  // filesystem doesn't support d_type. Report is as 'none' so we correctly
+  // set the cache to empty.
+  case DT_UNKNOWN:
+    break;
+  }
+  return file_type::none;
+}
+#endif // defined(DT_BLK)
+
+template <class DirEntT>
+static file_type get_file_type(DirEntT*, long) {
+  return file_type::none;
+}
+
+static pair<string_view, file_type> posix_readdir(DIR* dir_stream,
+                                                  error_code& ec) {
+  struct dirent* dir_entry_ptr = nullptr;
+  errno = 0; // zero errno in order to detect errors
+  ec.clear();
+  if ((dir_entry_ptr = ::readdir(dir_stream)) == nullptr) {
+    if (errno)
+      ec = capture_errno();
+    return {};
+  } else {
+    return {dir_entry_ptr->d_name, get_file_type(dir_entry_ptr, 0)};
+  }
+}
+
+#else // _LIBCPP_WIN32API
+
+static file_type get_file_type(const WIN32_FIND_DATAW& data) {
+  if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
+      data.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
+    return file_type::symlink;
+  if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+    return file_type::directory;
+  return file_type::regular;
+}
+static uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
+  return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
+}
+static file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
+  ULARGE_INTEGER tmp;
+  const FILETIME& time = data.ftLastWriteTime;
+  tmp.u.LowPart = time.dwLowDateTime;
+  tmp.u.HighPart = time.dwHighDateTime;
+  return file_time_type(file_time_type::duration(tmp.QuadPart));
+}
+
+#endif // !_LIBCPP_WIN32API
 
 } // namespace
 } // end namespace detail
lib/libcxx/src/filesystem/operations.cpp
@@ -1,4 +1,4 @@
-//===--------------------- filesystem/ops.cpp -----------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -24,9 +24,10 @@
 # define NOMINMAX
 # include <windows.h>
 #else
-# include <unistd.h>
+# include <dirent.h>
 # include <sys/stat.h>
 # include <sys/statvfs.h>
+# include <unistd.h>
 #endif
 #include <time.h>
 #include <fcntl.h> /* values for fchmodat */
@@ -1338,6 +1339,19 @@ bool __remove(const path& p, error_code* ec) {
   return true;
 }
 
+// We currently have two implementations of `__remove_all`. The first one is general and
+// used on platforms where we don't have access to the `openat()` family of POSIX functions.
+// That implementation uses `directory_iterator`, however it is vulnerable to some race
+// conditions, see https://reviews.llvm.org/D118134 for details.
+//
+// The second implementation is used on platforms where `openat()` & friends are available,
+// and it threads file descriptors through recursive calls to avoid such race conditions.
+#if defined(_LIBCPP_WIN32API)
+# define REMOVE_ALL_USE_DIRECTORY_ITERATOR
+#endif
+
+#if defined(REMOVE_ALL_USE_DIRECTORY_ITERATOR)
+
 namespace {
 
 uintmax_t remove_all_impl(path const& p, error_code& ec) {
@@ -1377,6 +1391,99 @@ uintmax_t __remove_all(const path& p, error_code* ec) {
   return count;
 }
 
+#else // !REMOVE_ALL_USE_DIRECTORY_ITERATOR
+
+namespace {
+
+template <class Cleanup>
+struct scope_exit {
+  explicit scope_exit(Cleanup const& cleanup)
+    : cleanup_(cleanup)
+  { }
+
+  ~scope_exit() { cleanup_(); }
+
+private:
+  Cleanup cleanup_;
+};
+
+uintmax_t remove_all_impl(int parent_directory, const path& p, error_code& ec) {
+  // First, try to open the path as a directory.
+  const int options = O_CLOEXEC | O_RDONLY | O_DIRECTORY | O_NOFOLLOW;
+  int fd = ::openat(parent_directory, p.c_str(), options);
+  if (fd != -1) {
+    // If that worked, iterate over the contents of the directory and
+    // remove everything in it, recursively.
+    DIR* stream = ::fdopendir(fd);
+    if (stream == nullptr) {
+      ::close(fd);
+      ec = detail::capture_errno();
+      return 0;
+    }
+    // Note: `::closedir` will also close the associated file descriptor, so
+    // there should be no call to `close(fd)`.
+    scope_exit close_stream([=] { ::closedir(stream); });
+
+    uintmax_t count = 0;
+    while (true) {
+      auto [str, type] = detail::posix_readdir(stream, ec);
+      static_assert(std::is_same_v<decltype(str), std::string_view>);
+      if (str == "." || str == "..") {
+        continue;
+      } else if (ec || str.empty()) {
+        break; // we're done iterating through the directory
+      } else {
+        count += remove_all_impl(fd, str, ec);
+      }
+    }
+
+    // Then, remove the now-empty directory itself.
+    if (::unlinkat(parent_directory, p.c_str(), AT_REMOVEDIR) == -1) {
+      ec = detail::capture_errno();
+      return count;
+    }
+
+    return count + 1; // the contents of the directory + the directory itself
+  }
+
+  ec = detail::capture_errno();
+
+  // If we failed to open `p` because it didn't exist, it's not an
+  // error -- it might have moved or have been deleted already.
+  if (ec == errc::no_such_file_or_directory) {
+    ec.clear();
+    return 0;
+  }
+
+  // If opening `p` failed because it wasn't a directory, remove it as
+  // a normal file instead. Note that `openat()` can return either ENOTDIR
+  // or ELOOP depending on the exact reason of the failure.
+  if (ec == errc::not_a_directory || ec == errc::too_many_symbolic_link_levels) {
+    ec.clear();
+    if (::unlinkat(parent_directory, p.c_str(), /* flags = */0) == -1) {
+      ec = detail::capture_errno();
+      return 0;
+    }
+    return 1;
+  }
+
+  // Otherwise, it's a real error -- we don't remove anything.
+  return 0;
+}
+
+} // end namespace
+
+uintmax_t __remove_all(const path& p, error_code* ec) {
+  ErrorHandler<uintmax_t> err("remove_all", ec, &p);
+  error_code mec;
+  uintmax_t count = remove_all_impl(AT_FDCWD, p, mec);
+  if (mec)
+    return err.report(mec);
+  return count;
+}
+
+#endif // REMOVE_ALL_USE_DIRECTORY_ITERATOR
+
 void __rename(const path& from, const path& to, error_code* ec) {
   ErrorHandler<void> err("rename", ec, &from, &to);
   if (detail::rename(from.c_str(), to.c_str()) == -1)
lib/libcxx/src/include/ryu/common.h
@@ -0,0 +1,107 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
+#define _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __decimalLength9(const uint32_t __v) {
+  // Function precondition: __v is not a 10-digit number.
+  // (f2s: 9 digits are sufficient for round-tripping.)
+  // (d2fixed: We print 9-digit blocks.)
+  _LIBCPP_ASSERT(__v < 1000000000, "");
+  if (__v >= 100000000) { return 9; }
+  if (__v >= 10000000) { return 8; }
+  if (__v >= 1000000) { return 7; }
+  if (__v >= 100000) { return 6; }
+  if (__v >= 10000) { return 5; }
+  if (__v >= 1000) { return 4; }
+  if (__v >= 100) { return 3; }
+  if (__v >= 10) { return 2; }
+  return 1;
+}
+
+// Returns __e == 0 ? 1 : ceil(log_2(5^__e)).
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI  inline int32_t __pow5bits(const int32_t __e) {
+  // This approximation works up to the point that the multiplication overflows at __e = 3529.
+  // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater
+  // than 2^9297.
+  _LIBCPP_ASSERT(__e >= 0, "");
+  _LIBCPP_ASSERT(__e <= 3528, "");
+  return static_cast<int32_t>(((static_cast<uint32_t>(__e) * 1217359) >> 19) + 1);
+}
+
+// Returns floor(log_10(2^__e)).
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI  inline uint32_t __log10Pow2(const int32_t __e) {
+  // The first value this approximation fails for is 2^1651 which is just greater than 10^297.
+  _LIBCPP_ASSERT(__e >= 0, "");
+  _LIBCPP_ASSERT(__e <= 1650, "");
+  return (static_cast<uint32_t>(__e) * 78913) >> 18;
+}
+
+// Returns floor(log_10(5^__e)).
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __log10Pow5(const int32_t __e) {
+  // The first value this approximation fails for is 5^2621 which is just greater than 10^1832.
+  _LIBCPP_ASSERT(__e >= 0, "");
+  _LIBCPP_ASSERT(__e <= 2620, "");
+  return (static_cast<uint32_t>(__e) * 732923) >> 20;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __float_to_bits(const float __f) {
+  uint32_t __bits = 0;
+  _VSTD::memcpy(&__bits, &__f, sizeof(float));
+  return __bits;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __double_to_bits(const double __d) {
+  uint64_t __bits = 0;
+  _VSTD::memcpy(&__bits, &__d, sizeof(double));
+  return __bits;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
lib/libcxx/src/include/ryu/d2fixed.h
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
+#define _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+#include "cstdint"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+void __append_n_digits(const uint32_t __olength, uint32_t __digits, char* const __result);
+void __append_nine_digits(uint32_t __digits, char* const __result);
+
+[[nodiscard]] to_chars_result __d2fixed_buffered_n(char* _First, char* const _Last, const double __d, const uint32_t __precision);
+[[nodiscard]] to_chars_result __d2exp_buffered_n(char* _First, char* const _Last, const double __d, uint32_t __precision);
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
lib/libcxx/src/include/ryu/d2fixed_full_table.h
@@ -0,0 +1,4451 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
+#define _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __TABLE_SIZE = 64;
+
+inline constexpr uint16_t __POW10_OFFSET[__TABLE_SIZE] = {
+  0, 2, 5, 8, 12, 16, 21, 26, 32, 39,
+  46, 54, 62, 71, 80, 90, 100, 111, 122, 134,
+  146, 159, 173, 187, 202, 217, 233, 249, 266, 283,
+  301, 319, 338, 357, 377, 397, 418, 440, 462, 485,
+  508, 532, 556, 581, 606, 632, 658, 685, 712, 740,
+  769, 798, 828, 858, 889, 920, 952, 984, 1017, 1050,
+  1084, 1118, 1153, 1188
+};
+
+inline constexpr uint64_t __POW10_SPLIT[1224][3] = {
+  {                    1u,    72057594037927936u,                    0u },
+  {   699646928636035157u,             72057594u,                    0u },
+  {                    1u,                    0u,                  256u },
+  { 11902091922964236229u,        4722366482869u,                    0u },
+  {  6760415703743915872u,                 4722u,                    0u },
+  {                    1u,                    0u,             16777216u },
+  { 13369850649504950658u,   309485009821345068u,                    0u },
+  { 15151142278969419334u,            309485009u,                    0u },
+  {                    1u,                    0u,          75511627776u },
+  {  4635408826454083567u,  9437866644873197963u,                 1099u },
+  { 12367138975830625353u,       20282409603651u,                    0u },
+  {  7555853734021184432u,                20282u,                    0u },
+  {                    1u,                    0u,         250037927936u },
+  {  5171444645924616995u,   699646928636035156u,             72057594u },
+  { 16672297533003297786u,  1329227995784915872u,                    0u },
+  { 14479142226848862515u,           1329227995u,                    0u },
+  {                    1u,                    0u,         181645213696u },
+  { 12214193123817091081u, 11902091922964236228u,         114366482869u },
+  { 16592893013671929435u,  6760415703743915871u,                 4722u },
+  {  4549827147718617003u,       87112285931760u,                    0u },
+  {  5274510003815168971u,                87112u,                    0u },
+  {                    1u,                    0u,          44724781056u },
+  {  9794971998307800535u, 13369850649504950657u,         209821345068u },
+  { 14720142899209240169u, 15151142278969419333u,            309485009u },
+  {  4300745446091561535u,  5708990770823839524u,                    0u },
+  { 15197156861335443364u,           5708990770u,                    0u },
+  {                    1u,                    0u,         139251286016u },
+  { 13484604155038683037u,  4635408826454083566u,          67670423947u },
+  {  8356963862052375699u, 12367138975830625352u,          58409603651u },
+  {  5850852848337610021u,  7555853734021184431u,                20282u },
+  {  2712780827214982050u,      374144419156711u,                    0u },
+  {  7732076577307618052u,               374144u,                    0u },
+  {                    1u,                    0u,          84280344576u },
+  { 17296309485351745867u,  5171444645924616994u,         160903807060u },
+  { 16598859101615853088u, 16672297533003297785u,         219784915872u },
+  {  7469952526870444257u, 14479142226848862514u,           1329227995u },
+  { 13531654022114669524u,  6073184580144670117u,                    1u },
+  { 15757609704383306943u,          24519928653u,                    0u },
+  {  9590990814237149590u,                   24u,                    0u },
+  {                    1u,                    0u,         196662132736u },
+  { 15408590707489433890u, 12214193123817091080u,          95899502532u },
+  { 18332056844289122710u, 16592893013671929434u,         240246646623u },
+  { 11114572877353986193u,  4549827147718617002u,          72285931760u },
+  {  1703393793997526525u,  5274510003815168970u,                87112u },
+  {  5082852056285196265u,     1606938044258990u,                    0u },
+  {   816434266573722365u,              1606938u,                    0u },
+  {                    1u,                    0u,         129530986496u },
+  {  5736523019264798742u,  9794971998307800534u,          69797980545u },
+  { 10129314776268243339u, 14720142899209240168u,          36233143877u },
+  { 16511595775483995364u,  4300745446091561534u,          50823839524u },
+  { 12367293405401453325u, 15197156861335443363u,           5708990770u },
+  { 16934621733248854291u, 13078571300009428617u,                    5u },
+  { 10278280417769171336u,         105312291668u,                    0u },
+  {  5760764486226151240u,                  105u,                    0u },
+  {                    1u,                    0u,         238731001856u },
+  {  4128368337188369761u, 13484604155038683036u,          72453031918u },
+  { 10240941003671005056u,  8356963862052375698u,         175317175368u },
+  { 17933378316822368251u,  5850852848337610020u,         231147060143u },
+  {  8346249813075698616u,  2712780827214982049u,         128419156711u },
+  { 15906203609160902695u,  7732076577307618051u,               374144u },
+  { 14525607416135386328u,     6901746346790563u,                    0u },
+  {  6397156777364256320u,              6901746u,                    0u },
+  {                    1u,                    0u,          34937634816u },
+  { 16798760952716600048u, 17296309485351745866u,         249899825954u },
+  {  2419982808370854967u, 16598859101615853087u,          50404946937u },
+  {  2922947087773078956u,  7469952526870444256u,         165733552434u },
+  { 15419220167069510190u, 13531654022114669523u,          77854221733u },
+  {  3452124642157173416u, 15757609704383306942u,          24519928653u },
+  {  5979700067267186899u,  9590990814237149589u,                   24u },
+  {  4913998146922579597u,         452312848583u,                    0u },
+  {  5771037749337678924u,                  452u,                    0u },
+  {                    1u,                    0u,           8835301376u },
+  {  3464734175350698519u, 15408590707489433889u,          90993782792u },
+  {  9334527711335850125u, 18332056844289122709u,         170602522202u },
+  {  7269882896518450106u, 11114572877353986192u,         202092341162u },
+  {  1372511258182263196u,  1703393793997526524u,         174275541962u },
+  {  7571228438575951046u,  5082852056285196264u,          26044258990u },
+  {  2992506536646070406u,   816434266573722364u,              1606938u },
+  {   524517896824344606u,    29642774844752946u,                    0u },
+  { 15582941400898702773u,             29642774u,                    0u },
+  {                    1u,                    0u,         214310977536u },
+  {  3846112492507251066u,  5736523019264798741u,         104549111254u },
+  { 16681117750123089487u, 10129314776268243338u,          62895095400u },
+  { 14986314536556547267u, 16511595775483995363u,         163670432318u },
+  {  2573712825027107389u, 12367293405401453324u,         137918027683u },
+  {  7504855874008324928u, 16934621733248854290u,          84557186697u },
+  {  9572138030626879787u, 10278280417769171335u,         105312291668u },
+  {  8520676959353394843u,  5760764486226151239u,                  105u },
+  { 13448984662897903496u,        1942668892225u,                    0u },
+  { 12338883700918130648u,                 1942u,                    0u },
+  {                    1u,                    0u,         156223799296u },
+  {  2517285787892561600u,  4128368337188369760u,         146555162524u },
+  {  4338831817635138103u, 10240941003671005055u,          36972170386u },
+  {  1561495325934523196u, 17933378316822368250u,         161452451108u },
+  { 12262635050079398786u,  8346249813075698615u,           3862277025u },
+  { 11144065765517284188u, 15906203609160902694u,         163787434755u },
+  {  1212260522471875711u, 14525607416135386327u,         242346790563u },
+  {  9695352922247418869u,  6397156777364256319u,              6901746u },
+  {  7227025834627242948u,   127314748520905380u,                    0u },
+  {  9609008238705447829u,            127314748u,                    0u },
+  {                    1u,                    0u,          74910662656u },
+  {  3609144142396852269u, 16798760952716600047u,          31131187530u },
+  { 11568848377382068865u,  2419982808370854966u,         224158453279u },
+  { 10068303578029323957u,  2922947087773078955u,         211835877600u },
+  { 11645070846862630231u, 15419220167069510189u,         190187140051u },
+  { 12449386705878485055u,  3452124642157173415u,         149324160190u },
+  { 15025619323517318418u,  5979700067267186898u,         199266388373u },
+  { 14996237555047131272u,  4913998146922579596u,         196312848583u },
+  { 10211005638256058413u,  5771037749337678923u,                  452u },
+  {  1014743503555840530u,        8343699359066u,                    0u },
+  { 12900897707145290678u,                 8343u,                    0u },
+  {                    1u,                    0u,          33187823616u },
+  {  4718003016239473662u,  3464734175350698518u,         149506025761u },
+  { 14865830648693666725u,  9334527711335850124u,         144394101141u },
+  { 14754517212823091778u,  7269882896518450105u,         252074403984u },
+  { 11113946551474911901u,  1372511258182263195u,         232410437116u },
+  {  1963520352638130630u,  7571228438575951045u,         252162224104u },
+  { 13342587341404964200u,  2992506536646070405u,          50028434172u },
+  {  6240392545013573291u,   524517896824344605u,          22844752946u },
+  { 14377490861349714758u, 15582941400898702772u,             29642774u },
+  {  1717863312631397839u,   546812681195752981u,                    0u },
+  {  3611005143890591770u,            546812681u,                    0u },
+  {                    1u,                    0u,          21208498176u },
+  { 13168252824351245504u,  3846112492507251065u,         138904285205u },
+  {   735883891883379688u, 16681117750123089486u,         227812409738u },
+  { 10609203866866106404u, 14986314536556547266u,          12139521251u },
+  { 12358191111890306470u,  2573712825027107388u,          18406839052u },
+  { 15229916368406413528u,  7504855874008324927u,         135518906642u },
+  {  7241424335568075942u,  9572138030626879786u,          71461906823u },
+  {  6049715868779871913u,  8520676959353394842u,          65729070919u },
+  {  2000548404719336762u, 13448984662897903495u,         150668892225u },
+  {  1410974761895205301u, 12338883700918130647u,                 1942u },
+  { 16000132467694084868u,       35835915874844u,                    0u },
+  { 16894908866816792556u,                35835u,                    0u },
+  {                    1u,                    0u,          96136462336u },
+  {   589096329272056762u,  2517285787892561599u,         127235208544u },
+  {  7097729792403256904u,  4338831817635138102u,         250084648831u },
+  {  8553736750439287020u,  1561495325934523195u,         183664758778u },
+  {  2114152625261065696u, 12262635050079398785u,          38604121015u },
+  {  9817523680007641224u, 11144065765517284187u,         215065716774u },
+  { 13047215537500048015u,  1212260522471875710u,          63525586135u },
+  { 16755544192002345880u,  9695352922247418868u,         164391777855u },
+  {  6930119832670648356u,  7227025834627242947u,          60520905380u },
+  { 14560698131901886167u,  9609008238705447828u,            127314748u },
+  { 16408020927503338035u,  2348542582773833227u,                    0u },
+  { 14274703510609809116u,           2348542582u,                    0u },
+  {                    1u,                    0u,         239195652096u },
+  { 16428432973129962470u,  3609144142396852268u,          54627148527u },
+  {  3721112279790863774u, 11568848377382068864u,         171545803830u },
+  { 18032764903259620753u, 10068303578029323956u,          45631280555u },
+  { 18058455550468776079u, 11645070846862630230u,         167674882605u },
+  { 15692090139033993190u, 12449386705878485054u,         210814540455u },
+  {   389416944300619393u, 15025619323517318417u,         140812947666u },
+  { 12009691357260487293u, 14996237555047131271u,          75553539724u },
+  { 13494259174449809900u, 10211005638256058412u,          90055009355u },
+  { 18288583400616279877u,  1014743503555840529u,         151699359066u },
+  {     7216107869057472u, 12900897707145290677u,                 8343u },
+  { 17237061291959073878u,      153914086704665u,                    0u },
+  {  1599418782488783273u,               153914u,                    0u },
+  {                    1u,                    0u,          22255763456u },
+  {  9565464987240335777u,  4718003016239473661u,         140805878294u },
+  {   857713933775880687u, 14865830648693666724u,         185799843980u },
+  {  4621617820081363356u, 14754517212823091777u,         155602488249u },
+  {  9630162611715632528u, 11113946551474911900u,         197106442651u },
+  {  9283986497984645815u,  1963520352638130629u,         133723303109u },
+  {  8981807745082630996u, 13342587341404964199u,          29338292357u },
+  { 18350140531565934622u,  6240392545013573290u,         180779405341u },
+  {  4411619033127524143u, 14377490861349714757u,          21093125556u },
+  {  1852297584111266889u,  1717863312631397838u,           9195752981u },
+  { 11746243463811666096u,  3611005143890591769u,            546812681u },
+  {  6335244004343789147u, 10086913586276986678u,                    0u },
+  {  5109502367228239844u,          10086913586u,                    0u },
+  {  1603272682579847821u,                   10u,                    0u },
+  {                    1u,                    0u,         121713852416u },
+  {  6609546910952910052u, 13168252824351245503u,          78039892345u },
+  {  3911171343112928288u,   735883891883379687u,         194575126094u },
+  {  5254510615100863555u, 10609203866866106403u,          60669938882u },
+  {  3881927570803887650u, 12358191111890306469u,          63825615420u },
+  {  6379348759607163190u, 15229916368406413527u,          42392558399u },
+  { 14595733737222406466u,  7241424335568075941u,         154327955754u },
+  { 14670223432002373542u,  6049715868779871912u,         135108449946u },
+  {  4045087795619708513u,  2000548404719336761u,         215076489095u },
+  { 12598467307137142718u,  1410974761895205300u,          28867368919u },
+  {   734704388050777108u, 16000132467694084867u,         251915874844u },
+  {  5682201693687285822u, 16894908866816792555u,                35835u },
+  { 11048712694145438788u,      661055968790248u,                    0u },
+  { 17871025777010319485u,               661055u,                    0u },
+  {                    1u,                    0u,         191031934976u },
+  { 15268761435931663695u,   589096329272056761u,          54384768703u },
+  {  5016238054648555438u,  7097729792403256903u,          59463698998u },
+  { 14236047313993899750u,  8553736750439287019u,         129114608443u },
+  {  6957759675154690848u,  2114152625261065695u,          91532209025u },
+  { 18439367135478514473u,  9817523680007641223u,         126707290971u },
+  {  8539004472540641041u, 13047215537500048014u,         244908319870u },
+  {  1908462039431738399u, 16755544192002345879u,         195375682548u },
+  {   714690453250792146u,  6930119832670648355u,         148789337027u },
+  { 13782189447673929633u, 14560698131901886166u,          11889480596u },
+  {  3584742913798803164u, 16408020927503338034u,         118773833227u },
+  {  4347581515245125291u, 14274703510609809115u,           2348542582u },
+  { 16836742268156371392u,  6429475823218628948u,                    2u },
+  { 11764082328865615308u,          43322963970u,                    0u },
+  {  5957633711383291746u,                   43u,                    0u },
+  {                    1u,                    0u,          44890587136u },
+  {  9917186842884466953u, 16428432973129962469u,         128201721900u },
+  {  4751011869809829335u,  3721112279790863773u,         180977558144u },
+  { 11068497969931435029u, 18032764903259620752u,          86978950836u },
+  { 17118056985122509954u, 18058455550468776078u,          62850669910u },
+  { 14607066080907684459u, 15692090139033993189u,          17021110334u },
+  { 11768892370493391107u,   389416944300619392u,         135651046673u },
+  {  4043396447647747170u, 12009691357260487292u,          44731525255u },
+  {  1670341095362518057u, 13494259174449809899u,          17991426092u },
+  {  3190817644167043165u, 18288583400616279876u,         181000391185u },
+  { 10425820027224322486u,     7216107869057471u,          25934422965u },
+  { 13139964660506311565u, 17237061291959073877u,          58086704665u },
+  {  2297772885416059937u,  1599418782488783272u,               153914u },
+  {  7677687919964523763u,     2839213766779714u,                    0u },
+  { 14144589152747892828u,              2839213u,                    0u },
+  {                    1u,                    0u,         253518544896u },
+  { 17069730341503660290u,  9565464987240335776u,         164046496765u },
+  { 18167423787163077107u,   857713933775880686u,          65250538404u },
+  {  3765746945827805904u,  4621617820081363355u,         156522052161u },
+  { 10241734342430761691u,  9630162611715632527u,         197503285916u },
+  { 13345717282537140784u,  9283986497984645814u,         103486904773u },
+  {  9313926784816939953u,  8981807745082630995u,         170994763111u },
+  {   550974205049535019u, 18350140531565934621u,          69239154346u },
+  {  4494692285504086222u,  4411619033127524142u,         206100413253u },
+  {  1134308559863725587u,  1852297584111266888u,          25636765134u },
+  { 17587558045116130233u, 11746243463811666095u,          54343434265u },
+  {  9817142032346161594u,  6335244004343789146u,          50276986678u },
+  {  6071944935834172568u,  5109502367228239843u,          10086913586u },
+  { 11564168293299416955u,  1603272682579847820u,                   10u },
+  { 12458266507226064437u,         186070713419u,                    0u },
+  {  1304432355328256915u,                  186u,                    0u },
+  {                    1u,                    0u,         191358304256u },
+  { 15946798815542087355u,  6609546910952910051u,         231212025023u },
+  { 12082566083831286138u,  3911171343112928287u,          35284847591u },
+  { 11449623684706196411u,  5254510615100863554u,         165210439715u },
+  { 17518743620362604446u,  3881927570803887649u,         215345825189u },
+  {  9451061563087633805u,  6379348759607163189u,         165791236311u },
+  { 13191114787623314926u, 14595733737222406465u,         168795274405u },
+  {  8367349876734474799u, 14670223432002373541u,          57219284648u },
+  {  6544253801674393507u,  4045087795619708512u,         180682964281u },
+  { 16113906253336597498u, 12598467307137142717u,           3039828404u },
+  { 10294087136797312392u,   734704388050777107u,         235308032771u },
+  {  9127173070014462803u,  5682201693687285821u,         232598951915u },
+  { 16266900839595484952u, 11048712694145438787u,          63968790248u },
+  {  3299745387370952632u, 17871025777010319484u,               661055u },
+  { 12061115182604399189u,    12194330274671844u,                    0u },
+  {  5066801222582989646u,             12194330u,                    0u },
+  {                    1u,                    0u,         185827721216u },
+  {  7568423425299591513u, 15268761435931663694u,          71271930809u },
+  { 16561505984665207377u,  5016238054648555437u,         235771737671u },
+  {  4329114621856906245u, 14236047313993899749u,         223377180907u },
+  {  1477500474861899139u,  6957759675154690847u,         135999600095u },
+  { 16891579639263969684u, 18439367135478514472u,         142462900359u },
+  {  4684451357140027420u,  8539004472540641040u,         151103457934u },
+  { 14727186580409080709u,  1908462039431738398u,          35038743447u },
+  { 15864176859687308834u,   714690453250792145u,         214747133987u },
+  {  1755486942842684438u, 13782189447673929632u,          50194329302u },
+  { 17417077516652710041u,  3584742913798803163u,         219235682866u },
+  {  4290982361913532783u,  4347581515245125290u,          84912721627u },
+  { 11826659981004351409u, 16836742268156371391u,           2637732180u },
+  {   932930645678090820u, 11764082328865615307u,          43322963970u },
+  { 12707792781328052617u,  5957633711383291745u,                   43u },
+  { 16491596426880311906u,         799167628880u,                    0u },
+  {  3092207065214166010u,                  799u,                    0u },
+  {                    1u,                    0u,         229537611776u },
+  {  8142946531605512550u,  9917186842884466952u,         157257552869u },
+  {  5328402096432654515u,  4751011869809829334u,         144600024477u },
+  {  1932004361303814512u, 11068497969931435028u,         142927971728u },
+  {  2511477647985517771u, 17118056985122509953u,         229791850638u },
+  { 17451375493324716694u, 14607066080907684458u,         128637992933u },
+  {  9489266854478998489u, 11768892370493391106u,         124219192960u },
+  {  8803053132063235169u,  4043396447647747169u,         235090549372u },
+  { 16198682197142616773u,  1670341095362518056u,          68172974571u },
+  { 13696242485403414202u,  3190817644167043164u,         191565184836u },
+  { 16409082426079859931u, 10425820027224322485u,          85712318911u },
+  { 11653410736879597610u, 13139964660506311564u,         168124562517u },
+  { 13589514120653213261u,  2297772885416059936u,          66416208296u },
+  {  8032934885905905774u,  7677687919964523762u,         173766779714u },
+  {  2753021350129449273u, 14144589152747892827u,              2839213u },
+  { 16974897459201404133u,    52374249726338269u,                    0u },
+  { 13398576176159101589u,             52374249u,                    0u },
+  {                    1u,                    0u,         160925351936u },
+  { 10284586955251725351u, 17069730341503660289u,         238984858016u },
+  {  5294476488634150891u, 18167423787163077106u,         155204141550u },
+  { 15833244538135063323u,  3765746945827805903u,         143555205531u },
+  { 10348512742273116664u, 10241734342430761690u,         182723472783u },
+  { 13658504610142595663u, 13345717282537140783u,          83504908982u },
+  { 11956362239240850266u,  9313926784816939952u,          29029868371u },
+  { 13415901703662731781u,   550974205049535018u,          46243657757u },
+  {  5161774027546852762u,  4494692285504086221u,          72061490990u },
+  { 15274384838790587711u,  1134308559863725586u,         175953423432u },
+  { 14233354597679374929u, 17587558045116130232u,          90532188335u },
+  {  4274656492162486921u,  9817142032346161593u,         227329160794u },
+  { 12040276505541795046u,  6071944935834172567u,         140626894819u },
+  { 13238307206256765457u, 11564168293299416954u,          75675363980u },
+  { 12850161204172713271u, 12458266507226064436u,         186070713419u },
+  { 17531777095001445154u,  1304432355328256914u,                  186u },
+  {  5623628114515245990u,        3432398830065u,                    0u },
+  {  7357116143579573377u,                 3432u,                    0u },
+  {                    1u,                    0u,         227864477696u },
+  {  3555734177475596582u, 15946798815542087354u,          31654997219u },
+  { 14001876724756424382u, 12082566083831286137u,          66620685343u },
+  { 18159905057231476140u, 11449623684706196410u,          33949692994u },
+  {  5585207679308509467u, 17518743620362604445u,          53512343073u },
+  { 13948697622866724672u,  9451061563087633804u,          65715091765u },
+  {  9807691927739036432u, 13191114787623314925u,         165453594945u },
+  { 15818010096140820918u,  8367349876734474798u,          96354764709u },
+  {  5629845624785010943u,  6544253801674393506u,         189873536608u },
+  {  9517635131137734707u, 16113906253336597497u,          19558043581u },
+  {   619338244618780585u, 10294087136797312391u,          61494785043u },
+  { 11632367007491958899u,  9127173070014462802u,          67881830461u },
+  { 12083314261009739916u, 16266900839595484951u,         124178879555u },
+  { 16880538609458881650u,  3299745387370952631u,         228653834364u },
+  { 17404223674486504228u, 12061115182604399188u,          26274671844u },
+  {  7089067015287185433u,  5066801222582989645u,             12194330u },
+  {  2592264228029443648u,   224945689727159819u,                    0u },
+  { 13413731084370224440u,            224945689u,                    0u },
+  {                    1u,                    0u,          78410285056u },
+  {  9323915941641553425u,  7568423425299591512u,         173897801038u },
+  { 12155831029092699564u, 16561505984665207376u,         229234681773u },
+  { 17397171276588232676u,  4329114621856906244u,          31080095461u },
+  { 11874560617553253769u,  1477500474861899138u,          40915694367u },
+  { 13444839516837727954u, 16891579639263969683u,          16253944616u },
+  { 16994416043584590671u,  4684451357140027419u,          30798362384u },
+  { 15879694502877015730u, 14727186580409080708u,         209859998750u },
+  {  4234647645735263359u, 15864176859687308833u,         160095165137u },
+  {  7978589901512919496u,  1755486942842684437u,         219944181664u },
+  {  6114237175390859894u, 17417077516652710040u,         170232614619u },
+  {  8658612872088282708u,  4290982361913532782u,         191641124522u },
+  { 10253813330683324853u, 11826659981004351408u,         203050574271u },
+  { 13289465061747830991u,   932930645678090819u,          97688890827u },
+  {  4123165538545565412u, 12707792781328052616u,          80894011233u },
+  {  7846417485927038481u, 16491596426880311905u,          31167628880u },
+  { 10562273346358018864u,  3092207065214166009u,                  799u },
+  {  2691512658346619120u,       14742040721959u,                    0u },
+  {   751187558544605998u,                14742u,                    0u },
+  {                    1u,                    0u,           8441430016u },
+  {  3757709791947931308u,  8142946531605512549u,         214288853256u },
+  {  3452755398462519465u,  5328402096432654514u,          20104734166u },
+  {  3105818720159874523u,  1932004361303814511u,         129136147476u },
+  { 16859138458894499364u,  2511477647985517770u,         106946040961u },
+  { 12271894740606233755u, 17451375493324716693u,           2514414186u },
+  {  5429638071845793701u,  9489266854478998488u,          97477214466u },
+  {   145278150038876889u,  8803053132063235168u,          40878132321u },
+  {  9050266019724932450u, 16198682197142616772u,          92742474792u },
+  { 11907016253451490866u, 13696242485403414201u,         181889538140u },
+  {  2472757296513770735u, 16409082426079859930u,         140631732661u },
+  { 10558733798178239360u, 11653410736879597609u,          32736689036u },
+  { 15917322570831255850u, 13589514120653213260u,         242435466272u },
+  { 12254334656791355238u,  8032934885905905773u,          91149241586u },
+  {  7869542424662730262u,  2753021350129449272u,         221920211035u },
+  {  1378558986933000253u, 16974897459201404132u,         233726338269u },
+  { 13521405041909411105u, 13398576176159101588u,             52374249u },
+  {  3206744593298092012u,   966134380754314586u,                    0u },
+  { 13914648122214918505u,            966134380u,                    0u },
+  {                    1u,                    0u,           1557528576u },
+  {  1235541077112082496u, 10284586955251725350u,         242287014145u },
+  { 12014985518315533846u,  5294476488634150890u,         207858321906u },
+  {  1561535086344155741u, 15833244538135063322u,         218560993999u },
+  { 12761747276316224577u, 10348512742273116663u,          47740429018u },
+  {  9745594781103966137u, 13658504610142595662u,         176648155695u },
+  { 17514238702394846785u, 11956362239240850265u,          42727277488u },
+  {  2428898913707151713u, 13415901703662731780u,         205279820330u },
+  {    71666709959904945u,  5161774027546852761u,          18828026061u },
+  {  4049380135452919193u, 15274384838790587710u,         184771591698u },
+  { 18422240861777453733u, 14233354597679374928u,         185231729592u },
+  {  2914504416394425696u,  4274656492162486920u,         151652704697u },
+  { 12721377795748989418u, 12040276505541795045u,         122717650071u },
+  {  2626074459217717422u, 13238307206256765456u,          52696608634u },
+  {  4261529925046307655u, 12850161204172713270u,         146950399540u },
+  { 11536038685430305586u, 17531777095001445153u,         241304857490u },
+  { 12555757789435162768u,  5623628114515245989u,         104398830065u },
+  { 11905178684546080059u,  7357116143579573376u,                 3432u },
+  { 14032797718924543051u,       63316582777114u,                    0u },
+  { 10750340288005853484u,                63316u,                    0u },
+  {                    1u,                    0u,         186192756736u },
+  {  9660290106216358253u,  3555734177475596581u,         121759043258u },
+  { 14820142034615351103u, 14001876724756424381u,         186984450425u },
+  { 12674041783707777619u, 18159905057231476139u,         157302774714u },
+  { 15386686816442679994u,  5585207679308509466u,         140756160413u },
+  {  5679510383719146248u, 13948697622866724671u,         237531676044u },
+  {  1391101719248678506u,  9807691927739036431u,          46857496045u },
+  {  3364596672173710517u, 15818010096140820917u,         162305194542u },
+  { 11276509210104319732u,  5629845624785010942u,         249515952034u },
+  {  5316312656902630164u,  9517635131137734706u,         135033574393u },
+  { 17470981304473644647u,   619338244618780584u,          82630591879u },
+  {  7373293636384920591u, 11632367007491958898u,          23655037778u },
+  {  7616810902585191937u, 12083314261009739915u,         183915095831u },
+  { 12740295655921903924u, 16880538609458881649u,          84943484855u },
+  { 18366635945916526940u, 17404223674486504227u,          77384299092u },
+  {  4472171448243407067u,  7089067015287185432u,          11140526925u },
+  {   229592460858185629u,  2592264228029443647u,          25727159819u },
+  { 12749672866417114996u, 13413731084370224439u,            224945689u },
+  {  9452256722867098693u,  4149515568880992958u,                    0u },
+  { 16251451636418604634u,           4149515568u,                    0u },
+  {                    1u,                    0u,          88505450496u },
+  {  4515791283442995454u,  9323915941641553424u,          80658968920u },
+  { 13306155670047701346u, 12155831029092699563u,           4943102544u },
+  {  4456930152933417601u, 17397171276588232675u,         130643721220u },
+  {  9089157128546489637u, 11874560617553253768u,         147728846210u },
+  { 12437332180345515840u, 13444839516837727953u,          27921269139u },
+  {  3433060408790452524u, 16994416043584590670u,         132860839963u },
+  {  8275594526021936172u, 15879694502877015729u,          33229560708u },
+  {  3846512444641107689u,  4234647645735263358u,          21432520225u },
+  {  6210962618469046250u,  7978589901512919495u,         152331453461u },
+  {  7272858906616296575u,  6114237175390859893u,         110469384344u },
+  {  3710743300451225347u,  8658612872088282707u,         176555860334u },
+  {  6424677242672030600u, 10253813330683324852u,          67720423344u },
+  { 11485842256170301862u, 13289465061747830990u,         136223517251u },
+  {  7355797963557024308u,  4123165538545565411u,          97425355144u },
+  {  6358188982569427273u,  7846417485927038480u,         249572581985u },
+  { 12475094728768767402u, 10562273346358018863u,          39145907193u },
+  { 17288154837907896183u,  2691512658346619119u,         150040721959u },
+  {  2983850577727105262u,   751187558544605997u,                14742u },
+  { 13918604635001185935u,      271942652322184u,                    0u },
+  { 12033220395769876327u,               271942u,                    0u },
+  {                    1u,                    0u,         101203705856u },
+  {  5782377197813462997u,  3757709791947931307u,         178187174245u },
+  { 17732139848231399226u,  3452755398462519464u,         111168366770u },
+  {  3628839527415562921u,  3105818720159874522u,         202913935727u },
+  {  3188692267613601004u, 16859138458894499363u,         149665260746u },
+  {  5168130193478377352u, 12271894740606233754u,         216294341269u },
+  { 12556227529405091290u,  5429638071845793700u,          96007875544u },
+  { 15087090312791441192u,   145278150038876888u,         196490615904u },
+  { 10281804758610642494u,  9050266019724932449u,         185645480644u },
+  { 14238177586158586580u, 11907016253451490865u,         218134048441u },
+  {  7107927498217678128u,  2472757296513770734u,          41572390106u },
+  {  3845814658485364450u, 10558733798178239359u,          76862879785u },
+  {   714293333681725946u, 15917322570831255849u,         109664308812u },
+  { 16766172658649116982u, 12254334656791355237u,          56426608749u },
+  {   812461421432632215u,  7869542424662730261u,         228074731832u },
+  { 15218024718633799196u,  1378558986933000252u,         148732996836u },
+  {  8110797782612805146u, 13521405041909411104u,          90173837972u },
+  { 15941193964933529227u,  3206744593298092011u,         108754314586u },
+  { 14144280602323277933u, 13914648122214918504u,            966134380u },
+  { 15072402647813125245u, 17822033662586700072u,                    0u },
+  { 10822706091283369889u,          17822033662u,                    0u },
+  { 15163844593710966731u,                   17u,                    0u },
+  {                    1u,                    0u,          38066978816u },
+  {  2408529687792073670u,  1235541077112082495u,         234651333670u },
+  {  3980682212356510808u, 12014985518315533845u,          26084650986u },
+  {  4202670442792148519u,  1561535086344155740u,         247691815706u },
+  {  9419583343154651922u, 12761747276316224576u,          78528309751u },
+  { 16359166491570434575u,  9745594781103966136u,          89949448782u },
+  { 12567727056384237385u, 17514238702394846784u,           4131670873u },
+  {  2068388267923286639u,  2428898913707151712u,         153003885060u },
+  {  5689135844565021196u,    71666709959904944u,          62219517337u },
+  {  3104061965171139313u,  4049380135452919192u,          80998671678u },
+  {  7955173880156328016u, 18422240861777453732u,         136157995600u },
+  {  1445179403240833754u,  2914504416394425695u,         229689627272u },
+  { 12538201164459126715u, 12721377795748989417u,          16142359781u },
+  {  7580606719088482667u,  2626074459217717421u,          54231018000u },
+  {  8168318283218819755u,  4261529925046307654u,          33625369910u },
+  {  5249615277755961676u, 11536038685430305585u,         165680648993u },
+  {  6312997372068219831u, 12555757789435162767u,         128645381029u },
+  {  9183815417025176703u, 11905178684546080058u,          26760719488u },
+  { 10683849953373876937u, 14032797718924543050u,          84582777114u },
+  { 17175012155615667568u, 10750340288005853483u,                63316u },
+  { 18003508288378896912u,     1167984798111281u,                    0u },
+  { 14722554560950996951u,              1167984u,                    0u },
+  {                    1u,                    0u,          37523685376u },
+  { 15059324482416394930u,  9660290106216358252u,         189803401509u },
+  {  4134778595813308312u, 14820142034615351102u,         171687061181u },
+  { 16321118342639660948u, 12674041783707777618u,          26834113963u },
+  {  1523550293123468805u, 15386686816442679993u,          63307886874u },
+  {  8016371634569878509u,  5679510383719146247u,          15075411775u },
+  {  9884220139611134110u,  1391101719248678505u,         181182395151u },
+  {  7218073002727840414u,  3364596672173710516u,         254611300789u },
+  { 16062235669481359233u, 11276509210104319731u,          50288197886u },
+  { 15558048660560338002u,  5316312656902630163u,         168947103794u },
+  {  8394398745765058609u, 17470981304473644646u,         114399707048u },
+  {  5693296366442904274u,  7373293636384920590u,         139412908146u },
+  { 11783494675061161358u,  7616810902585191936u,         113690652811u },
+  { 13377293110865447894u, 12740295655921903923u,          35995657329u },
+  { 12840734051093062130u, 18366635945916526939u,          24242436899u },
+  {  7009868331566697505u,  4472171448243407066u,          63012446232u },
+  {  5019690705031194477u,   229592460858185628u,          55691161151u },
+  {  8608277240439804984u, 12749672866417114995u,         190512407863u },
+  { 12172482590657749222u,  9452256722867098692u,          48880992958u },
+  { 16613484892678771990u, 16251451636418604633u,           4149515568u },
+  {  5721488662757049244u,  2758075434182769113u,                    4u },
+  {   386931106438877039u,          76545051729u,                    0u },
+  { 10054429752182825659u,                   76u,                    0u },
+  {                    1u,                    0u,          16244801536u },
+  {  8634592106137071313u,  4515791283442995453u,         171721328144u },
+  { 12626356501369830731u, 13306155670047701345u,         227241610667u },
+  {  4803333258178976933u,  4456930152933417600u,         136492724195u },
+  { 13613083223558209297u,  9089157128546489636u,         209674229128u },
+  { 16106967997237446989u, 12437332180345515839u,          78186106577u },
+  { 14832921244380020170u,  3433060408790452523u,         177448620878u },
+  { 13774024637717231397u,  8275594526021936171u,         126208519857u },
+  {  9673012968505228885u,  3846512444641107688u,         199336696958u },
+  {  5391832334264815667u,  6210962618469046249u,         117394262471u },
+  { 16514436292632703088u,  7272858906616296574u,          83201159797u },
+  { 12025036352783454153u,  3710743300451225346u,         180348282451u },
+  {  7059867105311401050u,  6424677242672030599u,         206622648756u },
+  { 12769210631552594670u, 11485842256170301861u,         227398758606u },
+  {  8328873878884556145u,  7355797963557024307u,          16344678115u },
+  {  1016565892414238685u,  6358188982569427272u,          47676276240u },
+  {  9662978461927250281u, 12475094728768767401u,         239937192751u },
+  { 13729967277551868112u, 17288154837907896182u,          45161754863u },
+  {  6371593776693359475u,  2983850577727105261u,         136754529069u },
+  { 17617208110845643245u, 13918604635001185934u,          70652322184u },
+  { 14960960225633086797u, 12033220395769876326u,               271942u },
+  { 12090634301321662558u,     5016456510113118u,                    0u },
+  {  9409926148478635503u,              5016456u,                    0u },
+  {                    1u,                    0u,         171313463296u },
+  {  4307062684900157136u,  5782377197813462996u,         168961261227u },
+  { 15300759383869911853u, 17732139848231399225u,         218196719784u },
+  { 16007534237643445447u,  3628839527415562920u,          35172859354u },
+  {  7138502295759677634u,  3188692267613601003u,         154280164899u },
+  {  8218537071653683708u,  5168130193478377351u,         164680674458u },
+  {  2254219416760329296u, 12556227529405091289u,         216817872804u },
+  {  3057410459568460683u, 15087090312791441191u,          97557377752u },
+  {  8217810929938874370u, 10281804758610642493u,          49771853153u },
+  { 11741126472498340929u, 14238177586158586579u,         238385321521u },
+  {  1175325363726654805u,  7107927498217678127u,         127208482030u },
+  {  9428843070696730900u,  3845814658485364449u,          41038721919u },
+  { 12662500978715131896u,   714293333681725945u,         101908896041u },
+  {  6443045597035184564u, 16766172658649116981u,          21044043621u },
+  {  1921385512639171183u,   812461421432632214u,          60824970773u },
+  { 10469475094355551399u, 15218024718633799195u,          32439687228u },
+  { 14679174489076953574u,  8110797782612805145u,         235864173856u },
+  { 11853074234719825644u, 15941193964933529226u,         104766762987u },
+  {  8270896886596139124u, 14144280602323277932u,          40817076584u },
+  { 16532667046659118126u, 15072402647813125244u,         254586700072u },
+  {   148341279888833483u, 10822706091283369888u,          17822033662u },
+  { 10364629296397276041u, 15163844593710966730u,                   17u },
+  { 14265682585545771671u,         328758493846u,                    0u },
+  { 13991741872911347878u,                  328u,                    0u },
+  {                    1u,                    0u,          63130566656u },
+  { 14029045786848724433u,  2408529687792073669u,          21215793215u },
+  {  4005878521026842341u,  3980682212356510807u,          92227827221u },
+  {  3428326338640386488u,  4202670442792148518u,          64510636636u },
+  {  1010001558294829380u,  9419583343154651921u,         184886832192u },
+  {  2012063724327403418u, 16359166491570434574u,          64681297848u },
+  { 10997154538851372612u, 12567727056384237384u,          96112127552u },
+  {  1917749645489607898u,  2068388267923286638u,         176308408672u },
+  {  9763872523711218805u,  5689135844565021195u,         152168271536u },
+  { 15875699078454059311u,  3104061965171139312u,         164431250840u },
+  { 10966529452671276106u,  7955173880156328015u,          95078343332u },
+  { 18073244132105736913u,  1445179403240833753u,         233679697247u },
+  {  4435241176994913173u, 12538201164459126714u,         173410945513u },
+  {  5464400086219074323u,  7580606719088482666u,          70442805421u },
+  {  2445909179323258812u,  8168318283218819754u,          49284582214u },
+  {   873962058644121211u,  5249615277755961675u,         143342228273u },
+  { 16675872194112650857u,  6312997372068219830u,          58497855631u },
+  { 10680102689274800355u,  9183815417025176702u,          74579172666u },
+  {  2370498083108897524u, 10683849953373876936u,          43931059274u },
+  { 15354400521451334666u, 17175012155615667567u,          49975972139u },
+  {   259991949657381021u, 18003508288378896911u,         112798111281u },
+  { 10335286558772966917u, 14722554560950996950u,              1167984u },
+  { 16337526653906757263u,    21545516652742137u,                    0u },
+  { 12040967163702784894u,             21545516u,                    0u },
+  {                    1u,                    0u,         108816367616u },
+  {  3373309160242342187u, 15059324482416394929u,          62224146796u },
+  { 13639841054510584221u,  4134778595813308311u,          82884769598u },
+  { 15898855427739708031u, 16321118342639660947u,         185082591826u },
+  {  4544387940067005419u,  1523550293123468804u,           7434568377u },
+  {  5281598644835398575u,  8016371634569878508u,         105535824647u },
+  { 13675642405083408835u,  9884220139611134109u,         180391292521u },
+  {  3973392623768015721u,  7218073002727840413u,         243870735540u },
+  {  4491285101509114191u, 16062235669481359232u,          19843403507u },
+  { 15002304272810270500u, 15558048660560338001u,         102455061267u },
+  { 17325098540619893468u,  8394398745765058608u,          14308634214u },
+  {  1137212864974584822u,  5693296366442904273u,            638784526u },
+  {  2619406097224859078u, 11783494675061161357u,          51725184512u },
+  {  8281347529729293732u, 13377293110865447893u,          91696097587u },
+  { 11344719666795450104u, 12840734051093062129u,         218380005723u },
+  { 17283870506679425783u,  7009868331566697504u,         156272117978u },
+  { 11054210518010603775u,  5019690705031194476u,         115466655644u },
+  {  6399455551799092885u,  8608277240439804983u,          68659871603u },
+  { 12930529916573967170u, 12172482590657749221u,          89900618820u },
+  { 14550097052337552404u, 16613484892678771989u,         217310162521u },
+  { 12487632712206414748u,  5721488662757049243u,          81020975577u },
+  {  5791017277843595715u,   386931106438877038u,          76545051729u },
+  { 10227264183449036113u, 10054429752182825658u,                   76u },
+  {  2006055278511721441u,        1412006979354u,                    0u },
+  {   128746359043876333u,                 1412u,                    0u },
+  {                    1u,                    0u,         253468082176u },
+  {  7408146306870995754u,  8634592106137071312u,          97684476157u },
+  {  8299024588195267962u, 12626356501369830730u,         128260389217u },
+  {  1497052939192040881u,  4803333258178976932u,          36737966720u },
+  { 16771714264265803747u, 13613083223558209296u,          63873160484u },
+  {   142988846654429432u, 16106967997237446988u,          43804094271u },
+  { 11839838367716104145u, 14832921244380020169u,          43746691371u },
+  {  6019646776647679765u, 13774024637717231396u,         232524375083u },
+  {  4611972391702034948u,  9673012968505228884u,         233292291816u },
+  { 16447182322205429545u,  5391832334264815666u,         126895249385u },
+  {  2113477168726764245u, 16514436292632703087u,           2651878526u },
+  {  3536261187802311516u, 12025036352783454152u,         135382716162u },
+  { 18444381860986709854u,  7059867105311401049u,         165692220295u },
+  {  4734315730275909838u, 12769210631552594669u,          51451509157u },
+  {  9974936316849658174u,  8328873878884556144u,          72055108147u },
+  { 11864423681540657642u,  1016565892414238684u,         169523831112u },
+  {  8207245621417902667u,  9662978461927250280u,         118744303017u },
+  {  7992526918695295028u, 13729967277551868111u,         237345404790u },
+  {  8679354522130259987u,  6371593776693359474u,         142955030765u },
+  {  6065763799692166461u, 17617208110845643244u,         102811035278u },
+  { 18143341109049024976u, 14960960225633086796u,          94655434598u },
+  { 15242492331283350570u, 12090634301321662557u,         136510113118u },
+  {  9986352353182266963u,  9409926148478635502u,              5016456u },
+  { 17340463289911536077u,    92537289398950870u,                    0u },
+  {  7359344614214233035u,             92537289u,                    0u },
+  {                    1u,                    0u,         212233486336u },
+  {   419091135888749535u,  4307062684900157135u,          57829455828u },
+  {  1073142712661309790u, 15300759383869911852u,         168867770169u },
+  { 11076438902195672286u, 16007534237643445446u,         235386978984u },
+  {  1820390940081322073u,  7138502295759677633u,         135445527787u },
+  { 18417808973944523597u,  8218537071653683707u,         217122201479u },
+  { 10251294197731582957u,  2254219416760329295u,          39165742553u },
+  {  1502394029870156428u,  3057410459568460682u,          61445488423u },
+  {   321014853559106075u,  8217810929938874369u,         211636487741u },
+  {  2390953058510591778u, 11741126472498340928u,          47063714515u },
+  { 10685224265907994087u,  1175325363726654804u,         225511138607u },
+  {  5967405799190505023u,  9428843070696730899u,         249686435553u },
+  { 11210723659228214761u, 12662500978715131895u,          53349278201u },
+  { 12327123641078462773u,  6443045597035184563u,         150104158517u },
+  {  1709976940107894237u,  1921385512639171182u,          27567551382u },
+  { 16607686590938553511u, 10469475094355551398u,          25795759643u },
+  { 18332088094272679457u, 14679174489076953573u,         138642556441u },
+  {  2946170632136780882u, 11853074234719825643u,         108448366218u },
+  {  4824449494694383419u,  8270896886596139123u,         124896237676u },
+  { 17008332258693407134u, 16532667046659118125u,         160008041596u },
+  {  1773419466622750661u,   148341279888833482u,         202561867680u },
+  {  3892343466023784379u, 10364629296397276040u,         150773344202u },
+  { 12001571085575422796u, 14265682585545771670u,          72758493846u },
+  { 12933506765500977582u, 13991741872911347877u,                  328u },
+  { 11884830007749143734u,        6064523798049u,                    0u },
+  {  9662368568096205337u,                 6064u,                    0u },
+  {                    1u,                    0u,         197760516096u },
+  { 16801499925276664442u, 14029045786848724432u,          87217159109u },
+  { 10492407990787637084u,  4005878521026842340u,          38185849943u },
+  {  7673849751013230269u,  3428326338640386487u,          17054752294u },
+  {  6046724489853072367u,  1010001558294829379u,          14109074193u },
+  {  3723941391207507903u,  2012063724327403417u,          72596156942u },
+  { 16844122108860347659u, 10997154538851372611u,         110103961416u },
+  { 10622020182694668027u,  1917749645489607897u,          11529300590u },
+  {  8741198820686854862u,  9763872523711218804u,         240860623371u },
+  {  6855480461211306807u, 15875699078454059310u,          79594496752u },
+  { 10005708458011566304u, 10966529452671276105u,         217979752527u },
+  {  8932093106442919061u, 18073244132105736912u,         186240434905u },
+  {  9062763476260756743u,  4435241176994913172u,         106296225722u },
+  { 13664977682032775521u,  5464400086219074322u,         170132593002u },
+  {  1078499125430623453u,  2445909179323258811u,          75047377578u },
+  {  6554586738078431161u,   873962058644121210u,         182904000843u },
+  { 12177313698643242883u, 16675872194112650856u,         126578969526u },
+  { 16615072271904633953u, 10680102689274800354u,         200128504958u },
+  { 16375404983106569285u,  2370498083108897523u,         111832363720u },
+  { 13552251831473522729u, 15354400521451334665u,          15014094191u },
+  {  8330500218412111874u,   259991949657381020u,         214560277007u },
+  {  7044338079053294004u, 10335286558772966916u,         249885659094u },
+  {  2688849443046530184u, 16337526653906757262u,          44652742137u },
+  {   855940991879596845u, 12040967163702784893u,             21545516u },
+  {  7344363609485825662u,   397444631628981487u,                    0u },
+  { 11602660525134634992u,            397444631u,                    0u },
+  {                    1u,                    0u,         177182867456u },
+  { 16945343208344873835u,  3373309160242342186u,         151739417265u },
+  {  9617992661337889145u, 13639841054510584220u,         147861878679u },
+  { 18280344933262742088u, 15898855427739708030u,           4246351763u },
+  {  5179975582362777795u,  4544387940067005418u,         236286316036u },
+  {  1798918997870037130u,  5281598644835398574u,         157741358060u },
+  {  6327667344756325883u, 13675642405083408834u,         157215398045u },
+  { 18380327574124007701u,  3973392623768015720u,         128243473053u },
+  { 18015447557304295289u,  4491285101509114190u,          81813276544u },
+  { 10315590748073249878u, 15002304272810270499u,          48939195473u },
+  {  7697916092577993382u, 17325098540619893467u,         209061648432u },
+  {  3124132817942110723u,  1137212864974584821u,         141141998289u },
+  {  7448238998520507049u,  2619406097224859077u,         213448932749u },
+  { 13892823322374205297u,  8281347529729293731u,         241614998485u },
+  { 11042137840046332564u, 11344719666795450103u,          32936960497u },
+  { 10513966307445593804u, 17283870506679425782u,         108599249952u },
+  {  9388437460943526958u, 11054210518010603774u,          55346915180u },
+  { 10967228614677896228u,  6399455551799092884u,         229700965431u },
+  {  2310996671540235542u, 12930529916573967169u,          21788762341u },
+  {  4989110555003898587u, 14550097052337552403u,         155676955925u },
+  { 16271452421983657679u, 12487632712206414747u,         110313931675u },
+  {  9523160181437090473u,  5791017277843595714u,         186554421102u },
+  { 13137707423765072250u, 10227264183449036112u,          26108748474u },
+  { 16846859744221860705u,  2006055278511721440u,         132006979354u },
+  {  7767140033449795569u,   128746359043876332u,                 1412u },
+  { 17169456915721160017u,       26046931378436u,                    0u },
+  { 17180899661833327819u,                26046u,                    0u },
+  {                    1u,                    0u,         208401596416u },
+  { 17572520700934791416u,  7408146306870995753u,          74449891024u },
+  { 17968798858233825417u,  8299024588195267961u,         164081155402u },
+  { 15338423313945305609u,  1497052939192040880u,          16909196452u },
+  { 17895321323836726301u, 16771714264265803746u,          76007751440u },
+  {   814069333008965773u,   142988846654429431u,         201641838924u },
+  {  7200328959852723947u, 11839838367716104144u,          36326325705u },
+  {   759884557248133773u,  6019646776647679764u,          84250015524u },
+  { 13410165861863974851u,  4611972391702034947u,          50891603540u },
+  {  6278452420856351570u, 16447182322205429544u,         111114571826u },
+  {  9072115382556676442u,  2113477168726764244u,         200191701103u },
+  {  2755882551854926563u,  3536261187802311515u,          89999871944u },
+  {  8496072611504649269u, 18444381860986709853u,         237256647769u },
+  {  4122009033579215815u,  4734315730275909837u,         112540742381u },
+  { 10222217724450527221u,  9974936316849658173u,         220643171696u },
+  {  2064539481554006325u, 11864423681540657641u,         104444915676u },
+  {  7935605886598063693u,  8207245621417902666u,         207433275752u },
+  {  7805147585347548429u,  7992526918695295027u,         114470508751u },
+  {  5709020905457661273u,  8679354522130259986u,         236328825714u },
+  { 16257370307404906674u,  6065763799692166460u,          76983552492u },
+  { 14971258192939373646u, 18143341109049024975u,          93826297164u },
+  {  1133404845901376390u, 15242492331283350569u,         238541361245u },
+  {  9460827548162822047u,  9986352353182266962u,         214940028398u },
+  {  1273897659779791346u, 17340463289911536076u,         201398950870u },
+  {  7833262224435092783u,  7359344614214233034u,             92537289u },
+  {  3033420566713364587u,  1707011694817242694u,                    0u },
+  { 15075466825360349103u,           1707011694u,                    0u },
+  {                    1u,                    0u,         207022718976u },
+  {  2484134775182816690u,   419091135888749534u,          44058175183u },
+  { 18400539815335991277u,  1073142712661309789u,         198600454956u },
+  {   485494064952118286u, 11076438902195672285u,         193098683590u },
+  { 17577048805241314891u,  1820390940081322072u,         251998431425u },
+  {  2863946907557583807u, 18417808973944523596u,          79555723771u },
+  { 13045307417786230800u, 10251294197731582956u,         138081444943u },
+  { 12032088871615097766u,  1502394029870156427u,           1017402250u },
+  {  8848763446997690580u,   321014853559106074u,          64129613825u },
+  { 10031289150307672684u,  2390953058510591777u,          84579247168u },
+  { 11592215575498656563u, 10685224265907994086u,          19323493716u },
+  { 15894436747956898388u,  5967405799190505022u,         247607734547u },
+  {  2091546719588500923u, 11210723659228214760u,         179668254711u },
+  {  5863809244813756109u, 12327123641078462772u,         110092698035u },
+  { 11303008753675411245u,  1709976940107894236u,         166900304494u },
+  { 13238426537506910532u, 16607686590938553510u,         229993784486u },
+  { 17258458071023005565u, 18332088094272679456u,         235159712229u },
+  {  8385733444777075179u,  2946170632136780881u,         115261533931u },
+  {  9530757096163247300u,  4824449494694383418u,          45922023539u },
+  { 14423000845391072217u, 17008332258693407133u,         202096137261u },
+  { 10953140011159884311u,  1773419466622750660u,         136211004362u },
+  { 12228340237948264127u,  3892343466023784378u,         150650606472u },
+  { 11279134946966259189u, 12001571085575422795u,         165701126806u },
+  { 14640097792684582651u, 12933506765500977581u,          33644277925u },
+  {  6232313315128656728u, 11884830007749143733u,         176523798049u },
+  { 16136121832933322088u,  9662368568096205336u,                 6064u },
+  { 15074767079673358271u,      111870718431542u,                    0u },
+  { 13252722804829281908u,               111870u,                    0u },
+  {                    1u,                    0u,         208910811136u },
+  {  7740175894281560509u, 16801499925276664441u,         228568794576u },
+  { 15670495392425593226u, 10492407990787637083u,         183416000228u },
+  { 15152257626756992778u,  7673849751013230268u,          67327793591u },
+  {  4090073428152440422u,  6046724489853072366u,         153201875267u },
+  { 14450327772834205584u,  3723941391207507902u,          67913121689u },
+  {  4466091895542494216u, 16844122108860347658u,         217575820867u },
+  { 10454115378553795377u, 10622020182694668026u,         116473861337u },
+  {  2267817233475657788u,  8741198820686854861u,          46371636340u },
+  {  5500455702636497521u,  6855480461211306806u,          73542410542u },
+  { 15178768299492252549u, 10005708458011566303u,         208484209737u },
+  {  7062359872332045590u,  8932093106442919060u,         148491293392u },
+  { 12297347290027942576u,  9062763476260756742u,          18740779924u },
+  {  8030124596941085588u, 13664977682032775520u,         187058465554u },
+  {  6526656990996654843u,  1078499125430623452u,         122355324859u },
+  {  6254287345256979850u,  6554586738078431160u,         104660133498u },
+  {  6642007136244870032u, 12177313698643242882u,         226900704872u },
+  {  2027592955437164718u, 16615072271904633952u,         243887712482u },
+  {   942718349157325567u, 16375404983106569284u,           9734669043u },
+  { 14617066671884002278u, 13552251831473522728u,         156451597321u },
+  {  6831631114396133348u,  8330500218412111873u,           4381874332u },
+  { 14603040013386939258u,  7044338079053294003u,         142145762820u },
+  {  9906106765319401103u,  2688849443046530183u,         125046400654u },
+  {  1396179595609933063u,   855940991879596844u,         239398138749u },
+  { 11524884268464976417u,  7344363609485825661u,          23628981487u },
+  {   382929570730827274u, 11602660525134634991u,            397444631u },
+  {  6109721884461301381u,  7331559403129590068u,                    0u },
+  {  2390514825000339691u,           7331559403u,                    0u },
+  {  6116191454763441755u,                    7u,                    0u },
+  {                    1u,                    0u,          42918608896u },
+  { 11598868771099176310u, 16945343208344873834u,         156521392426u },
+  { 14449966445520085105u,  9617992661337889144u,         126990979484u },
+  { 11675595287405614726u, 18280344933262742087u,         234280807038u },
+  { 15860796398550489897u,  5179975582362777794u,         174097519594u },
+  { 16180408435245829662u,  1798918997870037129u,         194343023534u },
+  { 13756992797154950706u,  6327667344756325882u,         104996399554u },
+  {  8830551328786758466u, 18380327574124007700u,          78976619368u },
+  { 16699955256560951264u, 18015447557304295288u,          35559209294u },
+  { 10038983627153402074u, 10315590748073249877u,         219417304867u },
+  { 15085100736692127346u,  7697916092577993381u,         245169359579u },
+  { 10007783780289711125u,  3124132817942110722u,         197403769845u },
+  { 17596907048353602192u,  7448238998520507048u,         163753131461u },
+  { 13530650344896573509u, 13892823322374205296u,         247598595491u },
+  {  6337724853398437005u, 11042137840046332563u,         246569963255u },
+  { 12768885008904063297u, 10513966307445593803u,         254508948214u },
+  {  2759773619512884114u,  9388437460943526957u,         148594534654u },
+  {  8434364600126655292u, 10967228614677896227u,          65125279380u },
+  {  3843827521199949338u,  2310996671540235541u,          19270460225u },
+  {  4661660852957808994u,  4989110555003898586u,         155882077203u },
+  { 15298044134177324417u, 16271452421983657678u,         194516251547u },
+  {  7747773274913338217u,  9523160181437090472u,          80712196546u },
+  { 10348785912020632966u, 13137707423765072249u,         224913270096u },
+  {  4175372293197190170u, 16846859744221860704u,         236421057504u },
+  { 11326064156813083145u,  7767140033449795568u,           4930758124u },
+  {  8100407170505981763u, 17169456915721160016u,         190931378436u },
+  {  1706556116319916846u, 17180899661833327818u,                26046u },
+  { 15028897280749641942u,      480481077043500u,                    0u },
+  {  1421201742071739121u,               480481u,                    0u },
+  {                    1u,                    0u,          41952608256u },
+  {  8480737406125178272u, 17572520700934791415u,         121974090537u },
+  { 10947205650755620361u, 17968798858233825416u,         176831497593u },
+  {   868577942165647781u, 15338423313945305608u,         226970107312u },
+  { 16017710019091388479u, 17895321323836726300u,         247044130786u },
+  {  6610879150827623375u,   814069333008965772u,         208390330615u },
+  { 12110095866223762092u,  7200328959852723946u,          20041193424u },
+  {  7756802952949470775u,   759884557248133772u,           3726966548u },
+  {  2941800790804618759u, 13410165861863974850u,          40340355587u },
+  { 11703600274199927522u,  6278452420856351569u,         212491800360u },
+  {   806737539257940346u,  9072115382556676441u,          91149396692u },
+  { 14579028397110132023u,  2755882551854926562u,          93460573019u },
+  { 14247808875344366934u,  8496072611504649268u,         205223454557u },
+  {  9713379923695279513u,  4122009033579215814u,          61554147533u },
+  {  2246428675703313877u, 10222217724450527220u,         233111918909u },
+  {  3549783776592680620u,  2064539481554006324u,          74430190057u },
+  { 12645029747929213033u,  7935605886598063692u,          51423117898u },
+  { 16279009267476580506u,  7805147585347548428u,          18309486643u },
+  {   343358782242907186u,  5709020905457661272u,          60881313810u },
+  { 10077054739085890321u, 16257370307404906673u,         207811593532u },
+  { 10526715404712173586u, 14971258192939373645u,          41061441999u },
+  { 11438715865125144243u,  1133404845901376389u,          82512872489u },
+  {  5040916178827294801u,  9460827548162822046u,         204069058130u },
+  { 16643761637275849508u,  1273897659779791345u,         202424641996u },
+  {  4852542977279030386u,  7833262224435092782u,          70164442058u },
+  {  7883373066544387129u,  3033420566713364586u,         110817242694u },
+  { 16699064314768500978u, 15075466825360349102u,           1707011694u },
+  {  6805863634444817214u, 13042063791413317777u,                    1u },
+  {  2266540253968903500u,          31488807865u,                    0u },
+  {  9016913589137908810u,                   31u,                    0u },
+  {                    1u,                    0u,         222134665216u },
+  { 11654451024602552034u,  2484134775182816689u,          93997495262u },
+  {  5299013208454526793u, 18400539815335991276u,         221026318685u },
+  { 14918550373926182540u,   485494064952118285u,          88952853725u },
+  {  6225552657491071054u, 17577048805241314890u,          76155254872u },
+  { 10344713496596235785u,  2863946907557583806u,         236707187532u },
+  { 12972405634433280209u, 13045307417786230799u,         139652260844u },
+  { 12911885282402784945u, 12032088871615097765u,          26479692427u },
+  {  6934311832970995868u,  8848763446997690579u,          33543797274u },
+  {  9975729197003430461u, 10031289150307672683u,         230628415265u },
+  {  1982857556803548935u, 11592215575498656562u,          62861639142u },
+  {  2095735223386298223u, 15894436747956898387u,         232113382974u },
+  {  7110931538347639365u,  2091546719588500922u,          52317877736u },
+  { 15822183724630969535u,  5863809244813756108u,         220612737332u },
+  { 16931982690156327501u, 11303008753675411244u,         166717656540u },
+  {  6740069226761666110u, 13238426537506910531u,          32935582886u },
+  {  3138792961008474902u, 17258458071023005564u,          81454591520u },
+  { 12154594426971851390u,  8385733444777075178u,          58516663377u },
+  { 15780127219221910902u,  9530757096163247299u,         157781872442u },
+  { 16421541930960194381u, 14423000845391072216u,         196593770909u },
+  {  7485894627196740576u, 10953140011159884310u,         186662899652u },
+  {  8897269432694476707u, 12228340237948264126u,          75611443130u },
+  { 17189823634941678805u, 11279134946966259188u,         173793641291u },
+  {  9585582064286255216u, 14640097792684582650u,         181337854381u },
+  { 12835472279575022097u,  6232313315128656727u,          24874740917u },
+  {  6776016669542754608u, 16136121832933322087u,          54817204760u },
+  { 18340015775620871027u, 15074767079673358270u,         254718431542u },
+  {  5254188752292365830u, 13252722804829281907u,               111870u },
+  {  6798802596750151183u,     2063650512248692u,                    0u },
+  {  9449320530215272000u,              2063650u,                    0u },
+  {                    1u,                    0u,         121419595776u },
+  { 17110720482574968811u,  7740175894281560508u,          91849499257u },
+  { 16172441693558688213u, 15670495392425593225u,         188821405531u },
+  {  6234654946353717320u, 15152257626756992777u,         238221723324u },
+  { 11180283100679445438u,  4090073428152440421u,         190783353838u },
+  { 14852260031176961272u, 14450327772834205583u,          10242107326u },
+  {  4481533167346438750u,  4466091895542494215u,         250566718730u },
+  {  4269718344362365664u, 10454115378553795376u,         205122938618u },
+  { 11520029752381101466u,  2267817233475657787u,          54298180301u },
+  { 16778682550309368417u,  5500455702636497520u,         223822842678u },
+  {  9687587467301363608u, 15178768299492252548u,         148382851295u },
+  { 10093971076828497318u,  7062359872332045589u,           6666640532u },
+  {  1913763026490934696u, 12297347290027942575u,          96435313926u },
+  { 12701450127613557000u,  8030124596941085587u,         220353810784u },
+  {  8974572160711134644u,  6526656990996654842u,         184339045596u },
+  {  9890000077336694124u,  6254287345256979849u,         130360063928u },
+  {  4292326716201059148u,  6642007136244870031u,          96109916034u },
+  { 14644519175104337420u,  2027592955437164717u,          68051104864u },
+  {  5051178622270136798u,   942718349157325566u,          40792392772u },
+  {   675983118348065839u, 14617066671884002277u,           1370343464u },
+  {  4431647660065117244u,  6831631114396133347u,         179791632385u },
+  {  8316115180008411962u, 14603040013386939257u,         135537011123u },
+  {  9621158095544965602u,  9906106765319401102u,          44075687047u },
+  { 15283478958951102072u,  1396179595609933062u,         125624765228u },
+  { 13981553073094447813u, 11524884268464976416u,         239020758653u },
+  {  4558368743929911607u,   382929570730827273u,          52331208687u },
+  { 15217004469858477791u,  6109721884461301380u,         235129590068u },
+  { 11589190369996515737u,  2390514825000339690u,           7331559403u },
+  {  3670624237398152929u,  6116191454763441754u,                    7u },
+  { 13471713758418039777u,         135243399970u,                    0u },
+  {  4489936967610296411u,                  135u,                    0u },
+  {                    1u,                    0u,         106628775936u },
+  {  9052049303222747950u, 11598868771099176309u,         120783334250u },
+  {  1011330006193020538u, 14449966445520085104u,          71632935288u },
+  { 17412075644359478612u, 11675595287405614725u,         194859815495u },
+  {  6358678384745980468u, 15860796398550489896u,         137877141698u },
+  { 15262353928842850919u, 16180408435245829661u,         250745768073u },
+  { 11145257686438581736u, 13756992797154950705u,          20478705146u },
+  {  1600562031807691890u,  8830551328786758465u,         120905306388u },
+  {  6775147337046626724u, 16699955256560951263u,          85544214392u },
+  { 15772127322106297822u, 10038983627153402073u,         165817764949u },
+  {  4141472200527441474u, 15085100736692127345u,           2542523045u },
+  { 18246007807879281267u, 10007783780289711124u,         168953930242u },
+  {   960746958654787123u, 17596907048353602191u,         112733498024u },
+  { 11355981212264408477u, 13530650344896573508u,         147343568752u },
+  {  1573078209576251481u,  6337724853398437004u,         203692202643u },
+  {  6245294478780491367u, 12768885008904063296u,          45149607627u },
+  {  7523292955659721510u,  2759773619512884113u,          35457227821u },
+  { 14454736751015226505u,  8434364600126655291u,          21208374307u },
+  {  7219786377781411316u,  3843827521199949337u,         218252709141u },
+  { 10597123082209392431u,  4661660852957808993u,         206829308634u },
+  {  6922353544343010714u, 15298044134177324416u,         168420007630u },
+  { 14317523356293377430u,  7747773274913338216u,         121561008808u },
+  {  4057766168681892717u, 10348785912020632965u,          96226347385u },
+  { 15214083611901244045u,  4175372293197190169u,         240613987168u },
+  {  8390569016883950721u, 11326064156813083144u,          80439123952u },
+  { 10680472538208175055u,  8100407170505981762u,         202092512592u },
+  { 12173567833130544927u,  1706556116319916845u,          44814718154u },
+  {  1386341248286610026u, 15028897280749641941u,         225077043500u },
+  { 12487300952797237352u,  1421201742071739120u,               480481u },
+  {  2614759871804869720u,     8863311460481781u,                    0u },
+  {  8494389567327729477u,              8863311u,                    0u },
+  {                    1u,                    0u,         247459741696u },
+  {  6260469580539185878u,  8480737406125178271u,         136593449207u },
+  { 17818573101084525841u, 10947205650755620360u,           8047085704u },
+  {  2201029069927307150u,   868577942165647780u,          28868321800u },
+  { 10397997613804897039u, 16017710019091388478u,         140358376476u },
+  { 14269915965770103741u,  6610879150827623374u,         234656489612u },
+  { 16776139909196366727u, 12110095866223762091u,         140420497130u },
+  {  6246513436385199720u,  7756802952949470774u,         194159475340u },
+  {  2926026498821554288u,  2941800790804618758u,          81634453442u },
+  { 15725499391028340982u, 11703600274199927521u,          89043733329u },
+  {  8576577277771450827u,   806737539257940345u,         226790330713u },
+  { 15523351176022259335u, 14579028397110132022u,          52772375266u },
+  {  4775158829429176134u, 14247808875344366933u,         198526563380u },
+  { 10141817222123532462u,  9713379923695279512u,         244121779142u },
+  { 12847658900242624586u,  2246428675703313876u,          52192434164u },
+  { 13708197964460514655u,  3549783776592680619u,          76685488436u },
+  {  1951540006613246932u, 12645029747929213032u,          12882486860u },
+  {  9979297327280092199u, 16279009267476580505u,          88018613516u },
+  { 15381307706282553684u,   343358782242907185u,         177546278232u },
+  { 10037428657543061177u, 10077054739085890320u,          77570654385u },
+  {  2584877324547208668u, 10526715404712173585u,         133620094029u },
+  {  1126624732730703576u, 11438715865125144242u,         158273268613u },
+  {  1501064139624981020u,  5040916178827294800u,         241902260126u },
+  {  5219661484955306109u, 16643761637275849507u,          46263056881u },
+  {  5336997298570282212u,  4852542977279030385u,         106427358510u },
+  { 12191131175733833362u,  7883373066544387128u,         174905258090u },
+  {  3707068178994436536u, 16699064314768500977u,         145368946606u },
+  {  5045484691732942022u,  6805863634444817213u,         185122869393u },
+  { 14847900542908711232u,  2266540253968903499u,          31488807865u },
+  {  9097257915916965135u,  9016913589137908809u,                   31u },
+  {  2472027983230314217u,         580865979874u,                    0u },
+  { 15974509111133272205u,                  580u,                    0u },
+  {                    1u,                    0u,         177631789056u },
+  { 12099486841948187399u, 11654451024602552033u,         236287260081u },
+  {  5319910566029976328u,  5299013208454526792u,          13808736236u },
+  { 11549214421017285864u, 14918550373926182539u,          74337487885u },
+  {  1998791413186046700u,  6225552657491071053u,         190560788042u },
+  { 17075171930090011210u, 10344713496596235784u,          15703235518u },
+  { 15158296003813501474u, 12972405634433280208u,         165699954703u },
+  {  1360083178079384115u, 12911885282402784944u,         211375909797u },
+  {  6167980558592741158u,  6934311832970995867u,         107540785363u },
+  {  3630180428124865653u,  9975729197003430460u,          50107490923u },
+  {  2276550099763657677u,  1982857556803548934u,          83113610034u },
+  {   407006713016100655u,  2095735223386298222u,         186385484371u },
+  { 14242579061653496002u,  7110931538347639364u,         204857722298u },
+  { 17944493332678643704u, 15822183724630969534u,          44917884620u },
+  {   987185901870869452u, 16931982690156327500u,          67365379884u },
+  {  5578665155415167745u,  6740069226761666109u,         124170154307u },
+  {  4849210377429577536u,  3138792961008474901u,         234658901884u },
+  { 10811995403388891862u, 12154594426971851389u,         195855442410u },
+  {  7051931074990177294u, 15780127219221910901u,         216890213571u },
+  {  2030832259446664275u, 16421541930960194380u,          22405811160u },
+  {  6069512651054767896u,  7485894627196740575u,         190482321942u },
+  { 10608701253763958799u,  8897269432694476706u,         244931862206u },
+  { 15700053443426906717u, 17189823634941678804u,         250519635444u },
+  { 17759719234725541222u,  9585582064286255215u,          87695812346u },
+  { 15187321568916405210u, 12835472279575022096u,         103367328599u },
+  { 11040156458113129594u,  6776016669542754607u,         190994214247u },
+  {  2800727824598008497u, 18340015775620871026u,         115284830142u },
+  {  2997236166375604479u,  5254188752292365829u,         116368563827u },
+  {  6260091886451512841u,  6798802596750151182u,          34512248692u },
+  { 17573059315228347474u,  9449320530215271999u,              2063650u },
+  {  7519453664590169251u,    38067632857031246u,                    0u },
+  { 15809436065653866529u,             38067632u,                    0u },
+  {                    1u,                    0u,         188927574016u },
+  {   228921437623588922u, 17110720482574968810u,         137876709820u },
+  {  2195862230003073884u, 16172441693558688212u,           9337981321u },
+  {   960207412233973688u,  6234654946353717319u,         101606084361u },
+  {  2464387149230492479u, 11180283100679445437u,         143805142629u },
+  {  3631866936444955213u, 14852260031176961271u,           7242944399u },
+  {  1578304441149380227u,  4481533167346438749u,          48231461895u },
+  { 18190538519673445181u,  4269718344362365663u,          59624502064u },
+  {  1271000736479934749u, 11520029752381101465u,         112909574203u },
+  { 18292963032817745634u, 16778682550309368416u,         132525165168u },
+  { 17168014021925537455u,  9687587467301363607u,          21547195268u },
+  { 18046757712870378949u, 10093971076828497317u,         175103745301u },
+  { 14857998893911743220u,  1913763026490934695u,         147688546991u },
+  { 11933607369968684575u, 12701450127613556999u,         250486512531u },
+  {  3483798509902859162u,  8974572160711134643u,         137536137978u },
+  {  7378828438829845831u,  9890000077336694123u,         143232687497u },
+  { 15791137430347699565u,  4292326716201059147u,         173793880975u },
+  { 17044141236829932641u, 14644519175104337419u,         254273824941u },
+  {  9075651910862456484u,  5051178622270136797u,         229036645118u },
+  { 17811207355884564095u,   675983118348065838u,         227240240101u },
+  {  4438638126207305937u,  4431647660065117243u,         121450817507u },
+  { 12507972635512950185u,  8316115180008411961u,         142521564025u },
+  { 14658269128098109408u,  9621158095544965601u,           6828519054u },
+  {  3642436268910286111u, 15283478958951102071u,          32757941510u },
+  {  3783099432964819561u, 13981553073094447812u,           9247109664u },
+  {  9497579866027539638u,  4558368743929911606u,         132824915465u },
+  {  3395179445046271361u, 15217004469858477790u,         234628251268u },
+  {  5938502732309497276u, 11589190369996515736u,          90198984938u },
+  {  5793671185917606255u,  3670624237398152928u,          34730303066u },
+  {   889272970253526588u, 13471713758418039776u,         135243399970u },
+  {  8594177504370135501u,  4489936967610296410u,                  135u },
+  {  7374354721120724712u,        2494800386918u,                    0u },
+  { 14764532643665507567u,                 2494u,                    0u },
+  {                    1u,                    0u,         117490712576u },
+  {  5392404173658087695u,  9052049303222747949u,         112054824309u },
+  {  4976586473237854316u,  1011330006193020537u,         133943910512u },
+  {  6308932742419013569u, 17412075644359478611u,          40344704645u },
+  {  4831846642430703059u,  6358678384745980467u,          29827373864u },
+  { 18139507855949846901u, 15262353928842850918u,          49604185629u },
+  {  4865833876326628410u, 11145257686438581735u,          65086766641u },
+  { 14296661839130179261u,  1600562031807691889u,         223367281473u },
+  {  9254773150378118248u,  6775147337046626723u,         217855008735u },
+  { 12174712433727875143u, 15772127322106297821u,         113224509657u },
+  {   705653145340915199u,  4141472200527441473u,          20989118065u },
+  { 17763928858962481812u, 18246007807879281266u,         143052082196u },
+  {  3982836567612046296u,   960746958654787122u,          68615608975u },
+  { 12730849277561967739u, 11355981212264408476u,         140085276740u },
+  { 17314488764367235908u,  1573078209576251480u,          64338558092u },
+  { 15951418930590301119u,  6245294478780491366u,         145407838528u },
+  {  7193356087283467261u,  7523292955659721509u,          59783592849u },
+  { 17592945625696089446u, 14454736751015226504u,          25391385403u },
+  {  3554461664875361428u,  7219786377781411315u,          97574471193u },
+  {  2213779057785318208u, 10597123082209392430u,         128375261537u },
+  {  3880940796082421148u,  6922353544343010713u,         104776154496u },
+  {  4528237545358141043u, 14317523356293377429u,         133219971944u },
+  { 11681196539088147363u,  4057766168681892716u,          25824757125u },
+  {  9835005502912643017u, 15214083611901244044u,           8454853657u },
+  {  4964088126040986696u,  8390569016883950720u,          66578989576u },
+  {  3355564873147047622u, 10680472538208175054u,          45659930434u },
+  {  1853093467828272927u, 12173567833130544926u,         213075153709u },
+  { 14755341584803008677u,  1386341248286610025u,         240676937941u },
+  {  4701571132542556621u, 12487300952797237351u,         245141746416u },
+  {  6128849686644853851u,  2614759871804869719u,          79460481781u },
+  { 12026867901170202094u,  8494389567327729476u,              8863311u },
+  { 17909760324981426303u,   163499238157084246u,                    0u },
+  {  2897692901883393664u,            163499238u,                    0u },
+  {                    1u,                    0u,         159339380736u },
+  { 12323704802554838154u,  6260469580539185877u,           8965946783u },
+  {  7135886931147821732u, 17818573101084525840u,         164119318024u },
+  { 15341283120292884947u,  2201029069927307149u,          62563676580u },
+  {  3092789040392634166u, 10397997613804897038u,         206773573694u },
+  {  8811761390822097865u, 14269915965770103740u,         171909436366u },
+  { 16870860798610218169u, 16776139909196366726u,          54338624171u },
+  { 17452041453591904833u,  6246513436385199719u,           6158620214u },
+  { 10314783684009874908u,  2926026498821554287u,         225852481030u },
+  {  4932636630789274903u, 15725499391028340981u,         121464937185u },
+  { 18143884346082124480u,  8576577277771450826u,          54841522553u },
+  {  2823209155405527322u, 15523351176022259334u,          85258861878u },
+  { 16195396106620226251u,  4775158829429176133u,         152549789013u },
+  {  1150544491807648944u, 10141817222123532461u,         212696472984u },
+  {  7767455475523884824u, 12847658900242624585u,         171743122900u },
+  { 15204378045683991808u, 13708197964460514654u,         104105793195u },
+  { 17239732561718805622u,  1951540006613246931u,         153540978792u },
+  { 12886430624522800062u,  9979297327280092198u,          49833822361u },
+  { 18162250541178258136u, 15381307706282553683u,          16544130097u },
+  { 17028935366700158084u, 10037428657543061176u,          17140126480u },
+  { 16075467823964198637u,  2584877324547208667u,         178061074449u },
+  {  9803858825574498304u,  1126624732730703575u,          80081372850u },
+  { 17464070808143041817u,  1501064139624981019u,          35282958416u },
+  { 17682703471239266776u,  5219661484955306108u,         113289319203u },
+  { 18147688354161351336u,  5336997298570282211u,          56660882545u },
+  {  6663423873348080051u, 12191131175733833361u,         241200960568u },
+  {  9417270363716235133u,  3707068178994436535u,          61273516273u },
+  {  9295013721571344179u,  5045484691732942021u,          75804906301u },
+  {  6199479138350037783u, 14847900542908711231u,          73493163339u },
+  {   887603005365085688u,  9097257915916965134u,         226134008905u },
+  {   333989628642975696u,  2472027983230314216u,          68865979874u },
+  {  4620735991403939439u, 15974509111133272204u,                  580u },
+  { 12418523063962801201u,       10715086071862u,                    0u },
+  {  1587745622680169419u,                10715u,                    0u },
+  {                    1u,                    0u,         225655914496u },
+  { 10968905082284365638u, 12099486841948187398u,          72288392929u },
+  { 14076907092801977812u,  5319910566029976327u,         139626084168u },
+  {  3438322122816124202u, 11549214421017285863u,          77108354699u },
+  { 14645413324829073676u,  1998791413186046699u,           8925646925u },
+  { 12271281439492289999u, 17075171930090011209u,         208821732872u },
+  {  6233751789862708246u, 15158296003813501473u,         176073730256u },
+  {  1962644459455827991u,  1360083178079384114u,         155334366896u },
+  {  8726934184642952500u,  6167980558592741157u,          60196792475u },
+  {  4531087719737475147u,  3630180428124865652u,           6123412028u },
+  {   481513520412720775u,  2276550099763657676u,         110022063878u },
+  {   992149349835802669u,   407006713016100654u,          68772091758u },
+  { 11165474436676191361u, 14242579061653496001u,         190972772932u },
+  { 10240785855143707184u, 17944493332678643703u,          76053515454u },
+  { 10059329918238932466u,   987185901870869451u,          61302420044u },
+  { 14791716450947031886u,  5578665155415167744u,          21262876221u },
+  { 15378882314737417403u,  4849210377429577535u,         125586119445u },
+  { 14726970229242271128u, 10811995403388891861u,         117382285949u },
+  {  5090110549507128156u,  7051931074990177293u,          76110091637u },
+  { 17185220781106503841u,  2030832259446664274u,         223329028940u },
+  {  9858517691519529306u,  6069512651054767895u,         162575098847u },
+  {  5595905546638020703u, 10608701253763958798u,         212851101602u },
+  { 15555173226968030256u, 15700053443426906716u,         111962756308u },
+  { 10745236628845355771u, 17759719234725541221u,          16823306351u },
+  {  9973314042399760760u, 15187321568916405209u,          47598488080u },
+  {  4374506813558796576u, 11040156458113129593u,         114151827759u },
+  { 15960826480426749933u,  2800727824598008496u,           5162480498u },
+  {  9636454862798615738u,  2997236166375604478u,          14339360261u },
+  { 17973331528911319269u,  6260091886451512840u,          63952637454u },
+  {  7366495200039369602u, 17573059315228347473u,          78407630399u },
+  { 10505831326526933399u,  7519453664590169250u,         176857031246u },
+  {  2803218632575724145u, 15809436065653866528u,             38067632u },
+  {  8425731874431741636u,   702223880805592151u,                    0u },
+  { 14860552245711912111u,            702223880u,                    0u },
+  {                    1u,                    0u,         234012409856u },
+  {  6993664200669526994u,   228921437623588921u,         212119037930u },
+  {  4065363582031999356u,  2195862230003073883u,          71052052948u },
+  {  6899780515342669867u,   960207412233973687u,         189133594695u },
+  { 17713500890201844939u,  2464387149230492478u,         247196883901u },
+  {  6445781125105107086u,  3631866936444955212u,          93085560055u },
+  { 13563044070717478571u,  1578304441149380226u,         223986111069u },
+  { 13167612994149348885u, 18190538519673445180u,         153068901087u },
+  {  5505463469596727288u,  1271000736479934748u,          96991663513u },
+  { 12125446212518819372u, 18292963032817745633u,         151930679904u },
+  { 12537707724735421794u, 17168014021925537454u,         165978316695u },
+  { 15173675086703777069u, 18046757712870378948u,         167805453733u },
+  { 13535510174093048476u, 14857998893911743219u,           7646922151u },
+  { 10698912997087096629u, 11933607369968684574u,         179188857095u },
+  { 16952559548431933861u,  3483798509902859161u,         107400007091u },
+  { 13528255827744249993u,  7378828438829845830u,          75856039275u },
+  { 14122167436324771955u, 15791137430347699564u,          11923964747u },
+  { 13071007137740038297u, 17044141236829932640u,         221491992075u },
+  { 13011887609328904025u,  9075651910862456483u,          46965547485u },
+  {  3116434332871336590u, 17811207355884564094u,          59240619054u },
+  {  9050993820536772770u,  4438638126207305936u,          57678058555u },
+  { 11993719123438634238u, 12507972635512950184u,         225794626361u },
+  {  1414857165879849301u, 14658269128098109407u,         119197456865u },
+  { 13819438220812375094u,  3642436268910286110u,         196205082231u },
+  {  6073063033888264440u,  3783099432964819560u,          54514864836u },
+  {  6828883869150720294u,  9497579866027539637u,         222184053046u },
+  {  4548265621068768345u,  3395179445046271360u,         152321926878u },
+  { 10422524923581371874u,  5938502732309497275u,         224314075544u },
+  {  1858996082510682634u,  5793671185917606254u,         224048207584u },
+  {   890276727450878316u,   889272970253526587u,          90465891296u },
+  {  3886008133802710905u,  8594177504370135500u,         102399764570u },
+  {   612074409233016757u,  7374354721120724711u,         190800386918u },
+  {  3927020336901729264u, 14764532643665507566u,                 2494u },
+  {  5298603480094474942u,       46020944252475u,                    0u },
+  { 17418383752590430025u,                46020u,                    0u },
+  {                    1u,                    0u,          45292322816u },
+  {  8973799690601597929u,  5392404173658087694u,         121269781293u },
+  {  1343055462055792431u,  4976586473237854315u,          83342007929u },
+  { 17425118728683169659u,  6308932742419013568u,          51261934931u },
+  { 18389781726026675967u,  4831846642430703058u,         102983344691u },
+  {   272526939565961561u, 18139507855949846900u,         231263777382u },
+  { 11293026845930963228u,  4865833876326628409u,         113775023591u },
+  { 13997416438903902597u, 14296661839130179260u,         163501702257u },
+  {  6186605805999441184u,  9254773150378118247u,         221659992483u },
+  {  4401776373281836138u, 12174712433727875142u,          65038253533u },
+  { 16338917089754547008u,   705653145340915198u,         114962984513u },
+  { 13337700757935003056u, 17763928858962481811u,          50215910002u },
+  { 14612496890816348693u,  3982836567612046295u,         156690140722u },
+  {  3219935399907691719u, 12730849277561967738u,          88938620316u },
+  { 10887238730052330387u, 17314488764367235907u,         102864728152u },
+  {   360256418697768294u, 15951418930590301118u,          37389952614u },
+  {   321440824631118565u,  7193356087283467260u,         136953715493u },
+  { 10069228080701402580u, 17592945625696089445u,         243192687752u },
+  {  9428069607611622975u,  3554461664875361427u,          46120009203u },
+  { 14736799017468812344u,  2213779057785318207u,         153210386222u },
+  { 10875332567307979280u,  3880940796082421147u,         149245476249u },
+  {  4611492910339012807u,  4528237545358141042u,         108633238933u },
+  { 10743508637597314786u, 11681196539088147362u,         140533156716u },
+  {  9356196315668016028u,  9835005502912643016u,         128269103756u },
+  { 15755598617722189347u,  4964088126040986695u,         206181905536u },
+  {  1275276394173375542u,  3355564873147047621u,          30100456398u },
+  { 12644999363867216251u,  1853093467828272926u,         105799888670u },
+  {  4553830511509832021u, 14755341584803008676u,         103254872681u },
+  {  8869400642218174412u,  4701571132542556620u,          87332245607u },
+  { 16570849151159054040u,  6128849686644853850u,          68651977815u },
+  { 16127119334101797673u, 12026867901170202093u,          86970890052u },
+  {  9686867250420930550u, 17909760324981426302u,         230157084246u },
+  { 10678226869774428035u,  2897692901883393663u,            163499238u },
+  {  7767227962910162068u,  3016028602530220424u,                    0u },
+  {  9780840471948993674u,           3016028602u,                    0u },
+  {                    1u,                    0u,         213668069376u },
+  {  6288709332106746357u, 12323704802554838153u,          16386837205u },
+  {  9066785620141948673u,  7135886931147821731u,         141831652624u },
+  {  8442375916704414909u, 15341283120292884946u,          14167660429u },
+  { 11604629218100425803u,  3092789040392634165u,         188477686542u },
+  {  3877248044010875762u,  8811761390822097864u,         134914571196u },
+  { 16435137704395217283u, 16870860798610218168u,         103946077062u },
+  { 14994442577577813271u, 17452041453591904832u,         111559165543u },
+  {  4410105917142436089u, 10314783684009874907u,         245267398767u },
+  {  4632574728444936970u,  4932636630789274902u,         202983581941u },
+  {  9117147535650050359u, 18143884346082124479u,         134153046474u },
+  {   588939301256904809u,  2823209155405527321u,          69877954182u },
+  {   324393982565305683u, 16195396106620226250u,         173062371141u },
+  {  9380909186923521175u,  1150544491807648943u,          73421074605u },
+  {  4463385697777230217u,  7767455475523884823u,          94824230985u },
+  { 16378985502426333808u, 15204378045683991807u,         211934567774u },
+  { 18210894922387834354u, 17239732561718805621u,          38698574803u },
+  {  1555748035329493205u, 12886430624522800061u,          83984577574u },
+  {  4277055533891898507u, 18162250541178258135u,         184923140435u },
+  { 11574429772510874408u, 17028935366700158083u,         219871452856u },
+  { 17391099253493808815u, 16075467823964198636u,         215531468251u },
+  {  5791212393959129882u,  9803858825574498303u,          27946729175u },
+  { 11254268231455680880u, 17464070808143041816u,         124958581275u },
+  { 16355477587312235322u, 17682703471239266775u,         227983788156u },
+  {  2411485149249320633u, 18147688354161351335u,         145361224931u },
+  { 12763114642070638360u,  6663423873348080050u,         183510511249u },
+  {  1147543073987366419u,  9417270363716235132u,         197503883703u },
+  {  8410777835225272692u,  9295013721571344178u,          63336074437u },
+  {  8134725822306818018u,  6199479138350037782u,          14048117055u },
+  {  8899607004752328377u,   887603005365085687u,         232018105614u },
+  {   690976506652396830u,   333989628642975695u,         140250490600u },
+  { 12281570945595192074u,  4620735991403939438u,          54673209484u },
+  { 12592957291365552899u, 12418523063962801200u,         219086071862u },
+  { 13595807339013970272u,  1587745622680169418u,                10715u },
+  {  9698096389749839992u,      197658450495420u,                    0u },
+  {  8310173728816391804u,               197658u,                    0u },
+};
+
+inline constexpr int __TABLE_SIZE_2 = 69;
+inline constexpr int __ADDITIONAL_BITS_2 = 120;
+
+inline constexpr uint16_t __POW10_OFFSET_2[__TABLE_SIZE_2] = {
+     0,    2,    6,   12,   20,   29,   40,   52,   66,   80,
+    95,  112,  130,  150,  170,  192,  215,  240,  265,  292,
+   320,  350,  381,  413,  446,  480,  516,  552,  590,  629,
+   670,  712,  755,  799,  845,  892,  940,  989, 1040, 1092,
+  1145, 1199, 1254, 1311, 1369, 1428, 1488, 1550, 1613, 1678,
+  1743, 1810, 1878, 1947, 2017, 2088, 2161, 2235, 2311, 2387,
+  2465, 2544, 2625, 2706, 2789, 2873, 2959, 3046, 3133
+};
+
+inline constexpr uint8_t __MIN_BLOCK_2[__TABLE_SIZE_2] = {
+     0,    0,    0,    0,    0,    0,    1,    1,    2,    3,
+     3,    4,    4,    5,    5,    6,    6,    7,    7,    8,
+     8,    9,    9,   10,   11,   11,   12,   12,   13,   13,
+    14,   14,   15,   15,   16,   16,   17,   17,   18,   19,
+    19,   20,   20,   21,   21,   22,   22,   23,   23,   24,
+    24,   25,   26,   26,   27,   27,   28,   28,   29,   29,
+    30,   30,   31,   31,   32,   32,   33,   34,    0
+};
+
+inline constexpr uint64_t __POW10_SPLIT_2[3133][3] = {
+  {                    0u,                    0u,              3906250u },
+  {                    0u,                    0u,         202000000000u },
+  {                    0u, 11153727427136454656u,                   59u },
+  {                    0u,  7205759403792793600u,          59604644775u },
+  {                    0u,                    0u,         167390625000u },
+  {                    0u,                    0u,         232000000000u },
+  {                    0u,    16777216000000000u,                    0u },
+  {                    0u, 12945425605062557696u,               909494u },
+  {                    0u,  4388757836872548352u,         182701772928u },
+  {                    0u,  1152921504606846976u,         128237915039u },
+  {                    0u,                    0u,         159062500000u },
+  {                    0u,                    0u,         160000000000u },
+  {                    0u,         256000000000u,                    0u },
+  {                    0u, 16192327041775828992u,                   13u },
+  {                    0u, 15024075324038053888u,          13877787807u },
+  {                    0u,  5449091666327633920u,         159814456755u },
+  {                    0u,  2494994193563254784u,         179295395851u },
+  {                    0u,  4611686018427387904u,          11135253906u },
+  {                    0u,                    0u,         146250000000u },
+  {                    0u,                    0u,         128000000000u },
+  {                    0u,              3906250u,                    0u },
+  {                    0u,     3906250000000000u,                    0u },
+  {                    0u,  4368439412768899072u,               211758u },
+  {                    0u,  1563676642168012800u,          46236813575u },
+  {                    0u, 11532349341402398720u,           7084767080u },
+  {                    0u,  9048364970084925440u,         104625169910u },
+  {                    0u, 16609275425742389248u,         246490512847u },
+  {                    0u,                    0u,         207900390625u },
+  {                    0u,                    0u,         225000000000u },
+  { 11153727427136454656u,                   59u,                    0u },
+  {  7205759403792793600u,          59604644775u,                    0u },
+  {                    0u,  4264412554261970152u,                    3u },
+  {                    0u, 14485570586272534528u,           3231174267u },
+  {                    0u, 17827675094632103936u,         123785264354u },
+  {                    0u,  7347197909193981952u,         226966440203u },
+  {                    0u, 13677404030777688064u,          11398292396u },
+  {                    0u,  3810326759732150272u,         172741453558u },
+  {                    0u,  9943947977234055168u,         246206558227u },
+  {                    0u,                    0u,          19539062500u },
+  {                    0u,                    0u,         228000000000u },
+  { 12945425605062557696u,               909494u,                    0u },
+  {  4388757836872548352u,      909494701772928u,                    0u },
+  {  1152921504606846976u, 14878706826214591391u,                49303u },
+  {                    0u,  4387341015746028192u,         151806576313u },
+  {                    0u,   651726680428265472u,         185237838233u },
+  {                    0u,  2570638187944738816u,         153035330174u },
+  {                    0u,  7419175577111756800u,         126139354575u },
+  {                    0u, 17299322326264840192u,         207402194313u },
+  {                    0u,  7990511638862102528u,         137937798142u },
+  {                    0u, 16717361816799281152u,         254433166503u },
+  {                    0u,                    0u,         167906250000u },
+  {                    0u,                    0u,          16000000000u },
+  { 16192327041775828992u,                   13u,                    0u },
+  { 15024075324038053888u,          13877787807u,                    0u },
+  {  5449091666327633920u, 13877787807814456755u,                    0u },
+  {  2494994193563254784u,  9707857417284919307u,            752316384u },
+  {  4611686018427387904u,  1844515466944871826u,         224526264005u },
+  {                    0u, 15167599819856275072u,         197099991383u },
+  {                    0u, 14830185305589481472u,          87822237233u },
+  {                    0u,  6163721531743535104u,          49803945956u },
+  {                    0u, 14122847407012052992u,         228334136013u },
+  {                    0u,   335491783960035328u,         205765601092u },
+  {                    0u,   941252322120433664u,          68018187046u },
+  {                    0u, 11529215046068469760u,          38051025390u },
+  {                    0u,                    0u,         238625000000u },
+  {                    0u,                    0u,          64000000000u },
+  {  4368439412768899072u,               211758u,                    0u },
+  {  1563676642168012800u,      211758236813575u,                    0u },
+  { 11532349341402398720u,  8061591463141767016u,                11479u },
+  {  9048364970084925440u, 16628725344207857142u,         215437019748u },
+  { 16609275425742389248u,  3555541870038531535u,         100901445007u },
+  {                    0u, 18316647450161853665u,         143192746310u },
+  {                    0u, 16709574568378075648u,          70992947447u },
+  {                    0u,  7696022835795591168u,         247905827852u },
+  {                    0u, 16664449640376041472u,          12417202233u },
+  {                    0u,  3109186955116544000u,          57903381625u },
+  {                    0u, 10515518101817131008u,         121168549362u },
+  {                    0u,  9961962375743537152u,         242570047378u },
+  {                    0u,  9223372036854775808u,         146540039062u },
+  {                    0u,                    0u,         150500000000u },
+  { 14485570586272534528u,           3231174267u,                    0u },
+  { 17827675094632103936u,  3231174267785264354u,                    0u },
+  {  7347197909193981952u,   748977172262750475u,            175162308u },
+  { 13677404030777688064u, 15965033457315095468u,         196040602133u },
+  {  3810326759732150272u, 16809402149066729206u,          21865466197u },
+  {  9943947977234055168u,  7563769067065700371u,          85911239516u },
+  {                    0u, 13550322810840051428u,          92410032742u },
+  {                    0u,  8663209637545764864u,         102734564471u },
+  {                    0u,  8969247575312957440u,         119469633535u },
+  {                    0u,  6193172891660451840u,         255486223885u },
+  {                    0u,  3427954273864908800u,          13335732575u },
+  {                    0u, 10058367555266936832u,          95185829773u },
+  {                    0u, 13907115649320091648u,         141545265197u },
+  {                    0u,                    0u,          45753906250u },
+  {                    0u,                    0u,          74000000000u },
+  { 14878706826214591391u,                49303u,                    0u },
+  {  4387341015746028192u,       49303806576313u,                    0u },
+  {   651726680428265472u, 14106411361315920281u,                 2672u },
+  {  2570638187944738816u,  3609034283485221502u,         112764710092u },
+  {  7419175577111756800u,  9896072247338192335u,         204195646140u },
+  { 17299322326264840192u,  8889095178479228297u,         188536467151u },
+  {  7990511638862102528u,  3631796911038383102u,         207481878815u },
+  { 16717361816799281152u,   898318840772166823u,          31196880105u },
+  {                    0u, 17293677953982795024u,         233048697961u },
+  {                    0u,  7353628266884669440u,         105937492160u },
+  {                    0u,  2404693032470315008u,         192398640987u },
+  {                    0u,  9191155893041889280u,          91130358670u },
+  {                    0u,  6353946855033798656u,         142498253559u },
+  {                    0u,  3767824038248841216u,         247344448149u },
+  {                    0u,  7205759403792793600u,         149204254150u },
+  {                    0u,                    0u,         198390625000u },
+  {                    0u,                    0u,         232000000000u },
+  {  9707857417284919307u,            752316384u,                    0u },
+  {  1844515466944871826u,   752316384526264005u,                    0u },
+  { 15167599819856275072u, 17063068157692817751u,             40783152u },
+  { 14830185305589481472u,  5385330256507239985u,          48924990778u },
+  {  6163721531743535104u,  3373050282752075748u,          58291939338u },
+  { 14122847407012052992u,  4116064001262906061u,          10182853422u },
+  {   335491783960035328u, 11306582046748043076u,          46223132276u },
+  {   941252322120433664u, 17035410946089626406u,         116612931040u },
+  { 11529215046068469760u, 15618595715183448558u,         224923491477u },
+  {                    0u,  5141740092277295680u,         149846685770u },
+  {                    0u, 16973644291514990592u,          74278734288u },
+  {                    0u, 14625255268443750400u,         208920143100u },
+  {                    0u, 14021170507320131584u,         252792836676u },
+  {                    0u,  4451355232865091584u,          68760089176u },
+  {                    0u, 12891553933348044800u,          88241308450u },
+  {                    0u,  1152921504606846976u,          34698852539u },
+  {                    0u,                    0u,         187062500000u },
+  {                    0u,                    0u,         160000000000u },
+  {  8061591463141767016u,                11479u,                    0u },
+  { 16628725344207857142u,       11479437019748u,                    0u },
+  {  3555541870038531535u,  5562205901560339855u,                  622u },
+  { 18316647450161853665u,  2106077949367544134u,         110301527786u },
+  { 16709574568378075648u,  7496855998374373623u,         234114170714u },
+  {  7696022835795591168u,   229183437194837004u,          90406405378u },
+  { 16664449640376041472u,   465169186276472889u,           2012424059u },
+  {  3109186955116544000u,  2152980561625316473u,         123025216872u },
+  { 10515518101817131008u,  2059790725449340402u,         104116713310u },
+  {  9961962375743537152u, 17891190926410198930u,          94111661478u },
+  {  9223372036854775808u,  9930696175609809814u,         166969883403u },
+  {                    0u,  7276914261609005312u,          11538344118u },
+  {                    0u, 10539762974036983808u,         182394482312u },
+  {                    0u, 12851089458992250880u,         136571361695u },
+  {                    0u,  9449311677678878720u,         159696658955u },
+  {                    0u,  8699564697382289408u,          11512248212u },
+  {                    0u,  4224376450473525248u,         148471604347u },
+  {                    0u,  4611686018427387904u,         123229003906u },
+  {                    0u,                    0u,         130250000000u },
+  {                    0u,                    0u,         128000000000u },
+  {   748977172262750475u,            175162308u,                    0u },
+  { 15965033457315095468u,   175162308040602133u,                    0u },
+  { 16809402149066729206u, 13756840147955779925u,              9495567u },
+  {  7563769067065700371u, 13788447602092505948u,          15745759798u },
+  { 13550322810840051428u,  4972540435632173670u,          54747473242u },
+  {  8663209637545764864u,  2844874687533091959u,          90269561957u },
+  {  8969247575312957440u, 15377573779532804095u,         101154220965u },
+  {  6193172891660451840u, 17824715805091194381u,         165833619944u },
+  {  3427954273864908800u, 18277569135638159711u,         232966279779u },
+  { 10058367555266936832u,  4254645803379752845u,          99990829008u },
+  { 13907115649320091648u,  2933643244178200621u,         208230644811u },
+  {                    0u, 17188148801879487562u,          75159033118u },
+  {                    0u, 11069762501163246592u,          30931771413u },
+  {                    0u, 11676570643941818368u,          21600093027u },
+  {                    0u, 17840016768744030208u,          99632988162u },
+  {                    0u, 16463817321652158464u,           2967109246u },
+  {                    0u,  6954191143357644800u,         126892505325u },
+  {                    0u,  5080060379673919488u,         237376987457u },
+  {                    0u,                    0u,          65275390625u },
+  {                    0u,                    0u,         161000000000u },
+  { 14106411361315920281u,                 2672u,                    0u },
+  {  3609034283485221502u,        2672764710092u,                    0u },
+  {  9896072247338192335u, 16433563478020213436u,                  144u },
+  {  8889095178479228297u,  4194750497955655375u,         144890865261u },
+  {  3631796911038383102u,  2691539602252904735u,         109227397880u },
+  {   898318840772166823u,  3775467271962795241u,         248145908654u },
+  { 17293677953982795024u, 16980212613224918121u,         174204668490u },
+  {  7353628266884669440u,  4172857038337333440u,          74920499170u },
+  {  2404693032470315008u,  5936867627376461659u,         226226211033u },
+  {  9191155893041889280u, 17856837443266866062u,         217321838238u },
+  {  6353946855033798656u,  8956297047799810807u,         158968021097u },
+  {  3767824038248841216u, 15356974049716912789u,         105485521835u },
+  {  7205759403792793600u,  6923608913322982854u,         171832503231u },
+  {                    0u,  4855902993563955944u,         191375329591u },
+  {                    0u, 13835893222288330752u,          55263239028u },
+  {                    0u,  9114973913760137216u,         116750045274u },
+  {                    0u, 17937099003422310400u,          90494123725u },
+  {                    0u,  7007960010734960640u,         205972372085u },
+  {                    0u,  7683422439270776832u,         117379902273u },
+  {                    0u,   720575940379279360u,          65416519165u },
+  {                    0u,                    0u,         253039062500u },
+  {                    0u,                    0u,         228000000000u },
+  { 17063068157692817751u,             40783152u,                    0u },
+  {  5385330256507239985u,    40783152924990778u,                    0u },
+  {  3373050282752075748u,  2768933352715741194u,              2210859u },
+  {  4116064001262906061u, 15201941611824153390u,          43150104177u },
+  { 11306582046748043076u,  1418128541727000180u,         113824098906u },
+  { 17035410946089626406u,  5353350204565757408u,          90076876902u },
+  { 15618595715183448558u,  1721001680354286741u,         102290205696u },
+  {  5141740092277295680u,   637631411660453962u,             93295688u },
+  { 16973644291514990592u,  1630012588870568400u,          72034566068u },
+  { 14625255268443750400u,  9253063571656828156u,         180088363159u },
+  { 14021170507320131584u,  6029146854993203780u,         151501609581u },
+  {  4451355232865091584u, 16987401965352759896u,         109326840705u },
+  { 12891553933348044800u, 14499131620542087970u,         129920888905u },
+  {  1152921504606846976u,  1978417255298660539u,          73785999500u },
+  {                    0u,  5790079354402454176u,         140107250214u },
+  {                    0u, 13748918935842078720u,          38313880830u },
+  {                    0u, 18047438014740692992u,         254745330388u },
+  {                    0u,  3116889656839372800u,         212978353575u },
+  {                    0u, 15995952446606147584u,         167168966926u },
+  {                    0u, 12530140063251562496u,          14867142319u },
+  {                    0u, 16717361816799281152u,         175679260253u },
+  {                    0u,                    0u,          93906250000u },
+  {                    0u,                    0u,          16000000000u },
+  {  5562205901560339855u,                  622u,                    0u },
+  {  2106077949367544134u,         622301527786u,                    0u },
+  {  7496855998374373623u, 13558973353698967386u,                   33u },
+  {   229183437194837004u,  6228991722850501890u,          33735033418u },
+  {   465169186276472889u, 16886831391703377787u,          74337674317u },
+  {  2152980561625316473u,  1181713637872883048u,          77915436964u },
+  {  2059790725449340402u, 12393932434925221726u,         164064060824u },
+  { 17891190926410198930u, 10684799845419711910u,         152671876423u },
+  {  9930696175609809814u,  4590318792215640843u,          71579224160u },
+  {  7276914261609005312u,  6383712187366189238u,          96248841680u },
+  { 10539762974036983808u,  1904270214927675016u,         208346061731u },
+  { 12851089458992250880u,  3711506775113308575u,         163103230695u },
+  {  9449311677678878720u,  8091219444738793995u,         231201201185u },
+  {  8699564697382289408u,    39436684991068052u,          33438625885u },
+  {  4224376450473525248u, 18025182908196512891u,          93002137866u },
+  {  4611686018427387904u,  7853924592034603138u,          10977147123u },
+  {                    0u,  4815749283615688320u,         243425762105u },
+  {                    0u, 14242399906544287744u,          57261062291u },
+  {                    0u,    76242322576113664u,         147772082046u },
+  {                    0u, 10858088421377703936u,         126004133104u },
+  {                    0u, 14293835879041466368u,         240588618152u },
+  {                    0u, 12182236992037191680u,         168774870395u },
+  {                    0u, 11529215046068469760u,         123660400390u },
+  {                    0u,                    0u,           6625000000u },
+  {                    0u,                    0u,          64000000000u },
+  { 13756840147955779925u,              9495567u,                    0u },
+  { 13788447602092505948u,     9495567745759798u,                    0u },
+  {  4972540435632173670u, 14000097438505379162u,               514755u },
+  {  2844874687533091959u, 16451062686452429925u,         195758946802u },
+  { 15377573779532804095u,  4009347599785716645u,         242891813895u },
+  { 17824715805091194381u, 16544162347546196456u,           7217347168u },
+  { 18277569135638159711u, 17674258299745817187u,          96896860837u },
+  {  4254645803379752845u,  5215238411201214416u,         165958123462u },
+  {  2933643244178200621u, 14253990228345322571u,         198282718640u },
+  { 17188148801879487562u, 11214836553940194590u,         176772710358u },
+  { 11069762501163246592u, 14620711348380590101u,         214607957507u },
+  { 11676570643941818368u,  6638710787931587427u,           3792590350u },
+  { 17840016768744030208u, 17320000343692853250u,          14359885232u },
+  { 16463817321652158464u,    75147386268843646u,         176938919100u },
+  {  6954191143357644800u, 17938801582125480173u,         188004073747u },
+  {  5080060379673919488u,  6573358613626446145u,          19972464382u },
+  {                    0u,  8688505427903736481u,         254356342484u },
+  {                    0u,   539870168696556032u,         212471004823u },
+  {                    0u,  9002861336394465280u,         151029266420u },
+  {                    0u, 17989846818158018560u,         244488046090u },
+  {                    0u,  2700938287723315200u,          10975231550u },
+  {                    0u, 17800090499088908288u,          62146418157u },
+  {                    0u,  8809040871136690176u,         237964944839u },
+  {                    0u,  9223372036854775808u,         199477539062u },
+  {                    0u,                    0u,         246500000000u },
+  { 16433563478020213436u,                  144u,                    0u },
+  {  4194750497955655375u,         144890865261u,                    0u },
+  {  2691539602252904735u, 15763656745260536568u,                    7u },
+  {  3775467271962795241u,  8787336846248645550u,           7854549544u },
+  { 16980212613224918121u, 17584084447880694346u,          40476362484u },
+  {  4172857038337333440u, 18041672551129683938u,         244953235127u },
+  {  5936867627376461659u, 14025886302294509785u,         183978041028u },
+  { 17856837443266866062u, 18430498103283160734u,         196760344819u },
+  {  8956297047799810807u,  3292348826238025833u,         243999119304u },
+  { 15356974049716912789u,  9211721212658275243u,         200178478587u },
+  {  6923608913322982854u, 10233245872666307519u,         251499368407u },
+  {  4855902993563955944u,  6200995035623311671u,         215554745370u },
+  { 13835893222288330752u,  8480542380570450804u,          26336156614u },
+  {  9114973913760137216u, 11870363864499900506u,         198459731123u },
+  { 17937099003422310400u,  9301051379839581901u,         179643493714u },
+  {  7007960010734960640u, 11456694803569638005u,          82504211005u },
+  {  7683422439270776832u, 14327208890643983169u,          61621068669u },
+  {   720575940379279360u,  4510081789599866365u,         125776679550u },
+  {                    0u, 13255356976020303332u,         126244492023u },
+  {                    0u,  9658806854127314944u,         247718574341u },
+  {                    0u, 13708435528809971712u,           5523604968u },
+  {                    0u,  1580190652103131136u,         232743135779u },
+  {                    0u, 16557336970347413504u,          35085662306u },
+  {                    0u, 12751520132434493440u,          98897575035u },
+  {                    0u,  9295429630892703744u,         123691261291u },
+  {                    0u,                    0u,         107503906250u },
+  {                    0u,                    0u,         202000000000u },
+  {  2768933352715741194u,              2210859u,                    0u },
+  { 15201941611824153390u,     2210859150104177u,                    0u },
+  {  1418128541727000180u, 16872870088062921306u,               119850u },
+  {  5353350204565757408u,  5112979788807802982u,          42914680120u },
+  {  1721001680354286741u, 13742728082020150272u,          56277175189u },
+  {   637631411660453962u,  2217110934613627976u,         149744994782u },
+  {  1630012588870568400u, 11021433940188610484u,         222120189824u },
+  {  9253063571656828156u,  1713669895470733463u,         128597473131u },
+  {  6029146854993203780u,  3313382510572018285u,         107092898231u },
+  { 16987401965352759896u, 14976595232784069505u,         183179618825u },
+  { 14499131620542087970u,  7213172372862496841u,           9811882854u },
+  {  1978417255298660539u, 15836474542502248588u,         102391026857u },
+  {  5790079354402454176u,  3221099285878340134u,         169858497005u },
+  { 13748918935842078720u,  3265814602578095358u,         237174616142u },
+  { 18047438014740692992u,  6502528252282225364u,          78177040164u },
+  {  3116889656839372800u, 16392476834556790183u,          36352502762u },
+  { 15995952446606147584u, 15167629413417091342u,         234888637949u },
+  { 12530140063251562496u,  1366763272626280111u,         253822238838u },
+  { 16717361816799281152u,  8720523635169216093u,         118074092385u },
+  {                    0u,  9649171375767398672u,          97472740533u },
+  {                    0u,  7647980704001073152u,         181523082628u },
+  {                    0u, 13286434495608651776u,         132414597864u },
+  {                    0u,  4358271637167013888u,         232720259057u },
+  {                    0u, 15954987941890097152u,         241236262378u },
+  {                    0u,  7911135695429697536u,         234864921629u },
+  {                    0u,  7205759403792793600u,          29428863525u },
+  {                    0u,                    0u,          37390625000u },
+  {                    0u,                    0u,         232000000000u },
+  { 13558973353698967386u,                   33u,                    0u },
+  {  6228991722850501890u,          33735033418u,                    0u },
+  { 16886831391703377787u, 15288289344628122701u,                    1u },
+  {  1181713637872883048u,   952589339068938148u,           1828779826u },
+  { 12393932434925221726u, 10058155040190817688u,          50051639971u },
+  { 10684799845419711910u,  5322725640026584391u,         163545253677u },
+  {  4590318792215640843u,  2269982385930389600u,          45288545535u },
+  {  6383712187366189238u, 13216683679976310224u,         255123055991u },
+  {  1904270214927675016u, 17417440642083494819u,         119716477857u },
+  {  3711506775113308575u,  3029180749090900711u,         161944201349u },
+  {  8091219444738793995u,  8315443826261908513u,         133164212217u },
+  {    39436684991068052u,  1488962797247197277u,         249450781113u },
+  { 18025182908196512891u, 18009099634999034122u,         185080716834u },
+  {  7853924592034603138u,  8092455412807497971u,          34976275247u },
+  {  4815749283615688320u, 17808458047236758329u,          47438692886u },
+  { 14242399906544287744u,  3164591817527425171u,          22965398445u },
+  {    76242322576113664u,  3314036340472350590u,         173171552866u },
+  { 10858088421377703936u,    33234902404332784u,          98179654270u },
+  { 14293835879041466368u, 12349284717857274280u,         126001801667u },
+  { 12182236992037191680u, 18209607903013119355u,         195669456065u },
+  { 11529215046068469760u,  7891549145984268038u,         193987144822u },
+  {                    0u,  7703609897518594624u,         118427801736u },
+  {                    0u,  6336912652634587136u,         136417613529u },
+  {                    0u,  4461621834659397632u,         217343524723u },
+  {                    0u,  5484660635557953536u,         115241865004u },
+  {                    0u, 15142619273265938432u,          44297324048u },
+  {                    0u, 12170977992968765440u,          16820883035u },
+  {                    0u,  1152921504606846976u,          91659790039u },
+  {                    0u,                    0u,         215062500000u },
+  {                    0u,                    0u,         160000000000u },
+  { 14000097438505379162u,               514755u,                    0u },
+  { 16451062686452429925u,      514755758946802u,                    0u },
+  {  4009347599785716645u, 17812314011563521031u,                27904u },
+  { 16544162347546196456u,  7684138864490314336u,            965607477u },
+  { 17674258299745817187u,  9740522787420029605u,          53416558002u },
+  {  5215238411201214416u,  6701109407732989894u,         178528034798u },
+  { 14253990228345322571u, 16534886227502443952u,         238363267868u },
+  { 11214836553940194590u,  8908667306968317910u,          28896357978u },
+  { 14620711348380590101u,  7531472173477105155u,          90482939822u },
+  {  6638710787931587427u, 11527371604834801166u,         174408281924u },
+  { 17320000343692853250u, 15688593496691078576u,          68624900066u },
+  {    75147386268843646u, 11394944804253312188u,         226850480357u },
+  { 17938801582125480173u, 11182279880854372627u,         229617721195u },
+  {  6573358613626446145u,   150579373068361470u,         107606192607u },
+  {  8688505427903736481u,  3147220002440857300u,         223008162924u },
+  {   539870168696556032u,  3630514817795505815u,         108170611138u },
+  {  9002861336394465280u, 11708796588334233588u,         194196810602u },
+  { 17989846818158018560u, 16844495466426369546u,         106634735134u },
+  {  2700938287723315200u, 17636655472325475902u,          30913141928u },
+  { 17800090499088908288u, 17038926655686645229u,         168956085008u },
+  {  8809040871136690176u, 15602838456783529415u,          16923682064u },
+  {  9223372036854775808u, 10869815869248876790u,          16845831567u },
+  {                    0u, 18407124180939800832u,         143589253898u },
+  {                    0u,  5705018517251293184u,          10997852201u },
+  {                    0u,  9660452258743058432u,          41309269673u },
+  {                    0u,  5646292272224927744u,         169523694166u },
+  {                    0u,  7410409304047484928u,          86306086117u },
+  {                    0u,  5953758707383795712u,         229401719093u },
+  {                    0u,  4611686018427387904u,          53322753906u },
+  {                    0u,                    0u,         114250000000u },
+  {                    0u,                    0u,         128000000000u },
+  { 15763656745260536568u,                    7u,                    0u },
+  {  8787336846248645550u,           7854549544u,                    0u },
+  { 17584084447880694346u,  7854549544476362484u,                    0u },
+  { 18041672551129683938u,    15035424419724983u,            425795984u },
+  { 14025886302294509785u, 18280822466032836292u,         144000815071u },
+  { 18430498103283160734u, 11524250747302615283u,         223991005371u },
+  {  3292348826238025833u, 15212285943691810760u,         187624730884u },
+  {  9211721212658275243u,  7951804027551297019u,           4824659673u },
+  { 10233245872666307519u,  1706416229965221847u,         217431068160u },
+  {  6200995035623311671u,  3406023111930700826u,             92505009u },
+  {  8480542380570450804u, 16132696204133391302u,         177184640882u },
+  { 11870363864499900506u, 11593846688794356915u,         114874555213u },
+  {  9301051379839581901u,  6875759884161133906u,          77628503688u },
+  { 11456694803569638005u,  3593593325323835965u,         136372735690u },
+  { 14327208890643983169u,  9542049733257388925u,         202194809084u },
+  {  4510081789599866365u,  9926551925937787518u,         252517275552u },
+  { 13255356976020303332u,  3128491553219547895u,         160538119458u },
+  {  9658806854127314944u, 17158408656931354885u,          34169595866u },
+  { 13708435528809971712u,  2065169543154992616u,         218930159197u },
+  {  1580190652103131136u,  4832622393556232739u,          93111953065u },
+  { 16557336970347413504u, 16505930714733656162u,         169261976984u },
+  { 12751520132434493440u, 18270988073492888699u,         152894788296u },
+  {  9295429630892703744u,  2525111411519708523u,         200990472248u },
+  {                    0u, 16728989342518570442u,          56136886563u },
+  {                    0u,  7974052022039438336u,          35906880329u },
+  {                    0u,  5356554962386550784u,          73432274226u },
+  {                    0u,  6693869495028547584u,          50290379426u },
+  {                    0u,  8157517147199766528u,         162362875392u },
+  {                    0u, 12065776720423157760u,            442219890u },
+  {                    0u, 11997589407315001344u,         114654087066u },
+  {                    0u,                    0u,         154650390625u },
+  {                    0u,                    0u,          97000000000u },
+  { 16872870088062921306u,               119850u,                    0u },
+  {  5112979788807802982u,      119850914680120u,                    0u },
+  { 13742728082020150272u,  2418433229320326037u,                 6497u },
+  {  2217110934613627976u,  1143911773589293534u,          97131103528u },
+  { 11021433940188610484u,  9276183703610924928u,          40062011581u },
+  {  1713669895470733463u,  3532180128827684715u,         189502862926u },
+  {  3313382510572018285u,  8563997501322031543u,          78191479868u },
+  { 14976595232784069505u, 14843890409658460681u,          60464255234u },
+  {  7213172372862496841u,  9489417861634552678u,           2804688911u },
+  { 15836474542502248588u,  1113198223322322089u,          15514422373u },
+  {  3221099285878340134u, 11190777557146597869u,         101060346596u },
+  {  3265814602578095358u, 17764553645932638286u,         228606653266u },
+  {  6502528252282225364u, 14900777150991234852u,          82963018382u },
+  { 16392476834556790183u, 17364899863357893610u,         142807772747u },
+  { 15167629413417091342u, 15537570181590167037u,          75941353107u },
+  {  1366763272626280111u,  5558052627121307766u,         147842293367u },
+  {  8720523635169216093u, 12095241565795232609u,         119301302636u },
+  {  9649171375767398672u,  2187936505958366389u,         108655684359u },
+  {  7647980704001073152u, 12009203621325860228u,           7118608275u },
+  { 13286434495608651776u, 14814842834750302952u,         147651020232u },
+  {  4358271637167013888u,  5965296499605198833u,         200803114239u },
+  { 15954987941890097152u,  4051026394962148842u,         255323379371u },
+  {  7911135695429697536u, 16799526299141688349u,         171219606580u },
+  {  7205759403792793600u,  9460214166646215205u,          52910704145u },
+  {                    0u, 10750736995029068008u,          17512839237u },
+  {                    0u,  5377963045376430080u,          69582798620u },
+  {                    0u, 15996910350253424640u,          28291539960u },
+  {                    0u, 13651157529655246848u,         248867194247u },
+  {                    0u,  9771305410219737088u,         135740030732u },
+  {                    0u, 12709439623416250368u,          12529703527u },
+  {                    0u,  9943947977234055168u,         103688980102u },
+  {                    0u,                    0u,         134539062500u },
+  {                    0u,                    0u,         228000000000u },
+  {   952589339068938148u,           1828779826u,                    0u },
+  { 10058155040190817688u,  1828779826051639971u,                    0u },
+  {  5322725640026584391u,   371564423966525229u,             99138353u },
+  {  2269982385930389600u, 14464859121514339583u,          49020142547u },
+  { 13216683679976310224u,  3913119023023056247u,         211784141584u },
+  { 17417440642083494819u,  5493396321716566945u,          16212130607u },
+  {  3029180749090900711u,  5837454566818211973u,          47297797611u },
+  {  8315443826261908513u,  2886670683193253881u,         235316449046u },
+  {  1488962797247197277u,  5504823105587173817u,          22156486731u },
+  { 18009099634999034122u,  9431834277334851106u,          75298417058u },
+  {  8092455412807497971u, 12921661346456247087u,         162511300760u },
+  { 17808458047236758329u,  3643076516404724246u,         152700484665u },
+  {  3164591817527425171u, 12559396953196866477u,          57197491573u },
+  {  3314036340472350590u,  1626880974916825698u,         117680846273u },
+  {    33234902404332784u,  6806994170946429566u,         193088193394u },
+  { 12349284717857274280u,  7596631230206896579u,         114369007893u },
+  { 18209607903013119355u,  3100480253729502401u,          21411814204u },
+  {  7891549145984268038u,  6310570748781063286u,          60168077371u },
+  {  7703609897518594624u, 14251867077375744136u,          59342096725u },
+  {  6336912652634587136u,  6701165793751570137u,          85772595262u },
+  {  4461621834659397632u, 10856833140463959923u,          62363270925u },
+  {  5484660635557953536u, 15867563727561248556u,          13588550103u },
+  { 15142619273265938432u,  5048961008671491600u,         215860182353u },
+  { 12170977992968765440u, 13278183119599849051u,          81273704724u },
+  {  1152921504606846976u,  4547591784941053655u,          20719811749u },
+  {                    0u, 11815437715887182496u,         165246525444u },
+  {                    0u,   398495392178782208u,           4640516162u },
+  {                    0u,  9154841240825495552u,          66021602478u },
+  {                    0u,  1902683298245640192u,         174496284938u },
+  {                    0u,  5081900962138816512u,          10103144668u },
+  {                    0u,  3234710432358858752u,         220275490403u },
+  {                    0u, 16717361816799281152u,          99175354003u },
+  {                    0u,                    0u,         147906250000u },
+  {                    0u,                    0u,          16000000000u },
+  { 17812314011563521031u,                27904u,                    0u },
+  {  7684138864490314336u,       27904965607477u,                    0u },
+  {  9740522787420029605u, 13488568028574514610u,                 1512u },
+  {  6701109407732989894u,   275784718433886190u,         232731216738u },
+  { 16534886227502443952u, 10020568880357102364u,          98014950319u },
+  {  8908667306968317910u,  8876397213146246746u,         175543216127u },
+  {  7531472173477105155u,  2155905919114811310u,         255481190457u },
+  { 11527371604834801166u,  1087100407155601220u,          57116871894u },
+  { 15688593496691078576u,  2903498381705011170u,         214058931831u },
+  { 11394944804253312188u, 12223476257006657765u,         119157398962u },
+  { 11182279880854372627u, 12148657163736735595u,         178662635975u },
+  {   150579373068361470u,  8951241323311673823u,         199658580024u },
+  {  3147220002440857300u,  8463862715901576300u,          56485247764u },
+  {  3630514817795505815u,  3873401978748963266u,          20458826917u },
+  { 11708796588334233588u,   248364795947002730u,         165209977542u },
+  { 16844495466426369546u, 10454378025404001822u,         198013463882u },
+  { 17636655472325475902u,  6574176865628265640u,          74566732968u },
+  { 17038926655686645229u,    16703315293848336u,         168356386842u },
+  { 15602838456783529415u,  9896033222450013456u,          26000905488u },
+  { 10869815869248876790u, 17311376269334085007u,          16536465035u },
+  { 18407124180939800832u, 18378511316495639306u,         139938451587u },
+  {  5705018517251293184u, 15120796393727584297u,         131996301094u },
+  {  9660452258743058432u, 18253447805740347049u,          38819700014u },
+  {  5646292272224927744u,  5842497225601731158u,          46989521388u },
+  {  7410409304047484928u,  4369968404176723173u,         236316722409u },
+  {  5953758707383795712u, 16142207253674488117u,         233236896461u },
+  {  4611686018427387904u, 12124259227391928178u,         205875070808u },
+  {                    0u, 13019483264566077056u,          88657257409u },
+  {                    0u,    74901376448135168u,         193705787602u },
+  {                    0u, 13897060093813325824u,         210004060411u },
+  {                    0u,  4495486210810052608u,         251753361137u },
+  {                    0u, 14885496280087265280u,         241243700795u },
+  {                    0u,  4976477588244398080u,          59806944370u },
+  {                    0u, 11529215046068469760u,         114269775390u },
+  {                    0u,                    0u,          30625000000u },
+  {                    0u,                    0u,          64000000000u },
+  {    15035424419724983u,            425795984u,                    0u },
+  { 18280822466032836292u,   425795984000815071u,                    0u },
+  { 11524250747302615283u, 10043594327130472635u,             23082446u },
+  { 15212285943691810760u,  8336034337032909060u,         206544464339u },
+  {  7951804027551297019u, 16717215784895280857u,         211451897326u },
+  {  1706416229965221847u, 10968831263951212032u,         238906242083u },
+  {  3406023111930700826u,  5536629379734406065u,          35594621534u },
+  { 16132696204133391302u,  1618806894932332402u,          94300141280u },
+  { 11593846688794356915u, 11363331325254998861u,         224087755697u },
+  {  6875759884161133906u,  8775167772751754888u,         177616007425u },
+  {  3593593325323835965u,  2898202945316114122u,           1475702798u },
+  {  9542049733257388925u,  8868842714495185148u,          14157111896u },
+  {  9926551925937787518u, 17052094667531999136u,          88480780926u },
+  {  3128491553219547895u,  3658615537031138594u,         126924395904u },
+  { 17158408656931354885u, 12486952437987190746u,         128198333945u },
+  {  2065169543154992616u,   912079238520577629u,         249676919048u },
+  {  4832622393556232739u, 10960072898031888041u,           8049443914u },
+  { 16505930714733656162u,  6129550094334741912u,          74594146742u },
+  { 18270988073492888699u,  7965724516573729480u,         182332283576u },
+  {  2525111411519708523u,  5801761178810791992u,         184431822791u },
+  { 16728989342518570442u, 13197466483098446115u,         199314514103u },
+  {  7974052022039438336u, 11326268638393107273u,         183715436091u },
+  {  5356554962386550784u,  3597339351794947378u,          59613998253u },
+  {  6693869495028547584u,   353880726151383714u,         173195012157u },
+  {  8157517147199766528u, 11154818162602073600u,          61019183912u },
+  { 12065776720423157760u,  5141043976157511026u,          40604703904u },
+  { 11997589407315001344u,  7188225141808859034u,         160278696552u },
+  {                    0u, 13894168943295705185u,         104389674465u },
+  {                    0u, 12176538069834828288u,         225753204407u },
+  {                    0u,  7994239409235165184u,         183660091451u },
+  {                    0u, 13707777025480065024u,          59433368586u },
+  {                    0u, 10120227247676719104u,          10743100081u },
+  {                    0u,  7358494763030413312u,         177548618618u },
+  {                    0u,  7656119366529843200u,         122398904800u },
+  {                    0u,  9223372036854775808u,         224415039062u },
+  {                    0u,                    0u,          86500000000u },
+  {  2418433229320326037u,                 6497u,                    0u },
+  {  1143911773589293534u,        6497131103528u,                    0u },
+  {  9276183703610924928u,  3877189582299842749u,                  352u },
+  {  3532180128827684715u,  7625565791857948238u,          96210182868u },
+  {  8563997501322031543u, 16568435163612007484u,         212413382749u },
+  { 14843890409658460681u, 17592071940521808130u,          93898176669u },
+  {  9489417861634552678u, 15158637878035490831u,         157953668130u },
+  {  1113198223322322089u, 17789243229146401893u,          34821751405u },
+  { 11190777557146597869u, 14677686051252896484u,         109964356807u },
+  { 17764553645932638286u,  3531237481269211986u,         199795678955u },
+  { 14900777150991234852u,  8074435404989280910u,         235191428767u },
+  { 17364899863357893610u,  7086549341467684427u,         159437716020u },
+  { 15537570181590167037u, 10556134770918626963u,          52384162609u },
+  {  5558052627121307766u, 10772666134712966775u,          49572249212u },
+  { 12095241565795232609u,  6195173298198112620u,         124583987401u },
+  {  2187936505958366389u,  8144773843324250887u,         201335841017u },
+  { 12009203621325860228u, 14144284817150924691u,         249441529074u },
+  { 14814842834750302952u,  6464447844648863176u,         242766763216u },
+  {  5965296499605198833u, 15760468443293179135u,         208350438419u },
+  {  4051026394962148842u,  5172191224908322475u,          19854376706u },
+  { 16799526299141688349u,  2357554307308969012u,           2280385048u },
+  {  9460214166646215205u,  1602046917604361745u,          24127803275u },
+  { 10750736995029068008u,  7830970218109515845u,         139086847137u },
+  {  5377963045376430080u,  2899479134887821084u,         161424517746u },
+  { 15996910350253424640u, 15792042302392017912u,         114157181078u },
+  { 13651157529655246848u, 11286099112296056199u,         150856088328u },
+  {  9771305410219737088u, 15161477829153947404u,           8611820658u },
+  { 12709439623416250368u,   423831848142641767u,         114821905360u },
+  {  9943947977234055168u,  9707413321046312582u,         208022975970u },
+  {                    0u, 10969483299803835620u,         226526239930u },
+  {                    0u,  4326479556120930304u,         186594656881u },
+  {                    0u, 12876227232041795584u,         113234538926u },
+  {                    0u, 16967986827791171584u,         174698021676u },
+  {                    0u,  1288146316538413056u,          44919836409u },
+  {                    0u, 13715290452691779584u,         249069830551u },
+  {                    0u,  4683743612465315840u,         151743507385u },
+  {                    0u,                    0u,         185253906250u },
+  {                    0u,                    0u,          74000000000u },
+  {   371564423966525229u,             99138353u,                    0u },
+  { 14464859121514339583u,    99138353020142547u,                    0u },
+  {  3913119023023056247u, 16344805304534272784u,              5374300u },
+  {  5493396321716566945u,    26429987091348271u,          92886053671u },
+  {  5837454566818211973u,  8691371289609838059u,          39001432772u },
+  {  2886670683193253881u, 12980168378493046550u,         196471160181u },
+  {  5504823105587173817u, 14010125458129496139u,         117703656337u },
+  {  9431834277334851106u, 17061829677031795106u,         145759490422u },
+  { 12921661346456247087u,  2227928323072698520u,         118924923640u },
+  {  3643076516404724246u,  7394752319272287289u,         248120776236u },
+  { 12559396953196866477u,  8805771303577744757u,          44400870326u },
+  {  1626880974916825698u, 16371027194302248385u,         182477361818u },
+  {  6806994170946429566u,  9114324123731231602u,         154887475162u },
+  {  7596631230206896579u, 14468189808746991893u,         218494088500u },
+  {  3100480253729502401u,  2376054557800684348u,          52784322141u },
+  {  6310570748781063286u, 12462238943546048571u,          93128806175u },
+  { 14251867077375744136u, 15334855370842605909u,          31675579326u },
+  {  6701165793751570137u,  7211347914013798462u,         190831304175u },
+  { 10856833140463959923u, 13763642332572548877u,         239390927953u },
+  { 15867563727561248556u, 16868268377740071383u,          81746128545u },
+  {  5048961008671491600u,  1120013377627684177u,         161914430661u },
+  { 13278183119599849051u, 15898107650717274388u,         197060716046u },
+  {  4547591784941053655u, 12281923376333274277u,          14861838142u },
+  { 11815437715887182496u,  6383530489286615044u,          62665804400u },
+  {   398495392178782208u,  4253822060257126466u,         112346051881u },
+  {  9154841240825495552u, 17614372438391501998u,          41230600155u },
+  {  1902683298245640192u,  4309951310554333450u,         219954877043u },
+  {  5081900962138816512u, 13106185988973773020u,         115233642928u },
+  {  3234710432358858752u,  2070134359761960547u,         176710487766u },
+  { 16717361816799281152u,  9399359914137865875u,         214112222208u },
+  {                    0u, 17415053284723541264u,            509540321u },
+  {                    0u,  4840502610448261120u,         225944071930u },
+  {                    0u,  5690599259712258048u,         250262404172u },
+  {                    0u,   114769594245185536u,          76308488004u },
+  {                    0u,  3150620882578178048u,          68006221672u },
+  {                    0u,  5136918324969472000u,         104170795500u },
+  {                    0u,  7205759403792793600u,         236278472900u },
+  {                    0u,                    0u,         196390625000u },
+  {                    0u,                    0u,         232000000000u },
+  { 13488568028574514610u,                 1512u,                    0u },
+  {   275784718433886190u,        1512731216738u,                    0u },
+  { 10020568880357102364u,    98202693831717807u,                   82u },
+  {  8876397213146246746u, 12909287260170414079u,          82005323578u },
+  {  2155905919114811310u, 11728631949380786233u,          58699813864u },
+  {  1087100407155601220u, 18263701925522197718u,         232635810411u },
+  {  2903498381705011170u,  4868886449713321591u,         107990077265u },
+  { 12223476257006657765u,  5870139507184082354u,          81263942863u },
+  { 12148657163736735595u,  5978562500822661575u,         207318220900u },
+  {  8951241323311673823u, 10821136839630268472u,         100324098522u },
+  {  8463862715901576300u,  9490907630136752916u,         218586615003u },
+  {  3873401978748963266u, 10564005678001613989u,         219514503133u },
+  {   248364795947002730u,  5754050547468481222u,         221572675895u },
+  { 10454378025404001822u,  3833909949855542602u,          55311927705u },
+  {  6574176865628265640u, 15446538552665967784u,         153207836674u },
+  {    16703315293848336u, 14924837848804399130u,           2837358532u },
+  {  9896033222450013456u, 18140170340418344208u,         196809077080u },
+  { 17311376269334085007u, 11380424819825208971u,          88983380604u },
+  { 18378511316495639306u, 12416915664152252547u,         124616934065u },
+  { 15120796393727584297u, 17195282241626289958u,         177673122346u },
+  { 18253447805740347049u,  2649541045825281326u,          42932158118u },
+  {  5842497225601731158u, 16577429864268509676u,         166143631907u },
+  {  4369968404176723173u, 12051257060168107241u,          35898664273u },
+  { 16142207253674488117u,  5363884561143470797u,          81653299954u },
+  { 12124259227391928178u, 13054029903083620184u,         242290776764u },
+  { 13019483264566077056u,   566314952158634945u,         188707660379u },
+  {    74901376448135168u,  1329472079642345682u,          91030699995u },
+  { 13897060093813325824u, 15686237486658857211u,         219072070825u },
+  {  4495486210810052608u,  1069073549290598129u,         169850352638u },
+  { 14885496280087265280u,  4323599065125928507u,         254057954593u },
+  {  4976477588244398080u, 17861823329752681586u,          33234382774u },
+  { 11529215046068469760u, 17220149985412802078u,         182968291382u },
+  {                    0u,  4344934572159429184u,          54933506201u },
+  {                    0u,  2252927464837120000u,         153235539375u },
+  {                    0u, 10910018171964489728u,         175122131442u },
+  {                    0u,  3597328585515335680u,         242591433270u },
+  {                    0u,  6972808074239148032u,          54195011573u },
+  {                    0u,  2227030015734710272u,         245377996683u },
+  {                    0u,  1152921504606846976u,         139120727539u },
+  {                    0u,                    0u,         243062500000u },
+  {                    0u,                    0u,         160000000000u },
+  { 10043594327130472635u,             23082446u,                    0u },
+  {  8336034337032909060u,    23082446544464339u,                    0u },
+  { 16717215784895280857u, 17238287503805244910u,              1251301u },
+  { 10968831263951212032u,  1434575446038410275u,         229934489438u },
+  {  5536629379734406065u, 14009569747841241694u,          94077768490u },
+  {  1618806894932332402u, 14938795732275951328u,          42759460297u },
+  { 11363331325254998861u,  6687653542888983473u,         201809833739u },
+  {  8775167772751754888u,    28238723295162625u,          11362538425u },
+  {  2898202945316114122u,  4745270274832691214u,         185001530824u },
+  {  8868842714495185148u,   926478968112308824u,         200257241617u },
+  { 17052094667531999136u,  9213681606604198526u,          17050224525u },
+  {  3658615537031138594u, 13346223820579313024u,         141499474680u },
+  { 12486952437987190746u,   691642518601291257u,         248723500243u },
+  {   912079238520577629u,  1153720150033789192u,         211037494016u },
+  { 10960072898031888041u, 12089015034721780810u,             62543294u },
+  {  6129550094334741912u,  3555868702841788854u,         190655346818u },
+  {  7965724516573729480u, 11708406782758214328u,         130192764028u },
+  {  5801761178810791992u,  9417497762905343943u,         124634714003u },
+  { 13197466483098446115u, 12838336066957615287u,         147510523576u },
+  { 11326268638393107273u, 13737708142128207419u,         184695967592u },
+  {  3597339351794947378u, 11683434809834695853u,         104744722650u },
+  {   353880726151383714u,  2689114340106315837u,         218633360270u },
+  { 11154818162602073600u,  8859225263374261032u,         142145777180u },
+  {  5141043976157511026u, 15761671984578600096u,          28480259563u },
+  {  7188225141808859034u,  7087267079878005352u,         235854441950u },
+  { 13894168943295705185u,  4601291730423121377u,         222384201518u },
+  { 12176538069834828288u,  9559411037059581623u,          46249436524u },
+  {  7994239409235165184u, 12969820289641388091u,         108518216710u },
+  { 13707777025480065024u, 13628239920285957130u,           6703095366u },
+  { 10120227247676719104u,  8049893933765800625u,          70738788366u },
+  {  7358494763030413312u, 10391755948840250234u,          14436385624u },
+  {  7656119366529843200u, 14454650777462444512u,          88563338218u },
+  {  9223372036854775808u, 14244638523341127254u,         234783588188u },
+  {                    0u, 12246016810439753984u,          92772203401u },
+  {                    0u,  9382741764551081984u,         137663857901u },
+  {                    0u,  4608696190291148800u,         237508639450u },
+  {                    0u,  1696483666416369664u,         218249837921u },
+  {                    0u, 15416683541605384192u,          97091966563u },
+  {                    0u,  7683140964294066176u,          99835740089u },
+  {                    0u,  4611686018427387904u,         185416503906u },
+  {                    0u,                    0u,          98250000000u },
+  {                    0u,                    0u,         128000000000u },
+  {  3877189582299842749u,                  352u,                    0u },
+  {  7625565791857948238u,         352210182868u,                    0u },
+  { 16568435163612007484u,  1722045467931902045u,                   19u },
+  { 17592071940521808130u, 16095324008152856733u,          19093352271u },
+  { 15158637878035490831u, 15216188060094280738u,          79872529262u },
+  { 17789243229146401893u, 10793385929903030893u,         110824871207u },
+  { 14677686051252896484u, 12613277226875940039u,          39585110623u },
+  {  3531237481269211986u, 10644539625155600107u,          95683767128u },
+  {  8074435404989280910u,  6181262895644173983u,          88577041649u },
+  {  7086549341467684427u,   148914399627082292u,         241335086933u },
+  { 10556134770918626963u, 14379289774887985969u,          85008072665u },
+  { 10772666134712966775u, 11743339675582627452u,         217779502860u },
+  {  6195173298198112620u,  7841621929809463497u,          12636607719u },
+  {  8144773843324250887u, 11168944680251236601u,         231425095176u },
+  { 14144284817150924691u,  6178560202529287410u,           8605469704u },
+  {  6464447844648863176u, 13295243308201596112u,           8334940419u },
+  { 15760468443293179135u, 17040673746172470291u,           3720736583u },
+  {  5172191224908322475u, 14957442487039409922u,          71923776774u },
+  {  2357554307308969012u, 17778155426506992152u,           6810844581u },
+  {  1602046917604361745u, 14945404984219733899u,         165963755736u },
+  {  7830970218109515845u, 11590754866058681505u,         216810192027u },
+  {  2899479134887821084u,  6020790784469412466u,         155628336080u },
+  { 15792042302392017912u,  7934351824569522326u,         208326387722u },
+  { 11286099112296056199u,  5038361112172116744u,          10430122074u },
+  { 15161477829153947404u,  3305187319649924210u,          90273130103u },
+  {   423831848142641767u, 11470175511099161552u,         119179174563u },
+  {  9707413321046312582u,  7308362160352048610u,         163621799460u },
+  { 10969483299803835620u, 10666410671225576634u,          36396187106u },
+  {  4326479556120930304u,  2181639019945820785u,         226578227281u },
+  { 12876227232041795584u,  4615749499734847918u,          81118266888u },
+  { 16967986827791171584u, 14076159200958497580u,           8250220281u },
+  {  1288146316538413056u,  5470405257862074105u,         249763070119u },
+  { 13715290452691779584u,  4565741478181339543u,         167296551263u },
+  {  4683743612465315840u,  8901832997861862329u,          95247509341u },
+  {                    0u, 14190141170191714122u,          93482569333u },
+  {                    0u,  4240772322245764096u,         117769249094u },
+  {                    0u,  4422842195340951552u,          70229892728u },
+  {                    0u, 15448426386733137920u,         120239762755u },
+  {                    0u,  9203504548935630848u,          67837460872u },
+  {                    0u,  5936377627571912704u,         136498922981u },
+  {                    0u,   468374361246531584u,         229321811676u },
+  {                    0u,                    0u,         220025390625u },
+  {                    0u,                    0u,          33000000000u },
+  { 16344805304534272784u,              5374300u,                    0u },
+  {    26429987091348271u,     5374300886053671u,                    0u },
+  {  8691371289609838059u,  8020875056524075716u,               291341u },
+  { 12980168378493046550u,  1400288714762747253u,          13434812508u },
+  { 14010125458129496139u,  6136037711314764689u,          92075909803u },
+  { 17061829677031795106u, 15735488086392394102u,         171332635270u },
+  {  2227928323072698520u,  7735094782793634552u,         134853022518u },
+  {  7394752319272287289u,  7273689191766726188u,          54419320328u },
+  {  8805771303577744757u,  3410634565056431030u,           8394307481u },
+  { 16371027194302248385u,  4600927904885215898u,         153184890870u },
+  {  9114324123731231602u,  9154871331680374746u,         246249416801u },
+  { 14468189808746991893u,  6117978272461042996u,          97496286569u },
+  {  2376054557800684348u, 13116904339287496285u,         105331656266u },
+  { 12462238943546048571u,   867037205615660831u,          74711068809u },
+  { 15334855370842605909u,  1802487145191504830u,         137047002181u },
+  {  7211347914013798462u, 17242009718457409007u,          69097713023u },
+  { 13763642332572548877u, 13620802355488468049u,         127934691219u },
+  { 16868268377740071383u,  4442227880594435745u,         147738385175u },
+  {  1120013377627684177u, 17354849212854314181u,          23240813655u },
+  { 15898107650717274388u, 18202319179831567886u,          87940808260u },
+  { 12281923376333274277u, 17568634016348874558u,          68986749699u },
+  {  6383530489286615044u,  7496925598312450672u,           3952397558u },
+  {  4253822060257126466u,   601870379496813865u,         246406409151u },
+  { 17614372438391501998u, 11995106565680728027u,         191032627458u },
+  {  4309951310554333450u, 16331071694764184179u,           2650256029u },
+  { 13106185988973773020u,  9665962217000524208u,         157885309170u },
+  {  2070134359761960547u, 13682661374415474390u,         242523992861u },
+  {  9399359914137865875u,  6940361789924260864u,          29741738559u },
+  { 17415053284723541264u,  9658039831644010465u,          63376237766u },
+  {  4840502610448261120u,  6843715893910236922u,         198523563388u },
+  {  5690599259712258048u,    47089792870595660u,         124370998582u },
+  {   114769594245185536u, 14510386192097156932u,          54002552742u },
+  {  3150620882578178048u, 12059931208360040296u,         166786609611u },
+  {  5136918324969472000u, 14877013468459184620u,         203653770180u },
+  {  7205759403792793600u,  2397668560671695044u,         196806484516u },
+  {                    0u,  2195572305559232232u,          36129977873u },
+  {                    0u,  3261686279425953792u,          17119022213u },
+  {                    0u,  9333850662059900928u,         133176816367u },
+  {                    0u,  5036522340217782272u,         239505989058u },
+  {                    0u,  2800120215143186432u,         194273030423u },
+  {                    0u,   441634238459019264u,          23151794821u },
+  {                    0u,   720575940379279360u,         133023941040u },
+  {                    0u,                    0u,         176039062500u },
+  {                    0u,                    0u,         228000000000u },
+  {    98202693831717807u,                   82u,                    0u },
+  { 12909287260170414079u,          82005323578u,                    0u },
+  { 11728631949380786233u,  8218347283861607400u,                    4u },
+  { 18263701925522197718u, 17896200385973633643u,           4445517498u },
+  {  4868886449713321591u, 16333242102094352209u,         186970154966u },
+  {  5870139507184082354u,  9981905728606788815u,         214885426828u },
+  {  5978562500822661575u, 15219470018924839012u,         140541120193u },
+  { 10821136839630268472u, 17152070168529617370u,         193825049122u },
+  {  9490907630136752916u, 17841343440958328027u,          34929815586u },
+  { 10564005678001613989u, 17291078023923990493u,          34967181165u },
+  {  5754050547468481222u, 16744804581790759223u,         109937351217u },
+  {  3833909949855542602u,  5001622214111594905u,          49907737675u },
+  { 15446538552665967784u,  9676746897435398146u,          75271138483u },
+  { 14924837848804399130u,  8109025833995118532u,         179524577500u },
+  { 18140170340418344208u,  5495826424046694744u,         220439591171u },
+  { 11380424819825208971u,  7890288164365705852u,           3297929347u },
+  { 12416915664152252547u,  8616438349039895217u,         131427733378u },
+  { 17195282241626289958u, 15787154801788760618u,         130467098058u },
+  {  2649541045825281326u, 12418659311480782502u,         202855823376u },
+  { 16577429864268509676u,  4486988874116669987u,          16673216870u },
+  { 12051257060168107241u,  4828971301551875409u,         102243240154u },
+  {  5363884561143470797u, 14769106422014442226u,         218261779058u },
+  { 13054029903083620184u,  7763933466423188156u,         114800634863u },
+  {   566314952158634945u, 10449097116253839963u,         239420883676u },
+  {  1329472079642345682u, 12870692502472900571u,         220566446689u },
+  { 15686237486658857211u, 11597479481311003817u,          97697721638u },
+  {  1069073549290598129u,  8294994869530047486u,          38628700622u },
+  {  4323599065125928507u, 16879315829924478241u,         206449672572u },
+  { 17861823329752681586u, 11873324837601439670u,         124915029544u },
+  { 17220149985412802078u,  3277599055636107318u,          40643654229u },
+  {  4344934572159429184u, 15363467897354242201u,          85177679000u },
+  {  2252927464837120000u, 10351182204479784367u,         152832855263u },
+  { 10910018171964489728u, 12811517584931924466u,         223561138711u },
+  {  3597328585515335680u, 16988930699558748726u,          23694513759u },
+  {  6972808074239148032u, 11683499918824718325u,          95920971778u },
+  {  2227030015734710272u, 13119300691281647499u,           2633363799u },
+  {  1152921504606846976u, 10125549106595354099u,          87711198715u },
+  {                    0u, 17505352699870800544u,         251548907116u },
+  {                    0u,  6756039242241163264u,         108948967071u },
+  {                    0u,  3537338758766526464u,         159366245621u },
+  {                    0u,  6522626374119718912u,         245191759518u },
+  {                    0u,  4733294203482669056u,         158353592284u },
+  {                    0u, 16997710893603094528u,         220256592392u },
+  {                    0u, 16717361816799281152u,           8921447753u },
+  {                    0u,                    0u,          73906250000u },
+  {                    0u,                    0u,          16000000000u },
+  { 17238287503805244910u,              1251301u,                    0u },
+  {  1434575446038410275u,     1251301934489438u,                    0u },
+  { 14009569747841241694u,  3943737498063000362u,                67833u },
+  { 14938795732275951328u,  2870731037991212489u,         249213790438u },
+  {  6687653542888983473u,  7389433400402095883u,         230155622641u },
+  {    28238723295162625u,  5675049236146197433u,         241400581987u },
+  {  4745270274832691214u,  9953779846262904264u,          99307645035u },
+  {   926478968112308824u, 12691978937179636241u,         107539595486u },
+  {  9213681606604198526u, 15523327331528198029u,         222688033556u },
+  { 13346223820579313024u, 15722603279568118520u,          20841521260u },
+  {   691642518601291257u, 11838632364171816147u,         108852324031u },
+  {  1153720150033789192u,  7832751832367143680u,         191641773546u },
+  { 12089015034721780810u, 12167724027162940862u,         234424614327u },
+  {  3555868702841788854u,  4108211144748152962u,         183659613641u },
+  { 11708406782758214328u,  7530983398136343676u,         201222706572u },
+  {  9417497762905343943u,  1117587133956542355u,         140408255428u },
+  { 12838336066957615287u, 17134748625149490872u,         196060584519u },
+  { 13737708142128207419u,  4039918359454207848u,          71928876584u },
+  { 11683434809834695853u,  1830218764589441242u,          40219004413u },
+  {  2689114340106315837u,   637895981480825742u,         253099216358u },
+  {  8859225263374261032u,  8246879226348334620u,         230034580410u },
+  { 15761671984578600096u, 12389239568142583275u,         186447064218u },
+  {  7087267079878005352u, 14041257178803154398u,         154671622022u },
+  {  4601291730423121377u, 16312515716494630702u,         134761178076u },
+  {  9559411037059581623u, 17088522799596987756u,         220884303248u },
+  { 12969820289641388091u,  3588932524637852678u,         144926370677u },
+  { 13628239920285957130u,   107218049069817414u,         117194556422u },
+  {  8049893933765800625u,  1596707240462008334u,           6005812302u },
+  { 10391755948840250234u, 17461913142391587672u,          78086557672u },
+  { 14454650777462444512u,  4366474266651610090u,         232946612208u },
+  { 14244638523341127254u,  5539304013194805084u,         240236707044u },
+  { 12246016810439753984u,  4762470619211987849u,         228300286272u },
+  {  9382741764551081984u, 10835638458986644717u,          64258174049u },
+  {  4608696190291148800u, 16141642290510052058u,          97587401137u },
+  {  1696483666416369664u, 17390568670756355425u,         177875040181u },
+  { 15416683541605384192u, 12536768491333867107u,         181942744616u },
+  {  7683140964294066176u, 13145148522871947193u,          40679619581u },
+  {  4611686018427387904u,  5665349945233068642u,         253712599929u },
+  {                    0u, 17074607537751066240u,         121307119235u },
+  {                    0u,  6241525660962062336u,         131925616329u },
+  {                    0u,  1142860629783085056u,         201338353784u },
+  {                    0u, 16287527416870469632u,         120061954598u },
+  {                    0u,  9028002014738513920u,          38882948630u },
+  {                    0u, 16217462258161156096u,          22489408969u },
+  {                    0u, 11529215046068469760u,         201879150390u },
+  {                    0u,                    0u,          54625000000u },
+  {                    0u,                    0u,          64000000000u },
+  {  1722045467931902045u,                   19u,                    0u },
+  { 16095324008152856733u,          19093352271u,                    0u },
+  { 15216188060094280738u,   646608198162977646u,                    1u },
+  { 10793385929903030893u, 12170458846894708007u,           1035052700u },
+  { 12613277226875940039u,  1797330480103086687u,         156659761896u },
+  { 10644539625155600107u, 10332188564497263448u,         232097433480u },
+  {  6181262895644173983u,  7524259485079594225u,         136560109064u },
+  {   148914399627082292u,    62681109059153749u,           8407890924u },
+  { 14379289774887985969u, 13480636451804037081u,         236003397949u },
+  { 11743339675582627452u,  6948168233012789004u,          61730786766u },
+  {  7841621929809463497u, 12015502974041806055u,         206376660954u },
+  { 11168944680251236601u,  7343801660689004040u,         218651361721u },
+  {  6178560202529287410u, 13670580858640731144u,         185398108285u },
+  { 13295243308201596112u,  5605073897566574851u,         125741083673u },
+  { 17040673746172470291u, 15387788940505247559u,          25303851664u },
+  { 14957442487039409922u, 17565181499678113030u,         144834173709u },
+  { 17778155426506992152u,  1893743623847493029u,          13952210397u },
+  { 14945404984219733899u, 10243498996716269784u,         221102660047u },
+  { 11590754866058681505u,  5619675836950314139u,         207555301193u },
+  {  6020790784469412466u, 10224869737511515088u,          73304643237u },
+  {  7934351824569522326u,  2574495974386198538u,         165554291299u },
+  {  5038361112172116744u,  7825756347302873178u,          99139563706u },
+  {  3305187319649924210u, 12071550103794656887u,         186424235101u },
+  { 11470175511099161552u,  7195875213867606691u,          93654400042u },
+  {  7308362160352048610u, 18271364438406891044u,          42390089176u },
+  { 10666410671225576634u, 16966521933952564706u,         216990492650u },
+  {  2181639019945820785u,   289920862029570129u,         234919756997u },
+  {  4615749499734847918u,  7804199568098625032u,         197015716641u },
+  { 14076159200958497580u,  5758118571242446585u,          33423066506u },
+  {  5470405257862074105u,  4030788293606375591u,         138312148233u },
+  {  4565741478181339543u,  4387716460037196127u,           9218509471u },
+  {  8901832997861862329u, 16807506478881285981u,         159237858585u },
+  { 14190141170191714122u, 17033060604413529717u,          25911136751u },
+  {  4240772322245764096u, 10498418508292170054u,         239923364065u },
+  {  4422842195340951552u, 13237752038744465016u,         225569120407u },
+  { 15448426386733137920u, 17737618428304633155u,         151717619975u },
+  {  9203504548935630848u, 13546183833248825736u,           7961558221u },
+  {  5936377627571912704u,   826778452978976229u,         205734340097u },
+  {   468374361246531584u, 13728076626990147292u,           1044819749u },
+  {                    0u,  2794860281883592225u,          37744200525u },
+  {                    0u,  8680705720425908736u,          77151509679u },
+  {                    0u,   731520517439488000u,         175470582000u },
+  {                    0u, 13120812320768917504u,         240039655806u },
+  {                    0u,  2722954908557901824u,         126711280661u },
+  {                    0u,  6860847004205973504u,          21147611681u },
+  {                    0u,  6503197861922996224u,          33371927261u },
+  {                    0u,  9223372036854775808u,         221352539062u },
+  {                    0u,                    0u,         182500000000u },
+  {  8020875056524075716u,               291341u,                    0u },
+  {  1400288714762747253u,      291341434812508u,                    0u },
+  {  6136037711314764689u, 12005656413127238315u,                15793u },
+  { 15735488086392394102u,  4821130826186787462u,         177650827938u },
+  {  7735094782793634552u, 14377899467066168118u,         162261354025u },
+  {  7273689191766726188u, 16575613239625444872u,          41779427491u },
+  {  3410634565056431030u,  4317827099179284377u,         163898565794u },
+  {  4600927904885215898u,  1242354770412171254u,         162234069876u },
+  {  9154871331680374746u,   994838588328896609u,         116067348187u },
+  {  6117978272461042996u, 17283309862013060457u,         219053930307u },
+  { 13116904339287496285u,   124242522249856586u,          67936930105u },
+  {   867037205615660831u, 11564608014666985609u,          57006735200u },
+  {  1802487145191504830u, 12401028575581654085u,          96626918656u },
+  { 17242009718457409007u,  2490725392961465727u,            672261106u },
+  { 13620802355488468049u,  1949482237120640915u,         242135022494u },
+  {  4442227880594435745u, 15410502396166200087u,         158105681643u },
+  { 17354849212854314181u, 15694919529799920727u,         235835405008u },
+  { 18202319179831567886u, 10324869370171768388u,         208850823292u },
+  { 17568634016348874558u,  1631866459122189059u,         124559712290u },
+  {  7496925598312450672u,   172020494461226230u,          34088463658u },
+  {   601870379496813865u, 12734610307908856767u,          42009325249u },
+  { 11995106565680728027u,  1467513250829340930u,         193690344608u },
+  { 16331071694764184179u, 13558759428494307997u,         160079554052u },
+  {  9665962217000524208u,  7915355143999496434u,           4735021821u },
+  { 13682661374415474390u,  2876370200608797469u,         253429092262u },
+  {  6940361789924260864u,   343685370404989503u,         166155928341u },
+  {  9658039831644010465u,  4837266557407634630u,          21018631221u },
+  {  6843715893910236922u,  9622591415747161468u,          53262228745u },
+  {    47089792870595660u, 16503783814424220982u,           9521641725u },
+  { 14510386192097156932u,  5377083431343591334u,         253894671913u },
+  { 12059931208360040296u, 16508482371299291595u,          41291492276u },
+  { 14877013468459184620u, 10515883558812249028u,         180894926622u },
+  {  2397668560671695044u,    63492062913405476u,          30570067190u },
+  {  2195572305559232232u, 11571919759617799697u,         246003441911u },
+  {  3261686279425953792u,  2956602334970088581u,         247627315027u },
+  {  9333850662059900928u, 13604736747717849839u,          83160277733u },
+  {  5036522340217782272u, 16573540719338151362u,         229737514256u },
+  {  2800120215143186432u, 12620703004601168151u,          16898453442u },
+  {   441634238459019264u, 14649407809089591941u,         194684169680u },
+  {   720575940379279360u, 11290375247898624432u,         208794145988u },
+  {                    0u, 11020319450292874212u,         196612052468u },
+  {                    0u,  8754634933362354176u,         244597412714u },
+  {                    0u, 12976319450332528640u,         106474589710u },
+  {                    0u, 17447331119627239424u,          14703447686u },
+  {                    0u,  3665184902673858560u,         134945821715u },
+  {                    0u, 12949678516038795264u,          19198690071u },
+  {                    0u,    72057594037927936u,          23702003479u },
+  {                    0u,                    0u,          23003906250u },
+  {                    0u,                    0u,         202000000000u },
+  {  8218347283861607400u,                    4u,                    0u },
+  { 17896200385973633643u,           4445517498u,                    0u },
+  { 16333242102094352209u,  4445517498970154966u,                    0u },
+  {  9981905728606788815u,  9413159735776077452u,            240991986u },
+  { 15219470018924839012u, 14279163482889998017u,         242510288411u },
+  { 17152070168529617370u,  8693044629541194274u,          27774075003u },
+  { 17841343440958328027u, 11863110253260222498u,         123471250893u },
+  { 17291078023923990493u,  8319293368489531245u,         205643100495u },
+  { 16744804581790759223u,  3376307525676489265u,          79450989797u },
+  {  5001622214111594905u, 13205662254759912523u,         229183029997u },
+  {  9676746897435398146u,  5276250334231686323u,         237715880385u },
+  {  8109025833995118532u, 13790198520922745052u,         193286026103u },
+  {  5495826424046694744u, 14195535250150996227u,         119747568159u },
+  {  7890288164365705852u, 16425228796427004035u,          31769541507u },
+  {  8616438349039895217u,  4295900841296269186u,         131890413437u },
+  { 15787154801788760618u,  4533952595483946442u,         125232881251u },
+  { 12418659311480782502u, 12885038019373447184u,          99245786062u },
+  {  4486988874116669987u, 12140736240487831910u,         206698499310u },
+  {  4828971301551875409u,  6927124077155322074u,         238658150630u },
+  { 14769106422014442226u, 12477788342407819890u,         230375520148u },
+  {  7763933466423188156u,  7980854329409711087u,         148676422261u },
+  { 10449097116253839963u,  2062671021810827996u,         117432642980u },
+  { 12870692502472900571u,  2739521363598172769u,         164111817620u },
+  { 11597479481311003817u, 12897585686593465638u,         148148509750u },
+  {  8294994869530047486u,  1127632646629044686u,          54699179521u },
+  { 16879315829924478241u,  4833775019274666364u,           1061129088u },
+  { 11873324837601439670u, 15867662672939849256u,         128262039468u },
+  {  3277599055636107318u,  2092350330982953557u,         172860187717u },
+  { 15363467897354242201u, 13330062299842493592u,          69113426538u },
+  { 10351182204479784367u,  4479193352178519263u,         106722624125u },
+  { 12811517584931924466u,  3149393938889064983u,         125242817558u },
+  { 16988930699558748726u,  9736379904070620767u,          22170728987u },
+  { 11683499918824718325u,  3816238703055069186u,          27527810212u },
+  { 13119300691281647499u, 11598915938798661975u,         164206878714u },
+  { 10125549106595354099u, 17821633264606555643u,         250628778492u },
+  { 17505352699870800544u,  2514623558764574316u,         252966112675u },
+  {  6756039242241163264u,  4976730480406253215u,         163136318016u },
+  {  3537338758766526464u, 17276563697191611637u,          64269789099u },
+  {  6522626374119718912u, 12524734095940998814u,         171936564394u },
+  {  4733294203482669056u, 15331551308930355164u,         170678967195u },
+  { 16997710893603094528u, 15417115581125943816u,         155831125061u },
+  { 16717361816799281152u,  6010750237807115593u,          69835763510u },
+  {                    0u,  5624630987553628432u,          54325843423u },
+  {                    0u, 14881848243837640704u,         223304911856u },
+  {                    0u, 15281613886881529856u,         240806746609u },
+  {                    0u, 14057902358273196032u,         241828417948u },
+  {                    0u, 16075318494433902592u,         156762080413u },
+  {                    0u, 13891916000577716224u,         157871444761u },
+  {                    0u,  7205759403792793600u,          25753082275u },
+  {                    0u,                    0u,         163390625000u },
+  {                    0u,                    0u,         232000000000u },
+  {  3943737498063000362u,                67833u,                    0u },
+  {  2870731037991212489u,       67833213790438u,                    0u },
+  {  7389433400402095883u,  4535831408134330609u,                 3677u },
+  {  5675049236146197433u,  6204770794376564579u,          93245887913u },
+  {  9953779846262904264u, 13869812122751887467u,         169336361298u },
+  { 12691978937179636241u, 14253229412394467550u,          82751884021u },
+  { 15523327331528198029u, 12776557610216045332u,         245772669114u },
+  { 15722603279568118520u, 16493640728678654060u,         186692618575u },
+  { 11838632364171816147u,  9434398296825833151u,          79894122055u },
+  {  7832751832367143680u,  8773374058285327850u,          71511439756u },
+  { 12167724027162940862u, 12932015276748029367u,         140475605560u },
+  {  4108211144748152962u, 16293958583527755209u,          56701045952u },
+  {  7530983398136343676u, 13511893936143127948u,         192883297264u },
+  {  1117587133956542355u, 18409936402005226436u,         240732481237u },
+  { 17134748625149490872u,  2189663026458466887u,         213998004652u },
+  {  4039918359454207848u,  9497725274248154664u,         172118701870u },
+  {  1830218764589441242u, 14766925481127792125u,          46514872718u },
+  {   637895981480825742u,  6982373971809635814u,         142800516634u },
+  {  8246879226348334620u,  8616702383006884794u,          26378515251u },
+  { 12389239568142583275u,  3059473300040871066u,          51467112372u },
+  { 14041257178803154398u, 17123843157031495558u,         180165854379u },
+  { 16312515716494630702u, 11210627174210626524u,         171928285397u },
+  { 17088522799596987756u, 15868067138625928592u,         213607729316u },
+  {  3588932524637852678u,  4467869511636937589u,         164860209643u },
+  {   107218049069817414u, 10052108125844341766u,         235242203691u },
+  {  1596707240462008334u,  7470588003218451534u,          43544925873u },
+  { 17461913142391587672u,  2613527085490786280u,         177404981387u },
+  {  4366474266651610090u,  3632919450036549616u,         139141679587u },
+  {  5539304013194805084u,   179367907231218916u,         227196940958u },
+  {  4762470619211987849u, 13553068184555874624u,         158009723553u },
+  { 10835638458986644717u,  8798774862365584481u,         161734713298u },
+  { 16141642290510052058u,   910911255817064881u,         210476982541u },
+  { 17390568670756355425u,  2304331144765093813u,          13049380598u },
+  { 12536768491333867107u, 12248937023083640360u,         246124918041u },
+  { 13145148522871947193u, 10206039550662130685u,          25664016206u },
+  {  5665349945233068642u, 12267881323837852537u,          78553270512u },
+  { 17074607537751066240u,  2858642007937891971u,         240665043179u },
+  {  6241525660962062336u, 14171330289750320841u,         235154967293u },
+  {  1142860629783085056u,  6601103619749017720u,         253768229354u },
+  { 16287527416870469632u,  4919573414486739494u,         234357846544u },
+  {  9028002014738513920u,  3401998285294974486u,          16266690609u },
+  { 16217462258161156096u, 10799436256515532233u,          49184422696u },
+  { 11529215046068469760u, 10083786644665753398u,          40585438612u },
+  {                    0u,  6481194517685688896u,         148546643169u },
+  {                    0u, 15104161756860547072u,         225351346258u },
+  {                    0u,  9556039274244079616u,          82818798249u },
+  {                    0u,  1376343134954323968u,         169518033927u },
+  {                    0u, 15682488278596976640u,           7074611710u },
+  {                    0u,  1506454075355430912u,         254850149393u },
+  {                    0u,  1152921504606846976u,          17081665039u },
+  {                    0u,                    0u,          15062500000u },
+  {                    0u,                    0u,         160000000000u },
+  { 12170458846894708007u,           1035052700u,                    0u },
+  {  1797330480103086687u,  1035052700659761896u,                    0u },
+  { 10332188564497263448u,  6172559441576707976u,             56110319u },
+  {  7524259485079594225u, 15083329738554729992u,         239334615117u },
+  {    62681109059153749u, 10013126833549229036u,          77817668943u },
+  { 13480636451804037081u,  5817156823499936061u,          79542812693u },
+  {  6948168233012789004u,  5282692560913632718u,          21315348703u },
+  { 12015502974041806055u, 10252307034225766362u,         223286375337u },
+  {  7343801660689004040u, 17981881283247669689u,         169555778677u },
+  { 13670580858640731144u, 11689290159733383293u,         117974799737u },
+  {  5605073897566574851u,  5530668968487988249u,         121633677689u },
+  { 15387788940505247559u, 10083765740821947024u,         121299818165u },
+  { 17565181499678113030u,  2798423656816843533u,         181546642036u },
+  {  1893743623847493029u,  7614494481582904797u,         116151702850u },
+  { 10243498996716269784u, 17811318500083423695u,          66412782572u },
+  {  5619675836950314139u, 11641467412200329033u,         236965553510u },
+  { 10224869737511515088u, 17733593025296340645u,         102631085212u },
+  {  2574495974386198538u,  3689424000190644835u,         156961340004u },
+  {  7825756347302873178u, 14966634145516728506u,         100200004075u },
+  { 12071550103794656887u, 14171681941562070109u,         235811342862u },
+  {  7195875213867606691u,  8130575762882608170u,          14768248417u },
+  { 18271364438406891044u,  5234550794400656856u,          97440759395u },
+  { 16966521933952564706u,  3020576149360486378u,          99283765567u },
+  {   289920862029570129u,  3038675756589057221u,          63163745761u },
+  {  7804199568098625032u, 15470260187120878369u,         225164726942u },
+  {  5758118571242446585u,  3497929414841828746u,         158838644485u },
+  {  4030788293606375591u,  9935840636861015305u,           5189623133u },
+  {  4387716460037196127u,  3647355485153741471u,          93538623000u },
+  { 16807506478881285981u,   766100215038272793u,          24197723537u },
+  { 17033060604413529717u, 16128087474216800751u,         145041530375u },
+  { 10498418508292170054u, 16216631732633731297u,           7874305373u },
+  { 13237752038744465016u, 13760220872779997335u,          93879105367u },
+  { 17737618428304633155u,  3826276262374222087u,          87745943068u },
+  { 13546183833248825736u, 14938032745839181005u,          28207422851u },
+  {   826778452978976229u, 14479259995009508865u,         131809792377u },
+  { 13728076626990147292u,  2372033248156102437u,         121784922257u },
+  {  2794860281883592225u,   792005346826701645u,         145128588180u },
+  {  8680705720425908736u, 16278924527931792559u,         148042934695u },
+  {   731520517439488000u, 17442516423538940144u,         167882482266u },
+  { 13120812320768917504u,    13844184233048446u,          90945560710u },
+  {  2722954908557901824u, 13486193870480782357u,         134000750494u },
+  {  6860847004205973504u, 11931315179184648737u,         158731088034u },
+  {  6503197861922996224u, 16492562205587485405u,         162646797891u },
+  {  9223372036854775808u, 12128987217680380854u,          67894063588u },
+  {                    0u, 10568123814189138176u,         228657513714u },
+  {                    0u, 17007583519117541376u,         242572899139u },
+  {                    0u,   143791533903052800u,          67921982950u },
+  {                    0u, 12398714235792654336u,         230007794954u },
+  {                    0u,  9659957317919047680u,          10672135645u },
+  {                    0u,  9412523221204336640u,         221523667335u },
+  {                    0u,  4611686018427387904u,         135510253906u },
+  {                    0u,                    0u,          82250000000u },
+  {                    0u,                    0u,         128000000000u },
+  { 12005656413127238315u,                15793u,                    0u },
+  {  4821130826186787462u,       15793650827938u,                    0u },
+  { 14377899467066168118u,  3237900842885170729u,                  856u },
+  { 16575613239625444872u,  7515893506498066595u,          88175526956u },
+  {  4317827099179284377u,  7300206309181072546u,          44407437403u },
+  {  1242354770412171254u,     5999737279837044u,          91395744977u },
+  {   994838588328896609u,  7556839307242450651u,         209000325246u },
+  { 17283309862013060457u, 12946035041643640643u,         126409657079u },
+  {   124242522249856586u, 15885877642352740665u,         247701805965u },
+  { 11564608014666985609u, 10770818348246089568u,         141861175152u },
+  { 12401028575581654085u, 11635415503599551744u,         112583887232u },
+  {  2490725392961465727u,  6248053924100826098u,         128630757138u },
+  {  1949482237120640915u, 16894170802729859998u,          18338707681u },
+  { 15410502396166200087u,  6143589029651889899u,         225915834834u },
+  { 15694919529799920727u, 11812087701837886160u,         210333044628u },
+  { 10324869370171768388u,  7306705080150829180u,         148640334557u },
+  {  1631866459122189059u,  1485332570280714274u,         221396097276u },
+  {   172020494461226230u, 18042602303295630634u,         252080520039u },
+  { 12734610307908856767u, 13397029889257074369u,         103978091430u },
+  {  1467513250829340930u,  9948104869613411488u,         166726254445u },
+  { 13558759428494307997u, 10836066241170646532u,         109539287845u },
+  {  7915355143999496434u, 18330574781234459389u,          37587424327u },
+  {  2876370200608797469u,   666297360208433062u,          71993702450u },
+  {   343685370404989503u,  5035352224889324309u,          50036120052u },
+  {  4837266557407634630u,  1341745796439923765u,         244272966991u },
+  {  9622591415747161468u,  6846932182653803785u,          79072736185u },
+  { 16503783814424220982u,  6727685027257825533u,         185371172937u },
+  {  5377083431343591334u,  2168538874806877737u,          73364708536u },
+  { 16508482371299291595u, 17694936100676971444u,         184117556727u },
+  { 10515883558812249028u,  2163944241059563294u,         247959244408u },
+  {    63492062913405476u,  6727780864524301558u,         120117307652u },
+  { 11571919759617799697u,  8599551977795002615u,           4364713731u },
+  {  2956602334970088581u, 15428264807806859091u,           3466182646u },
+  { 13604736747717849839u,  2126771385339683557u,         246836367911u },
+  { 16573540719338151362u, 15094316562082972944u,          39115292507u },
+  { 12620703004601168151u,  8111300598225956802u,          91818264540u },
+  { 14649407809089591941u,  9481215200564260304u,         220439714486u },
+  { 11290375247898624432u, 16836674128623424708u,         182513977705u },
+  { 11020319450292874212u,  7087243115299722740u,         105912717933u },
+  {  8754634933362354176u,  2343560867338408810u,         109384200219u },
+  { 12976319450332528640u,  3431385749090422286u,          27127044689u },
+  { 17447331119627239424u,  3504545517469224582u,          81186015794u },
+  {  3665184902673858560u,  3333759805712094227u,          50189981793u },
+  { 12949678516038795264u,  3595183476205994775u,          97180723481u },
+  {    72057594037927936u, 14191566632569921303u,          25194895286u },
+  {                    0u, 12917427671358095562u,         182769326368u },
+  {                    0u,  3883793922738316288u,          32700255157u },
+  {                    0u,  7857281689266421760u,         181210540890u },
+  {                    0u, 15987081651486195712u,          90425944093u },
+  {                    0u, 16827562156399525888u,          29866661432u },
+  {                    0u,  7012737938513461248u,          56912223972u },
+  {                    0u,  7385903388887613440u,         228380161285u },
+  {                    0u,                    0u,           5400390625u },
+  {                    0u,                    0u,         225000000000u },
+  {  9413159735776077452u,            240991986u,                    0u },
+  { 14279163482889998017u,   240991986510288411u,                    0u },
+  {  8693044629541194274u, 14135788013842776187u,             13064201u },
+  { 11863110253260222498u, 13284322918167594445u,           9766302603u },
+  {  8319293368489531245u,  7264587765474046287u,         139720144588u },
+  {  3376307525676489265u, 16176482219778368741u,         204393814091u },
+  { 13205662254759912523u,  5401983818872095469u,          75876928858u },
+  {  5276250334231686323u, 11208857446851049921u,          90292842129u },
+  { 13790198520922745052u, 13794690008281035639u,         145607633379u },
+  { 14195535250150996227u, 14519782740993303071u,         227747811643u },
+  { 16425228796427004035u, 10885858587044789123u,          59787118999u },
+  {  4295900841296269186u,  8710500938899914621u,         151590123576u },
+  {  4533952595483946442u,  1284182587483102819u,          56472197202u },
+  { 12885038019373447184u, 10346074482131502030u,          82069615677u },
+  { 12140736240487831910u,  9429804686255246574u,          61560861821u },
+  {  6927124077155322074u,  6412022633845121254u,         125511190736u },
+  { 12477788342407819890u,  8892351297529018260u,         208347596443u },
+  {  7980854329409711087u, 14098160105983060597u,         155482055329u },
+  {  2062671021810827996u, 13793833029739474340u,         161764262790u },
+  {  2739521363598172769u, 16367653765996977044u,         134747765186u },
+  { 12897585686593465638u, 10684788343333772342u,         194887292288u },
+  {  1127632646629044686u, 13272681218705145345u,         128579223536u },
+  {  4833775019274666364u, 11093568615497829248u,         240719513490u },
+  { 15867662672939849256u, 12488220765137758124u,         146601383559u },
+  {  2092350330982953557u,  3727114642519696453u,         135676987804u },
+  { 13330062299842493592u, 11549865375695057514u,         156202047289u },
+  {  4479193352178519263u, 11292809154908783229u,          57626119456u },
+  {  3149393938889064983u, 17723904861837310998u,          32612184410u },
+  {  9736379904070620767u, 14877674388187150875u,          90960814807u },
+  {  3816238703055069186u, 12178961950105734308u,         215806520344u },
+  { 11598915938798661975u,  4540604068069253114u,          24660222850u },
+  { 17821633264606555643u, 13832478722153359868u,         130246146639u },
+  {  2514623558764574316u,  1308046668730371491u,          79749860174u },
+  {  4976730480406253215u, 18400531023544756800u,          78070909351u },
+  { 17276563697191611637u,  9789823458621466539u,         167997494785u },
+  { 12524734095940998814u,  1924870562610267306u,           1530707393u },
+  { 15331551308930355164u,  5290016144582400923u,         193104347442u },
+  { 15417115581125943816u, 15162883663174059077u,          50286772349u },
+  {  6010750237807115593u,  8078086116520046390u,         125821981570u },
+  {  5624630987553628432u, 15731407332173190623u,         130437913925u },
+  { 14881848243837640704u,  5346389182763011056u,          69852801300u },
+  { 15281613886881529856u,  6368422217216252401u,          20289828338u },
+  { 14057902358273196032u,  2961453088119116188u,         242345232860u },
+  { 16075318494433902592u, 10932141691610170525u,         220160540693u },
+  { 13891916000577716224u, 11034016191361782553u,          21592632588u },
+  {  7205759403792793600u,  5455325785621453219u,          12598155216u },
+  {                    0u,  7735615202566149352u,         208295733803u },
+  {                    0u,  7502396497775759360u,          43419348540u },
+  {                    0u,  1601286435751591936u,          60406705729u },
+  {                    0u, 11449383158571597824u,          65086805911u },
+  {                    0u, 13043944595690356736u,         151620672304u },
+  {                    0u,  7773494431818186752u,          48707113653u },
+  {                    0u,  9943947977234055168u,         181421401977u },
+  {                    0u,                    0u,         121539062500u },
+  {                    0u,                    0u,         228000000000u },
+  {  4535831408134330609u,                 3677u,                    0u },
+  {  6204770794376564579u,        3677245887913u,                    0u },
+  { 13869812122751887467u,  6343817245135589714u,                  199u },
+  { 14253229412394467550u, 17549323075660516085u,         199343899021u },
+  { 12776557610216045332u,  3948641822109421754u,         141951350710u },
+  { 16493640728678654060u,  1750739713693534543u,         182214056302u },
+  {  9434398296825833151u,   962163898128633415u,         110094907790u },
+  {  8773374058285327850u,  7967320249386531212u,         142052159009u },
+  { 12932015276748029367u,  3018466665533383224u,          33431909296u },
+  { 16293958583527755209u, 15076865731854945472u,         176163631405u },
+  { 13511893936143127948u,   691187172844604400u,          45817318529u },
+  { 18409936402005226436u, 13274492813370992341u,         129037469331u },
+  {  2189663026458466887u,  6364168818499152300u,         147719611697u },
+  {  9497725274248154664u, 17599380787401914158u,          49345002282u },
+  { 14766925481127792125u,  3782323149461692814u,          42954064344u },
+  {  6982373971809635814u, 14470163442442237466u,         216205040148u },
+  {  8616702383006884794u,   476109872130437939u,          20784429132u },
+  {  3059473300040871066u, 16330548844673355700u,          76025809967u },
+  { 17123843157031495558u, 14089158961463739563u,          47885280826u },
+  { 11210627174210626524u, 13385510793074798805u,          58763774837u },
+  { 15868067138625928592u,  1549401308746959012u,         117725629994u },
+  {  4467869511636937589u,  4607384943843027435u,          42083993213u },
+  { 10052108125844341766u,  5157353797716093483u,         125249766838u },
+  {  7470588003218451534u, 10846828782671550129u,         182279580709u },
+  {  2613527085490786280u,  9915857350819131531u,          37588007766u },
+  {  3632919450036549616u,  1673544973504317923u,          86537539704u },
+  {   179367907231218916u, 14780986291622785694u,         120090723054u },
+  { 13553068184555874624u,  8168111319515466401u,         238801278872u },
+  {  8798774862365584481u, 16345760387859734482u,         152442794201u },
+  {   910911255817064881u,  3177475373321281805u,         217886105446u },
+  {  2304331144765093813u,  2558676822419554038u,         102172251285u },
+  { 12248937023083640360u,  8813474062662382873u,         149138706148u },
+  { 10206039550662130685u,  5426294560236228430u,         228477779386u },
+  { 12267881323837852537u,  9919177474128333040u,         186294160017u },
+  {  2858642007937891971u,  6197383943089627371u,         145537719688u },
+  { 14171330289750320841u, 13673239314867423997u,         136335960856u },
+  {  6601103619749017720u,  9309584098968723946u,          24741227788u },
+  {  4919573414486739494u,  4647101757759615504u,          12504673565u },
+  {  3401998285294974486u,  1405809295505096753u,          29251919891u },
+  { 10799436256515532233u, 11332704079573859112u,          19076209074u },
+  { 10083786644665753398u,  2960072434514044308u,         178614347119u },
+  {  6481194517685688896u,  3887266602785432801u,         111160465848u },
+  { 15104161756860547072u, 14545546084687849554u,         184210729144u },
+  {  9556039274244079616u,  4617763804182385321u,         184788515633u },
+  {  1376343134954323968u,  7857823815580249095u,          49250329477u },
+  { 15682488278596976640u, 10939326736548364798u,         133425973482u },
+  {  1506454075355430912u, 12262012446566951953u,         234593022090u },
+  {  1152921504606846976u, 12555024338687723023u,         138664725026u },
+  {                    0u,  3332969632922829472u,          34680609233u },
+  {                    0u, 15535060143360327680u,         209180680645u },
+  {                    0u, 15794322927987458048u,         197842157297u },
+  {                    0u, 10571474314433921024u,         241856211961u },
+  {                    0u, 16679514427547975680u,         249573080770u },
+  {                    0u, 16925653299565166592u,         194904198288u },
+  {                    0u, 16717361816799281152u,         144917541503u },
+  {                    0u,                    0u,         127906250000u },
+  {                    0u,                    0u,          16000000000u },
+  {  6172559441576707976u,             56110319u,                    0u },
+  { 15083329738554729992u,    56110319334615117u,                    0u },
+  { 10013126833549229036u,  9335385384027907407u,              3041746u },
+  {  5817156823499936061u, 13237828406194798613u,         210506072255u },
+  {  5282692560913632718u, 15667486867836528863u,         191717624115u },
+  { 10252307034225766362u, 17982325043592934313u,          51849336164u },
+  { 17981881283247669689u, 17159117626917379189u,         100974823793u },
+  { 11689290159733383293u,  8336208968408929657u,         113930197630u },
+  {  5530668968487988249u, 12767090573379150201u,         126451906793u },
+  { 10083765740821947024u, 14736070002412246709u,         233692105366u },
+  {  2798423656816843533u,  9697296975344560756u,         150798843955u },
+  {  7614494481582904797u,  7291706381199103298u,          51525691522u },
+  { 17811318500083423695u, 18098546597780825068u,         130395284194u },
+  { 11641467412200329033u,   132913902678533478u,         226981124177u },
+  { 17733593025296340645u,  1879347741692007580u,          81007205277u },
+  {  3689424000190644835u,  4056624629214083684u,         157101879645u },
+  { 14966634145516728506u, 14713227692042795499u,          93219910061u },
+  { 14171681941562070109u,  7366415124022528526u,         173797605671u },
+  {  8130575762882608170u,   825770353378039393u,          39399334164u },
+  {  5234550794400656856u, 10244023944395357795u,          20044765100u },
+  {  3020576149360486378u, 14302658294713551167u,         172555329650u },
+  {  3038675756589057221u, 14246653166206862817u,         114775348659u },
+  { 15470260187120878369u, 12404486258134291102u,         179772312615u },
+  {  3497929414841828746u,  8887442218637942533u,          39672448547u },
+  {  9935840636861015305u,  1186724038081863005u,          35481789208u },
+  {  3647355485153741471u,   211331772484951576u,          24064332439u },
+  {   766100215038272793u,  6311919513247413649u,         151011456318u },
+  { 16128087474216800751u,  8131780018703965703u,          62342169842u },
+  { 16216631732633731297u,  2262544347226725725u,         242440824678u },
+  { 13760220872779997335u, 15318188749880522583u,         102122652774u },
+  {  3826276262374222087u,  1073117094162650652u,         102830400676u },
+  { 14938032745839181005u,  4447950380665871747u,         164058173794u },
+  { 14479259995009508865u,  5373227185066463609u,          98241123873u },
+  {  2372033248156102437u,  6739731406934274193u,          33291283229u },
+  {   792005346826701645u, 12328812617001239444u,          29365361571u },
+  { 16278924527931792559u,  3246111484407310759u,         163668346271u },
+  { 17442516423538940144u,  3250825415176839770u,         159175972056u },
+  {    13844184233048446u, 16146270540000862342u,         216176227598u },
+  { 13486193870480782357u, 15686773375425916830u,          14875291079u },
+  { 11931315179184648737u, 11920791905793880226u,         199850381688u },
+  { 16492562205587485405u,  1853290561644080707u,         120646227424u },
+  { 12128987217680380854u, 12157689141506159076u,         224100467082u },
+  { 10568123814189138176u, 18100318838862562546u,         138659069648u },
+  { 17007583519117541376u,  7171257882533475139u,         208981220250u },
+  {   143791533903052800u, 14477550873015039462u,         154388754668u },
+  { 12398714235792654336u,  8109481182495403274u,         236784829605u },
+  {  9659957317919047680u, 14565395719337663965u,         165439615855u },
+  {  9412523221204336640u,  1860318978161305991u,         111789591684u },
+  {  4611686018427387904u, 16268646275151585618u,         132100848093u },
+  {                    0u, 13759019338835519104u,         221881925081u },
+  {                    0u, 17003783176010661888u,         217745877932u },
+  {                    0u, 18357489540307877888u,         172921776932u },
+  {                    0u,   905481790074912768u,          36995161502u },
+  {                    0u,  3638882110636294144u,         158049086266u },
+  {                    0u,  9011702854368362496u,          58197264194u },
+  {                    0u, 11529215046068469760u,          66488525390u },
+  {                    0u,                    0u,          78625000000u },
+  {                    0u,                    0u,          64000000000u },
+  {  3237900842885170729u,                  856u,                    0u },
+  {  7515893506498066595u,         856175526956u,                    0u },
+  {  7300206309181072546u,  7625299565768063067u,                   46u },
+  {     5999737279837044u, 13889021769065194705u,          46413368317u },
+  {  7556839307242450651u, 14498170692313014398u,         253752925378u },
+  { 12946035041643640643u,  1541631360972245751u,         194785947408u },
+  { 15885877642352740665u,  9903958882920799117u,          16083572003u },
+  { 10770818348246089568u, 15744148547788062576u,          35536894686u },
+  { 11635415503599551744u, 17936061801321712000u,         222853492002u },
+  {  6248053924100826098u,  9986394078324430610u,          34972315858u },
+  { 16894170802729859998u, 13849561248103430369u,         210541363507u },
+  {  6143589029651889899u, 12142378807953854930u,          51750786219u },
+  { 11812087701837886160u,  2513847703931031444u,         171658239674u },
+  {  7306705080150829180u,  1752183758129038045u,         186136275957u },
+  {  1485332570280714274u, 15824833342220556540u,         245094986071u },
+  { 18042602303295630634u,  8168747198299470695u,          87857865934u },
+  { 13397029889257074369u, 17414799840149357478u,         206442828672u },
+  {  9948104869613411488u,    83147520704167789u,         128944058191u },
+  { 10836066241170646532u,  2383542703041471269u,          79004507436u },
+  { 18330574781234459389u, 15540952725549257799u,          44129212108u },
+  {   666297360208433062u,  6949835416232048690u,         204842476735u },
+  {  5035352224889324309u, 15398868937585367540u,         191376751332u },
+  {  1341745796439923765u, 14710915985268256079u,         228834774357u },
+  {  6846932182653803785u,  9665704836873335737u,          85797480353u },
+  {  6727685027257825533u,  2528789298740305993u,         161523978909u },
+  {  2168538874806877737u, 10562914675687726264u,         157137085942u },
+  { 17694936100676971444u, 17671658300096837111u,         246572616751u },
+  {  2163944241059563294u,   356471401631698552u,          47957982516u },
+  {  6727780864524301558u,  7450677157218003204u,          52019324353u },
+  {  8599551977795002615u,   317174560787152643u,         193403902018u },
+  { 15428264807806859091u,  7251937674440720374u,          66017194067u },
+  {  2126771385339683557u,  1252631516699038247u,          83393128329u },
+  { 15094316562082972944u, 10818009768860843867u,         137067905290u },
+  {  8111300598225956802u, 12330114194950162396u,          10586445484u },
+  {  9481215200564260304u, 15826681638261168822u,         172668416829u },
+  { 16836674128623424708u, 14240150078499211625u,          61857966130u },
+  {  7087243115299722740u, 10725372116242125421u,          50771960082u },
+  {  2343560867338408810u,  8434925524647833627u,          18581423587u },
+  {  3431385749090422286u, 17133902668520348241u,         227457258228u },
+  {  3504545517469224582u, 15093996047981365810u,         244928830724u },
+  {  3333759805712094227u,  6187974166976813153u,           4818247165u },
+  {  3595183476205994775u, 13946144707720259865u,         253335450751u },
+  { 14191566632569921303u,  9138079832881862582u,         127756022019u },
+  { 12917427671358095562u,  6600697628576225568u,           3495376300u },
+  {  3883793922738316288u,  8137099536646556597u,         172357824535u },
+  {  7857281689266421760u, 14169855543453903706u,          23441113049u },
+  { 15987081651486195712u,  3706403268650100765u,         217768149408u },
+  { 16827562156399525888u, 14736932266877982264u,         160200924523u },
+  {  7012737938513461248u, 18004795125138956004u,         107798890698u },
+  {  7385903388887613440u,  9068489270661002501u,         202976041899u },
+  {                    0u,  7758835715193269217u,         171491603788u },
+  {                    0u, 16943947811135261184u,          76420607326u },
+  {                    0u,  6745843108403216384u,          94918533251u },
+  {                    0u, 12338229654069444608u,         131365692887u },
+  {                    0u, 14358176069683511296u,         215668856769u },
+  {                    0u,  7083775185760813056u,         193778358284u },
+  {                    0u,  5350276357316149248u,          12384012222u },
+  {                    0u,  9223372036854775808u,         190290039062u },
+  {                    0u,                    0u,          22500000000u },
+  { 14135788013842776187u,             13064201u,                    0u },
+  { 13284322918167594445u,    13064201766302603u,                    0u },
+  {  7264587765474046287u, 14699116688460625612u,               708211u },
+  { 16176482219778368741u,  6684126021499623499u,         115796840712u },
+  {  5401983818872095469u, 12614606079692508506u,           8362347197u },
+  { 11208857446851049921u, 15358270276683001489u,         189683839165u },
+  { 13794690008281035639u, 18077126190953408995u,         189832573499u },
+  { 14519782740993303071u,  7864121581925945659u,          59979962974u },
+  { 10885858587044789123u,  3518026639210514839u,          94426314885u },
+  {  8710500938899914621u,  4698310163811252280u,         133190712606u },
+  {  1284182587483102819u,  6101155398200416338u,          30254695904u },
+  { 10346074482131502030u, 16049178580360033341u,         224330744296u },
+  {  9429804686255246574u,  3167464649127375997u,         232870027714u },
+  {  6412022633845121254u, 12778923935480989904u,         194171708602u },
+  {  8892351297529018260u, 11875553912612980379u,         186692746854u },
+  { 14098160105983060597u, 10628760849351697057u,         102643775067u },
+  { 13793833029739474340u,  3408944711673234310u,          91576186280u },
+  { 16367653765996977044u,  2102091496050506178u,         168184799263u },
+  { 10684788343333772342u,  6254611118630245760u,          31113954608u },
+  { 13272681218705145345u,  2647941151989776368u,          48339063148u },
+  { 11093568615497829248u,  8855437735410157458u,         108143545177u },
+  { 12488220765137758124u, 10184270603132180103u,          89480054241u },
+  {  3727114642519696453u, 12079083162535627164u,         225552090415u },
+  { 11549865375695057514u,  5952952868716156729u,          47654808410u },
+  { 11292809154908783229u, 11958907037815852320u,          90322710221u },
+  { 17723904861837310998u, 10101562137321697626u,         205648293649u },
+  { 14877674388187150875u, 13633527411279258327u,          17547606780u },
+  { 12178961950105734308u, 16555627393501768728u,         252739075001u },
+  {  4540604068069253114u,  6359650463500280706u,         185897482359u },
+  { 13832478722153359868u,  8093923611102181967u,         119344757342u },
+  {  1308046668730371491u,  2848827352928635726u,          94438772478u },
+  { 18400531023544756800u,  4686723431961561511u,         254154435240u },
+  {  9789823458621466539u,  6245554925867652609u,         168254067786u },
+  {  1924870562610267306u, 17527406820792516033u,          74338572210u },
+  {  5290016144582400923u, 12119966834653692210u,         178950162627u },
+  { 15162883663174059077u, 11606502845877928061u,         195657024718u },
+  {  8078086116520046390u,   424311496652297090u,         206629189780u },
+  { 15731407332173190623u,  5977664048034127173u,         148023001972u },
+  {  5346389182763011056u,  6702712461535947028u,         116324049817u },
+  {  6368422217216252401u, 11384349854055020018u,         153363354770u },
+  {  2961453088119116188u,  3782955013294836188u,         146617146842u },
+  { 10932141691610170525u,  3531805968821207061u,         218205074402u },
+  { 11034016191361782553u,  3867566898657193228u,         226191459585u },
+  {  5455325785621453219u, 12688734637425072080u,           1209661221u },
+  {  7735615202566149352u, 18435982764454619691u,          37687857682u },
+  {  7502396497775759360u,  4728836163964677692u,          18999416628u },
+  {  1601286435751591936u,  2120012917348838977u,          52256350722u },
+  { 11449383158571597824u,  9856965465824679831u,           2114926130u },
+  { 13043944595690356736u, 11217197671061248816u,          50534347168u },
+  {  7773494431818186752u,  3840562972677739189u,         160608085504u },
+  {  9943947977234055168u, 17104366978925258617u,            208197335u },
+  {                    0u, 16177877219841993444u,         215927229591u },
+  {                    0u,  7338522384267208704u,         151877004481u },
+  {                    0u, 10935240458612244480u,         193397822095u },
+  {                    0u,  1732868046462124032u,         143592800573u },
+  {                    0u,   557965042578882560u,          61093938965u },
+  {                    0u, 10454684322475540480u,          21030247345u },
+  {                    0u, 13907115649320091648u,         177566749572u },
+  {                    0u,                    0u,         132753906250u },
+  {                    0u,                    0u,          74000000000u },
+  {  6343817245135589714u,                  199u,                    0u },
+  { 17549323075660516085u,         199343899021u,                    0u },
+  {  3948641822109421754u, 14876458284855834550u,                   10u },
+  {  1750739713693534543u, 10450704926982265198u,          10806454419u },
+  {   962163898128633415u,  5385653213018257806u,         147566533849u },
+  {  7967320249386531212u, 12735569669880147489u,         217291956845u },
+  {  3018466665533383224u,  3619762560577729456u,         109690396615u },
+  { 15076865731854945472u, 11123448126624084269u,         199196227721u },
+  {   691187172844604400u,  4072715118852885633u,         137603003331u },
+  { 13274492813370992341u, 18239087231420827283u,         195220782328u },
+  {  6364168818499152300u,   423431461216085297u,         248988742900u },
+  { 17599380787401914158u,  9360976716520160042u,         244022954265u },
+  {  3782323149461692814u, 11655927117263208920u,          25507459564u },
+  { 14470163442442237466u,  2646622721938364948u,         236631869075u },
+  {   476109872130437939u,  4496462484548171852u,         147143473705u },
+  { 16330548844673355700u, 13140258519803350063u,          41243753719u },
+  { 14089158961463739563u, 13089764333320627770u,         247712334841u },
+  { 13385510793074798805u,  6926286827289840501u,         249709597546u },
+  {  1549401308746959012u,  4985580225290866218u,         106375474761u },
+  {  4607384943843027435u, 10478790837359789693u,          73270268845u },
+  {  5157353797716093483u, 10041191967455692214u,         173568056389u },
+  { 10846828782671550129u,  5035461258013813797u,          69544334107u },
+  {  9915857350819131531u, 14208759661559249750u,          27272972901u },
+  {  1673544973504317923u, 12347272163241758840u,         101770258404u },
+  { 14780986291622785694u,  3372534174410277614u,         228669346965u },
+  {  8168111319515466401u, 17226704187274712984u,         149182825443u },
+  { 16345760387859734482u,  4250480179449852121u,         227933861505u },
+  {  3177475373321281805u,  4303723537755414374u,         129230418992u },
+  {  2558676822419554038u,  8680503847344854165u,          48233305320u },
+  {  8813474062662382873u,  8817608623911079652u,         232470571056u },
+  {  5426294560236228430u,  5692030448698539450u,          48478003521u },
+  {  9919177474128333040u, 16908836314686769809u,          65308565588u },
+  {  6197383943089627371u,  6073762347067727240u,          84916629853u },
+  { 13673239314867423997u, 10931066692585106200u,          93329259316u },
+  {  9309584098968723946u, 14466591364061539596u,          52592574312u },
+  {  4647101757759615504u,  4958077340960173341u,         104784235489u },
+  {  1405809295505096753u,  4076890037156765715u,         225268777911u },
+  { 11332704079573859112u, 14083973146609179058u,         183221008651u },
+  {  2960072434514044308u,  2565183738039805295u,          11763493714u },
+  {  3887266602785432801u,  1482420938751351224u,          82139058889u },
+  { 14545546084687849554u,  2151089495335413944u,         201080362200u },
+  {  4617763804182385321u,  3738604531753220913u,         216116610795u },
+  {  7857823815580249095u, 14195686514836005765u,         235202670157u },
+  { 10939326736548364798u, 17808833916231796970u,          77769549707u },
+  { 12262012446566951953u,  1302384553035657354u,         139965418821u },
+  { 12555024338687723023u,  1672033517974833698u,          69070602408u },
+  {  3332969632922829472u, 11673925532927662545u,         168090641118u },
+  { 15535060143360327680u,  3905334232240480709u,         222632844771u },
+  { 15794322927987458048u, 17411087320267472625u,         227211708592u },
+  { 10571474314433921024u, 16573305231063706617u,         176943856934u },
+  { 16679514427547975680u, 15481103236037148354u,          38898440676u },
+  { 16925653299565166592u,   907440704754420880u,         228839232288u },
+  { 16717361816799281152u,  3224970785139077759u,          32049192459u },
+  {                    0u, 10560826509734608144u,          11174826016u },
+  {                    0u,  4700940027512659968u,          32572503552u },
+  {                    0u,  9733694683502084096u,            254838469u },
+  {                    0u,  1995535635724632064u,         197527664646u },
+  {                    0u, 10629833226245373952u,           6108178203u },
+  {                    0u, 15729384648544878592u,          27576244413u },
+  {                    0u,  7205759403792793600u,         189852691650u },
+  {                    0u,                    0u,         194390625000u },
+  {                    0u,                    0u,         232000000000u },
+  {  9335385384027907407u,              3041746u,                    0u },
+  { 13237828406194798613u,     3041746506072255u,                    0u },
+  { 15667486867836528863u,  7535526066623007027u,               164893u },
+  { 17982325043592934313u, 11302146918409311588u,          29408501686u },
+  { 17159117626917379189u,  2480833299122194801u,         182612690612u },
+  {  8336208968408929657u, 11513226205589330558u,         180134486242u },
+  { 12767090573379150201u,  4073957068281936105u,         226624133243u },
+  { 14736070002412246709u,  3729887061093812886u,         123220849655u },
+  {  9697296975344560756u, 13616911779739451443u,         247202197582u },
+  {  7291706381199103298u, 13039053282195777666u,          78738174266u },
+  { 18098546597780825068u, 14490756113210417890u,          58706848494u },
+  {   132913902678533478u, 17432486112977557585u,         238785545462u },
+  {  1879347741692007580u, 14308820825344039837u,         246945016965u },
+  {  4056624629214083684u,  4190949538817536349u,         133775682731u },
+  { 14713227692042795499u, 13616552502810964397u,         171227191829u },
+  {  7366415124022528526u,  4898145803694965031u,          21738154790u },
+  {   825770353378039393u,  1399036321001644308u,          38265529016u },
+  { 10244023944395357795u, 17170331128243738540u,         184075841910u },
+  { 14302658294713551167u, 10641321388205367410u,         118930805515u },
+  { 14246653166206862817u,  6648873641312572851u,          11576867188u },
+  { 12404486258134291102u,  5988456964560374823u,         116360436162u },
+  {  8887442218637942533u,  9972593758348346915u,         194324634902u },
+  {  1186724038081863005u, 16709668921872818968u,          22540615390u },
+  {   211331772484951576u,  6094829131503407767u,         222905832967u },
+  {  6311919513247413649u,  4892016478899926334u,           7330401349u },
+  {  8131780018703965703u, 13150857244079031538u,          69265196744u },
+  {  2262544347226725725u, 12983943395318785894u,         200712909399u },
+  { 15318188749880522583u, 15341644584614757478u,          87703860981u },
+  {  1073117094162650652u,  7507635124856644772u,         245831672219u },
+  {  4447950380665871747u, 11619655367084544354u,         155406989715u },
+  {  5373227185066463609u, 11553116952478783009u,         147629902779u },
+  {  6739731406934274193u, 17392150014233193245u,         187626295724u },
+  { 12328812617001239444u,  8877887560294980515u,         172942830341u },
+  {  3246111484407310759u, 18404180619915609503u,           5481271248u },
+  {  3250825415176839770u, 10079413095288181976u,         208997692630u },
+  { 16146270540000862342u, 14102802966539105550u,         214546406078u },
+  { 15686773375425916830u, 13333966026135891399u,         190764514480u },
+  { 11920791905793880226u, 12344968670173516152u,         176722835746u },
+  {  1853290561644080707u, 10577007819804726752u,          34669222092u },
+  { 12157689141506159076u, 15337041354031088010u,         204573380742u },
+  { 18100318838862562546u, 14333607285614673616u,         134831422677u },
+  {  7171257882533475139u, 17171597563219696538u,         213777026407u },
+  { 14477550873015039462u,  2849642930482147564u,         103930874169u },
+  {  8109481182495403274u, 14791248423979435173u,          57154479452u },
+  { 14565395719337663965u, 13882371364576310127u,          92801835183u },
+  {  1860318978161305991u, 11735995808941329540u,         175752564859u },
+  { 16268646275151585618u, 11376996674339273181u,         123636209607u },
+  { 13759019338835519104u,  9849638057168043481u,         199616748225u },
+  { 17003783176010661888u, 18241520229279361964u,         193533949948u },
+  { 18357489540307877888u,  1865852368526961444u,         252988874793u },
+  {   905481790074912768u, 10601487369276448158u,          41101148059u },
+  {  3638882110636294144u, 15999931310312762170u,         155574707781u },
+  {  9011702854368362496u,  5773775867713013570u,          69867358014u },
+  { 11529215046068469760u, 17726239863982547534u,          62312997016u },
+  {                    0u,  9711316695888316992u,         152960941388u },
+  {                    0u, 17872002620723724288u,          76526451532u },
+  {                    0u,  7429694208660733952u,          76968843203u },
+  {                    0u,  1782821038871019520u,         195402764530u },
+  {                    0u,  3225250234313474048u,         242096646922u },
+  {                    0u, 10009250171830927360u,          10174841165u },
+  {                    0u,  1152921504606846976u,          77542602539u },
+  {                    0u,                    0u,          43062500000u },
+  {                    0u,                    0u,         160000000000u },
+  {  7625299565768063067u,                   46u,                    0u },
+  { 13889021769065194705u,          46413368317u,                    0u },
+  { 14498170692313014398u,  9519880170333822146u,                    2u },
+  {  1541631360972245751u,  2285186318012886800u,           2516073738u },
+  {  9903958882920799117u,  9706420951402272035u,          10123880198u },
+  { 15744148547788062576u,  2369632031840402142u,           6526186134u },
+  { 17936061801321712000u, 15599123897979399458u,         150128458009u },
+  {  9986394078324430610u, 17579576584023912658u,          25845630200u },
+  { 13849561248103430369u,  3480927339588501811u,         248952990756u },
+  { 12142378807953854930u,  3547346616671294635u,          36188701449u },
+  {  2513847703931031444u,  7705317123868384954u,           9192302045u },
+  {  1752183758129038045u,  4969425237478353909u,         221417706078u },
+  { 15824833342220556540u, 17043246700132217175u,          94269393081u },
+  {  8168747198299470695u, 17053788362783499470u,         185923916254u },
+  { 17414799840149357478u, 11102988228454224768u,         222924487719u },
+  {    83147520704167789u, 16944305387801685839u,          39601894197u },
+  {  2383542703041471269u, 11725142977459199276u,          53918552635u },
+  { 15540952725549257799u,  8175984171998533324u,          59635621274u },
+  {  6949835416232048690u,  1372352885142856895u,         154443220990u },
+  { 15398868937585367540u, 17975093466502888164u,         254074395398u },
+  { 14710915985268256079u,  6467823391459085653u,           6974431769u },
+  {  9665704836873335737u, 11319386883146885025u,          25350621408u },
+  {  2528789298740305993u,  9141999262922068637u,         224613625192u },
+  { 10562914675687726264u,  1587330393383478774u,         104495588773u },
+  { 17671658300096837111u,   884187548095712303u,         165086049353u },
+  {   356471401631698552u,   488841225726377268u,          73047931903u },
+  {  7450677157218003204u, 17462624199405856193u,         255026500135u },
+  {   317174560787152643u, 13183677579115583554u,          39946650754u },
+  {  7251937674440720374u, 11645015818917277779u,         130714688593u },
+  {  1252631516699038247u,  8760523002035971977u,          81631277572u },
+  { 10818009768860843867u, 10068817678491468042u,           4474908903u },
+  { 12330114194950162396u,  1273658177787418284u,         231545831700u },
+  { 15826681638261168822u,  3100019384328057661u,          20069045148u },
+  { 14240150078499211625u, 10363063568089458738u,         156168052387u },
+  { 10725372116242125421u, 13030756371481403666u,         163561782801u },
+  {  8434925524647833627u,  6538878900684195299u,          17706398718u },
+  { 17133902668520348241u,  8984884716779098868u,         254354473335u },
+  { 15093996047981365810u,  8728727397070363908u,         119487071576u },
+  {  6187974166976813153u,  6398650562917867005u,          88473185260u },
+  { 13946144707720259865u,  1190873176164938879u,         236346871542u },
+  {  9138079832881862582u,  4383628525805121795u,         246064557364u },
+  {  6600697628576225568u, 10189374699734119852u,          52237636978u },
+  {  8137099536646556597u,  5276291920541626391u,         114552367109u },
+  { 14169855543453903706u,  2692252373800386521u,           5286028358u },
+  {  3706403268650100765u, 11578684995169173920u,          70145947293u },
+  { 14736932266877982264u,  5799408022254132587u,         157627681771u },
+  { 18004795125138956004u, 15548569837712345290u,         235314386538u },
+  {  9068489270661002501u, 15763030464322902955u,         106842889659u },
+  {  7758835715193269217u, 13257749746581255500u,         187854515593u },
+  { 16943947811135261184u, 16152470009188707678u,         137718704053u },
+  {  6745843108403216384u, 13806790848493904003u,         181875627153u },
+  { 12338229654069444608u, 11981226523265951191u,         145748467631u },
+  { 14358176069683511296u,  5133628726077003713u,         175649503591u },
+  {  7083775185760813056u, 16183955741910833164u,         103278294570u },
+  {  5350276357316149248u, 13640425554331371454u,          42877333998u },
+  {  9223372036854775808u, 18108120906868035862u,         238739448950u },
+  {                    0u,  6324011669895037184u,         118981643201u },
+  {                    0u, 10444437689515769856u,         193342825359u },
+  {                    0u, 12324712543665782784u,         143566194101u },
+  {                    0u, 13928941951563857920u,         181668124005u },
+  {                    0u,  3975288688270639104u,         101755089456u },
+  {                    0u, 11141905478114607104u,          48215500831u },
+  {                    0u,  4611686018427387904u,          31604003906u },
+  {                    0u,                    0u,          66250000000u },
+  {                    0u,                    0u,         128000000000u },
+  { 14699116688460625612u,               708211u,                    0u },
+  {  6684126021499623499u,      708211796840712u,                    0u },
+  { 12614606079692508506u,  4398362855256705725u,                38392u },
+  { 15358270276683001489u,  2812083125569302717u,         248238435728u },
+  { 18077126190953408995u, 12868509142973100603u,         144152443331u },
+  {  7864121581925945659u,  8726243776748165726u,         195697603278u },
+  {  3518026639210514839u,   358304413426858117u,         206473050623u },
+  {  4698310163811252280u,  3180720351566429470u,         255019423721u },
+  {  6101155398200416338u, 14053818240400098784u,         233172427195u },
+  { 16049178580360033341u,  7340140541492429288u,         187761859013u },
+  {  3167464649127375997u,  1323571167904965058u,         197397909816u },
+  { 12778923935480989904u, 14463851737583396026u,          56071750936u },
+  { 11875553912612980379u, 15122784818916048486u,          24784086973u },
+  { 10628760849351697057u, 13557974621377508955u,         189819807807u },
+  {  3408944711673234310u, 17525172074563876264u,          63734979276u },
+  {  2102091496050506178u, 15148880683074215967u,         204950041481u },
+  {  6254611118630245760u,  6744828147558597936u,         137821222467u },
+  {  2647941151989776368u,  9799290779647971692u,          67365637866u },
+  {  8855437735410157458u, 11170890203898678105u,         234531220617u },
+  { 10184270603132180103u,  7068779781287527905u,         137605575171u },
+  { 12079083162535627164u, 14474741922505540911u,           3383199319u },
+  {  5952952868716156729u, 17107062680405191514u,          87784677331u },
+  { 11958907037815852320u,  2712598571300237005u,         211927375726u },
+  { 10101562137321697626u,  3767556054903418641u,         110147050263u },
+  { 13633527411279258327u, 18158239681706277628u,          23204239622u },
+  { 16555627393501768728u, 10531652712128330681u,           6984360145u },
+  {  6359650463500280706u,  9548395326934120567u,         209570922037u },
+  {  8093923611102181967u, 15875647850297719390u,          53517619547u },
+  {  2848827352928635726u,  8215825295203192574u,          91860620594u },
+  {  4686723431961561511u, 12747310908260543144u,          50445380781u },
+  {  6245554925867652609u,    77706528053613642u,         173691033109u },
+  { 17527406820792516033u,  6024737704056756146u,          21004212479u },
+  { 12119966834653692210u,  6819452388570089667u,         255326601685u },
+  { 11606502845877928061u, 13695926775373186254u,         213369683254u },
+  {   424311496652297090u,  3746531715392682132u,          54742457678u },
+  {  5977664048034127173u,  4717376233154528116u,          78203099891u },
+  {  6702712461535947028u,   385190957950313369u,         243255729478u },
+  { 11384349854055020018u, 12388374310648616082u,          70020881243u },
+  {  3782955013294836188u,  1078067332084407770u,          91671575117u },
+  {  3531805968821207061u,  3257295319358714850u,          77058442147u },
+  {  3867566898657193228u,  1545453099660723457u,         163176578333u },
+  { 12688734637425072080u,  7495477664653506341u,          29083779180u },
+  { 18435982764454619691u,  7225503732673614354u,         108406330658u },
+  {  4728836163964677692u,  3935478326103643956u,          34391695342u },
+  {  2120012917348838977u, 10082240682742686210u,         238213342707u },
+  {  9856965465824679831u, 10838712705567897138u,         243546559362u },
+  { 11217197671061248816u,  2142546572501643680u,         130587567793u },
+  {  3840562972677739189u,  7893042119150331392u,         177116147682u },
+  { 17104366978925258617u, 12084811642251302615u,         226427882670u },
+  { 16177877219841993444u, 15317234482572954775u,         174655118951u },
+  {  7338522384267208704u,  2283226355108359361u,         103830348945u },
+  { 10935240458612244480u, 13359725152575722127u,         145123773948u },
+  {  1732868046462124032u, 13126551011491594557u,         252724232151u },
+  {   557965042578882560u,  3598021288691861269u,         215711591756u },
+  { 10454684322475540480u, 16462621795896662961u,          76195049124u },
+  { 13907115649320091648u, 14682112756964627332u,         164892440515u },
+  {                    0u,  7174112100896070218u,         195795918927u },
+  {                    0u,  5023109019590616064u,          79388909396u },
+  {                    0u, 10765223023086141440u,          84272303285u },
+  {                    0u,  8228137177297453056u,         181583583909u },
+  {                    0u,  2891199497780592640u,         165446048210u },
+  {                    0u, 15294857653247803392u,         210156732238u },
+  {                    0u, 14303432416528695296u,          78829135894u },
+  {                    0u,                    0u,          22775390625u },
+  {                    0u,                    0u,         161000000000u },
+  { 14876458284855834550u,                   10u,                    0u },
+  { 10450704926982265198u,          10806454419u,                    0u },
+  {  5385653213018257806u, 10806454419566533849u,                    0u },
+  { 12735569669880147489u, 17118225092618494573u,            585819067u },
+  {  3619762560577729456u, 13385738875341807559u,         187927980841u },
+  { 11123448126624084269u,  8272682717439277193u,          41725642358u },
+  {  4072715118852885633u, 13402436483369350083u,         118448463028u },
+  { 18239087231420827283u, 10946328903241612536u,         180726547537u },
+  {   423431461216085297u, 16265808923426731252u,          81593401678u },
+  {  9360976716520160042u, 11080374459871185177u,          78881771268u },
+  { 11655927117263208920u,  1240761893433831916u,           4600668303u },
+  {  2646622721938364948u,   367264070493390483u,         143067261837u },
+  {  4496462484548171852u,  2863675693461092905u,         141019909425u },
+  { 13140258519803350063u,  7511929581752138999u,          49155240170u },
+  { 13089764333320627770u, 11154557789993845753u,         234407222518u },
+  {  6926286827289840501u,  8325416539745948522u,         246604689789u },
+  {  4985580225290866218u, 17745129874679852617u,         125451321734u },
+  { 10478790837359789693u,  1074820986392253357u,         134961965418u },
+  { 10041191967455692214u,  7820952682162838597u,         106058266162u },
+  {  5035461258013813797u,  8215518006273528603u,          50423974694u },
+  { 14208759661559249750u,  9680426791089900133u,          38445364123u },
+  { 12347272163241758840u, 16128495723604797412u,         155524776987u },
+  {  3372534174410277614u,  2264789053583348885u,          27874327505u },
+  { 17226704187274712984u, 11175458488686298083u,         209122774460u },
+  {  4250480179449852121u, 11026777810412287617u,         188605822818u },
+  {  4303723537755414374u, 16199890034895598640u,          98597762822u },
+  {  8680503847344854165u,  9094320719494763752u,           6878197798u },
+  {  8817608623911079652u,  1250835564687222832u,          38493004114u },
+  {  5692030448698539450u, 15362466642459337025u,          82067807931u },
+  { 16908836314686769809u,  7831109835595423828u,         187832800985u },
+  {  6073762347067727240u, 15426237284335022429u,         217424525314u },
+  { 10931066692585106200u, 15636308361455434548u,           2836257998u },
+  { 14466591364061539596u, 13967173875944980328u,         206847645974u },
+  {  4958077340960173341u, 18245979923595824097u,          22757162012u },
+  {  4076890037156765715u, 11335054479675278263u,          28989116553u },
+  { 14083973146609179058u, 11165339882630461707u,         137614474534u },
+  {  2565183738039805295u, 15944437408299395922u,          38605274287u },
+  {  1482420938751351224u, 15806416348777321161u,         175864349683u },
+  {  2151089495335413944u,  4201030477408556248u,         243856867547u },
+  {  3738604531753220913u,  9485474942554588907u,         219227738318u },
+  { 14195686514836005765u, 18238757647663230541u,         206514208626u },
+  { 17808833916231796970u,  4642199687824746379u,         114988725033u },
+  {  1302384553035657354u,  6134575894869364037u,          41251654149u },
+  {  1672033517974833698u, 11524208547121316008u,           5332556025u },
+  { 11673925532927662545u,  2734683241527878366u,         249624728597u },
+  {  3905334232240480709u, 10629223456178675171u,          21148247475u },
+  { 17411087320267472625u,  2788042336985254064u,         179576211358u },
+  { 16573305231063706617u, 17285498758066142502u,         158151140077u },
+  { 15481103236037148354u,  5525538192421886436u,         237937048765u },
+  {   907440704754420880u, 11414325503043801888u,         189299540025u },
+  {  3224970785139077759u,  7246608114685173259u,          57618771825u },
+  { 10560826509734608144u,  1007884269852184608u,         113392839413u },
+  {  4700940027512659968u, 13823717876510029312u,         245054637515u },
+  {  9733694683502084096u, 12487410768239429317u,         203749385247u },
+  {  1995535635724632064u,  3361062421598631942u,          31676943894u },
+  { 10629833226245373952u, 17853337379088328475u,          22182203558u },
+  { 15729384648544878592u, 11551561037491869885u,         166967831358u },
+  {  7205759403792793600u, 11480877996635204802u,          62626211378u },
+  {                    0u,  5527488381934471912u,          50622379643u },
+  {                    0u, 11143438404407726080u,         123299645745u },
+  {                    0u,  6472279730688098304u,          49604087006u },
+  {                    0u,  4561816853579563008u,         222350862987u },
+  {                    0u,  2888714464062865408u,         139247296587u },
+  {                    0u, 16258276129784201216u,          75156597524u },
+  {                    0u,   720575940379279360u,          20881362915u },
+  {                    0u,                    0u,         227039062500u },
+  {                    0u,                    0u,         228000000000u },
+  {  7535526066623007027u,               164893u,                    0u },
+  { 11302146918409311588u,      164893408501686u,                    0u },
+  {  2480833299122194801u, 16409970870640346804u,                 8938u },
+  { 11513226205589330558u,  7721907286269370594u,         234889586303u },
+  {  4073957068281936105u, 14300743897882155131u,         127418605432u },
+  {  3729887061093812886u,  2068482633821123575u,         120775244880u },
+  { 13616911779739451443u,  4922882895416406094u,          80112132668u },
+  { 13039053282195777666u,  9317632875623428410u,          60266870016u },
+  { 14490756113210417890u,  5693844901999766254u,            505109890u },
+  { 17432486112977557585u, 11569484900262102262u,         130308663950u },
+  { 14308820825344039837u,  3138170119352085637u,         142627183033u },
+  {  4190949538817536349u,   950584692575235243u,         185170120543u },
+  { 13616552502810964397u,  8136430299747162645u,          95051531299u },
+  {  4898145803694965031u,  6698711700804594470u,          35441076770u },
+  {  1399036321001644308u, 17401191571004302008u,          34363137888u },
+  { 17170331128243738540u,  4721732028538188150u,          96943320485u },
+  { 10641321388205367410u,  2984214103553086219u,         165255965606u },
+  {  6648873641312572851u, 13128675202005662068u,         166161774570u },
+  {  5988456964560374823u, 14638512997670672834u,         234711706908u },
+  {  9972593758348346915u, 12942085665769692438u,          28793555379u },
+  { 16709668921872818968u, 14131134357119205086u,         179701591869u },
+  {  6094829131503407767u,  8921946894736102919u,          61766050328u },
+  {  4892016478899926334u,  5601522560505809989u,          24483659710u },
+  { 13150857244079031538u,  8602606493507716808u,         190303659146u },
+  { 12983943395318785894u,  8576789731078566487u,         138466348232u },
+  { 15341644584614757478u, 17881118138842658549u,         200464948702u },
+  {  7507635124856644772u, 11624372674432704923u,         222969337356u },
+  { 11619655367084544354u,  6826284072848095635u,          12630158505u },
+  { 11553116952478783009u,  1646466632033733563u,         169370053601u },
+  { 17392150014233193245u, 17871081657060299180u,         225089255134u },
+  {  8877887560294980515u, 15910893124677544709u,         222968793277u },
+  { 18404180619915609503u, 11031217459450580944u,         189862531244u },
+  { 10079413095288181976u, 13554987390037243094u,         172598003496u },
+  { 14102802966539105550u, 15026714590903687870u,          40734817338u },
+  { 13333966026135891399u,  4406379654994689200u,          58814599830u },
+  { 12344968670173516152u, 13596329092861950242u,         150238870319u },
+  { 10577007819804726752u,   284812388227373260u,          47737058477u },
+  { 15337041354031088010u,  9285079159392309382u,         173015439710u },
+  { 14333607285614673616u, 15046108141952711893u,          94503345149u },
+  { 17171597563219696538u, 13795366909944958311u,         253815651156u },
+  {  2849642930482147564u, 12909920641180059961u,          84747848338u },
+  { 14791248423979435173u,  5333762939889788252u,         146699848200u },
+  { 13882371364576310127u,  6411331390005944495u,           8289143868u },
+  { 11735995808941329540u,  1447104583224217723u,          60347558971u },
+  { 11376996674339273181u, 11940049226167932871u,          59078447696u },
+  {  9849638057168043481u,  9772290783590472385u,          80647271365u },
+  { 18241520229279361964u, 16351989577831528444u,         197529756944u },
+  {  1865852368526961444u,  4376738725895725097u,          16886443131u },
+  { 10601487369276448158u, 13851276297739812763u,         123237263481u },
+  { 15999931310312762170u, 12641996203470333509u,         121750879192u },
+  {  5773775867713013570u,  7707081716407945022u,         216685323987u },
+  { 17726239863982547534u,   417638323657040024u,         211417801737u },
+  {  9711316695888316992u, 16438047707692449100u,           9022640218u },
+  { 17872002620723724288u, 14850108107043306316u,          90891108351u },
+  {  7429694208660733952u, 10423290807904720835u,         255805025973u },
+  {  1782821038871019520u, 16951162310302339314u,         181565047726u },
+  {  3225250234313474048u,  2752437506572397322u,         174918924350u },
+  { 10009250171830927360u,  3925815842962784589u,          62149209936u },
+  {  1152921504606846976u,  5274166674003605291u,          80212818903u },
+  {                    0u,  5538963350863452832u,         215285913148u },
+  {                    0u, 16900671634439028736u,          60300267804u },
+  {                    0u,  2326997710751662080u,          28916187245u },
+  {                    0u, 12327726161625874432u,         109126146798u },
+  {                    0u,  5756455743825903616u,         238668287374u },
+  {                    0u,  3018537650245074944u,         142312058091u },
+  {                    0u, 16717361816799281152u,         235163635253u },
+  {                    0u,                    0u,          53906250000u },
+  {                    0u,                    0u,          16000000000u },
+  {  2285186318012886800u,           2516073738u,                    0u },
+  {  9706420951402272035u,  2516073738123880198u,                    0u },
+  {  2369632031840402142u, 11997425759292732054u,            136396630u },
+  { 15599123897979399458u, 11491152661270395161u,          86650381753u },
+  { 17579576584023912658u, 18181063258234881272u,         185622936633u },
+  {  3480927339588501811u,  2466921813123869732u,          57985597414u },
+  {  3547346616671294635u,  8430880678232179465u,         230133732099u },
+  {  7705317123868384954u,  6738034873677997533u,           3457038957u },
+  {  4969425237478353909u,  7678250951042929246u,         109365269602u },
+  { 17043246700132217175u,  1853560606315563193u,          98416238818u },
+  { 17053788362783499470u, 14942676593409905118u,         226100481721u },
+  { 11102988228454224768u,  4909892170837638183u,         185810044121u },
+  { 16944305387801685839u, 16871149368312132405u,         217266165787u },
+  { 11725142977459199276u, 16096130589333770811u,          27914586839u },
+  {  8175984171998533324u, 12512479187631824282u,         215872572987u },
+  {  1372352885142856895u, 16980304980540557310u,          59678302855u },
+  { 17975093466502888164u,  8640919162749295366u,         135920504177u },
+  {  6467823391459085653u,  7862382415464063513u,         113468425166u },
+  { 11319386883146885025u, 14534157903009925344u,         206426220604u },
+  {  9141999262922068637u, 12627464554215107944u,          60787898278u },
+  {  1587330393383478774u,  2456849734836299173u,         166684536225u },
+  {   884187548095712303u, 18428252197697827913u,         161133186090u },
+  {   488841225726377268u,  7244734215936736255u,          42998997553u },
+  { 17462624199405856193u, 14756175050504770087u,          49392737828u },
+  { 13183677579115583554u,  6764116534566945922u,          36799933852u },
+  { 11645015818917277779u,  1588822142405565521u,         156366683492u },
+  {  8760523002035971977u, 17053265624843842052u,         100086130220u },
+  { 10068817678491468042u, 16996891591759999207u,          44924459381u },
+  {  1273658177787418284u,  8565556232370585876u,         117921403339u },
+  {  3100019384328057661u, 14464960359145886620u,         203464339733u },
+  { 10363063568089458738u,  5813189542048784035u,          21784147072u },
+  { 13030756371481403666u,  9739241026882027025u,         128315133636u },
+  {  6538878900684195299u, 18175068535675302910u,         196527965313u },
+  {  8984884716779098868u, 10562697212061761911u,         129985272439u },
+  {  8728727397070363908u,  4264834835660801368u,         119572604963u },
+  {  6398650562917867005u, 13019066443690126316u,          35231197159u },
+  {  1190873176164938879u,  1828040177823321846u,         231705765006u },
+  {  4383628525805121795u, 11240369830376975668u,         142099098256u },
+  { 10189374699734119852u,  8886938465302549874u,         144609341669u },
+  {  5276291920541626391u,  9985240313589688325u,         229481761899u },
+  {  2692252373800386521u,   722909126956573766u,         107541300962u },
+  { 11578684995169173920u,  5493363474638452381u,         226039188982u },
+  {  5799408022254132587u, 12410535279213120491u,         246297795830u },
+  { 15548569837712345290u, 10543108918366869098u,         246672776465u },
+  { 15763030464322902955u, 12953909016524823995u,          17571543079u },
+  { 13257749746581255500u, 16505942145872588169u,          39702232814u },
+  { 16152470009188707678u, 12428594380392015797u,         238894788916u },
+  { 13806790848493904003u,  7528259605829768337u,          52673755451u },
+  { 11981226523265951191u, 18147447600042811311u,          59408107770u },
+  {  5133628726077003713u, 12021069431116183911u,         250983775105u },
+  { 16183955741910833164u, 11819985069665662506u,         129651663479u },
+  { 13640425554331371454u, 10401877114068152814u,         119640762674u },
+  { 18108120906868035862u,  4611631138117837942u,          50563886888u },
+  {  6324011669895037184u, 17200813398607252417u,          40249997024u },
+  { 10444437689515769856u, 14100466137553658767u,         224932457962u },
+  { 12324712543665782784u, 17887776768825509301u,         234764387800u },
+  { 13928941951563857920u, 12632656857970087269u,         216969698321u },
+  {  3975288688270639104u,  8923681664054686256u,          17684817700u },
+  { 11141905478114607104u,  6213926103737837599u,          36483753752u },
+  {  4611686018427387904u,  1233118281776157762u,          24336857609u },
+  {                    0u,    30716279628678784u,           9066847476u },
+  {                    0u, 15775734650898546688u,         244001665132u },
+  {                    0u,   976806005729918976u,         108855204289u },
+  {                    0u, 12460098853279891456u,         193052952759u },
+  {                    0u,  5635665595421687808u,         183675463312u },
+  {                    0u,  1805943450575568896u,         144305510044u },
+  {                    0u, 11529215046068469760u,         156097900390u },
+  {                    0u,                    0u,         102625000000u },
+  {                    0u,                    0u,          64000000000u },
+  {  4398362855256705725u,                38392u,                    0u },
+  {  2812083125569302717u,       38392238435728u,                    0u },
+  { 12868509142973100603u,  4564018338575530435u,                 2081u },
+  {  8726243776748165726u, 16553437246451512014u,          33247415929u },
+  {   358304413426858117u,  4339777136957372927u,         121897363631u },
+  {  3180720351566429470u, 18439463366554654697u,         175235259789u },
+  { 14053818240400098784u,  1370067356680643003u,         141999605312u },
+  {  7340140541492429288u,  4210124040914115013u,          64074271500u },
+  {  1323571167904965058u, 10692225626142609720u,          12228231281u },
+  { 14463851737583396026u, 11592856673895384344u,         113579626712u },
+  { 15122784818916048486u, 10284479231227406269u,         216628450019u },
+  { 13557974621377508955u,  4961071383534266431u,         227557522736u },
+  { 17525172074563876264u, 10960611551445686988u,          48268940218u },
+  { 15148880683074215967u, 14616396723115619209u,         186594175942u },
+  {  6744828147558597936u,  1025604265437492803u,         198792356454u },
+  {  9799290779647971692u, 11711588454892179178u,         102055598118u },
+  { 11170890203898678105u,  5580373263251565705u,          38634886482u },
+  {  7068779781287527905u, 14109334653033148931u,          82302512640u },
+  { 14474741922505540911u,  2899414033769399895u,            764868564u },
+  { 17107062680405191514u, 13233457234892808147u,         212157177549u },
+  {  2712598571300237005u,  3287946691509034862u,         205717387154u },
+  {  3767556054903418641u,  5488480288717445911u,         146178239947u },
+  { 18158239681706277628u, 11687233053874362630u,         203297531112u },
+  { 10531652712128330681u,  6783772100089274577u,         232633566173u },
+  {  9548395326934120567u,  7898291058728402485u,         221367749022u },
+  { 15875647850297719390u,  4423684977486598491u,         158428167216u },
+  {  8215825295203192574u,  2750833684599526706u,          48239808443u },
+  { 12747310908260543144u, 15669689830489025709u,         187149122992u },
+  {    77706528053613642u, 15117307274214954517u,         176849455587u },
+  {  6024737704056756146u,  8148639818575698175u,         227819510869u },
+  {  6819452388570089667u, 13006484426078994901u,          85441738649u },
+  { 13695926775373186254u, 10287496057845513526u,         153705082933u },
+  {  3746531715392682132u, 14159876032966532430u,          53557686278u },
+  {  4717376233154528116u, 15742212196465548019u,           6767608417u },
+  {   385190957950313369u,  2892220461917134150u,          97853387033u },
+  { 12388374310648616082u,  7487151560715393883u,          25156787585u },
+  {  1078067332084407770u,  7245756744165177933u,         129405879299u },
+  {  3257295319358714850u,  3067122860671533987u,           3392793260u },
+  {  1545453099660723457u,  8135043905834122525u,         172166269063u },
+  {  7495477664653506341u, 14730019368921022572u,         135441001613u },
+  {  7225503732673614354u,   495969939682055458u,         141798515950u },
+  {  3935478326103643956u,  5617761407265775598u,         238026886584u },
+  { 10082240682742686210u,  2087044847072781811u,         184304539456u },
+  { 10838712705567897138u, 15929674232061203330u,          64113138927u },
+  {  2142546572501643680u,  8658086469608285873u,         239863549370u },
+  {  7893042119150331392u, 18369871790780313570u,         186469355807u },
+  { 12084811642251302615u,  3545648451947416750u,          31995832745u },
+  { 15317234482572954775u, 13347376792767929959u,         169192209987u },
+  {  2283226355108359361u, 14482164459838203025u,          67723562745u },
+  { 13359725152575722127u,  8899577765623565820u,         249785079708u },
+  { 13126551011491594557u,  7095320096604405719u,         156482447077u },
+  {  3598021288691861269u,  2968593824439315788u,         229384638073u },
+  { 16462621795896662961u, 12621408323612585636u,         121160927793u },
+  { 14682112756964627332u,  3954422936414648259u,          49684207916u },
+  {  7174112100896070218u, 17143730087577690191u,          44214369696u },
+  {  5023109019590616064u,  5033045529399041876u,         160929363470u },
+  { 10765223023086141440u, 15857648521994521781u,          14272841944u },
+  {  8228137177297453056u, 16655573486499109541u,         216859644848u },
+  {  2891199497780592640u, 16652154439190075858u,         176902900447u },
+  { 15294857653247803392u, 18016950600164130638u,         223902715100u },
+  { 14303432416528695296u,  2086292996072613910u,         220976700849u },
+  {                    0u, 17324462585194799521u,         177113098169u },
+  {                    0u, 11079151463184927232u,         185939160998u },
+  {                    0u,  5239846817488961536u,         166600602004u },
+  {                    0u,  2778806963520143360u,         148284052665u },
+  {                    0u,  6240890740138835968u,         185150639427u },
+  {                    0u, 17250651344549707776u,          67338319364u },
+  {                    0u,  4197354852709302272u,           4935159683u },
+  {                    0u,  9223372036854775808u,         131227539062u },
+  {                    0u,                    0u,         118500000000u },
+  { 17118225092618494573u,            585819067u,                    0u },
+  { 13385738875341807559u,   585819067927980841u,                    0u },
+  {  8272682717439277193u,  5654803392547571318u,             31757315u },
+  { 13402436483369350083u,  2931628102185393332u,           3306547506u },
+  { 10946328903241612536u, 15964697617980212305u,          50158923877u },
+  { 16265808923426731252u,   450380868305846606u,         101865447992u },
+  { 11080374459871185177u, 14631133530814566148u,          56024415195u },
+  {  1240761893433831916u,    31969822783742095u,         219793155338u },
+  {   367264070493390483u, 10437269029385743245u,          10001733087u },
+  {  2863675693461092905u, 15196146496377392433u,         223565805487u },
+  {  7511929581752138999u,  4409099735137480938u,         175823784752u },
+  { 11154557789993845753u, 10644987914903248118u,          48239017775u },
+  {  8325416539745948522u,  3154431617534062973u,          47577065951u },
+  { 17745129874679852617u, 11702056331247960454u,         223171002080u },
+  {  1074820986392253357u, 15575315065965259114u,         224634369744u },
+  {  7820952682162838597u, 10759747609480050226u,         208844339521u },
+  {  8215518006273528603u, 12538236653960743718u,          65583287086u },
+  {  9680426791089900133u, 17857942663978005403u,          46679699170u },
+  { 16128495723604797412u, 11443004154750813211u,         226968081011u },
+  {  2264789053583348885u,  4004313188770806737u,         115620326498u },
+  { 11175458488686298083u, 17134872954824183228u,          98217074252u },
+  { 11026777810412287617u,  2659553912986171234u,          76928883324u },
+  { 16199890034895598640u,  9501854300969137926u,         124144174706u },
+  {  9094320719494763752u, 14528169966301018150u,         114515096553u },
+  {  1250835564687222832u, 18172091996515901778u,         233787573671u },
+  { 15362466642459337025u,  1133541705604751035u,         167985111081u },
+  {  7831109835595423828u, 18280349987988641497u,          41061449418u },
+  { 15426237284335022429u,  9936015874712336386u,         202990979758u },
+  { 15636308361455434548u, 15876720399740689614u,         174538632499u },
+  { 13967173875944980328u,  8618117825152456982u,          51860678737u },
+  { 18245979923595824097u,  8085525680745921564u,          81467189103u },
+  { 11335054479675278263u,  8072355444669730953u,         111438317225u },
+  { 11165339882630461707u,  9395030504766848294u,         169437603265u },
+  { 15944437408299395922u,  3537903114058185903u,         193509305624u },
+  { 15806416348777321161u,  2126094743961928691u,          24191790112u },
+  {  4201030477408556248u,   289185362555601115u,          32115255827u },
+  {  9485474942554588907u, 16909937501450129614u,          19015676769u },
+  { 18238757647663230541u, 14449642060360499058u,          97916689548u },
+  {  4642199687824746379u, 12433818908498244393u,         140783316665u },
+  {  6134575894869364037u, 11884444034578008581u,         185674038673u },
+  { 11524208547121316008u,   988625838444140793u,         145644257002u },
+  {  2734683241527878366u,  1675370907158909973u,         234053593514u },
+  { 10629223456178675171u, 15920186275316934067u,         170090822038u },
+  {  2788042336985254064u,  5600921198503757726u,         150863035027u },
+  { 17285498758066142502u, 10457357161776341741u,         147303626546u },
+  {  5525538192421886436u, 12225356765775740093u,          50566894467u },
+  { 11414325503043801888u,  4486633318598164537u,         131662737918u },
+  {  7246608114685173259u, 10302486602879381361u,         254243220879u },
+  {  1007884269852184608u, 15536428611301239541u,         143558498917u },
+  { 13823717876510029312u, 12026126645955462603u,         101842231482u },
+  { 12487410768239429317u, 14877968141142123551u,         186651937631u },
+  {  3361062421598631942u,   734560801645383190u,          95806536269u },
+  { 17853337379088328475u, 15648943144911081638u,          77039820620u },
+  { 11551561037491869885u, 13664182862003235646u,          76848330907u },
+  { 11480877996635204802u,  3895127525902132786u,         155740736837u },
+  {  5527488381934471912u,  5249187334214137467u,          69211155286u },
+  { 11143438404407726080u, 10642260063359027505u,          86284559015u },
+  {  6472279730688098304u,   783598951897779422u,         167576918074u },
+  {  4561816853579563008u,  5538576558607624843u,          58042478984u },
+  {  2888714464062865408u, 15974581187564609611u,         136300246836u },
+  { 16258276129784201216u,  7474269406918257428u,          52865983781u },
+  {   720575940379279360u,  8045286838779138019u,          37405180956u },
+  {                    0u,  8184246376556341732u,          28436135873u },
+  {                    0u,  1493267152679331840u,         193443668885u },
+  {                    0u, 10179074811222818816u,         149080950174u },
+  {                    0u,  3892499202005008384u,         158551808751u },
+  {                    0u, 10341173215925108736u,         239211012804u },
+  {                    0u,  6230307872002015232u,         196560596123u },
+  {                    0u,  9295429630892703744u,         155337745666u },
+  {                    0u,                    0u,           2503906250u },
+  {                    0u,                    0u,         202000000000u },
+  { 16409970870640346804u,                 8938u,                    0u },
+  {  7721907286269370594u,        8938889586303u,                    0u },
+  { 14300743897882155131u, 10665454627995623288u,                  484u },
+  {  2068482633821123575u, 16803537892767562832u,         228578175453u },
+  {  4922882895416406094u,  8099123106849104444u,         221910921614u },
+  {  9317632875623428410u,  7077413686679401728u,         142439054343u },
+  {  5693844901999766254u, 13536636358372449666u,           7383667364u },
+  { 11569484900262102262u,  7280632235418610318u,         164733822527u },
+  {  3138170119352085637u,  6187823673116858809u,          63394683864u },
+  {   950584692575235243u,  8624343686231740255u,         216335442593u },
+  {  8136430299747162645u,   806211610822132771u,         161467526608u },
+  {  6698711700804594470u, 18388078233202190882u,         208043704818u },
+  { 17401191571004302008u,  7628864426595573600u,         242996819718u },
+  {  4721732028538188150u,  4530799784343874981u,           6413561569u },
+  {  2984214103553086219u,  8561580552078486438u,         225245615148u },
+  { 13128675202005662068u, 13349114951221999594u,          44464124211u },
+  { 14638512997670672834u, 10029144738508991772u,          51723656971u },
+  { 12942085665769692438u, 12601907197916268979u,          11543681025u },
+  { 14131134357119205086u,  1329580921391066941u,           1683150758u },
+  {  8921946894736102919u,  3198179786356761112u,         166072076726u },
+  {  5601522560505809989u, 11406753413634654142u,         182173373673u },
+  {  8602606493507716808u, 11131812960525182090u,         233618361341u },
+  {  8576789731078566487u, 14299636753645227208u,         253603456789u },
+  { 17881118138842658549u, 12964114684643663326u,          21775184861u },
+  { 11624372674432704923u,  5019257593846306316u,         221702786065u },
+  {  6826284072848095635u,  6929086798159998121u,          17272094499u },
+  {  1646466632033733563u, 18359765766933703649u,          35375626547u },
+  { 17871081657060299180u,  9993076234752063198u,          51995284896u },
+  { 15910893124677544709u,  3257189215046584509u,         160541725748u },
+  { 11031217459450580944u,  2905234736672690348u,          52176572581u },
+  { 13554987390037243094u, 12064985302079670056u,         165157493090u },
+  { 15026714590903687870u, 14315096064942799930u,          98654044163u },
+  {  4406379654994689200u, 11943971043551974038u,           3776022912u },
+  { 13596329092861950242u, 12472773152119929647u,         128647483967u },
+  {   284812388227373260u,  7791259796982183085u,          63676150387u },
+  {  9285079159392309382u, 16866829442051086686u,         115422365039u },
+  { 15046108141952711893u,  3702498393844653053u,         111914352656u },
+  { 13795366909944958311u,  2057239613841701716u,          16200712840u },
+  { 12909920641180059961u, 17201969976738286226u,         136111523182u },
+  {  5333762939889788252u, 18271566505443461640u,         110932520660u },
+  {  6411331390005944495u, 18368509115417119804u,         212990503604u },
+  {  1447104583224217723u,  7613923684154518587u,         180995758874u },
+  { 11940049226167932871u, 17984805084714865232u,          26412751629u },
+  {  9772290783590472385u,  4220802739051410373u,          13974958237u },
+  { 16351989577831528444u, 17812459042810815760u,         157228810174u },
+  {  4376738725895725097u, 10629526089664605307u,         190965615339u },
+  { 13851276297739812763u, 17437443267816548473u,         235576227763u },
+  { 12641996203470333509u, 12506371893701049304u,         179945285693u },
+  {  7707081716407945022u, 15737221540003030739u,          61677971778u },
+  {   417638323657040024u,  2358380859011605513u,          66853116489u },
+  { 16438047707692449100u, 10042972713837039706u,          73127848082u },
+  { 14850108107043306316u, 13424397272769642495u,         146544430641u },
+  { 10423290807904720835u,  6867102315755663029u,          49727738034u },
+  { 16951162310302339314u,  8690748404825506734u,         178372266362u },
+  {  2752437506572397322u,   956229930815387710u,         122471126415u },
+  {  3925815842962784589u,  7734449506297687888u,         143051837328u },
+  {  5274166674003605291u, 16332184961683848151u,         144419285347u },
+  {  5538963350863452832u, 15580777817612768828u,          99885369520u },
+  { 16900671634439028736u, 17404245271944696092u,         176844635657u },
+  {  2326997710751662080u, 13201420160494469229u,           9943486026u },
+  { 12327726161625874432u, 16511717657124068078u,          74715650420u },
+  {  5756455743825903616u, 14131292492116594062u,         116895102007u },
+  {  3018537650245074944u, 18429136031865875691u,          55766058900u },
+  { 16717361816799281152u,  2563978348305862197u,         148999045466u },
+  {                    0u, 14239974392147482896u,          90138993544u },
+  {                    0u, 11164201396098998272u,         136771950558u },
+  {                    0u,  7116971104932986880u,         222605212570u },
+  {                    0u, 12437629862867369984u,         154385811776u },
+  {                    0u, 16501893821638901760u,          64674245265u },
+  {                    0u, 10649324268870959104u,         145894569456u },
+  {                    0u,  7205759403792793600u,         240577301025u },
+  {                    0u,                    0u,          33390625000u },
+  {                    0u,                    0u,         232000000000u },
+  { 11997425759292732054u,            136396630u,                    0u },
+  { 11491152661270395161u,   136396630650381753u,                    0u },
+  { 18181063258234881272u,  3016823727048309817u,              7394076u },
+  {  2466921813123869732u, 17405973192644624358u,          28163542341u },
+  {  8430880678232179465u,  8937219978302591747u,          69943579697u },
+  {  6738034873677997533u, 15178463196824222317u,          49484487665u },
+  {  7678250951042929246u, 11979404627460330594u,         241822826138u },
+  {  1853560606315563193u,  2006448052689740002u,         154649404826u },
+  { 14942676593409905118u, 16330465320863239865u,         154108769766u },
+  {  4909892170837638183u, 17136208883957646553u,         230885276298u },
+  { 16871149368312132405u,   140455118208931867u,         138928955745u },
+  { 16096130589333770811u,  3964972929179372247u,          97007614087u },
+  { 12512479187631824282u,  3378050330022776379u,         135214941613u },
+  { 16980304980540557310u,  6065353437512901255u,         173183124475u },
+  {  8640919162749295366u, 12768753059854699889u,         251328803468u },
+  {  7862382415464063513u,  6848720690951013326u,         140692195490u },
+  { 14534157903009925344u, 10953228058585475132u,         162371269892u },
+  { 12627464554215107944u, 15539127852083296166u,           4593775682u },
+  {  2456849734836299173u, 14534853647735598497u,          66842377808u },
+  { 18428252197697827913u,  1506909603576368170u,          80787935995u },
+  {  7244734215936736255u,  5475702579938239025u,         251081689733u },
+  { 14756175050504770087u, 12039747373985783332u,         133296838431u },
+  {  6764116534566945922u, 17572399137760898460u,          31652676012u },
+  {  1588822142405565521u,   869552790852091236u,         172952601666u },
+  { 17053265624843842052u,  4549585778048181804u,          66047138551u },
+  { 16996891591759999207u,  4121918231767210357u,         247246633539u },
+  {  8565556232370585876u,  1558397953312543179u,          67223449635u },
+  { 14464960359145886620u,  6067524298738069781u,          35084480922u },
+  {  5813189542048784035u,  5811095224555517056u,         154328921151u },
+  {  9739241026882027025u,  6440894514158997188u,          63315020103u },
+  { 18175068535675302910u,  4612748874388784257u,          71349161591u },
+  { 10562697212061761911u,  9908101430749813367u,         119250057617u },
+  {  4264834835660801368u, 15150017990912190499u,         145537119254u },
+  { 13019066443690126316u, 17470426264690059239u,          22821284120u },
+  {  1828040177823321846u,  9615161096851907726u,          24947073705u },
+  { 11240369830376975668u,  9227932132124142224u,         169521238927u },
+  {  8886938465302549874u,  4794113194321211621u,         143500247203u },
+  {  9985240313589688325u,   391512698859146347u,         163259889397u },
+  {   722909126956573766u, 17209658878068655842u,         245021223945u },
+  {  5493363474638452381u,  3077364726606876150u,           9932937477u },
+  { 12410535279213120491u,  1952989567673965814u,           5166824276u },
+  { 10543108918366869098u, 11172860676923186449u,          84105871776u },
+  { 12953909016524823995u, 17338078544784947239u,         160605681990u },
+  { 16505942145872588169u,  4593380466519703278u,          70939899121u },
+  { 12428594380392015797u,   786884753602720052u,         241249007654u },
+  {  7528259605829768337u, 17848875822468020539u,          38042657107u },
+  { 18147447600042811311u,  2899664567187130618u,          83967589497u },
+  { 12021069431116183911u,  2973178834961857409u,         121157191131u },
+  { 11819985069665662506u, 11117453141176836727u,         219161176347u },
+  { 10401877114068152814u,  7535238370146462002u,          27602678342u },
+  {  4611631138117837942u, 10246175467290865448u,          70408486090u },
+  { 17200813398607252417u,  1203128834127050464u,         202555446285u },
+  { 14100466137553658767u, 14518048959078919658u,          13065221744u },
+  { 17887776768825509301u,  1553474987376920024u,         112787025011u },
+  { 12632656857970087269u, 14956572380830948369u,         115084214047u },
+  {  8923681664054686256u,  7594162606042048292u,          31810797413u },
+  {  6213926103737837599u, 14461296147288811288u,         101411680379u },
+  {  1233118281776157762u, 18305427728131488265u,         123783948434u },
+  {    30716279628678784u, 10253208939347909876u,         146992339225u },
+  { 15775734650898546688u,  6446028915490812012u,          25555827570u },
+  {   976806005729918976u, 12986063676957432257u,         114349439927u },
+  { 12460098853279891456u,  9769714697972762807u,         183703975922u },
+  {  5635665595421687808u,    97429465146664592u,         242529617295u },
+  {  1805943450575568896u, 16395571728207795868u,         143005281661u },
+  { 11529215046068469760u,  6331668478323650406u,         125888805724u },
+  {                    0u, 18129911846294207040u,          92343240435u },
+  {                    0u,  9890094564876124160u,         243982824490u },
+  {                    0u, 12290856656987750400u,          42536143100u },
+  {                    0u,  8498454992640802816u,         252666288674u },
+  {                    0u,  5341660584200896512u,          34460702168u },
+  {                    0u,  9288674231451648000u,         216289572000u },
+  {                    0u,  1152921504606846976u,         160503540039u },
+  {                    0u,                    0u,          71062500000u },
+  {                    0u,                    0u,         160000000000u },
+  {  4564018338575530435u,                 2081u,                    0u },
+  { 16553437246451512014u,        2081247415929u,                    0u },
+  {  4339777136957372927u, 15212079674427582639u,                  112u },
+  { 18439463366554654697u, 10179808126814248333u,         112824648491u },
+  {  1370067356680643003u,  6066766544199222848u,          43551848504u },
+  {  4210124040914115013u,  6625308131806923532u,          56328880073u },
+  { 10692225626142609720u,  9122786786400665713u,         201359158673u },
+  { 11592856673895384344u, 11932880778639151320u,         145494547262u },
+  { 10284479231227406269u,  3884040911779255011u,          62646882763u },
+  {  4961071383534266431u, 13441817515637357872u,         203210554279u },
+  { 10960611551445686988u, 11628577856022352826u,         167728682387u },
+  { 14616396723115619209u, 13296656925520243654u,         147630386468u },
+  {  1025604265437492803u,  5020720704545399398u,          36720813216u },
+  { 11711588454892179178u, 14121973606499014694u,         160272173814u },
+  {  5580373263251565705u,  3642481034345420114u,         246765553723u },
+  { 14109334653033148931u,  9845536238569696768u,          59197459292u },
+  {  2899414033769399895u, 17655403572195686356u,          92533727588u },
+  { 13233457234892808147u,  8377495365136654029u,         100957101345u },
+  {  3287946691509034862u, 13713682649609025426u,          33454144933u },
+  {  5488480288717445911u,  1367709905452854731u,         165743420226u },
+  { 11687233053874362630u,  9981467701727208680u,          66074143702u },
+  {  6783772100089274577u,  6277920117543306205u,         214541096448u },
+  {  7898291058728402485u,  9344111460418701726u,            340326731u },
+  {  4423684977486598491u,  4918507011364617264u,          75506545297u },
+  {  2750833684599526706u,  6554777203830755259u,         145266632799u },
+  { 15669689830489025709u,  4198262173120265648u,          95355335184u },
+  { 15117307274214954517u,  8080325935698446819u,          16227588248u },
+  {  8148639818575698175u, 12797633874200091733u,         152438035346u },
+  { 13006484426078994901u,  8376502502208665497u,         146693761122u },
+  { 10287496057845513526u,  9891973386793349173u,          98454091110u },
+  { 14159876032966532430u, 14877430279003795462u,         102536244951u },
+  { 15742212196465548019u,  8759933935842067041u,         215806507111u },
+  {  2892220461917134150u,  3753418510388703513u,         103474876970u },
+  {  7487151560715393883u,  2961383332545305985u,          42203473225u },
+  {  7245756744165177933u,  2497674184068629507u,          73160536912u },
+  {  3067122860671533987u, 15244544070742305452u,          80135399188u },
+  {  8135043905834122525u,    45953573565810823u,          20826408390u },
+  { 14730019368921022572u,  3960077421351906445u,         198002491148u },
+  {   495969939682055458u,  3173330011013883118u,          12214676227u },
+  {  5617761407265775598u, 11026266219545759160u,           3172026564u },
+  {  2087044847072781811u,  8886757764964685632u,         196597735089u },
+  { 15929674232061203330u, 13952322129918090479u,         177481752103u },
+  {  8658086469608285873u,  4127250666614902202u,          39756356898u },
+  { 18369871790780313570u, 17649958504065306911u,          34223738706u },
+  {  3545648451947416750u, 13269305359002216873u,          82956806167u },
+  { 13347376792767929959u, 16236593433831947843u,          23719330484u },
+  { 14482164459838203025u, 13580930396682424057u,         180880187493u },
+  {  8899577765623565820u,   421976357197961116u,         101736223712u },
+  {  7095320096604405719u,  2962130818798626533u,         224022875384u },
+  {  2968593824439315788u,  8234383947306356345u,         248160577433u },
+  { 12621408323612585636u,  4380469931801381425u,         153446386848u },
+  {  3954422936414648259u, 15279887469027055916u,         160237465750u },
+  { 17143730087577690191u,  8534542821713755552u,         150828324359u },
+  {  5033045529399041876u,  7814613482565088782u,           7462658493u },
+  { 15857648521994521781u, 13771954404705323224u,         189423631045u },
+  { 16655573486499109541u,  4568173274762548144u,         197746579144u },
+  { 16652154439190075858u,  8105292616250821343u,         200247641169u },
+  { 18016950600164130638u,  2923678426777275612u,          81439388793u },
+  {  2086292996072613910u,  1808633176918384049u,         121158492925u },
+  { 17324462585194799521u, 18118642609460438969u,         253098046200u },
+  { 11079151463184927232u, 18138164175864360870u,         248982213583u },
+  {  5239846817488961536u,  4031433690465792404u,         207983271850u },
+  {  2778806963520143360u,  5012226396942308537u,         170218544458u },
+  {  6240890740138835968u,  7889712298793536835u,          74271713337u },
+  { 17250651344549707776u, 13500762396543628804u,          57427702160u },
+  {  4197354852709302272u,   501020624068841347u,         144731877796u },
+  {  9223372036854775808u,  8370653768288261750u,         164027160382u },
+  {                    0u,   647579990023635200u,          62453774050u },
+  {                    0u, 11106569307181154304u,         226035105381u },
+  {                    0u, 10797461613892861952u,         101602088328u },
+  {                    0u, 17627230675448889344u,         136585331566u },
+  {                    0u, 12197735707942322176u,         110955574089u },
+  {                    0u, 12871287735024877568u,          73661240577u },
+  {                    0u,  4611686018427387904u,           1697753906u },
+  {                    0u,                    0u,          50250000000u },
+  {                    0u,                    0u,         128000000000u },
+  {  5654803392547571318u,             31757315u,                    0u },
+  {  2931628102185393332u,    31757315306547506u,                    0u },
+  { 15964697617980212305u,  9451803574512021605u,              1721567u },
+  {   450380868305846606u,  8662766454758138424u,         223512383298u },
+  { 14631133530814566148u,  9207992007314947035u,          66469609510u },
+  {    31969822783742095u, 17118602861291201802u,          38499166246u },
+  { 10437269029385743245u, 11186560605745599967u,          38928001320u },
+  { 15196146496377392433u, 10505549821532796847u,          40606424665u },
+  {  4409099735137480938u, 18133667530488679216u,          89569506996u },
+  { 10644987914903248118u, 10778135771244330799u,         180983028086u },
+  {  3154431617534062973u, 17087985777033767391u,         118584283910u },
+  { 11702056331247960454u,  2639185991757283040u,           6926341565u },
+  { 15575315065965259114u,  5401720287293896400u,         189143070559u },
+  { 10759747609480050226u,  9816495392633895233u,          95292827843u },
+  { 12538236653960743718u, 10042051500090034990u,         195532153281u },
+  { 17857942663978005403u, 11629689537856384738u,         193544380702u },
+  { 11443004154750813211u,  2099086731766010483u,          30630446733u },
+  {  4004313188770806737u, 13665537898516458594u,         141113791719u },
+  { 17134872954824183228u, 16375672064669490764u,         231740810293u },
+  {  2659553912986171234u,  7770550512184564348u,          53887726961u },
+  {  9501854300969137926u,  6197048880720627314u,         113421242387u },
+  { 14528169966301018150u, 17963594118523106281u,          19335942692u },
+  { 18172091996515901778u,  8255454642407818663u,          36973808388u },
+  {  1133541705604751035u, 16744201957549498409u,           4447529092u },
+  { 18280349987988641497u, 17442505417202859722u,         132907705006u },
+  {  9936015874712336386u,  6383975767786687150u,         174945560113u },
+  { 15876720399740689614u, 15245442964998335795u,          49346076019u },
+  {  8618117825152456982u,  2910016124519524433u,         115826457119u },
+  {  8085525680745921564u,  3847913871169988463u,          31157752290u },
+  {  8072355444669730953u, 17210451512590059177u,         226208595828u },
+  {  9395030504766848294u, 17899408909991454145u,         116932980445u },
+  {  3537903114058185903u,  5920601932753251608u,         221970328901u },
+  {  2126094743961928691u, 16521781895108979744u,          69320956473u },
+  {   289185362555601115u,  3697493405554698771u,          57895647591u },
+  { 16909937501450129614u,  2816108280295732065u,         103200441519u },
+  { 14449642060360499058u, 14251078772056398988u,         175152661535u },
+  { 12433818908498244393u,  4543066550096031417u,          31772552528u },
+  { 11884444034578008581u,  3099369389734296977u,          80246280131u },
+  {   988625838444140793u,  5243484113636490986u,         195168017151u },
+  {  1675370907158909973u,  6823370511605197226u,         255284249843u },
+  { 15920186275316934067u, 11396290277624641942u,         243369895656u },
+  {  5600921198503757726u, 15934361408437566099u,         232617794133u },
+  { 10457357161776341741u, 14939272230935131954u,          85863803462u },
+  { 12225356765775740093u,  7500666177940329347u,          70809859570u },
+  {  4486633318598164537u,  4806714453065462270u,         242406611928u },
+  { 10302486602879381361u, 11557851247268441487u,         216260572512u },
+  { 15536428611301239541u, 10655523157206817381u,          96626552371u },
+  { 12026126645955462603u, 14769600176490881210u,          51577637067u },
+  { 14877968141142123551u, 16688495540925795167u,         203800661629u },
+  {   734560801645383190u,   909793965395524173u,         125904685156u },
+  { 15648943144911081638u, 12724590949761703756u,         100049320029u },
+  { 13664182862003235646u, 10810739657314826395u,          93689801457u },
+  {  3895127525902132786u,  2431218615388671301u,         241586051371u },
+  {  5249187334214137467u,  4235001167959059286u,          43131796625u },
+  { 10642260063359027505u,  6253317787396334247u,         145229579873u },
+  {   783598951897779422u,  9534525563070371898u,          97338993036u },
+  {  5538576558607624843u,  8392783992374030728u,         140516867666u },
+  { 15974581187564609611u, 16356257019231647540u,          82454973731u },
+  {  7474269406918257428u, 12896334001521091877u,          35886674469u },
+  {  8045286838779138019u,  1427636373320877084u,          37699111667u },
+  {  8184246376556341732u, 16116755731295043521u,         243077392322u },
+  {  1493267152679331840u, 15945633911163986837u,         194873691078u },
+  { 10179074811222818816u,  7510154241072743838u,         198864414546u },
+  {  3892499202005008384u,  3571560509790395119u,          82407126277u },
+  { 10341173215925108736u,  3576991649007035076u,           5193614683u },
+  {  6230307872002015232u, 15509961892750732443u,          91193909105u },
+  {  9295429630892703744u, 17789791359353349378u,         113840796718u },
+  {                    0u, 18331227331079738314u,          46964386521u },
+  {                    0u, 15386712883100476416u,         217993737824u },
+  {                    0u, 14082462055028752384u,          96834115376u },
+  {                    0u, 12919043128765186048u,          48763411797u },
+  {                    0u,  6125373368465096704u,          85700342731u },
+  {                    0u, 12335992698065387520u,         203332057155u },
+  {                    0u,  2774217370460225536u,          67668735504u },
+  {                    0u,                    0u,          16150390625u },
+  {                    0u,                    0u,          97000000000u },
+  { 10665454627995623288u,                  484u,                    0u },
+  { 16803537892767562832u,         484578175453u,                    0u },
+  {  8099123106849104444u,  4962829537462579598u,                   26u },
+  {  7077413686679401728u,  5711259460785241095u,          26269035528u },
+  { 13536636358372449666u, 13845894607204897444u,           8309607995u },
+  {  7280632235418610318u, 12116633056637003327u,          59750587450u },
+  {  6187823673116858809u,  2965791047992089560u,          58656843994u },
+  {  8624343686231740255u, 16021997451315962529u,         218160775854u },
+  {   806211610822132771u,  3942052271663803856u,         174868554222u },
+  { 18388078233202190882u, 15669876414782439922u,         238213699081u },
+  {  7628864426595573600u, 10594415915406145286u,           9849465702u },
+  {  4530799784343874981u, 10789820553031921377u,         102574324437u },
+  {  8561580552078486438u,  3989990218583987244u,         213584917344u },
+  { 13349114951221999594u,  2937341169808224563u,          96216297803u },
+  { 10029144738508991772u, 16267436558584536843u,          75159233583u },
+  { 12601907197916268979u, 16221580362814625793u,          47881859502u },
+  {  1329580921391066941u,  9695437602320209830u,         174879373633u },
+  {  3198179786356761112u, 10729753156793715126u,          65525590725u },
+  { 11406753413634654142u,  2609241432056861929u,         197581661084u },
+  { 11131812960525182090u,  8462663743997037565u,         156141447261u },
+  { 14299636753645227208u, 14993422143908194069u,          93458761920u },
+  { 12964114684643663326u,  1307443894537745373u,         192812795043u },
+  {  5019257593846306316u, 10017257439419829265u,         163070876675u },
+  {  6929086798159998121u, 16754772009970777891u,           3543036613u },
+  { 18359765766933703649u, 11722573031602862387u,         197908278010u },
+  {  9993076234752063198u,  7363764277467092384u,         250635481957u },
+  {  3257189215046584509u,  6733958494847390772u,         101399190461u },
+  {  2905234736672690348u,  8799796600227451045u,         189365048621u },
+  { 12064985302079670056u, 10512023194742249826u,          45477037929u },
+  { 14315096064942799930u,  4572542132337197059u,         105569857919u },
+  { 11943971043551974038u, 12600500455757416832u,         127247878005u },
+  { 12472773152119929647u,  7873789864743195199u,         117683074498u },
+  {  7791259796982183085u, 15724851676325671539u,         194426839003u },
+  { 16866829442051086686u,  8748017220462413167u,         219852445917u },
+  {  3702498393844653053u, 14172589522760466448u,         221474230963u },
+  {  2057239613841701716u,  9520545591489413768u,         179768297617u },
+  { 17201969976738286226u, 12488551088392570222u,         145516109810u },
+  { 18271566505443461640u,  1135798823651241684u,         242677005711u },
+  { 18368509115417119804u, 11168725610120161972u,         143061571777u },
+  {  7613923684154518587u,  9580104948718508826u,         193605457828u },
+  { 17984805084714865232u, 16638722716909738765u,         164519338529u },
+  {  4220802739051410373u, 15732724012348272797u,          33901986965u },
+  { 17812459042810815760u, 12269722190021214142u,         149852872677u },
+  { 10629526089664605307u, 13110655916311972587u,         229665142972u },
+  { 17437443267816548473u,  6618112997062866867u,         188710730081u },
+  { 12506371893701049304u,  8457936459015989309u,          97358768624u },
+  { 15737221540003030739u,  3329167139937134914u,         240458505654u },
+  {  2358380859011605513u,  5245511557216705097u,         182180474512u },
+  { 10042972713837039706u,  5655931353280440466u,         144284359751u },
+  { 13424397272769642495u,   604622132328697393u,          71306608653u },
+  {  6867102315755663029u,  8673282619234652338u,          13032776631u },
+  {  8690748404825506734u, 16929477433058445690u,         183470179592u },
+  {   956229930815387710u, 11036952409253549455u,           8917748810u },
+  {  7734449506297687888u, 18199392190170386320u,          74598314388u },
+  { 16332184961683848151u,  9683116091880335715u,         148986591027u },
+  { 15580777817612768828u,  2993913337608915120u,          51524922775u },
+  { 17404245271944696092u,  4490779842162392585u,         151162300367u },
+  { 13201420160494469229u,   946849923353644618u,         207243445663u },
+  { 16511717657124068078u,  3613491058474899828u,         159051328837u },
+  { 14131292492116594062u, 14624054199004410935u,          69195887742u },
+  { 18429136031865875691u, 12088470271991908244u,         126792771566u },
+  {  2563978348305862197u, 10071980927725011290u,         238655317286u },
+  { 14239974392147482896u,  2833441711428854664u,          38546003180u },
+  { 11164201396098998272u, 17655572411864340446u,         236153601182u },
+  {  7116971104932986880u,  4997642792058747802u,         158957110498u },
+  { 12437629862867369984u, 11489200787635734848u,         226270922758u },
+  { 16501893821638901760u, 12983586226429536913u,           6622830822u },
+  { 10649324268870959104u, 12311150768725063152u,         230703841619u },
+  {  7205759403792793600u,  8530052476845967905u,          83667388820u },
+  {                    0u,  6282736361499820264u,         148462415071u },
+  {                    0u, 11337164765929082880u,         223340587820u },
+  {                    0u,  8343856200414134272u,          44614588933u },
+  {                    0u, 17889330377156198400u,           5452321350u },
+  {                    0u, 17730714064155312128u,          70969782542u },
+  {                    0u,  7449235258647511040u,          14961183935u },
+  {                    0u,  9943947977234055168u,         191403823852u },
+  {                    0u,                    0u,         236539062500u },
+  {                    0u,                    0u,         228000000000u },
+  {  3016823727048309817u,              7394076u,                    0u },
+  { 17405973192644624358u,     7394076163542341u,                    0u },
+  {  8937219978302591747u, 12396245121240683569u,               400833u },
+  { 15178463196824222317u, 10248996648596888561u,         193672001794u },
+  { 11979404627460330594u, 11257495103713935002u,           2555599221u },
+  {  2006448052689740002u,  7555396579247433114u,         117610270032u },
+  { 16330465320863239865u,  4805022328730367462u,          80409578869u },
+  { 17136208883957646553u,  7056637817080232586u,         117260480782u },
+  {   140455118208931867u, 10811411483818434913u,          14382541102u },
+  {  3964972929179372247u, 16962406704495245447u,          46586087790u },
+  {  3378050330022776379u, 18074517319117194669u,         110919533909u },
+  {  6065353437512901255u,  3702019776117654523u,          85979821547u },
+  { 12768753059854699889u,  3551977551381082764u,         235200686894u },
+  {  6848720690951013326u, 16442608985936005282u,          46192553088u },
+  { 10953228058585475132u,  3580046275479139588u,         128891355619u },
+  { 15539127852083296166u,  8737412692712715330u,         227194074697u },
+  { 14534853647735598497u,  3082033243045084752u,          73473656091u },
+  {  1506909603576368170u, 16401023756841128699u,          27167077356u },
+  {  5475702579938239025u,  7520296082779572869u,         236889101279u },
+  { 12039747373985783332u,  9854104766152464159u,         223407676067u },
+  { 17572399137760898460u, 14169188802648310188u,         163534192089u },
+  {   869552790852091236u,  2018609909210367042u,         217768113264u },
+  {  4549585778048181804u,  8270271948267674359u,         112109429062u },
+  {  4121918231767210357u, 12320338602894572099u,          70448332340u },
+  {  1558397953312543179u, 17538536685990080547u,          52667886893u },
+  {  6067524298738069781u, 15833914616956760474u,          45950765978u },
+  {  5811095224555517056u,  6137696141415969855u,         154858358231u },
+  {  6440894514158997188u,  9757490468419438919u,         215332725174u },
+  {  4612748874388784257u,  3566639201356598903u,         182528954618u },
+  {  9908101430749813367u,  9760900035773954449u,         250193347898u },
+  { 15150017990912190499u,  3873778773990716438u,          58529139451u },
+  { 17470426264690059239u,  2295668377270167832u,         251209997968u },
+  {  9615161096851907726u,  1791721710912807593u,         144124448432u },
+  {  9227932132124142224u, 10571009006922683279u,         176097129428u },
+  {  4794113194321211621u,  9840791932778184867u,         212573055546u },
+  {   391512698859146347u, 11525464956561274613u,          58533470399u },
+  { 17209658878068655842u,  4435781488897895433u,         191624796707u },
+  {  3077364726606876150u,  6395563367070996741u,          35240464196u },
+  {  1952989567673965814u, 15538690795135662932u,          68346704184u },
+  { 11172860676923186449u, 16294558813563371936u,          56842354115u },
+  { 17338078544784947239u,  4942096228426070342u,         195883329803u },
+  {  4593380466519703278u,  6910116424372647153u,          11267911573u },
+  {   786884753602720052u, 17923400669760829478u,         149374598161u },
+  { 17848875822468020539u,  4134686917293039955u,          17971629497u },
+  {  2899664567187130618u, 16857102463116098681u,         185224141826u },
+  {  2973178834961857409u, 11364321508775167451u,           2913825355u },
+  { 11117453141176836727u,  7966947780972783899u,          75616061103u },
+  {  7535238370146462002u, 11261055695926686278u,         175431889104u },
+  { 10246175467290865448u,  9227040437353594058u,         208610463052u },
+  {  1203128834127050464u,  7185344074282882061u,          76500198864u },
+  { 14518048959078919658u, 14197856148610578032u,         208389518282u },
+  {  1553474987376920024u,   885688687260429427u,         202769667324u },
+  { 14956572380830948369u, 17407816160380305183u,         252048013279u },
+  {  7594162606042048292u, 17812728703806357349u,         223943679604u },
+  { 14461296147288811288u, 17120198191964319867u,         116965629957u },
+  { 18305427728131488265u, 12091952048375408786u,           5928087803u },
+  { 10253208939347909876u,   405056939269888281u,         251655506034u },
+  {  6446028915490812012u, 12485440679452408690u,         114021958180u },
+  { 12986063676957432257u,  8394369900823444407u,          36676837095u },
+  {  9769714697972762807u,  2877421667354294258u,         231455059704u },
+  {    97429465146664592u,  2676980714750756239u,         248155985341u },
+  { 16395571728207795868u,  6119309228579057021u,         189145119415u },
+  {  6331668478323650406u, 18203256146533333852u,         183331728417u },
+  { 18129911846294207040u,   351919978865493747u,          33986800493u },
+  {  9890094564876124160u,  5190010931882390570u,         109019077620u },
+  { 12290856656987750400u,  6982466386088036604u,         244281351056u },
+  {  8498454992640802816u,  4707293888784996898u,         144378520261u },
+  {  5341660584200896512u,   690306801165964760u,         197255182913u },
+  {  9288674231451648000u, 12456770961278956704u,          65037421606u },
+  {  1152921504606846976u, 16946092489294063943u,          38675282906u },
+  {                    0u, 11098404173866185376u,         218918649514u },
+  {                    0u, 15152070965853306880u,         170601645695u },
+  {                    0u, 17370091362040414208u,         127821395412u },
+  {                    0u, 10141938552171134976u,         212941634539u },
+  {                    0u, 10586988556645826560u,         235549795590u },
+  {                    0u, 12169852093061922816u,           6573921799u },
+  {                    0u, 16717361816799281152u,           7659729003u },
+  {                    0u,                    0u,         107906250000u },
+  {                    0u,                    0u,          16000000000u },
+  { 15212079674427582639u,                  112u,                    0u },
+  { 10179808126814248333u,         112824648491u,                    0u },
+  {  6066766544199222848u,  2144184049294538808u,                    6u },
+  {  6625308131806923532u,  4108002197393276873u,           6116236450u },
+  {  9122786786400665713u,  6446230217393892753u,         162222695245u },
+  { 11932880778639151320u,  5571068025259989822u,          77349450840u },
+  {  3884040911779255011u, 14804812668872528331u,          88302008202u },
+  { 13441817515637357872u, 17369928488562523047u,         138802570502u },
+  { 11628577856022352826u,  2967474173531035027u,           6941625710u },
+  { 13296656925520243654u,  5291425437992807716u,         110160867097u },
+  {  5020720704545399398u, 14219547193739388064u,          25286848747u },
+  { 14121973606499014694u, 17720313647158217462u,         235770843197u },
+  {  3642481034345420114u, 12334850628290578491u,          61960620127u },
+  {  9845536238569696768u,  7818499847417334620u,          95668673592u },
+  { 17655403572195686356u,   136007040922198372u,          56423841726u },
+  {  8377495365136654029u,  8523477092112604449u,         190007372956u },
+  { 13713682649609025426u,   367934822655966629u,         156462058619u },
+  {  1367709905452854731u, 12964987687054730050u,         123019945786u },
+  {  9981467701727208680u, 15267036012420885462u,          58702833390u },
+  {  6277920117543306205u, 11142900264750765568u,         238827627680u },
+  {  9344111460418701726u, 13680181547777718603u,         160604057833u },
+  {  4918507011364617264u, 13001922925761426065u,         233741604127u },
+  {  6554777203830755259u,  2397730045956515935u,          31704835654u },
+  {  4198262173120265648u,  4482395522588406288u,          70129981206u },
+  {  8080325935698446819u,  3255525722490493080u,          22242991148u },
+  { 12797633874200091733u,   836222287193822098u,          44176482403u },
+  {  8376502502208665497u,   420898743993182306u,          99045331701u },
+  {  9891973386793349173u, 11652649973356574054u,         245022816966u },
+  { 14877430279003795462u, 15058402726661910231u,         198631691420u },
+  {  8759933935842067041u,  9600134495208339559u,         156816317647u },
+  {  3753418510388703513u, 14626343323989004842u,         207520424333u },
+  {  2961383332545305985u,  6813981265331086665u,         141792895660u },
+  {  2497674184068629507u, 10281745288790487888u,         172369386664u },
+  { 15244544070742305452u, 17569829347075761940u,         168557374528u },
+  {    45953573565810823u,  7654580675237889478u,          64952462357u },
+  {  3960077421351906445u, 16194838649686212364u,          21414955649u },
+  {  3173330011013883118u,  6495102772252453635u,         129877923962u },
+  { 11026266219545759160u, 14935159852819761348u,         122352100226u },
+  {  8886757764964685632u, 17381879863441579697u,         130809636637u },
+  { 13952322129918090479u,  9062335510435372583u,          29942273595u },
+  {  4127250666614902202u,  7569219009130126626u,          59491270192u },
+  { 17649958504065306911u, 12652124168176193362u,          48410328184u },
+  { 13269305359002216873u,  8940200224697247767u,         120685873025u },
+  { 16236593433831947843u,  5600570701927432884u,         129484649225u },
+  { 13580930396682424057u,  2018432801986093157u,           9303607546u },
+  {   421976357197961116u,  8235849749361824736u,         250109419461u },
+  {  2962130818798626533u,  9705097287982370040u,         197446466309u },
+  {  8234383947306356345u,  3517483139049842585u,           5526114378u },
+  {  4380469931801381425u,   958281614186777760u,          74190683143u },
+  { 15279887469027055916u,  7336473432636108950u,           7051948550u },
+  {  8534542821713755552u, 12955383920176764423u,           6397711021u },
+  {  7814613482565088782u, 10735469126281273789u,         173702312769u },
+  { 13771954404705323224u,  8637888232514730693u,          65581970947u },
+  {  4568173274762548144u,  6806336737533581000u,           3468260859u },
+  {  8105292616250821343u, 16142569672872330321u,         251368972253u },
+  {  2923678426777275612u,  8141285259947963513u,         221875090455u },
+  {  1808633176918384049u,  5220241098754220797u,          23441339958u },
+  { 18118642609460438969u,   154438799943119608u,          54282989837u },
+  { 18138164175864360870u,  2226876628677628879u,          13008372144u },
+  {  4031433690465792404u, 17219557081221357482u,         176120719223u },
+  {  5012226396942308537u, 15401507148161015114u,         119933474059u },
+  {  7889712298793536835u,  8842629766613985337u,          11834917375u },
+  { 13500762396543628804u,  3180100571546071440u,         255479359920u },
+  {   501020624068841347u,  7740848704392475044u,         176172393597u },
+  {  8370653768288261750u,  2014314126623495998u,         125419632249u },
+  {   647579990023635200u, 11209566016506885858u,         121109196187u },
+  { 11106569307181154304u,  7117166613733441125u,         155607671791u },
+  { 10797461613892861952u,  4197646860931880328u,         239385822375u },
+  { 17627230675448889344u,  5487263271238026094u,         167227554892u },
+  { 12197735707942322176u, 18148076225293562697u,          76297465137u },
+  { 12871287735024877568u,  9127276943027950849u,          49983809183u },
+  {  4611686018427387904u,  9691696125379324722u,         159494790674u },
+  {                    0u, 13102362262487705216u,          18525387899u },
+  {                    0u,  8929385439893192704u,         123710280481u },
+  {                    0u, 11891353410743566336u,          33484062954u },
+  {                    0u,  1587423090877399040u,         234644631560u },
+  {                    0u,  3489137423026225152u,           8086054378u },
+  {                    0u, 13046928120492326912u,         234189146518u },
+  {                    0u, 11529215046068469760u,         150707275390u },
+  {                    0u,                    0u,         126625000000u },
+  {                    0u,                    0u,          64000000000u },
+  {  9451803574512021605u,              1721567u,                    0u },
+  {  8662766454758138424u,     1721567512383298u,                    0u },
+  {  9207992007314947035u,  6674960280855494694u,                93326u },
+  { 17118602861291201802u, 16378845781483497510u,         142361850321u },
+  { 11186560605745599967u, 17606907750956804392u,         209887899008u },
+  { 10505549821532796847u, 13225609159240506969u,         128954472381u },
+  { 18133667530488679216u,  2668084873338435252u,         189716961709u },
+  { 10778135771244330799u, 14802814305275861366u,         173144637170u },
+  { 17087985777033767391u,  8005510553372365574u,         242802462171u },
+  {  2639185991757283040u, 12748500143273514429u,         219433979596u },
+  {  5401720287293896400u, 10393733905569036127u,         204691097577u },
+  {  9816495392633895233u,   603389089974790339u,         233563445444u },
+  { 10042051500090034990u,  2033494532597735873u,         196032709788u },
+  { 11629689537856384738u,  9204796763694620958u,         156110235959u },
+  {  2099086731766010483u,  7826260310402107021u,          55498993032u },
+  { 13665537898516458594u, 10122690201685169383u,         136424262421u },
+  { 16375672064669490764u,  7438455564568110133u,          21548752135u },
+  {  7770550512184564348u,  2805412574380520817u,           7403239484u },
+  {  6197048880720627314u,  7250965427231182867u,          60152081720u },
+  { 17963594118523106281u,  8136242944826085924u,          56393075623u },
+  {  8255454642407818663u, 15357191647956011780u,         167441066613u },
+  { 16744201957549498409u,  7369614426695395460u,         117832515027u },
+  { 17442505417202859722u, 10886957545142526638u,         211399507598u },
+  {  6383975767786687150u,  2030047207417538097u,         142590183151u },
+  { 15245442964998335795u, 11557093828502314355u,         239110049079u },
+  {  2910016124519524433u, 15201062539664128543u,          55626511311u },
+  {  3847913871169988463u,  8846936323343880674u,         207824051251u },
+  { 17210451512590059177u,  1485291750116245364u,          51479593379u },
+  { 17899408909991454145u,  2076024439668322013u,         163080517827u },
+  {  5920601932753251608u,  7029497773682748741u,         195112541510u },
+  { 16521781895108979744u, 16333533921668749881u,          70381069837u },
+  {  3697493405554698771u,  2065057316131928423u,          13885442648u },
+  {  2816108280295732065u,  7800502648925570223u,          88111946981u },
+  { 14251078772056398988u, 17011619967093802015u,         229422866095u },
+  {  4543066550096031417u,  5368819344429198672u,         175922201766u },
+  {  3099369389734296977u, 15598879366754275267u,         166291044279u },
+  {  5243484113636490986u, 16393893486035835647u,         183845616944u },
+  {  6823370511605197226u, 12042046205096920307u,          48888714746u },
+  { 11396290277624641942u, 15437070428008474344u,         250652800632u },
+  { 15934361408437566099u, 13704569163204647509u,         120836845264u },
+  { 14939272230935131954u, 18192483750856993350u,         208742926182u },
+  {  7500666177940329347u,  5152535865317963250u,         102986216520u },
+  {  4806714453065462270u, 17512614083933854680u,          72279319528u },
+  { 11557851247268441487u, 14481918350603613536u,         232949360711u },
+  { 10655523157206817381u, 16124419709964004915u,          71785066366u },
+  { 14769600176490881210u, 18088011566435813579u,         126874106543u },
+  { 16688495540925795167u, 15008862380698848893u,         175980553071u },
+  {   909793965395524173u, 18160498644611827812u,         111813632059u },
+  { 12724590949761703756u,  3604680497457231965u,          59984482604u },
+  { 10810739657314826395u,  5957615565551495921u,          44195410121u },
+  {  2431218615388671301u, 17528455034961565995u,         201322962986u },
+  {  4235001167959059286u,  8503772325120113809u,          42950219451u },
+  {  6253317787396334247u,  8501492578048509537u,         187460990421u },
+  {  9534525563070371898u,  2296237701094386060u,         213460866836u },
+  {  8392783992374030728u,  3753593040591076946u,          20124479295u },
+  { 16356257019231647540u,  8518075399775653155u,          63203482686u },
+  { 12896334001521091877u, 12757855675959554597u,          62461765792u },
+  {  1427636373320877084u,   121631169379748595u,         160691604742u },
+  { 16116755731295043521u, 16679062494579173314u,           6006593638u },
+  { 15945633911163986837u, 10739912744743898054u,         102904173789u },
+  {  7510154241072743838u,  9367340677776287570u,         221582211836u },
+  {  3571560509790395119u, 12227321512794715397u,         252507804555u },
+  {  3576991649007035076u,  7241061891859170651u,         139662844427u },
+  { 15509961892750732443u, 13148571323079237489u,          11392538751u },
+  { 17789791359353349378u, 12509763434355012654u,         127712785479u },
+  { 18331227331079738314u, 11812768946960181977u,          71678155634u },
+  { 15386712883100476416u, 14170358803552564832u,         114640371487u },
+  { 14082462055028752384u, 18179989524780635952u,          31768176689u },
+  { 12919043128765186048u, 17091718978514754901u,          49985539206u },
+  {  6125373368465096704u,  7394768384359232459u,         134926543942u },
+  { 12335992698065387520u,  6778628272692852803u,          70400871197u },
+  {  2774217370460225536u, 18193335045875234320u,          29367470174u },
+  {                    0u,  1378519212560967521u,          94986262669u },
+  {                    0u,  4677732610631043584u,         141074729676u },
+  {                    0u, 17296098591070486528u,         204253580392u },
+  {                    0u,  7343735382392963072u,         104937623383u },
+  {                    0u, 14525996728454217728u,          87398104692u },
+  {                    0u,  9691359370008330240u,         116787455860u },
+  {                    0u,  3044433348102455296u,         116525369644u },
+  {                    0u,  9223372036854775808u,          44165039062u },
+  {                    0u,                    0u,         214500000000u },
+  {  4962829537462579598u,                   26u,                    0u },
+  {  5711259460785241095u,          26269035528u,                    0u },
+  { 13845894607204897444u,  7822291454600056379u,                    1u },
+  { 12116633056637003327u,  8201586317771250746u,           1424047269u },
+  {  2965791047992089560u,  3278889188817135834u,         165444608885u },
+  { 16021997451315962529u,  1710725240251040430u,         117177748939u },
+  {  3942052271663803856u,  1850175733663425006u,         203092738601u },
+  { 15669876414782439922u,  9147599666163914249u,          41100298227u },
+  { 10594415915406145286u, 10221885933644344166u,         243495892371u },
+  { 10789820553031921377u, 14901479793736678101u,         147554129546u },
+  {  3989990218583987244u,  5181831442059703136u,         138807810838u },
+  {  2937341169808224563u,  6396246577759793483u,          22280907645u },
+  { 16267436558584536843u, 14167229556464870447u,         125346741221u },
+  { 16221580362814625793u,  2969982933326311854u,         229768007053u },
+  {  9695437602320209830u,  7892677766222018881u,         141161003097u },
+  { 10729753156793715126u,   798698968922663621u,          89427862919u },
+  {  2609241432056861929u, 15926812109043458972u,         135043297557u },
+  {  8462663743997037565u,  8663842590352697437u,          21863394214u },
+  { 14993422143908194069u, 17093523026636671168u,         166469667847u },
+  {  1307443894537745373u,   839764004742743203u,           7926641740u },
+  { 10017257439419829265u, 16894643909298232323u,          76045523697u },
+  { 16754772009970777891u,  9066702926218949317u,         241915860481u },
+  { 11722573031602862387u,  9119392417260546810u,           1491506950u },
+  {  7363764277467092384u,  9723021096578315109u,           6494363253u },
+  {  6733958494847390772u, 14787464248751217597u,         117527086029u },
+  {  8799796600227451045u,  3733434565920249133u,         205801630043u },
+  { 10512023194742249826u,  6643788868836820841u,          91202389893u },
+  {  4572542132337197059u,  4729646697422664063u,         133360160516u },
+  { 12600500455757416832u,  4090144564201555829u,           4256394661u },
+  {  7873789864743195199u,  2109480737093400002u,         165221727181u },
+  { 15724851676325671539u, 16577155033369419739u,         205114355179u },
+  {  8748017220462413167u,   745377248603805917u,         235898649375u },
+  { 14172589522760466448u, 11305561465807999667u,          31040406981u },
+  {  9520545591489413768u,  2211245518782892177u,         197612875715u },
+  { 12488551088392570222u, 14170095199249735666u,         195119871859u },
+  {  1135798823651241684u, 17849973668116118927u,         115768162399u },
+  { 11168725610120161972u,  9020960204585720001u,          95967649011u },
+  {  9580104948718508826u, 10807134002871850916u,         243489027232u },
+  { 16638722716909738765u,  3925122626254791201u,         160585855908u },
+  { 15732724012348272797u, 17208463291312718997u,         164212781323u },
+  { 12269722190021214142u,  5145077219589447653u,          11932872664u },
+  { 13110655916311972587u, 17602397765035489468u,         216278915194u },
+  {  6618112997062866867u, 16422643262490753377u,         122954227894u },
+  {  8457936459015989309u,  2902509461400906224u,         182890273275u },
+  {  3329167139937134914u,  3422418805967265206u,         251157345353u },
+  {  5245511557216705097u,  4228874576277237392u,          73185529695u },
+  {  5655931353280440466u,  2553488530807495751u,          95229247750u },
+  {   604622132328697393u, 11546099176912486413u,           6138424890u },
+  {  8673282619234652338u, 10460791037534167991u,          58625915290u },
+  { 16929477433058445690u,  8127117908566000904u,         154567080618u },
+  { 11036952409253549455u, 11541304458088287306u,         170440571944u },
+  { 18199392190170386320u,  6249718665174839700u,          40625655368u },
+  {  9683116091880335715u, 13102508413386290995u,          72338797927u },
+  {  2993913337608915120u,  6274675218640661911u,         103710288404u },
+  {  4490779842162392585u,  3404497118599817167u,          20340150825u },
+  {   946849923353644618u, 11258566093988562335u,          41184558158u },
+  {  3613491058474899828u, 16762592482501635397u,          78610328090u },
+  { 14624054199004410935u,  5550125446725071998u,          26908701959u },
+  { 12088470271991908244u,  6370033225258510318u,           7300872903u },
+  { 10071980927725011290u,  1503521728674735398u,         199345320193u },
+  {  2833441711428854664u,  4250415082606384364u,           1081506076u },
+  { 17655572411864340446u,  6020091901030562974u,          28230415463u },
+  {  4997642792058747802u, 16288222967151527138u,         103326349835u },
+  { 11489200787635734848u,  6377016228656203782u,          11882986336u },
+  { 12983586226429536913u,  8378856515587563750u,          96345698742u },
+  { 12311150768725063152u, 15812881490200838483u,         182454218721u },
+  {  8530052476845967905u,  4548570371183413652u,         225857218023u },
+  {  6282736361499820264u, 16731431495283420383u,         231246578493u },
+  { 11337164765929082880u, 14737727629551135532u,          61907012718u },
+  {  8343856200414134272u, 12413722258104293893u,         110798933815u },
+  { 17889330377156198400u,   800899742400762438u,          55672949232u },
+  { 17730714064155312128u,   603197008376033550u,         240043416862u },
+  {  7449235258647511040u,  6380777281587743935u,          30032699375u },
+  {  9943947977234055168u, 10001440249018225388u,         239345902629u },
+  {                    0u,  5505914461980436708u,          37542179162u },
+  {                    0u,  1105464290051876864u,          90298476221u },
+  {                    0u,  4500443576769970176u,         189059927339u },
+  {                    0u,  2843045143185981440u,          43243969535u },
+  {                    0u,   660949699682893824u,         255154121786u },
+  {                    0u,   276549164618219520u,          58035830155u },
+  {                    0u,  4683743612465315840u,         139014991760u },
+  {                    0u,                    0u,         144253906250u },
+  {                    0u,                    0u,          74000000000u },
+  { 12396245121240683569u,               400833u,                    0u },
+  { 10248996648596888561u,      400833672001794u,                    0u },
+  { 11257495103713935002u,  4370024159708535157u,                21729u },
+  {  7555396579247433114u,  7166684413908503888u,         225236899484u },
+  {  4805022328730367462u, 10217286283215687029u,         156388506740u },
+  {  7056637817080232586u,  4767369911989629198u,         116553880199u },
+  { 10811411483818434913u, 14407999214182082862u,         135258439640u },
+  { 16962406704495245447u,  8472271297615317358u,         216781059202u },
+  { 18074517319117194669u,  6236024012584764757u,         130459282747u },
+  {  3702019776117654523u,  1951826556984620523u,          59338055539u },
+  {  3551977551381082764u, 12357130551551830830u,         115105808729u },
+  { 16442608985936005282u,  8927758011099278464u,          89669881389u },
+  {  3580046275479139588u, 10199854049407140323u,          45483974731u },
+  {  8737412692712715330u, 17895455027038549577u,          75552935195u },
+  {  3082033243045084752u, 16539200343720527131u,          27970114560u },
+  { 16401023756841128699u,  3536976106235802604u,            896591847u },
+  {  7520296082779572869u, 16980391644793590751u,         231191739858u },
+  {  9854104766152464159u, 10090294316609084067u,         210920508875u },
+  { 14169188802648310188u, 17603457857266236889u,         203546995950u },
+  {  2018609909210367042u, 11164962743035868272u,         238954285362u },
+  {  8270271948267674359u,  1585686890718568774u,          50605253843u },
+  { 12320338602894572099u, 10882524700472655412u,         211085960258u },
+  { 17538536685990080547u,  2194808754940947757u,          66589942846u },
+  { 15833914616956760474u,   274100791137209242u,          62118980821u },
+  {  6137696141415969855u, 12203404582981010903u,         213014859033u },
+  {  9757490468419438919u,   541940706340938166u,          25661547888u },
+  {  3566639201356598903u, 10305434016011833594u,         112029378664u },
+  {  9760900035773954449u,  7900783531944543546u,         104558658697u },
+  {  3873778773990716438u,  8920818625012419323u,         137428302333u },
+  {  2295668377270167832u, 12532363335400447632u,         253483598546u },
+  {  1791721710912807593u, 13483507182924762800u,         210679380777u },
+  { 10571009006922683279u,   415911049779278804u,          41730942389u },
+  {  9840791932778184867u,  3441628281170127418u,         181022546583u },
+  { 11525464956561274613u, 17830811568183566527u,         151186571042u },
+  {  4435781488897895433u, 17897295813176613411u,          34966610231u },
+  {  6395563367070996741u,  2086148701331574596u,          55970214350u },
+  { 15538690795135662932u, 13015567826878853432u,         206113090347u },
+  { 16294558813563371936u, 12944531121587846595u,          43705575345u },
+  {  4942096228426070342u,  3534180912913737995u,         177701724438u },
+  {  6910116424372647153u,  3447584022400118677u,          22191588331u },
+  { 17923400669760829478u,  6375676813770849297u,         235186893904u },
+  {  4134686917293039955u, 11580694081479200185u,          80345626132u },
+  { 16857102463116098681u,  1872134358882196482u,          20627790684u },
+  { 11364321508775167451u, 17602652840520938059u,          92101488606u },
+  {  7966947780972783899u, 10331040597716338351u,         222954241722u },
+  { 11261055695926686278u,    73785407041056976u,         186560046833u },
+  {  9227040437353594058u, 17166209109167902028u,         241003999914u },
+  {  7185344074282882061u,  8762475644006589904u,         170930582060u },
+  { 14197856148610578032u,  8839001228645872586u,          44475014756u },
+  {   885688687260429427u, 13558262784529110268u,         100479163216u },
+  { 17407816160380305183u,  5640853896420358111u,          80734994898u },
+  { 17812728703806357349u,  8459930353450835572u,         210305791302u },
+  { 17120198191964319867u,  7643830211500171269u,          70458613743u },
+  { 12091952048375408786u,  1308629115231236347u,         239414372866u },
+  {   405056939269888281u,  8957268500971669618u,           2070940926u },
+  { 12485440679452408690u,  7645679094277669412u,         254485574498u },
+  {  8394369900823444407u,  3821107497040617191u,          98414473094u },
+  {  2877421667354294258u,  8847137191985934072u,         134207142652u },
+  {  2676980714750756239u,  3531126524756088253u,         252479604268u },
+  {  6119309228579057021u,  8726915034124352183u,          44191422752u },
+  { 18203256146533333852u, 17611136727168068641u,          32473087011u },
+  {   351919978865493747u, 18017743272784259949u,          35954701634u },
+  {  5190010931882390570u, 18113575006829616116u,          66976743819u },
+  {  6982466386088036604u, 12805550441678740368u,         139981938868u },
+  {  4707293888784996898u,  8061966093393027781u,         180694190280u },
+  {   690306801165964760u, 11954593141554100801u,         200437040057u },
+  { 12456770961278956704u, 14068656112359197734u,         185648059792u },
+  { 16946092489294063943u,   895878255770467290u,         144762663376u },
+  { 11098404173866185376u, 10319906489512197802u,         208048565657u },
+  { 15152070965853306880u, 14551142616794302079u,         153559443251u },
+  { 17370091362040414208u, 15933181735739307476u,          51788819021u },
+  { 10141938552171134976u, 11524527334398983147u,          77863739512u },
+  { 10586988556645826560u, 11828012606225556742u,         120624745878u },
+  { 12169852093061922816u,  3556238869349799431u,         150641197848u },
+  { 16717361816799281152u,  7403090230513381483u,          24192784095u },
+  {                    0u, 10172292854665622800u,         223401322325u },
+  {                    0u, 11240746576366182400u,          85551441100u },
+  {                    0u, 17021927826892259328u,         204609362092u },
+  {                    0u,  9046328496309141504u,         172922760556u },
+  {                    0u,  8038996803112140800u,         108490402450u },
+  {                    0u, 17098478935265509376u,         146435794889u },
+  {                    0u,  7205759403792793600u,         201926910400u },
+  {                    0u,                    0u,         192390625000u },
+  {                    0u,                    0u,         232000000000u },
+  {  2144184049294538808u,                    6u,                    0u },
+  {  4108002197393276873u,           6116236450u,                    0u },
+  {  6446230217393892753u,  6116236450222695245u,                    0u },
+  {  5571068025259989822u,  6240972538554414168u,            331561842u },
+  { 14804812668872528331u,  4356262642990299018u,         114338323799u },
+  { 17369928488562523047u,  1335108558830511366u,          87236153471u },
+  {  2967474173531035027u, 18435704923261947246u,         127072376379u },
+  {  5291425437992807716u,  8395401931972636441u,          59999401566u },
+  { 14219547193739388064u, 12482665946362458347u,          94455115650u },
+  { 17720313647158217462u, 16101242875289374781u,         130676686676u },
+  { 12334850628290578491u,  4708983440241068127u,          84872850125u },
+  {  7818499847417334620u, 14856666972541426744u,         205255274503u },
+  {   136007040922198372u,  6938795288315789246u,           7805381530u },
+  {  8523477092112604449u,  5556307628265073820u,         154376152846u },
+  {   367934822655966629u,  1441404248927865979u,          14301208040u },
+  { 12964987687054730050u, 16710378912353838906u,         232078138680u },
+  { 15267036012420885462u, 18289940136919312110u,          56905871455u },
+  { 11142900264750765568u, 10217414145292657824u,          95991499641u },
+  { 13680181547777718603u, 12461165826430955753u,         121553887130u },
+  { 13001922925761426065u,   662762458988270879u,         154675521153u },
+  {  2397730045956515935u, 16488546856395302470u,         129035928424u },
+  {  4482395522588406288u,  2612816787977180950u,         104893845916u },
+  {  3255525722490493080u, 16446616379327454252u,         156141641081u },
+  {   836222287193822098u,  7842178508581740643u,         121891572860u },
+  {   420898743993182306u, 14779029861369369333u,         124425125348u },
+  { 11652649973356574054u,  2697664446153849542u,         228801172814u },
+  { 15058402726661910231u, 12135106444393649308u,          78146240682u },
+  {  9600134495208339559u,  9550285041205189839u,         170657845438u },
+  { 14626343323989004842u,  8790318168586740109u,         190517721989u },
+  {  6813981265331086665u, 14038474217155846828u,         133476524102u },
+  { 10281745288790487888u,  4263144264274812072u,          70761027212u },
+  { 17569829347075761940u, 11940456333341715520u,         140231105513u },
+  {  7654580675237889478u, 15751110736831573013u,         233647293434u },
+  { 16194838649686212364u, 18384528705472318081u,         250853869423u },
+  {  6495102772252453635u,  2393654818032310394u,         111996627298u },
+  { 14935159852819761348u, 12812209822018626434u,          98129760287u },
+  { 17381879863441579697u,  3110778569433458461u,          31694551286u },
+  {  9062335510435372583u,  2860264756226872891u,         246168635644u },
+  {  7569219009130126626u,  2384146980060315184u,         252155055263u },
+  { 12652124168176193362u, 14117430062880324728u,         159129244866u },
+  {  8940200224697247767u,  3769610173216737153u,         194765307417u },
+  {  5600570701927432884u, 17731974340232672009u,          25204350976u },
+  {  2018432801986093157u,  1971479303384713466u,            961252255u },
+  {  8235849749361824736u,  3449462959779012549u,         159106874107u },
+  {  9705097287982370040u, 13743454852043766533u,         251186995761u },
+  {  3517483139049842585u,  7417711187131879498u,          49745034180u },
+  {   958281614186777760u,  3650992383501007879u,         196402114929u },
+  {  7336473432636108950u, 12838770342493958662u,         113197920693u },
+  { 12955383920176764423u, 16025068246546338477u,         181695991134u },
+  { 10735469126281273789u,  6579965938260177729u,          94868720690u },
+  {  8637888232514730693u,  4742939430174291459u,          50356700668u },
+  {  6806336737533581000u, 13062256857527449083u,         252257115261u },
+  { 16142569672872330321u,  2301174570202439645u,         125708106363u },
+  {  8141285259947963513u,  7638687886069412887u,         123124746923u },
+  {  5220241098754220797u,   936322449610274358u,         171414094100u },
+  {   154438799943119608u, 12926010544311283981u,          20050758141u },
+  {  2226876628677628879u, 12647854908989899184u,         253700720435u },
+  { 17219557081221357482u,  8862093163358513015u,          51685641588u },
+  { 15401507148161015114u,   444784343917630731u,         116480415033u },
+  {  8842629766613985337u, 11033952249213387263u,          57024111807u },
+  {  3180100571546071440u, 18168634046363183536u,         191598151749u },
+  {  7740848704392475044u,  3837904761417065597u,          69984923625u },
+  {  2014314126623495998u,   111459007020906105u,         233208053234u },
+  { 11209566016506885858u, 16191761957496794523u,         242006042204u },
+  {  7117166613733441125u,  9856250800340378607u,          92877757174u },
+  {  4197646860931880328u,  9491800102275105959u,         246534308426u },
+  {  5487263271238026094u, 10777328578953608268u,          74514551514u },
+  { 18148076225293562697u, 17424440628313779505u,         218584240152u },
+  {  9127276943027950849u,  3285814872419755679u,          24944580819u },
+  {  9691696125379324722u,  2824823424107240978u,         211178124381u },
+  { 13102362262487705216u, 12271707680713669755u,          93153133984u },
+  {  8929385439893192704u,  6951481875178001185u,         160665250606u },
+  { 11891353410743566336u, 10202522487003824362u,          46376840587u },
+  {  1587423090877399040u,  4834668463880990728u,         139553079852u },
+  {  3489137423026225152u, 10871520987687904746u,          44262087902u },
+  { 13046928120492326912u, 12057698794225322390u,         222589346333u },
+  { 11529215046068469760u,  7263351819222681214u,          29653649161u },
+  {                    0u,  1778055686910650944u,           9393747091u },
+  {                    0u, 17108187120491986944u,         147096388591u },
+  {                    0u,  3067636961549221888u,         239927436682u },
+  {                    0u, 16702141595163557888u,         138166296932u },
+  {                    0u,  2432053749942845440u,         100905424910u },
+  {                    0u, 17791470327927144448u,          14131841897u },
+  {                    0u,  1152921504606846976u,         105964477539u },
+  {                    0u,                    0u,          99062500000u },
+  {                    0u,                    0u,         160000000000u },
+  {  6674960280855494694u,                93326u,                    0u },
+  { 16378845781483497510u,       93326361850321u,                    0u },
+  { 17606907750956804392u,  4283581425266273664u,                 5059u },
+  { 13225609159240506969u,  6725911039793895357u,         195232213414u },
+  {  2668084873338435252u,  1188689198788975021u,         166364612368u },
+  { 14802814305275861366u, 10825527435847761650u,          16064438970u },
+  {  8005510553372365574u,  3917696829526085083u,         186586853018u },
+  { 12748500143273514429u, 12646861173976387276u,         154212378770u },
+  { 10393733905569036127u, 18398576063183996905u,         146685587717u },
+  {   603389089974790339u, 16919251228485834948u,           5997388806u },
+  {  2033494532597735873u, 17296019588687185052u,           6917194446u },
+  {  9204796763694620958u, 12365301604512770359u,         206937619100u },
+  {  7826260310402107021u,  2814271599679204744u,         156670324343u },
+  { 10122690201685169383u,  2154994415780170517u,         119152561969u },
+  {  7438455564568110133u,  6717373824370072839u,          49116822481u },
+  {  2805412574380520817u, 12709155755801344060u,         209364149564u },
+  {  7250965427231182867u,   826847911966403896u,          60688964714u },
+  {  8136242944826085924u,  2277322703890025383u,         106044823515u },
+  { 15357191647956011780u,  2774508958389496437u,         219123453911u },
+  {  7369614426695395460u,   245697774950120915u,         215150406432u },
+  { 10886957545142526638u,  1268929063431863950u,          32013319303u },
+  {  2030047207417538097u,  6735665673159411439u,         135068788782u },
+  { 11557093828502314355u, 14734771742997073207u,          46365141167u },
+  { 15201062539664128543u, 13683287077957612495u,         175798773576u },
+  {  8846936323343880674u, 15370263741354826803u,          72741772478u },
+  {  1485291750116245364u,    48035913070297507u,         190833223667u },
+  {  2076024439668322013u,  1206547475966802115u,         243002604032u },
+  {  7029497773682748741u, 13512340386605768006u,             65407069u },
+  { 16333533921668749881u,  2325760467700278797u,          93732505440u },
+  {  2065057316131928423u, 10848110652847753816u,          96126079727u },
+  {  7800502648925570223u, 15846378960784301285u,         239588077256u },
+  { 17011619967093802015u, 14121839924449844911u,         200859033924u },
+  {  5368819344429198672u,  5147613424753296550u,          68765546476u },
+  { 15598879366754275267u, 16817040482828810167u,         236279052682u },
+  { 16393893486035835647u,  5773528746119363888u,         138911653591u },
+  { 12042046205096920307u,  8716201595536184826u,         215312983620u },
+  { 15437070428008474344u,  5259122109038474872u,          68472506235u },
+  { 13704569163204647509u, 14744540084230155984u,         123285097580u },
+  { 18192483750856993350u, 10719345477982635878u,         108799303119u },
+  {  5152535865317963250u, 13698037261310555208u,         207581096882u },
+  { 17512614083933854680u, 16141171632951976936u,         178742572087u },
+  { 14481918350603613536u, 10060790174955808839u,          55875014667u },
+  { 16124419709964004915u,  4250043307981877118u,          11545396528u },
+  { 18088011566435813579u,  7075646198054337199u,          48230395309u },
+  { 15008862380698848893u, 18141738384245531503u,         173383571548u },
+  { 18160498644611827812u,  8174370508376809531u,          92983465608u },
+  {  3604680497457231965u,  3581964982731575596u,         136443133513u },
+  {  5957615565551495921u, 14798509948722114761u,          73194178710u },
+  { 17528455034961565995u, 14713923334885122090u,         150802228831u },
+  {  8503772325120113809u,  5042978054260414139u,          95797643382u },
+  {  8501492578048509537u,  2052996319372883413u,         118273380388u },
+  {  2296237701094386060u,  8825683007899981588u,          36111293153u },
+  {  3753593040591076946u,  9992196755378745151u,         225478441234u },
+  {  8518075399775653155u,  9301073417573669950u,          18541678071u },
+  { 12757855675959554597u,  5331614769144850592u,         247504212200u },
+  {   121631169379748595u, 14354009428310052102u,         232289027415u },
+  { 16679062494579173314u,  5581221063029119078u,          87778132410u },
+  { 10739912744743898054u,  1529260335339476189u,         186302558600u },
+  {  9367340677776287570u, 16483061525949201148u,         136082901368u },
+  { 12227321512794715397u, 14431217812333089675u,         120893548555u },
+  {  7241061891859170651u,  3452349151135392267u,          11782317885u },
+  { 13148571323079237489u,  9075317899834447999u,          61187152222u },
+  { 12509763434355012654u,  2764331337978901575u,          94491973969u },
+  { 11812768946960181977u,  1942890683708857202u,          81149854702u },
+  { 14170358803552564832u,   165089169728028447u,         238105324315u },
+  { 18179989524780635952u, 15193620741871233073u,          27008949501u },
+  { 17091718978514754901u, 14995000835194145926u,         253823647830u },
+  {  7394768384359232459u,  1788823614552255558u,          86812880624u },
+  {  6778628272692852803u,  8384901184618498845u,         240096972322u },
+  { 18193335045875234320u,   405511217862281310u,          34454546404u },
+  {  1378519212560967521u,  3111530463755196557u,         228021982807u },
+  {  4677732610631043584u,  7893558450035460812u,          87168676404u },
+  { 17296098591070486528u,   156573858237402216u,          52427910661u },
+  {  7343735382392963072u, 15915324019419451223u,           5008487885u },
+  { 14525996728454217728u, 16293363012778802804u,         205862771443u },
+  {  9691359370008330240u, 14342105318291351412u,         243883264978u },
+  {  3044433348102455296u,  3788398842525387052u,         210777487087u },
+  {  9223372036854775808u, 14118764407048307670u,         239205369512u },
+  {                    0u,  2705021334614720768u,         168765379752u },
+  {                    0u,  7017988973805568000u,         168146639500u },
+  {                    0u, 10956732053634154496u,         140380445944u },
+  {                    0u, 14657517938546835456u,         248593965634u },
+  {                    0u, 11268868284797157376u,          66794585639u },
+  {                    0u, 14600669991935148032u,          39610886573u },
+  {                    0u,  4611686018427387904u,         173791503906u },
+  {                    0u,                    0u,          34250000000u },
+  {                    0u,                    0u,         128000000000u },
+  {  8201586317771250746u,           1424047269u,                    0u },
+  {  3278889188817135834u,  1424047269444608885u,                    0u },
+  {  1710725240251040430u,  3001188830946823627u,             77197757u },
+  {  1850175733663425006u,  9732296932705387049u,         189162694772u },
+  {  9147599666163914249u, 16337535782679529459u,         116527588873u },
+  { 10221885933644344166u,  7969742269895046547u,           9885659589u },
+  { 14901479793736678101u,  2923592083903829642u,         197432040594u },
+  {  5181831442059703136u,  8144196241160608534u,         146158488244u },
+  {  6396246577759793483u, 16431078457793424253u,         180441497762u },
+  { 14167229556464870447u,   202362949592775653u,         162890730548u },
+  {  2969982933326311854u,  8835125248522947981u,          52010970117u },
+  {  7892677766222018881u,  7959873808777345113u,           5478953099u },
+  {   798698968922663621u, 14929747122315126151u,         139431505623u },
+  { 15926812109043458972u,  4310328817360515349u,         215809343213u },
+  {  8663842590352697437u,  7294899422760201126u,         237233663393u },
+  { 17093523026636671168u,  2047461597291187207u,         161395457290u },
+  {   839764004742743203u, 10942374468813517900u,          10110993115u },
+  { 16894643909298232323u, 10364795403063433969u,         219593187308u },
+  {  9066702926218949317u, 12330859528790939137u,         236561876684u },
+  {  9119392417260546810u,  8973160144879916806u,         204668457234u },
+  {  9723021096578315109u,  2895354388547509877u,          18486435986u },
+  { 14787464248751217597u, 16766844772497556429u,         146156957475u },
+  {  3733434565920249133u,  7442407174620948827u,          35908932476u },
+  {  6643788868836820841u,  6683013428676659077u,         124403453701u },
+  {  4729646697422664063u, 16713703375071907588u,           5362286883u },
+  {  4090144564201555829u,  8791044883080637861u,          35906051675u },
+  {  2109480737093400002u,   602844107089214413u,          91476563498u },
+  { 16577155033369419739u,  9754832281172880875u,          42032680244u },
+  {   745377248603805917u, 10587846778003503903u,          52528810517u },
+  { 11305561465807999667u, 17206244172922947013u,          21573968323u },
+  {  2211245518782892177u, 11620628420699303875u,         195932752365u },
+  { 14170095199249735666u, 17864732368219338611u,         237629955528u },
+  { 17849973668116118927u,  4146383014621345887u,         200968449082u },
+  {  9020960204585720001u, 11445705075042688243u,          58224775873u },
+  { 10807134002871850916u,  7369147888966546592u,         193620472915u },
+  {  3925122626254791201u,  9762476865090597796u,          83399482307u },
+  { 17208463291312718997u,  5507001428194242827u,         195529224931u },
+  {  5145077219589447653u, 11371471148365328344u,         227298535145u },
+  { 17602397765035489468u,  3148788104946538618u,         233616448686u },
+  { 16422643262490753377u,  3762722308424507574u,         174170696145u },
+  {  2902509461400906224u,  1156171244825745915u,         209203977585u },
+  {  3422418805967265206u, 14208921674868257865u,         113062676168u },
+  {  4228874576277237392u,  7903080886897905503u,         200770267187u },
+  {  2553488530807495751u,  6367240794154270982u,          51428426873u },
+  { 11546099176912486413u,  1623672396662369850u,         121345168815u },
+  { 10460791037534167991u, 18323231215381674394u,         175088019456u },
+  {  8127117908566000904u,  9842279843006544554u,            993304354u },
+  { 11541304458088287306u,  7376839231308610600u,          34533551059u },
+  {  6249718665174839700u,   609751749293657672u,         211399899256u },
+  { 13102508413386290995u, 10386457966860989799u,         120033054708u },
+  {  6274675218640661911u, 11160336020836149780u,         244563051014u },
+  {  3404497118599817167u, 17947559933847409193u,           6605003027u },
+  { 11258566093988562335u, 10229787001712704590u,          19972939173u },
+  { 16762592482501635397u, 10441677090043619866u,         165554557864u },
+  {  5550125446725071998u,  4996681336392922375u,         168566044449u },
+  {  6370033225258510318u,   124497102381021895u,          33270870638u },
+  {  1503521728674735398u,  8180812057779384577u,         110006749001u },
+  {  4250415082606384364u,  5294232873532946716u,          73443482710u },
+  {  6020091901030562974u,  2885620189169448039u,          86287000939u },
+  { 16288222967151527138u, 16662526875008170507u,         107156429783u },
+  {  6377016228656203782u, 15663095032402672480u,         215903277391u },
+  {  8378856515587563750u,  1824281504410546614u,          79849098083u },
+  { 15812881490200838483u,  9506565509584809953u,          99098894498u },
+  {  4548570371183413652u, 16941136942345070055u,         162515351948u },
+  { 16731431495283420383u, 15924115693705937725u,         140918380873u },
+  { 14737727629551135532u,  9247807690406628462u,          73863248041u },
+  { 12413722258104293893u,  7993916633864834871u,         169501324659u },
+  {   800899742400762438u,  1018504409177639408u,         115433351089u },
+  {   603197008376033550u, 12097800686634130718u,         177055213234u },
+  {  6380777281587743935u,  6221488888422637551u,         178655823089u },
+  { 10001440249018225388u,  8229322865256080421u,         241337267588u },
+  {  5505914461980436708u,  7927745108183101786u,         132446112486u },
+  {  1105464290051876864u,  8488683721235326653u,         230429763923u },
+  {  4500443576769970176u, 11165516518170922283u,          83460172466u },
+  {  2843045143185981440u,  5463648141113596927u,         178605283863u },
+  {   660949699682893824u,  3958440403860778042u,          23296184959u },
+  {   276549164618219520u,  5091534813990256011u,         127214587484u },
+  {  4683743612465315840u,  6100166970623291280u,          92276012655u },
+  {                    0u,  1913011027739012426u,         111330690714u },
+  {                    0u, 11310957650604221440u,         154103704535u },
+  {                    0u, 16303817257009020928u,         215613168242u },
+  {                    0u,  9090406322154766336u,         114883831704u },
+  {                    0u,  3003279315069566976u,         152492791914u },
+  {                    0u, 16582887146675765248u,         106162808097u },
+  {                    0u,  9691746398101307392u,          33898960113u },
+  {                    0u,                    0u,         241525390625u },
+  {                    0u,                    0u,          33000000000u },
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
lib/libcxx/src/include/ryu/d2s.h
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_DS2_H
+#define _LIBCPP_SRC_INCLUDE_RYU_DS2_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __DOUBLE_MANTISSA_BITS = 52;
+inline constexpr int __DOUBLE_EXPONENT_BITS = 11;
+inline constexpr int __DOUBLE_BIAS = 1023;
+
+inline constexpr int __DOUBLE_POW5_INV_BITCOUNT = 122;
+inline constexpr int __DOUBLE_POW5_BITCOUNT = 121;
+
+[[nodiscard]] to_chars_result __d2s_buffered_n(char* const _First, char* const _Last, const double __f, const chars_format _Fmt);
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_DS2_H
lib/libcxx/src/include/ryu/d2s_full_table.h
@@ -0,0 +1,368 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
+#define _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr uint64_t __DOUBLE_POW5_INV_SPLIT[292][2] = {
+  {                    1u, 288230376151711744u }, {  3689348814741910324u, 230584300921369395u },
+  {  2951479051793528259u, 184467440737095516u }, { 17118578500402463900u, 147573952589676412u },
+  { 12632330341676300947u, 236118324143482260u }, { 10105864273341040758u, 188894659314785808u },
+  { 15463389048156653253u, 151115727451828646u }, { 17362724847566824558u, 241785163922925834u },
+  { 17579528692795369969u, 193428131138340667u }, {  6684925324752475329u, 154742504910672534u },
+  { 18074578149087781173u, 247588007857076054u }, { 18149011334012135262u, 198070406285660843u },
+  {  3451162622983977240u, 158456325028528675u }, {  5521860196774363583u, 253530120045645880u },
+  {  4417488157419490867u, 202824096036516704u }, {  7223339340677503017u, 162259276829213363u },
+  {  7867994130342094503u, 259614842926741381u }, {  2605046489531765280u, 207691874341393105u },
+  {  2084037191625412224u, 166153499473114484u }, { 10713157136084480204u, 265845599156983174u },
+  { 12259874523609494487u, 212676479325586539u }, { 13497248433629505913u, 170141183460469231u },
+  { 14216899864323388813u, 272225893536750770u }, { 11373519891458711051u, 217780714829400616u },
+  {  5409467098425058518u, 174224571863520493u }, {  4965798542738183305u, 278759314981632789u },
+  {  7661987648932456967u, 223007451985306231u }, {  2440241304404055250u, 178405961588244985u },
+  {  3904386087046488400u, 285449538541191976u }, { 17880904128604832013u, 228359630832953580u },
+  { 14304723302883865611u, 182687704666362864u }, { 15133127457049002812u, 146150163733090291u },
+  { 16834306301794583852u, 233840261972944466u }, {  9778096226693756759u, 187072209578355573u },
+  { 15201174610838826053u, 149657767662684458u }, {  2185786488890659746u, 239452428260295134u },
+  {  5437978005854438120u, 191561942608236107u }, { 15418428848909281466u, 153249554086588885u },
+  {  6222742084545298729u, 245199286538542217u }, { 16046240111861969953u, 196159429230833773u },
+  {  1768945645263844993u, 156927543384667019u }, { 10209010661905972635u, 251084069415467230u },
+  {  8167208529524778108u, 200867255532373784u }, { 10223115638361732810u, 160693804425899027u },
+  {  1599589762411131202u, 257110087081438444u }, {  4969020624670815285u, 205688069665150755u },
+  {  3975216499736652228u, 164550455732120604u }, { 13739044029062464211u, 263280729171392966u },
+  {  7301886408508061046u, 210624583337114373u }, { 13220206756290269483u, 168499666669691498u },
+  { 17462981995322520850u, 269599466671506397u }, {  6591687966774196033u, 215679573337205118u },
+  { 12652048002903177473u, 172543658669764094u }, {  9175230360419352987u, 276069853871622551u },
+  {  3650835473593572067u, 220855883097298041u }, { 17678063637842498946u, 176684706477838432u },
+  { 13527506561580357021u, 282695530364541492u }, {  3443307619780464970u, 226156424291633194u },
+  {  6443994910566282300u, 180925139433306555u }, {  5155195928453025840u, 144740111546645244u },
+  { 15627011115008661990u, 231584178474632390u }, { 12501608892006929592u, 185267342779705912u },
+  {  2622589484121723027u, 148213874223764730u }, {  4196143174594756843u, 237142198758023568u },
+  { 10735612169159626121u, 189713759006418854u }, { 12277838550069611220u, 151771007205135083u },
+  { 15955192865369467629u, 242833611528216133u }, {  1696107848069843133u, 194266889222572907u },
+  { 12424932722681605476u, 155413511378058325u }, {  1433148282581017146u, 248661618204893321u },
+  { 15903913885032455010u, 198929294563914656u }, {  9033782293284053685u, 159143435651131725u },
+  { 14454051669254485895u, 254629497041810760u }, { 11563241335403588716u, 203703597633448608u },
+  { 16629290697806691620u, 162962878106758886u }, {   781423413297334329u, 260740604970814219u },
+  {  4314487545379777786u, 208592483976651375u }, {  3451590036303822229u, 166873987181321100u },
+  {  5522544058086115566u, 266998379490113760u }, {  4418035246468892453u, 213598703592091008u },
+  { 10913125826658934609u, 170878962873672806u }, { 10082303693170474728u, 273406340597876490u },
+  {  8065842954536379782u, 218725072478301192u }, { 17520720807854834795u, 174980057982640953u },
+  {  5897060404116273733u, 279968092772225526u }, {  1028299508551108663u, 223974474217780421u },
+  { 15580034865808528224u, 179179579374224336u }, { 17549358155809824511u, 286687326998758938u },
+  {  2971440080422128639u, 229349861599007151u }, { 17134547323305344204u, 183479889279205720u },
+  { 13707637858644275364u, 146783911423364576u }, { 14553522944347019935u, 234854258277383322u },
+  {  4264120725993795302u, 187883406621906658u }, { 10789994210278856888u, 150306725297525326u },
+  {  9885293106962350374u, 240490760476040522u }, {   529536856086059653u, 192392608380832418u },
+  {  7802327114352668369u, 153914086704665934u }, {  1415676938738538420u, 246262538727465495u },
+  {  1132541550990830736u, 197010030981972396u }, { 15663428499760305882u, 157608024785577916u },
+  { 17682787970132668764u, 252172839656924666u }, { 10456881561364224688u, 201738271725539733u },
+  { 15744202878575200397u, 161390617380431786u }, { 17812026976236499989u, 258224987808690858u },
+  {  3181575136763469022u, 206579990246952687u }, { 13613306553636506187u, 165263992197562149u },
+  { 10713244041592678929u, 264422387516099439u }, { 12259944048016053467u, 211537910012879551u },
+  {  6118606423670932450u, 169230328010303641u }, {  2411072648389671274u, 270768524816485826u },
+  { 16686253377679378312u, 216614819853188660u }, { 13349002702143502650u, 173291855882550928u },
+  { 17669055508687693916u, 277266969412081485u }, { 14135244406950155133u, 221813575529665188u },
+  {   240149081334393137u, 177450860423732151u }, { 11452284974360759988u, 283921376677971441u },
+  {  5472479164746697667u, 227137101342377153u }, { 11756680961281178780u, 181709681073901722u },
+  {  2026647139541122378u, 145367744859121378u }, { 18000030682233437097u, 232588391774594204u },
+  { 18089373360528660001u, 186070713419675363u }, {  3403452244197197031u, 148856570735740291u },
+  { 16513570034941246220u, 238170513177184465u }, { 13210856027952996976u, 190536410541747572u },
+  {  3189987192878576934u, 152429128433398058u }, {  1414630693863812771u, 243886605493436893u },
+  {  8510402184574870864u, 195109284394749514u }, { 10497670562401807014u, 156087427515799611u },
+  {  9417575270359070576u, 249739884025279378u }, { 14912757845771077107u, 199791907220223502u },
+  {  4551508647133041040u, 159833525776178802u }, { 10971762650154775986u, 255733641241886083u },
+  { 16156107749607641435u, 204586912993508866u }, {  9235537384944202825u, 163669530394807093u },
+  { 11087511001168814197u, 261871248631691349u }, { 12559357615676961681u, 209496998905353079u },
+  { 13736834907283479668u, 167597599124282463u }, { 18289587036911657145u, 268156158598851941u },
+  { 10942320814787415393u, 214524926879081553u }, { 16132554281313752961u, 171619941503265242u },
+  { 11054691591134363444u, 274591906405224388u }, { 16222450902391311402u, 219673525124179510u },
+  { 12977960721913049122u, 175738820099343608u }, { 17075388340318968271u, 281182112158949773u },
+  {  2592264228029443648u, 224945689727159819u }, {  5763160197165465241u, 179956551781727855u },
+  {  9221056315464744386u, 287930482850764568u }, { 14755542681855616155u, 230344386280611654u },
+  { 15493782960226403247u, 184275509024489323u }, {  1326979923955391628u, 147420407219591459u },
+  {  9501865507812447252u, 235872651551346334u }, { 11290841220991868125u, 188698121241077067u },
+  {  1653975347309673853u, 150958496992861654u }, { 10025058185179298811u, 241533595188578646u },
+  {  4330697733401528726u, 193226876150862917u }, { 14532604630946953951u, 154581500920690333u },
+  {  1116074521063664381u, 247330401473104534u }, {  4582208431592841828u, 197864321178483627u },
+  { 14733813189500004432u, 158291456942786901u }, { 16195403473716186445u, 253266331108459042u },
+  {  5577625149489128510u, 202613064886767234u }, {  8151448934333213131u, 162090451909413787u },
+  { 16731667109675051333u, 259344723055062059u }, { 17074682502481951390u, 207475778444049647u },
+  {  6281048372501740465u, 165980622755239718u }, {  6360328581260874421u, 265568996408383549u },
+  {  8777611679750609860u, 212455197126706839u }, { 10711438158542398211u, 169964157701365471u },
+  {  9759603424184016492u, 271942652322184754u }, { 11497031554089123517u, 217554121857747803u },
+  { 16576322872755119460u, 174043297486198242u }, { 11764721337440549842u, 278469275977917188u },
+  { 16790474699436260520u, 222775420782333750u }, { 13432379759549008416u, 178220336625867000u },
+  {  3045063541568861850u, 285152538601387201u }, { 17193446092222730773u, 228122030881109760u },
+  { 13754756873778184618u, 182497624704887808u }, { 18382503128506368341u, 145998099763910246u },
+  {  3586563302416817083u, 233596959622256395u }, {  2869250641933453667u, 186877567697805116u },
+  { 17052795772514404226u, 149502054158244092u }, { 12527077977055405469u, 239203286653190548u },
+  { 17400360011128145022u, 191362629322552438u }, {  2852241564676785048u, 153090103458041951u },
+  { 15631632947708587046u, 244944165532867121u }, {  8815957543424959314u, 195955332426293697u },
+  { 18120812478965698421u, 156764265941034957u }, { 14235904707377476180u, 250822825505655932u },
+  {  4010026136418160298u, 200658260404524746u }, { 17965416168102169531u, 160526608323619796u },
+  {  2919224165770098987u, 256842573317791675u }, {  2335379332616079190u, 205474058654233340u },
+  {  1868303466092863352u, 164379246923386672u }, {  6678634360490491686u, 263006795077418675u },
+  {  5342907488392393349u, 210405436061934940u }, {  4274325990713914679u, 168324348849547952u },
+  { 10528270399884173809u, 269318958159276723u }, { 15801313949391159694u, 215455166527421378u },
+  {  1573004715287196786u, 172364133221937103u }, { 17274202803427156150u, 275782613155099364u },
+  { 17508711057483635243u, 220626090524079491u }, { 10317620031244997871u, 176500872419263593u },
+  { 12818843235250086271u, 282401395870821749u }, { 13944423402941979340u, 225921116696657399u },
+  { 14844887537095493795u, 180736893357325919u }, { 15565258844418305359u, 144589514685860735u },
+  {  6457670077359736959u, 231343223497377177u }, { 16234182506113520537u, 185074578797901741u },
+  {  9297997190148906106u, 148059663038321393u }, { 11187446689496339446u, 236895460861314229u },
+  { 12639306166338981880u, 189516368689051383u }, { 17490142562555006151u, 151613094951241106u },
+  {  2158786396894637579u, 242580951921985771u }, { 16484424376483351356u, 194064761537588616u },
+  {  9498190686444770762u, 155251809230070893u }, { 11507756283569722895u, 248402894768113429u },
+  { 12895553841597688639u, 198722315814490743u }, { 17695140702761971558u, 158977852651592594u },
+  { 17244178680193423523u, 254364564242548151u }, { 10105994129412828495u, 203491651394038521u },
+  {  4395446488788352473u, 162793321115230817u }, { 10722063196803274280u, 260469313784369307u },
+  {  1198952927958798777u, 208375451027495446u }, { 15716557601334680315u, 166700360821996356u },
+  { 17767794532651667857u, 266720577315194170u }, { 14214235626121334286u, 213376461852155336u },
+  {  7682039686155157106u, 170701169481724269u }, {  1223217053622520399u, 273121871170758831u },
+  { 15735968901865657612u, 218497496936607064u }, { 16278123936234436413u, 174797997549285651u },
+  {   219556594781725998u, 279676796078857043u }, {  7554342905309201445u, 223741436863085634u },
+  {  9732823138989271479u, 178993149490468507u }, {   815121763415193074u, 286389039184749612u },
+  { 11720143854957885429u, 229111231347799689u }, { 13065463898708218666u, 183288985078239751u },
+  {  6763022304224664610u, 146631188062591801u }, {  3442138057275642729u, 234609900900146882u },
+  { 13821756890046245153u, 187687920720117505u }, { 11057405512036996122u, 150150336576094004u },
+  {  6623802375033462826u, 240240538521750407u }, { 16367088344252501231u, 192192430817400325u },
+  { 13093670675402000985u, 153753944653920260u }, {  2503129006933649959u, 246006311446272417u },
+  { 13070549649772650937u, 196805049157017933u }, { 17835137349301941396u, 157444039325614346u },
+  {  2710778055689733971u, 251910462920982955u }, {  2168622444551787177u, 201528370336786364u },
+  {  5424246770383340065u, 161222696269429091u }, {  1300097203129523457u, 257956314031086546u },
+  { 15797473021471260058u, 206365051224869236u }, {  8948629602435097724u, 165092040979895389u },
+  {  3249760919670425388u, 264147265567832623u }, {  9978506365220160957u, 211317812454266098u },
+  { 15361502721659949412u, 169054249963412878u }, {  2442311466204457120u, 270486799941460606u },
+  { 16711244431931206989u, 216389439953168484u }, { 17058344360286875914u, 173111551962534787u },
+  { 12535955717491360170u, 276978483140055660u }, { 10028764573993088136u, 221582786512044528u },
+  { 15401709288678291155u, 177266229209635622u }, {  9885339602917624555u, 283625966735416996u },
+  {  4218922867592189321u, 226900773388333597u }, { 14443184738299482427u, 181520618710666877u },
+  {  4175850161155765295u, 145216494968533502u }, { 10370709072591134795u, 232346391949653603u },
+  { 15675264887556728482u, 185877113559722882u }, {  5161514280561562140u, 148701690847778306u },
+  {   879725219414678777u, 237922705356445290u }, {   703780175531743021u, 190338164285156232u },
+  { 11631070584651125387u, 152270531428124985u }, {   162968861732249003u, 243632850284999977u },
+  { 11198421533611530172u, 194906280227999981u }, {  5269388412147313814u, 155925024182399985u },
+  {  8431021459435702103u, 249480038691839976u }, {  3055468352806651359u, 199584030953471981u },
+  { 17201769941212962380u, 159667224762777584u }, { 16454785461715008838u, 255467559620444135u },
+  { 13163828369372007071u, 204374047696355308u }, { 17909760324981426303u, 163499238157084246u },
+  {  2830174816776909822u, 261598781051334795u }, {  2264139853421527858u, 209279024841067836u },
+  { 16568707141704863579u, 167423219872854268u }, {  4373838538276319787u, 267877151796566830u },
+  {  3499070830621055830u, 214301721437253464u }, {  6488605479238754987u, 171441377149802771u },
+  {  3003071137298187333u, 274306203439684434u }, {  6091805724580460189u, 219444962751747547u },
+  { 15941491023890099121u, 175555970201398037u }, { 10748990379256517301u, 280889552322236860u },
+  {  8599192303405213841u, 224711641857789488u }, { 14258051472207991719u, 179769313486231590u }
+};
+
+inline constexpr uint64_t __DOUBLE_POW5_SPLIT[326][2] = {
+  {                    0u,  72057594037927936u }, {                    0u,  90071992547409920u },
+  {                    0u, 112589990684262400u }, {                    0u, 140737488355328000u },
+  {                    0u,  87960930222080000u }, {                    0u, 109951162777600000u },
+  {                    0u, 137438953472000000u }, {                    0u,  85899345920000000u },
+  {                    0u, 107374182400000000u }, {                    0u, 134217728000000000u },
+  {                    0u,  83886080000000000u }, {                    0u, 104857600000000000u },
+  {                    0u, 131072000000000000u }, {                    0u,  81920000000000000u },
+  {                    0u, 102400000000000000u }, {                    0u, 128000000000000000u },
+  {                    0u,  80000000000000000u }, {                    0u, 100000000000000000u },
+  {                    0u, 125000000000000000u }, {                    0u,  78125000000000000u },
+  {                    0u,  97656250000000000u }, {                    0u, 122070312500000000u },
+  {                    0u,  76293945312500000u }, {                    0u,  95367431640625000u },
+  {                    0u, 119209289550781250u }, {  4611686018427387904u,  74505805969238281u },
+  { 10376293541461622784u,  93132257461547851u }, {  8358680908399640576u, 116415321826934814u },
+  {   612489549322387456u,  72759576141834259u }, { 14600669991935148032u,  90949470177292823u },
+  { 13639151471491547136u, 113686837721616029u }, {  3213881284082270208u, 142108547152020037u },
+  {  4314518811765112832u,  88817841970012523u }, {   781462496279003136u, 111022302462515654u },
+  { 10200200157203529728u, 138777878078144567u }, { 13292654125893287936u,  86736173798840354u },
+  {  7392445620511834112u, 108420217248550443u }, {  4628871007212404736u, 135525271560688054u },
+  { 16728102434789916672u,  84703294725430033u }, {  7075069988205232128u, 105879118406787542u },
+  { 18067209522111315968u, 132348898008484427u }, {  8986162942105878528u,  82718061255302767u },
+  {  6621017659204960256u, 103397576569128459u }, {  3664586055578812416u, 129246970711410574u },
+  { 16125424340018921472u,  80779356694631608u }, {  1710036351314100224u, 100974195868289511u },
+  { 15972603494424788992u, 126217744835361888u }, {  9982877184015493120u,  78886090522101180u },
+  { 12478596480019366400u,  98607613152626475u }, { 10986559581596820096u, 123259516440783094u },
+  {  2254913720070624656u,  77037197775489434u }, { 12042014186943056628u,  96296497219361792u },
+  { 15052517733678820785u, 120370621524202240u }, {  9407823583549262990u,  75231638452626400u },
+  { 11759779479436578738u,  94039548065783000u }, { 14699724349295723422u, 117549435082228750u },
+  {  4575641699882439235u,  73468396926392969u }, { 10331238143280436948u,  91835496157991211u },
+  {  8302361660673158281u, 114794370197489014u }, {  1154580038986672043u, 143492962746861268u },
+  {  9944984561221445835u,  89683101716788292u }, { 12431230701526807293u, 112103877145985365u },
+  {  1703980321626345405u, 140129846432481707u }, { 17205888765512323542u,  87581154020301066u },
+  { 12283988920035628619u, 109476442525376333u }, {  1519928094762372062u, 136845553156720417u },
+  { 12479170105294952299u,  85528470722950260u }, { 15598962631618690374u, 106910588403687825u },
+  {  5663645234241199255u, 133638235504609782u }, { 17374836326682913246u,  83523897190381113u },
+  {  7883487353071477846u, 104404871487976392u }, {  9854359191339347308u, 130506089359970490u },
+  { 10770660513014479971u,  81566305849981556u }, { 13463325641268099964u, 101957882312476945u },
+  {  2994098996302961243u, 127447352890596182u }, { 15706369927971514489u,  79654595556622613u },
+  {  5797904354682229399u,  99568244445778267u }, {  2635694424925398845u, 124460305557222834u },
+  {  6258995034005762182u,  77787690973264271u }, {  3212057774079814824u,  97234613716580339u },
+  { 17850130272881932242u, 121543267145725423u }, { 18073860448192289507u,  75964541966078389u },
+  {  8757267504958198172u,  94955677457597987u }, {  6334898362770359811u, 118694596821997484u },
+  { 13182683513586250689u,  74184123013748427u }, { 11866668373555425458u,  92730153767185534u },
+  {  5609963430089506015u, 115912692208981918u }, { 17341285199088104971u,  72445432630613698u },
+  { 12453234462005355406u,  90556790788267123u }, { 10954857059079306353u, 113195988485333904u },
+  { 13693571323849132942u, 141494985606667380u }, { 17781854114260483896u,  88434366004167112u },
+  {  3780573569116053255u, 110542957505208891u }, {   114030942967678664u, 138178696881511114u },
+  {  4682955357782187069u,  86361685550944446u }, { 15077066234082509644u, 107952106938680557u },
+  {  5011274737320973344u, 134940133673350697u }, { 14661261756894078100u,  84337583545844185u },
+  {  4491519140835433913u, 105421979432305232u }, {  5614398926044292391u, 131777474290381540u },
+  { 12732371365632458552u,  82360921431488462u }, {  6692092170185797382u, 102951151789360578u },
+  { 17588487249587022536u, 128688939736700722u }, { 15604490549419276989u,  80430587335437951u },
+  { 14893927168346708332u, 100538234169297439u }, { 14005722942005997511u, 125672792711621799u },
+  { 15671105866394830300u,  78545495444763624u }, {  1142138259283986260u,  98181869305954531u },
+  { 15262730879387146537u, 122727336632443163u }, {  7233363790403272633u,  76704585395276977u },
+  { 13653390756431478696u,  95880731744096221u }, {  3231680390257184658u, 119850914680120277u },
+  {  4325643253124434363u,  74906821675075173u }, { 10018740084832930858u,  93633527093843966u },
+  {  3300053069186387764u, 117041908867304958u }, { 15897591223523656064u,  73151193042065598u },
+  { 10648616992549794273u,  91438991302581998u }, {  4087399203832467033u, 114298739128227498u },
+  { 14332621041645359599u, 142873423910284372u }, { 18181260187883125557u,  89295889943927732u },
+  {  4279831161144355331u, 111619862429909666u }, { 14573160988285219972u, 139524828037387082u },
+  { 13719911636105650386u,  87203017523366926u }, {  7926517508277287175u, 109003771904208658u },
+  {   684774848491833161u, 136254714880260823u }, {  7345513307948477581u,  85159196800163014u },
+  { 18405263671790372785u, 106448996000203767u }, { 18394893571310578077u, 133061245000254709u },
+  { 13802651491282805250u,  83163278125159193u }, {  3418256308821342851u, 103954097656448992u },
+  {  4272820386026678563u, 129942622070561240u }, {  2670512741266674102u,  81214138794100775u },
+  { 17173198981865506339u, 101517673492625968u }, {  3019754653622331308u, 126897091865782461u },
+  {  4193189667727651020u,  79310682416114038u }, { 14464859121514339583u,  99138353020142547u },
+  { 13469387883465536574u, 123922941275178184u }, {  8418367427165960359u,  77451838296986365u },
+  { 15134645302384838353u,  96814797871232956u }, {   471562554271496325u, 121018497339041196u },
+  {  9518098633274461011u,  75636560836900747u }, {  7285937273165688360u,  94545701046125934u },
+  { 18330793628311886258u, 118182126307657417u }, {  4539216990053847055u,  73863828942285886u },
+  { 14897393274422084627u,  92329786177857357u }, {  4786683537745442072u, 115412232722321697u },
+  { 14520892257159371055u,  72132645451451060u }, { 18151115321449213818u,  90165806814313825u },
+  {  8853836096529353561u, 112707258517892282u }, {  1843923083806916143u, 140884073147365353u },
+  { 12681666973447792349u,  88052545717103345u }, {  2017025661527576725u, 110065682146379182u },
+  { 11744654113764246714u, 137582102682973977u }, {   422879793461572340u,  85988814176858736u },
+  {   528599741826965425u, 107486017721073420u }, {   660749677283706782u, 134357522151341775u },
+  {  7330497575943398595u,  83973451344588609u }, { 13774807988356636147u, 104966814180735761u },
+  {  3383451930163631472u, 131208517725919702u }, { 15949715511634433382u,  82005323578699813u },
+  {  6102086334260878016u, 102506654473374767u }, {  3015921899398709616u, 128133318091718459u },
+  { 18025852251620051174u,  80083323807324036u }, {  4085571240815512351u, 100104154759155046u },
+  { 14330336087874166247u, 125130193448943807u }, { 15873989082562435760u,  78206370905589879u },
+  { 15230800334775656796u,  97757963631987349u }, {  5203442363187407284u, 122197454539984187u },
+  {   946308467778435600u,  76373409087490117u }, {  5794571603150432404u,  95466761359362646u },
+  { 16466586540792816313u, 119333451699203307u }, {  7985773578781816244u,  74583407312002067u },
+  {  5370530955049882401u,  93229259140002584u }, {  6713163693812353001u, 116536573925003230u },
+  { 18030785363914884337u,  72835358703127018u }, { 13315109668038829614u,  91044198378908773u },
+  {  2808829029766373305u, 113805247973635967u }, { 17346094342490130344u, 142256559967044958u },
+  {  6229622945628943561u,  88910349979403099u }, {  3175342663608791547u, 111137937474253874u },
+  { 13192550366365765242u, 138922421842817342u }, {  3633657960551215372u,  86826513651760839u },
+  { 18377130505971182927u, 108533142064701048u }, {  4524669058754427043u, 135666427580876311u },
+  {  9745447189362598758u,  84791517238047694u }, {  2958436949848472639u, 105989396547559618u },
+  { 12921418224165366607u, 132486745684449522u }, { 12687572408530742033u,  82804216052780951u },
+  { 11247779492236039638u, 103505270065976189u }, {   224666310012885835u, 129381587582470237u },
+  {  2446259452971747599u,  80863492239043898u }, { 12281196353069460307u, 101079365298804872u },
+  { 15351495441336825384u, 126349206623506090u }, { 14206370669262903769u,  78968254139691306u },
+  {  8534591299723853903u,  98710317674614133u }, { 15279925143082205283u, 123387897093267666u },
+  { 14161639232853766206u,  77117435683292291u }, { 13090363022639819853u,  96396794604115364u },
+  { 16362953778299774816u, 120495993255144205u }, { 12532689120651053212u,  75309995784465128u },
+  { 15665861400813816515u,  94137494730581410u }, { 10358954714162494836u, 117671868413226763u },
+  {  4168503687137865320u,  73544917758266727u }, {   598943590494943747u,  91931147197833409u },
+  {  5360365506546067587u, 114913933997291761u }, { 11312142901609972388u, 143642417496614701u },
+  {  9375932322719926695u,  89776510935384188u }, { 11719915403399908368u, 112220638669230235u },
+  { 10038208235822497557u, 140275798336537794u }, { 10885566165816448877u,  87672373960336121u },
+  { 18218643725697949000u, 109590467450420151u }, { 18161618638695048346u, 136988084313025189u },
+  { 13656854658398099168u,  85617552695640743u }, { 12459382304570236056u, 107021940869550929u },
+  {  1739169825430631358u, 133777426086938662u }, { 14922039196176308311u,  83610891304336663u },
+  { 14040862976792997485u, 104513614130420829u }, {  3716020665709083144u, 130642017663026037u },
+  {  4628355925281870917u,  81651261039391273u }, { 10397130925029726550u, 102064076299239091u },
+  {  8384727637859770284u, 127580095374048864u }, {  5240454773662356427u,  79737559608780540u },
+  {  6550568467077945534u,  99671949510975675u }, {  3576524565420044014u, 124589936888719594u },
+  {  6847013871814915412u,  77868710555449746u }, { 17782139376623420074u,  97335888194312182u },
+  { 13004302183924499284u, 121669860242890228u }, { 17351060901807587860u,  76043662651806392u },
+  {  3242082053549933210u,  95054578314757991u }, { 17887660622219580224u, 118818222893447488u },
+  { 11179787888887237640u,  74261389308404680u }, { 13974734861109047050u,  92826736635505850u },
+  {  8245046539531533005u, 116033420794382313u }, { 16682369133275677888u,  72520887996488945u },
+  {  7017903361312433648u,  90651109995611182u }, { 17995751238495317868u, 113313887494513977u },
+  {  8659630992836983623u, 141642359368142472u }, {  5412269370523114764u,  88526474605089045u },
+  { 11377022731581281359u, 110658093256361306u }, {  4997906377621825891u, 138322616570451633u },
+  { 14652906532082110942u,  86451635356532270u }, {  9092761128247862869u, 108064544195665338u },
+  {  2142579373455052779u, 135080680244581673u }, { 12868327154477877747u,  84425425152863545u },
+  {  2250350887815183471u, 105531781441079432u }, {  2812938609768979339u, 131914726801349290u },
+  {  6369772649532999991u,  82446704250843306u }, { 17185587848771025797u, 103058380313554132u },
+  {  3035240737254230630u, 128822975391942666u }, {  6508711479211282048u,  80514359619964166u },
+  { 17359261385868878368u, 100642949524955207u }, { 17087390713908710056u, 125803686906194009u },
+  {  3762090168551861929u,  78627304316371256u }, {  4702612710689827411u,  98284130395464070u },
+  { 15101637925217060072u, 122855162994330087u }, { 16356052730901744401u,  76784476871456304u },
+  {  1998321839917628885u,  95980596089320381u }, {  7109588318324424010u, 119975745111650476u },
+  { 13666864735807540814u,  74984840694781547u }, { 12471894901332038114u,  93731050868476934u },
+  {  6366496589810271835u, 117163813585596168u }, {  3979060368631419896u,  73227383490997605u },
+  {  9585511479216662775u,  91534229363747006u }, {  2758517312166052660u, 114417786704683758u },
+  { 12671518677062341634u, 143022233380854697u }, {  1002170145522881665u,  89388895863034186u },
+  { 10476084718758377889u, 111736119828792732u }, { 13095105898447972362u, 139670149785990915u },
+  {  5878598177316288774u,  87293843616244322u }, { 16571619758500136775u, 109117304520305402u },
+  { 11491152661270395161u, 136396630650381753u }, {   264441385652915120u,  85247894156488596u },
+  {   330551732066143900u, 106559867695610745u }, {  5024875683510067779u, 133199834619513431u },
+  { 10058076329834874218u,  83249896637195894u }, {  3349223375438816964u, 104062370796494868u },
+  {  4186529219298521205u, 130077963495618585u }, { 14145795808130045513u,  81298727184761615u },
+  { 13070558741735168987u, 101623408980952019u }, { 11726512408741573330u, 127029261226190024u },
+  {  7329070255463483331u,  79393288266368765u }, { 13773023837756742068u,  99241610332960956u },
+  { 17216279797195927585u, 124052012916201195u }, {  8454331864033760789u,  77532508072625747u },
+  {  5956228811614813082u,  96915635090782184u }, {  7445286014518516353u, 121144543863477730u },
+  {  9264989777501460624u,  75715339914673581u }, { 16192923240304213684u,  94644174893341976u },
+  {  1794409976670715490u, 118305218616677471u }, {  8039035263060279037u,  73940761635423419u },
+  {  5437108060397960892u,  92425952044279274u }, { 16019757112352226923u, 115532440055349092u },
+  {   788976158365366019u,  72207775034593183u }, { 14821278253238871236u,  90259718793241478u },
+  {  9303225779693813237u, 112824648491551848u }, { 11629032224617266546u, 141030810614439810u },
+  { 11879831158813179495u,  88144256634024881u }, {  1014730893234310657u, 110180320792531102u },
+  { 10491785653397664129u, 137725400990663877u }, {  8863209042587234033u,  86078375619164923u },
+  {  6467325284806654637u, 107597969523956154u }, { 17307528642863094104u, 134497461904945192u },
+  { 10817205401789433815u,  84060913690590745u }, { 18133192770664180173u, 105076142113238431u },
+  { 18054804944902837312u, 131345177641548039u }, { 18201782118205355176u,  82090736025967524u },
+  {  4305483574047142354u, 102613420032459406u }, { 14605226504413703751u, 128266775040574257u },
+  {  2210737537617482988u,  80166734400358911u }, { 16598479977304017447u, 100208418000448638u },
+  { 11524727934775246001u, 125260522500560798u }, {  2591268940807140847u,  78287826562850499u },
+  { 17074144231291089770u,  97859783203563123u }, { 16730994270686474309u, 122324729004453904u },
+  { 10456871419179046443u,  76452955627783690u }, {  3847717237119032246u,  95566194534729613u },
+  {  9421332564826178211u, 119457743168412016u }, {  5888332853016361382u,  74661089480257510u },
+  { 16583788103125227536u,  93326361850321887u }, { 16118049110479146516u, 116657952312902359u },
+  { 16991309721690548428u,  72911220195563974u }, { 12015765115258409727u,  91139025244454968u },
+  { 15019706394073012159u, 113923781555568710u }, {  9551260955736489391u, 142404726944460888u },
+  {  5969538097335305869u,  89002954340288055u }, {  2850236603241744433u, 111253692925360069u }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
lib/libcxx/src/include/ryu/d2s_intrinsics.h
@@ -0,0 +1,257 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
+#define _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if defined(_M_X64) && defined(_MSC_VER)
+#define _LIBCPP_INTRINSIC128 1
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
+  return _umul128(__a, __b, __productHi);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
+  // For the __shiftright128 intrinsic, the shift value is always
+  // modulo 64.
+  // In the current implementation of the double-precision version
+  // of Ryu, the shift value is always < 64.
+  // (The shift value is in the range [49, 58].)
+  // Check this here in case a future change requires larger shift
+  // values. In this case this function needs to be adjusted.
+  _LIBCPP_ASSERT(__dist < 64, "");
+  return __shiftright128(__lo, __hi, static_cast<unsigned char>(__dist));
+}
+
+// ^^^ intrinsics available ^^^ / vvv __int128 available vvv
+#elif defined(__SIZEOF_INT128__) && ( \
+    (defined(__clang__) && !defined(_MSC_VER)) || \
+    (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__)))
+#define _LIBCPP_INTRINSIC128 1
+  // We have __uint128 support in clang or gcc
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
+  auto __temp = __a * (unsigned __int128)__b;
+  *__productHi = __temp >> 64;
+  return static_cast<uint64_t>(__temp);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
+  // In the current implementation of the double-precision version
+  // of Ryu, the shift value is always < 64.
+  // (The shift value is in the range [49, 58].)
+  // Check this here in case a future change requires larger shift
+  // values. In this case this function needs to be adjusted.
+  _LIBCPP_ASSERT(__dist < 64, "");
+  auto __temp = __lo | ((unsigned __int128)__hi << 64);
+  // For x64 128-bit shfits using the `shrd` instruction and two 64-bit
+  // registers, the shift value is modulo 64.  Thus the `& 63` is free.
+  return static_cast<uint64_t>(__temp >> (__dist & 63));
+}
+#else // ^^^ __int128 available ^^^ / vvv intrinsics unavailable vvv
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_ALWAYS_INLINE uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
+  // TRANSITION, VSO-634761
+  // The casts here help MSVC to avoid calls to the __allmul library function.
+  const uint32_t __aLo = static_cast<uint32_t>(__a);
+  const uint32_t __aHi = static_cast<uint32_t>(__a >> 32);
+  const uint32_t __bLo = static_cast<uint32_t>(__b);
+  const uint32_t __bHi = static_cast<uint32_t>(__b >> 32);
+
+  const uint64_t __b00 = static_cast<uint64_t>(__aLo) * __bLo;
+  const uint64_t __b01 = static_cast<uint64_t>(__aLo) * __bHi;
+  const uint64_t __b10 = static_cast<uint64_t>(__aHi) * __bLo;
+  const uint64_t __b11 = static_cast<uint64_t>(__aHi) * __bHi;
+
+  const uint32_t __b00Lo = static_cast<uint32_t>(__b00);
+  const uint32_t __b00Hi = static_cast<uint32_t>(__b00 >> 32);
+
+  const uint64_t __mid1 = __b10 + __b00Hi;
+  const uint32_t __mid1Lo = static_cast<uint32_t>(__mid1);
+  const uint32_t __mid1Hi = static_cast<uint32_t>(__mid1 >> 32);
+
+  const uint64_t __mid2 = __b01 + __mid1Lo;
+  const uint32_t __mid2Lo = static_cast<uint32_t>(__mid2);
+  const uint32_t __mid2Hi = static_cast<uint32_t>(__mid2 >> 32);
+
+  const uint64_t __pHi = __b11 + __mid1Hi + __mid2Hi;
+  const uint64_t __pLo = (static_cast<uint64_t>(__mid2Lo) << 32) | __b00Lo;
+
+  *__productHi = __pHi;
+  return __pLo;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
+  // We don't need to handle the case __dist >= 64 here (see above).
+  _LIBCPP_ASSERT(__dist < 64, "");
+#ifdef _LIBCPP_64_BIT
+  _LIBCPP_ASSERT(__dist > 0, "");
+  return (__hi << (64 - __dist)) | (__lo >> __dist);
+#else // ^^^ 64-bit ^^^ / vvv 32-bit vvv
+  // Avoid a 64-bit shift by taking advantage of the range of shift values.
+  _LIBCPP_ASSERT(__dist >= 32, "");
+  return (__hi << (64 - __dist)) | (static_cast<uint32_t>(__lo >> 32) >> (__dist - 32));
+#endif // ^^^ 32-bit ^^^
+}
+
+#endif // ^^^ intrinsics unavailable ^^^
+
+#ifndef _LIBCPP_64_BIT
+
+// Returns the high 64 bits of the 128-bit product of __a and __b.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __umulh(const uint64_t __a, const uint64_t __b) {
+  // Reuse the __ryu_umul128 implementation.
+  // Optimizers will likely eliminate the instructions used to compute the
+  // low part of the product.
+  uint64_t __hi;
+  (void) __ryu_umul128(__a, __b, &__hi);
+  return __hi;
+}
+
+// On 32-bit platforms, compilers typically generate calls to library
+// functions for 64-bit divisions, even if the divisor is a constant.
+//
+// TRANSITION, LLVM-37932
+//
+// The functions here perform division-by-constant using multiplications
+// in the same way as 64-bit compilers would do.
+//
+// NB:
+// The multipliers and shift values are the ones generated by clang x64
+// for expressions like x/5, x/10, etc.
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div5(const uint64_t __x) {
+  return __umulh(__x, 0xCCCCCCCCCCCCCCCDu) >> 2;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div10(const uint64_t __x) {
+  return __umulh(__x, 0xCCCCCCCCCCCCCCCDu) >> 3;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div100(const uint64_t __x) {
+  return __umulh(__x >> 2, 0x28F5C28F5C28F5C3u) >> 2;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e8(const uint64_t __x) {
+  return __umulh(__x, 0xABCC77118461CEFDu) >> 26;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e9(const uint64_t __x) {
+  return __umulh(__x >> 9, 0x44B82FA09B5A53u) >> 11;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mod1e9(const uint64_t __x) {
+  // Avoid 64-bit math as much as possible.
+  // Returning static_cast<uint32_t>(__x - 1000000000 * __div1e9(__x)) would
+  // perform 32x64-bit multiplication and 64-bit subtraction.
+  // __x and 1000000000 * __div1e9(__x) are guaranteed to differ by
+  // less than 10^9, so their highest 32 bits must be identical,
+  // so we can truncate both sides to uint32_t before subtracting.
+  // We can also simplify static_cast<uint32_t>(1000000000 * __div1e9(__x)).
+  // We can truncate before multiplying instead of after, as multiplying
+  // the highest 32 bits of __div1e9(__x) can't affect the lowest 32 bits.
+  return static_cast<uint32_t>(__x) - 1000000000 * static_cast<uint32_t>(__div1e9(__x));
+}
+
+#else // ^^^ 32-bit ^^^ / vvv 64-bit vvv
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div5(const uint64_t __x) {
+  return __x / 5;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div10(const uint64_t __x) {
+  return __x / 10;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div100(const uint64_t __x) {
+  return __x / 100;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e8(const uint64_t __x) {
+  return __x / 100000000;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e9(const uint64_t __x) {
+  return __x / 1000000000;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mod1e9(const uint64_t __x) {
+  return static_cast<uint32_t>(__x - 1000000000 * __div1e9(__x));
+}
+
+#endif // ^^^ 64-bit ^^^
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow5Factor(uint64_t __value) {
+  uint32_t __count = 0;
+  for (;;) {
+    _LIBCPP_ASSERT(__value != 0, "");
+    const uint64_t __q = __div5(__value);
+    const uint32_t __r = static_cast<uint32_t>(__value) - 5 * static_cast<uint32_t>(__q);
+    if (__r != 0) {
+      break;
+    }
+    __value = __q;
+    ++__count;
+  }
+  return __count;
+}
+
+// Returns true if __value is divisible by 5^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf5(const uint64_t __value, const uint32_t __p) {
+  // I tried a case distinction on __p, but there was no performance difference.
+  return __pow5Factor(__value) >= __p;
+}
+
+// Returns true if __value is divisible by 2^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint64_t __value, const uint32_t __p) {
+  _LIBCPP_ASSERT(__value != 0, "");
+  _LIBCPP_ASSERT(__p < 64, "");
+  // __builtin_ctzll doesn't appear to be faster here.
+  return (__value & ((1ull << __p) - 1)) == 0;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
lib/libcxx/src/include/ryu/digit_table.h
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
+#define _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// A table of all two-digit numbers. This is used to speed up decimal digit
+// generation by copying pairs of digits into the final output.
+inline constexpr char __DIGIT_TABLE[200] = {
+  '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
+  '1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
+  '2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
+  '3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
+  '4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
+  '5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
+  '6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
+  '7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
+  '8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
+  '9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
lib/libcxx/src/include/ryu/f2s.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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_FS2_H
+#define _LIBCPP_SRC_INCLUDE_RYU_FS2_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+[[nodiscard]] to_chars_result __f2s_buffered_n(char* const _First, char* const _Last, const float __f, const chars_format _Fmt);
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_FS2_H
lib/libcxx/src/include/ryu/ryu.h
@@ -0,0 +1,148 @@
+// -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_RYU_H
+#define _LIBCPP_SRC_INCLUDE_RYU_RYU_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__charconv/chars_format.h"
+#include "__charconv/to_chars_result.h"
+#include "__config"
+#include "__debug"
+#include "__errc"
+#include "cstdint"
+#include "cstring"
+#include "type_traits"
+#include "include/ryu/f2s.h"
+#include "include/ryu/d2s.h"
+#include "include/ryu/d2fixed.h"
+
+#if defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
+#include <intrin0.h> // for _umul128() and __shiftright128()
+#endif // defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
+
+#if defined(_WIN64) || defined(_M_AMD64) || defined(__x86_64__) ||  defined(__aarch64__)
+#define _LIBCPP_64_BIT
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// https://github.com/ulfjack/ryu/tree/59661c3/ryu
+
+#if !defined(_LIBCPP_COMPILER_MSVC)
+_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __index, unsigned long long __mask) {
+  if (__mask == 0) {
+    return false;
+  }
+  *__index = __builtin_ctzll(__mask);
+  return true;
+}
+
+_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __index, unsigned int __mask) {
+  if (__mask == 0) {
+    return false;
+  }
+  *__index = __builtin_ctz(__mask);
+  return true;
+}
+#endif  // _LIBCPP_COMPILER_MSVC
+
+template <class _Floating>
+[[nodiscard]] to_chars_result _Floating_to_chars_ryu(
+    char* const _First, char* const _Last, const _Floating _Value, const chars_format _Fmt) noexcept {
+    if constexpr (_IsSame<_Floating, float>::value) {
+        return __f2s_buffered_n(_First, _Last, _Value, _Fmt);
+    } else {
+        return __d2s_buffered_n(_First, _Last, _Value, _Fmt);
+    }
+}
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI to_chars_result _Floating_to_chars_scientific_precision(
+    char* const _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+    // C11 7.21.6.1 "The fprintf function"/5:
+    // "A negative precision argument is taken as if the precision were omitted."
+    // /8: "e,E [...] if the precision is missing, it is taken as 6"
+
+    if (_Precision < 0) {
+        _Precision = 6;
+    } else if (_Precision < 1'000'000'000) { // Match ' to fix compilation with GCC in C++11 mode
+        // _Precision is ok.
+    } else {
+        // Avoid integer overflow.
+        // (This defensive check is slightly nonconformant; it can be carefully improved in the future.)
+        return {_Last, errc::value_too_large};
+    }
+
+    return __d2exp_buffered_n(_First, _Last, _Value, static_cast<uint32_t>(_Precision));
+}
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI to_chars_result _Floating_to_chars_fixed_precision(
+    char* const _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+    // C11 7.21.6.1 "The fprintf function"/5:
+    // "A negative precision argument is taken as if the precision were omitted."
+    // /8: "f,F [...] If the precision is missing, it is taken as 6"
+
+    if (_Precision < 0) {
+        _Precision = 6;
+    } else if (_Precision < 1'000'000'000) { // Match ' to fix compilation with GCC in C++11 mode
+        // _Precision is ok.
+    } else {
+        // Avoid integer overflow.
+        // (This defensive check is slightly nonconformant; it can be carefully improved in the future.)
+        return {_Last, errc::value_too_large};
+    }
+
+    return __d2fixed_buffered_n(_First, _Last, _Value, static_cast<uint32_t>(_Precision));
+}
+
+#undef _LIBCPP_64_BIT
+#undef _LIBCPP_INTRINSIC128
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_RYU_H
lib/libcxx/src/include/apple_availability.h
@@ -1,4 +1,4 @@
-//===------------------------ apple_availability.h ------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/include/atomic_support.h
@@ -24,7 +24,7 @@
                        && defined(__ATOMIC_ACQ_REL)                  \
                        && defined(__ATOMIC_SEQ_CST)
 #   define _LIBCPP_HAS_ATOMIC_BUILTINS
-#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
+#elif defined(_LIBCPP_COMPILER_GCC)
 #   define _LIBCPP_HAS_ATOMIC_BUILTINS
 #endif
 
@@ -146,7 +146,7 @@ _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
 template <class _ValueType>
 inline _LIBCPP_INLINE_VISIBILITY
 _ValueType __libcpp_atomic_exchange(_ValueType* __target,
-                                    _ValueType __value, int __order = _AO_Seq)
+                                    _ValueType __value, int = _AO_Seq)
 {
     _ValueType old = *__target;
     *__target = __value;
lib/libcxx/src/include/config_elast.h
@@ -1,4 +1,4 @@
-//===----------------------- config_elast.h -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/include/refstring.h
@@ -1,4 +1,4 @@
-//===------------------------ __refstring ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/include/to_chars_floating_point.h
@@ -0,0 +1,1076 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// This implementation is dedicated to the memory of Mary and Thavatchai.
+
+#ifndef _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
+#define _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__algorithm/find.h"
+#include "__algorithm/find_if.h"
+#include "__algorithm/lower_bound.h"
+#include "__algorithm/min.h"
+#include "__config"
+#include "__iterator/access.h"
+#include "__iterator/size.h"
+#include "bit"
+#include "cfloat"
+#include "climits"
+#include "include/ryu/ryu.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace __itoa {
+inline constexpr char _Charconv_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
+    'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
+static_assert(_VSTD::size(_Charconv_digits) == 36);
+} // __itoa
+
+// vvvvvvvvvv DERIVED FROM corecrt_internal_fltintrn.h vvvvvvvvvv
+
+template <class _FloatingType>
+struct _Floating_type_traits;
+
+template <>
+struct _Floating_type_traits<float> {
+    static constexpr int32_t _Mantissa_bits = FLT_MANT_DIG;
+    static constexpr int32_t _Exponent_bits = sizeof(float) * CHAR_BIT - FLT_MANT_DIG;
+
+    static constexpr int32_t _Maximum_binary_exponent = FLT_MAX_EXP - 1;
+    static constexpr int32_t _Minimum_binary_exponent = FLT_MIN_EXP - 1;
+
+    static constexpr int32_t _Exponent_bias = 127;
+
+    static constexpr int32_t _Sign_shift     = _Exponent_bits + _Mantissa_bits - 1;
+    static constexpr int32_t _Exponent_shift = _Mantissa_bits - 1;
+
+    using _Uint_type = uint32_t;
+
+    static constexpr uint32_t _Exponent_mask             = (1u << _Exponent_bits) - 1;
+    static constexpr uint32_t _Normal_mantissa_mask      = (1u << _Mantissa_bits) - 1;
+    static constexpr uint32_t _Denormal_mantissa_mask    = (1u << (_Mantissa_bits - 1)) - 1;
+    static constexpr uint32_t _Special_nan_mantissa_mask = 1u << (_Mantissa_bits - 2);
+    static constexpr uint32_t _Shifted_sign_mask         = 1u << _Sign_shift;
+    static constexpr uint32_t _Shifted_exponent_mask     = _Exponent_mask << _Exponent_shift;
+};
+
+template <>
+struct _Floating_type_traits<double> {
+    static constexpr int32_t _Mantissa_bits = DBL_MANT_DIG;
+    static constexpr int32_t _Exponent_bits = sizeof(double) * CHAR_BIT - DBL_MANT_DIG;
+
+    static constexpr int32_t _Maximum_binary_exponent = DBL_MAX_EXP - 1;
+    static constexpr int32_t _Minimum_binary_exponent = DBL_MIN_EXP - 1;
+
+    static constexpr int32_t _Exponent_bias = 1023;
+
+    static constexpr int32_t _Sign_shift     = _Exponent_bits + _Mantissa_bits - 1;
+    static constexpr int32_t _Exponent_shift = _Mantissa_bits - 1;
+
+    using _Uint_type = uint64_t;
+
+    static constexpr uint64_t _Exponent_mask             = (1ULL << _Exponent_bits) - 1;
+    static constexpr uint64_t _Normal_mantissa_mask      = (1ULL << _Mantissa_bits) - 1;
+    static constexpr uint64_t _Denormal_mantissa_mask    = (1ULL << (_Mantissa_bits - 1)) - 1;
+    static constexpr uint64_t _Special_nan_mantissa_mask = 1ULL << (_Mantissa_bits - 2);
+    static constexpr uint64_t _Shifted_sign_mask         = 1ULL << _Sign_shift;
+    static constexpr uint64_t _Shifted_exponent_mask     = _Exponent_mask << _Exponent_shift;
+};
+
+// ^^^^^^^^^^ DERIVED FROM corecrt_internal_fltintrn.h ^^^^^^^^^^
+
+// FUNCTION to_chars (FLOATING-POINT TO STRING)
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars_hex_precision(
+    char* _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+    // * Determine the effective _Precision.
+    // * Later, we'll decrement _Precision when printing each hexit after the decimal point.
+
+    // The hexits after the decimal point correspond to the explicitly stored fraction bits.
+    // float explicitly stores 23 fraction bits. 23 / 4 == 5.75, which is 6 hexits.
+    // double explicitly stores 52 fraction bits. 52 / 4 == 13, which is 13 hexits.
+    constexpr int _Full_precision         = _IsSame<_Floating, float>::value ? 6 : 13;
+    constexpr int _Adjusted_explicit_bits = _Full_precision * 4;
+
+    if (_Precision < 0) {
+        // C11 7.21.6.1 "The fprintf function"/5: "A negative precision argument is taken as if the precision were
+        // omitted." /8: "if the precision is missing and FLT_RADIX is a power of 2, then the precision is sufficient
+        // for an exact representation of the value"
+        _Precision = _Full_precision;
+    }
+
+    // * Extract the _Ieee_mantissa and _Ieee_exponent.
+    using _Traits    = _Floating_type_traits<_Floating>;
+    using _Uint_type = typename _Traits::_Uint_type;
+
+    const _Uint_type _Uint_value    = _VSTD::bit_cast<_Uint_type>(_Value);
+    const _Uint_type _Ieee_mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
+    const int32_t _Ieee_exponent    = static_cast<int32_t>(_Uint_value >> _Traits::_Exponent_shift);
+
+    // * Prepare the _Adjusted_mantissa. This is aligned to hexit boundaries,
+    // * with the implicit bit restored (0 for zero values and subnormal values, 1 for normal values).
+    // * Also calculate the _Unbiased_exponent. This unifies the processing of zero, subnormal, and normal values.
+    _Uint_type _Adjusted_mantissa;
+
+    if constexpr (_IsSame<_Floating, float>::value) {
+        _Adjusted_mantissa = _Ieee_mantissa << 1; // align to hexit boundary (23 isn't divisible by 4)
+    } else {
+        _Adjusted_mantissa = _Ieee_mantissa; // already aligned (52 is divisible by 4)
+    }
+
+    int32_t _Unbiased_exponent;
+
+    if (_Ieee_exponent == 0) { // zero or subnormal
+        // implicit bit is 0
+
+        if (_Ieee_mantissa == 0) { // zero
+            // C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the exponent is zero."
+            _Unbiased_exponent = 0;
+        } else { // subnormal
+            _Unbiased_exponent = 1 - _Traits::_Exponent_bias;
+        }
+    } else { // normal
+        _Adjusted_mantissa |= _Uint_type{1} << _Adjusted_explicit_bits; // implicit bit is 1
+        _Unbiased_exponent = _Ieee_exponent - _Traits::_Exponent_bias;
+    }
+
+    // _Unbiased_exponent is within [-126, 127] for float, [-1022, 1023] for double.
+
+    // * Decompose _Unbiased_exponent into _Sign_character and _Absolute_exponent.
+    char _Sign_character;
+    uint32_t _Absolute_exponent;
+
+    if (_Unbiased_exponent < 0) {
+        _Sign_character    = '-';
+        _Absolute_exponent = static_cast<uint32_t>(-_Unbiased_exponent);
+    } else {
+        _Sign_character    = '+';
+        _Absolute_exponent = static_cast<uint32_t>(_Unbiased_exponent);
+    }
+
+    // _Absolute_exponent is within [0, 127] for float, [0, 1023] for double.
+
+    // * Perform a single bounds check.
+    {
+        int32_t _Exponent_length;
+
+        if (_Absolute_exponent < 10) {
+            _Exponent_length = 1;
+        } else if (_Absolute_exponent < 100) {
+            _Exponent_length = 2;
+        } else if constexpr (_IsSame<_Floating, float>::value) {
+            _Exponent_length = 3;
+        } else if (_Absolute_exponent < 1000) {
+            _Exponent_length = 3;
+        } else {
+            _Exponent_length = 4;
+        }
+
+        // _Precision might be enormous; avoid integer overflow by testing it separately.
+        ptrdiff_t _Buffer_size = _Last - _First;
+
+        if (_Buffer_size < _Precision) {
+            return {_Last, errc::value_too_large};
+        }
+
+        _Buffer_size -= _Precision;
+
+        const int32_t _Length_excluding_precision = 1 // leading hexit
+                                                    + static_cast<int32_t>(_Precision > 0) // possible decimal point
+                                                    // excluding `+ _Precision`, hexits after decimal point
+                                                    + 2 // "p+" or "p-"
+                                                    + _Exponent_length; // exponent
+
+        if (_Buffer_size < _Length_excluding_precision) {
+            return {_Last, errc::value_too_large};
+        }
+    }
+
+    // * Perform rounding when we've been asked to omit hexits.
+    if (_Precision < _Full_precision) {
+        // _Precision is within [0, 5] for float, [0, 12] for double.
+
+        // _Dropped_bits is within [4, 24] for float, [4, 52] for double.
+        const int _Dropped_bits = (_Full_precision - _Precision) * 4;
+
+        // Perform rounding by adding an appropriately-shifted bit.
+
+        // This can propagate carries all the way into the leading hexit. Examples:
+        // "0.ff9" rounded to a precision of 2 is "1.00".
+        // "1.ff9" rounded to a precision of 2 is "2.00".
+
+        // Note that the leading hexit participates in the rounding decision. Examples:
+        // "0.8" rounded to a precision of 0 is "0".
+        // "1.8" rounded to a precision of 0 is "2".
+
+        // Reference implementation with suboptimal codegen:
+        // bool _Should_round_up(bool _Lsb_bit, bool _Round_bit, bool _Has_tail_bits) {
+        //    // If there are no insignificant set bits, the value is exactly-representable and should not be rounded.
+        //    //
+        //    // If there are insignificant set bits, we need to round according to round_to_nearest.
+        //    // We need to handle two cases: we round up if either [1] the value is slightly greater
+        //    // than the midpoint between two exactly-representable values or [2] the value is exactly the midpoint
+        //    // between two exactly-representable values and the greater of the two is even (this is "round-to-even").
+        //    return _Round_bit && (_Has_tail_bits || _Lsb_bit);
+        //}
+        // const bool _Lsb_bit       = (_Adjusted_mantissa & (_Uint_type{1} << _Dropped_bits)) != 0;
+        // const bool _Round_bit     = (_Adjusted_mantissa & (_Uint_type{1} << (_Dropped_bits - 1))) != 0;
+        // const bool _Has_tail_bits = (_Adjusted_mantissa & ((_Uint_type{1} << (_Dropped_bits - 1)) - 1)) != 0;
+        // const bool _Should_round = _Should_round_up(_Lsb_bit, _Round_bit, _Has_tail_bits);
+        // _Adjusted_mantissa += _Uint_type{_Should_round} << _Dropped_bits;
+
+        // Example for optimized implementation: Let _Dropped_bits be 8.
+        //          Bit index: ...[8]76543210
+        // _Adjusted_mantissa: ...[L]RTTTTTTT (not depicting known details, like hexit alignment)
+        // By focusing on the bit at index _Dropped_bits, we can avoid unnecessary branching and shifting.
+
+        // Bit index: ...[8]76543210
+        //  _Lsb_bit: ...[L]RTTTTTTT
+        const _Uint_type _Lsb_bit = _Adjusted_mantissa;
+
+        //  Bit index: ...9[8]76543210
+        // _Round_bit: ...L[R]TTTTTTT0
+        const _Uint_type _Round_bit = _Adjusted_mantissa << 1;
+
+        // We can detect (without branching) whether any of the trailing bits are set.
+        // Due to _Should_round below, this computation will be used if and only if R is 1, so we can assume that here.
+        //      Bit index: ...9[8]76543210
+        //     _Round_bit: ...L[1]TTTTTTT0
+        // _Has_tail_bits: ....[H]........
+
+        // If all of the trailing bits T are 0, then `_Round_bit - 1` will produce 0 for H (due to R being 1).
+        // If any of the trailing bits T are 1, then `_Round_bit - 1` will produce 1 for H (due to R being 1).
+        const _Uint_type _Has_tail_bits = _Round_bit - 1;
+
+        // Finally, we can use _Should_round_up() logic with bitwise-AND and bitwise-OR,
+        // selecting just the bit at index _Dropped_bits. This is the appropriately-shifted bit that we want.
+        const _Uint_type _Should_round = _Round_bit & (_Has_tail_bits | _Lsb_bit) & (_Uint_type{1} << _Dropped_bits);
+
+        // This rounding technique is dedicated to the memory of Peppermint. =^..^=
+        _Adjusted_mantissa += _Should_round;
+    }
+
+    // * Print the leading hexit, then mask it away.
+    {
+        const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Adjusted_explicit_bits);
+        _LIBCPP_ASSERT(_Nibble < 3, "");
+        const char _Leading_hexit = static_cast<char>('0' + _Nibble);
+
+        *_First++ = _Leading_hexit;
+
+        constexpr _Uint_type _Mask = (_Uint_type{1} << _Adjusted_explicit_bits) - 1;
+        _Adjusted_mantissa &= _Mask;
+    }
+
+    // * Print the decimal point and trailing hexits.
+
+    // C11 7.21.6.1 "The fprintf function"/8:
+    // "if the precision is zero and the # flag is not specified, no decimal-point character appears."
+    if (_Precision > 0) {
+        *_First++ = '.';
+
+        int32_t _Number_of_bits_remaining = _Adjusted_explicit_bits; // 24 for float, 52 for double
+
+        for (;;) {
+            _LIBCPP_ASSERT(_Number_of_bits_remaining >= 4, "");
+            _LIBCPP_ASSERT(_Number_of_bits_remaining % 4 == 0, "");
+            _Number_of_bits_remaining -= 4;
+
+            const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Number_of_bits_remaining);
+            _LIBCPP_ASSERT(_Nibble < 16, "");
+            const char _Hexit = __itoa::_Charconv_digits[_Nibble];
+
+            *_First++ = _Hexit;
+
+            // _Precision is the number of hexits that still need to be printed.
+            --_Precision;
+            if (_Precision == 0) {
+                break; // We're completely done with this phase.
+            }
+            // Otherwise, we need to keep printing hexits.
+
+            if (_Number_of_bits_remaining == 0) {
+                // We've finished printing _Adjusted_mantissa, so all remaining hexits are '0'.
+                _VSTD::memset(_First, '0', static_cast<size_t>(_Precision));
+                _First += _Precision;
+                break;
+            }
+
+            // Mask away the hexit that we just printed, then keep looping.
+            // (We skip this when breaking out of the loop above, because _Adjusted_mantissa isn't used later.)
+            const _Uint_type _Mask = (_Uint_type{1} << _Number_of_bits_remaining) - 1;
+            _Adjusted_mantissa &= _Mask;
+        }
+    }
+
+    // * Print the exponent.
+
+    // C11 7.21.6.1 "The fprintf function"/8: "The exponent always contains at least one digit, and only as many more
+    // digits as necessary to represent the decimal exponent of 2."
+
+    // Performance note: We should take advantage of the known ranges of possible exponents.
+
+    *_First++ = 'p';
+    *_First++ = _Sign_character;
+
+    // We've already printed '-' if necessary, so uint32_t _Absolute_exponent avoids testing that again.
+    return _VSTD::to_chars(_First, _Last, _Absolute_exponent);
+}
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars_hex_shortest(
+    char* _First, char* const _Last, const _Floating _Value) noexcept {
+
+    // This prints "1.728p+0" instead of "2.e5p-1".
+    // This prints "0.000002p-126" instead of "1p-149" for float.
+    // This prints "0.0000000000001p-1022" instead of "1p-1074" for double.
+    // This prioritizes being consistent with printf's de facto behavior (and hex-precision's behavior)
+    // over minimizing the number of characters printed.
+
+    using _Traits    = _Floating_type_traits<_Floating>;
+    using _Uint_type = typename _Traits::_Uint_type;
+
+    const _Uint_type _Uint_value = _VSTD::bit_cast<_Uint_type>(_Value);
+
+    if (_Uint_value == 0) { // zero detected; write "0p+0" and return
+        // C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the exponent is zero."
+        // Special-casing zero is necessary because of the exponent.
+        const char* const _Str = "0p+0";
+        const size_t _Len      = 4;
+
+        if (_Last - _First < static_cast<ptrdiff_t>(_Len)) {
+            return {_Last, errc::value_too_large};
+        }
+
+        _VSTD::memcpy(_First, _Str, _Len);
+
+        return {_First + _Len, errc{}};
+    }
+
+    const _Uint_type _Ieee_mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
+    const int32_t _Ieee_exponent    = static_cast<int32_t>(_Uint_value >> _Traits::_Exponent_shift);
+
+    char _Leading_hexit; // implicit bit
+    int32_t _Unbiased_exponent;
+
+    if (_Ieee_exponent == 0) { // subnormal
+        _Leading_hexit     = '0';
+        _Unbiased_exponent = 1 - _Traits::_Exponent_bias;
+    } else { // normal
+        _Leading_hexit     = '1';
+        _Unbiased_exponent = _Ieee_exponent - _Traits::_Exponent_bias;
+    }
+
+    // Performance note: Consider avoiding per-character bounds checking when there's plenty of space.
+
+    if (_First == _Last) {
+        return {_Last, errc::value_too_large};
+    }
+
+    *_First++ = _Leading_hexit;
+
+    if (_Ieee_mantissa == 0) {
+        // The fraction bits are all 0. Trim them away, including the decimal point.
+    } else {
+        if (_First == _Last) {
+            return {_Last, errc::value_too_large};
+        }
+
+        *_First++ = '.';
+
+        // The hexits after the decimal point correspond to the explicitly stored fraction bits.
+        // float explicitly stores 23 fraction bits. 23 / 4 == 5.75, so we'll print at most 6 hexits.
+        // double explicitly stores 52 fraction bits. 52 / 4 == 13, so we'll print at most 13 hexits.
+        _Uint_type _Adjusted_mantissa;
+        int32_t _Number_of_bits_remaining;
+
+        if constexpr (_IsSame<_Floating, float>::value) {
+            _Adjusted_mantissa        = _Ieee_mantissa << 1; // align to hexit boundary (23 isn't divisible by 4)
+            _Number_of_bits_remaining = 24; // 23 fraction bits + 1 alignment bit
+        } else {
+            _Adjusted_mantissa        = _Ieee_mantissa; // already aligned (52 is divisible by 4)
+            _Number_of_bits_remaining = 52; // 52 fraction bits
+        }
+
+        // do-while: The condition _Adjusted_mantissa != 0 is initially true - we have nonzero fraction bits and we've
+        // printed the decimal point. Each iteration, we print a hexit, mask it away, and keep looping if we still have
+        // nonzero fraction bits. If there would be trailing '0' hexits, this trims them. If there wouldn't be trailing
+        // '0' hexits, the same condition works (as we print the final hexit and mask it away); we don't need to test
+        // _Number_of_bits_remaining.
+        do {
+            _LIBCPP_ASSERT(_Number_of_bits_remaining >= 4, "");
+            _LIBCPP_ASSERT(_Number_of_bits_remaining % 4 == 0, "");
+            _Number_of_bits_remaining -= 4;
+
+            const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Number_of_bits_remaining);
+            _LIBCPP_ASSERT(_Nibble < 16, "");
+            const char _Hexit = __itoa::_Charconv_digits[_Nibble];
+
+            if (_First == _Last) {
+                return {_Last, errc::value_too_large};
+            }
+
+            *_First++ = _Hexit;
+
+            const _Uint_type _Mask = (_Uint_type{1} << _Number_of_bits_remaining) - 1;
+            _Adjusted_mantissa &= _Mask;
+
+        } while (_Adjusted_mantissa != 0);
+    }
+
+    // C11 7.21.6.1 "The fprintf function"/8: "The exponent always contains at least one digit, and only as many more
+    // digits as necessary to represent the decimal exponent of 2."
+
+    // Performance note: We should take advantage of the known ranges of possible exponents.
+
+    // float: _Unbiased_exponent is within [-126, 127].
+    // double: _Unbiased_exponent is within [-1022, 1023].
+
+    if (_Last - _First < 2) {
+        return {_Last, errc::value_too_large};
+    }
+
+    *_First++ = 'p';
+
+    if (_Unbiased_exponent < 0) {
+        *_First++          = '-';
+        _Unbiased_exponent = -_Unbiased_exponent;
+    } else {
+        *_First++ = '+';
+    }
+
+    // We've already printed '-' if necessary, so static_cast<uint32_t> avoids testing that again.
+    return _VSTD::to_chars(_First, _Last, static_cast<uint32_t>(_Unbiased_exponent));
+}
+
+// For general precision, we can use lookup tables to avoid performing trial formatting.
+
+// For a simple example, imagine counting the number of digits D in an integer, and needing to know
+// whether D is less than 3, equal to 3/4/5/6, or greater than 6. We could use a lookup table:
+// D | Largest integer with D digits
+// 2 |      99
+// 3 |     999
+// 4 |   9'999
+// 5 |  99'999
+// 6 | 999'999
+// 7 | table end
+// Looking up an integer in this table with lower_bound() will work:
+// * Too-small integers, like 7, 70, and 99, will cause lower_bound() to return the D == 2 row. (If all we care
+//   about is whether D is less than 3, then it's okay to smash the D == 1 and D == 2 cases together.)
+// * Integers in [100, 999] will cause lower_bound() to return the D == 3 row, and so forth.
+// * Too-large integers, like 1'000'000 and above, will cause lower_bound() to return the end of the table. If we
+//   compute D from that index, this will be considered D == 7, which will activate any "greater than 6" logic.
+
+// Floating-point is slightly more complicated.
+
+// The ordinary lookup tables are for X within [-5, 38] for float, and [-5, 308] for double.
+// (-5 absorbs too-negative exponents, outside the P > X >= -4 criterion. 38 and 308 are the maximum exponents.)
+// Due to the P > X condition, we can use a subset of the table for X within [-5, P - 1], suitably clamped.
+
+// When P is small, rounding can affect X. For example:
+// For P == 1, the largest double with X == 0 is: 9.4999999999999982236431605997495353221893310546875
+// For P == 2, the largest double with X == 0 is: 9.949999999999999289457264239899814128875732421875
+// For P == 3, the largest double with X == 0 is: 9.9949999999999992184029906638897955417633056640625
+
+// Exponent adjustment is a concern for P within [1, 7] for float, and [1, 15] for double (determined via
+// brute force). While larger values of P still perform rounding, they can't trigger exponent adjustment.
+// This is because only values with repeated '9' digits can undergo exponent adjustment during rounding,
+// and floating-point granularity limits the number of consecutive '9' digits that can appear.
+
+// So, we need special lookup tables for small values of P.
+// These tables have varying lengths due to the P > X >= -4 criterion. For example:
+// For P == 1, need table entries for X: -5, -4, -3, -2, -1, 0
+// For P == 2, need table entries for X: -5, -4, -3, -2, -1, 0, 1
+// For P == 3, need table entries for X: -5, -4, -3, -2, -1, 0, 1, 2
+// For P == 4, need table entries for X: -5, -4, -3, -2, -1, 0, 1, 2, 3
+
+// We can concatenate these tables for compact storage, using triangular numbers to access them.
+// The table for P begins at index (P - 1) * (P + 10) / 2 with length P + 5.
+
+// For both the ordinary and special lookup tables, after an index I is returned by lower_bound(), X is I - 5.
+
+// We need to special-case the floating-point value 0.0, which is considered to have X == 0.
+// Otherwise, the lookup tables would consider it to have a highly negative X.
+
+// Finally, because we're working with positive floating-point values,
+// representation comparisons behave identically to floating-point comparisons.
+
+// The following code generated the lookup tables for the scientific exponent X. Don't remove this code.
+#if 0
+// cl /EHsc /nologo /W4 /MT /O2 /std:c++17 generate_tables.cpp && generate_tables
+
+#include <algorithm>
+#include <assert.h>
+#include <charconv>
+#include <cmath>
+#include <limits>
+#include <map>
+#include <stdint.h>
+#include <stdio.h>
+#include <system_error>
+#include <type_traits>
+#include <vector>
+using namespace std;
+
+template <typename UInt, typename Pred>
+[[nodiscard]] UInt uint_partition_point(UInt first, const UInt last, Pred pred) {
+    // Find the beginning of the false partition in [first, last).
+    // [first, last) is partitioned when all of the true values occur before all of the false values.
+
+    static_assert(is_unsigned_v<UInt>);
+    assert(first <= last);
+
+    for (UInt n = last - first; n > 0;) {
+        const UInt n2  = n / 2;
+        const UInt mid = first + n2;
+
+        if (pred(mid)) {
+            first = mid + 1;
+            n     = n - n2 - 1;
+        } else {
+            n = n2;
+        }
+    }
+
+    return first;
+}
+
+template <typename Floating>
+[[nodiscard]] int scientific_exponent_X(const int P, const Floating flt) {
+    char buf[400]; // more than enough
+
+    // C11 7.21.6.1 "The fprintf function"/8 performs trial formatting with scientific precision P - 1.
+    const auto to_result = to_chars(buf, end(buf), flt, chars_format::scientific, P - 1);
+    assert(to_result.ec == errc{});
+
+    const char* exp_ptr = find(buf, to_result.ptr, 'e');
+    assert(exp_ptr != to_result.ptr);
+
+    ++exp_ptr; // advance past 'e'
+
+    if (*exp_ptr == '+') {
+        ++exp_ptr; // advance past '+' which from_chars() won't parse
+    }
+
+    int X;
+    const auto from_result = from_chars(exp_ptr, to_result.ptr, X);
+    assert(from_result.ec == errc{});
+    return X;
+}
+
+template <typename UInt>
+void print_table(const vector<UInt>& v, const char* const name) {
+    constexpr const char* UIntName = _IsSame<UInt, uint32_t>::value ? "uint32_t" : "uint64_t";
+
+    printf("static constexpr %s %s[%zu] = {\n", UIntName, name, v.size());
+
+    for (const auto& val : v) {
+        if constexpr (_IsSame<UInt, uint32_t>::value) {
+            printf("0x%08Xu,\n", val);
+        } else {
+            printf("0x%016llXu,\n", val);
+        }
+    }
+
+    printf("};\n");
+}
+
+enum class Mode { Tables, Tests };
+
+template <typename Floating>
+void generate_tables(const Mode mode) {
+    using Limits = numeric_limits<Floating>;
+    using UInt   = conditional_t<_IsSame<Floating, float>::value, uint32_t, uint64_t>;
+
+    map<int, map<int, UInt>> P_X_LargestValWithX;
+
+    constexpr int MaxP = Limits::max_exponent10 + 1; // MaxP performs no rounding during trial formatting
+
+    for (int P = 1; P <= MaxP; ++P) {
+        for (int X = -5; X < P; ++X) {
+            constexpr Floating first = static_cast<Floating>(9e-5); // well below 9.5e-5, otherwise arbitrary
+            constexpr Floating last  = Limits::infinity(); // one bit above Limits::max()
+
+            const UInt val_beyond_X = uint_partition_point(reinterpret_cast<const UInt&>(first),
+                reinterpret_cast<const UInt&>(last),
+                [P, X](const UInt u) { return scientific_exponent_X(P, reinterpret_cast<const Floating&>(u)) <= X; });
+
+            P_X_LargestValWithX[P][X] = val_beyond_X - 1;
+        }
+    }
+
+    constexpr const char* FloatingName = _IsSame<Floating, float>::value ? "float" : "double";
+
+    constexpr int MaxSpecialP = _IsSame<Floating, float>::value ? 7 : 15; // MaxSpecialP is affected by exponent adjustment
+
+    if (mode == Mode::Tables) {
+        printf("template <>\n");
+        printf("struct _General_precision_tables<%s> {\n", FloatingName);
+
+        printf("static constexpr int _Max_special_P = %d;\n", MaxSpecialP);
+
+        vector<UInt> special;
+
+        for (int P = 1; P <= MaxSpecialP; ++P) {
+            for (int X = -5; X < P; ++X) {
+                const UInt val = P_X_LargestValWithX[P][X];
+                special.push_back(val);
+            }
+        }
+
+        print_table(special, "_Special_X_table");
+
+        for (int P = MaxSpecialP + 1; P < MaxP; ++P) {
+            for (int X = -5; X < P; ++X) {
+                const UInt val = P_X_LargestValWithX[P][X];
+                assert(val == P_X_LargestValWithX[MaxP][X]);
+            }
+        }
+
+        printf("static constexpr int _Max_P = %d;\n", MaxP);
+
+        vector<UInt> ordinary;
+
+        for (int X = -5; X < MaxP; ++X) {
+            const UInt val = P_X_LargestValWithX[MaxP][X];
+            ordinary.push_back(val);
+        }
+
+        print_table(ordinary, "_Ordinary_X_table");
+
+        printf("};\n");
+    } else {
+        printf("==========\n");
+        printf("Test cases for %s:\n", FloatingName);
+
+        constexpr int Hexits         = _IsSame<Floating, float>::value ? 6 : 13;
+        constexpr const char* Suffix = _IsSame<Floating, float>::value ? "f" : "";
+
+        for (int P = 1; P <= MaxP; ++P) {
+            for (int X = -5; X < P; ++X) {
+                if (P <= MaxSpecialP || P == 25 || P == MaxP || X == P - 1) {
+                    const UInt val1   = P_X_LargestValWithX[P][X];
+                    const Floating f1 = reinterpret_cast<const Floating&>(val1);
+                    const UInt val2   = val1 + 1;
+                    const Floating f2 = reinterpret_cast<const Floating&>(val2);
+
+                    printf("{%.*a%s, chars_format::general, %d, \"%.*g\"},\n", Hexits, f1, Suffix, P, P, f1);
+                    if (isfinite(f2)) {
+                        printf("{%.*a%s, chars_format::general, %d, \"%.*g\"},\n", Hexits, f2, Suffix, P, P, f2);
+                    }
+                }
+            }
+        }
+    }
+}
+
+int main() {
+    printf("template <class _Floating>\n");
+    printf("struct _General_precision_tables;\n");
+    generate_tables<float>(Mode::Tables);
+    generate_tables<double>(Mode::Tables);
+    generate_tables<float>(Mode::Tests);
+    generate_tables<double>(Mode::Tests);
+}
+#endif // 0
+
+template <class _Floating>
+struct _General_precision_tables;
+
+template <>
+struct _General_precision_tables<float> {
+    static constexpr int _Max_special_P = 7;
+
+    static constexpr uint32_t _Special_X_table[63] = {0x38C73ABCu, 0x3A79096Bu, 0x3C1BA5E3u, 0x3DC28F5Cu, 0x3F733333u,
+        0x4117FFFFu, 0x38D0AAA7u, 0x3A826AA8u, 0x3C230553u, 0x3DCBC6A7u, 0x3F7EB851u, 0x411F3333u, 0x42C6FFFFu,
+        0x38D19C3Fu, 0x3A8301A7u, 0x3C23C211u, 0x3DCCB295u, 0x3F7FDF3Bu, 0x411FEB85u, 0x42C7E666u, 0x4479DFFFu,
+        0x38D1B468u, 0x3A8310C1u, 0x3C23D4F1u, 0x3DCCCA2Du, 0x3F7FFCB9u, 0x411FFDF3u, 0x42C7FD70u, 0x4479FCCCu,
+        0x461C3DFFu, 0x38D1B6D2u, 0x3A831243u, 0x3C23D6D4u, 0x3DCCCC89u, 0x3F7FFFACu, 0x411FFFCBu, 0x42C7FFBEu,
+        0x4479FFAEu, 0x461C3FCCu, 0x47C34FBFu, 0x38D1B710u, 0x3A83126Au, 0x3C23D704u, 0x3DCCCCC6u, 0x3F7FFFF7u,
+        0x411FFFFAu, 0x42C7FFF9u, 0x4479FFF7u, 0x461C3FFAu, 0x47C34FF9u, 0x497423F7u, 0x38D1B716u, 0x3A83126Eu,
+        0x3C23D709u, 0x3DCCCCCCu, 0x3F7FFFFFu, 0x411FFFFFu, 0x42C7FFFFu, 0x4479FFFFu, 0x461C3FFFu, 0x47C34FFFu,
+        0x497423FFu, 0x4B18967Fu};
+
+    static constexpr int _Max_P = 39;
+
+    static constexpr uint32_t _Ordinary_X_table[44] = {0x38D1B717u, 0x3A83126Eu, 0x3C23D70Au, 0x3DCCCCCCu, 0x3F7FFFFFu,
+        0x411FFFFFu, 0x42C7FFFFu, 0x4479FFFFu, 0x461C3FFFu, 0x47C34FFFu, 0x497423FFu, 0x4B18967Fu, 0x4CBEBC1Fu,
+        0x4E6E6B27u, 0x501502F8u, 0x51BA43B7u, 0x5368D4A5u, 0x551184E7u, 0x56B5E620u, 0x58635FA9u, 0x5A0E1BC9u,
+        0x5BB1A2BCu, 0x5D5E0B6Bu, 0x5F0AC723u, 0x60AD78EBu, 0x6258D726u, 0x64078678u, 0x65A96816u, 0x6753C21Bu,
+        0x69045951u, 0x6AA56FA5u, 0x6C4ECB8Fu, 0x6E013F39u, 0x6FA18F07u, 0x7149F2C9u, 0x72FC6F7Cu, 0x749DC5ADu,
+        0x76453719u, 0x77F684DFu, 0x799A130Bu, 0x7B4097CEu, 0x7CF0BDC2u, 0x7E967699u, 0x7F7FFFFFu};
+};
+
+template <>
+struct _General_precision_tables<double> {
+    static constexpr int _Max_special_P = 15;
+
+    static constexpr uint64_t _Special_X_table[195] = {0x3F18E757928E0C9Du, 0x3F4F212D77318FC5u, 0x3F8374BC6A7EF9DBu,
+        0x3FB851EB851EB851u, 0x3FEE666666666666u, 0x4022FFFFFFFFFFFFu, 0x3F1A1554FBDAD751u, 0x3F504D551D68C692u,
+        0x3F8460AA64C2F837u, 0x3FB978D4FDF3B645u, 0x3FEFD70A3D70A3D7u, 0x4023E66666666666u, 0x4058DFFFFFFFFFFFu,
+        0x3F1A3387ECC8EB96u, 0x3F506034F3FD933Eu, 0x3F84784230FCF80Du, 0x3FB99652BD3C3611u, 0x3FEFFBE76C8B4395u,
+        0x4023FD70A3D70A3Du, 0x4058FCCCCCCCCCCCu, 0x408F3BFFFFFFFFFFu, 0x3F1A368D04E0BA6Au, 0x3F506218230C7482u,
+        0x3F847A9E2BCF91A3u, 0x3FB99945B6C3760Bu, 0x3FEFFF972474538Eu, 0x4023FFBE76C8B439u, 0x4058FFAE147AE147u,
+        0x408F3F9999999999u, 0x40C387BFFFFFFFFFu, 0x3F1A36DA54164F19u, 0x3F506248748DF16Fu, 0x3F847ADA91B16DCBu,
+        0x3FB99991361DC93Eu, 0x3FEFFFF583A53B8Eu, 0x4023FFF972474538u, 0x4058FFF7CED91687u, 0x408F3FF5C28F5C28u,
+        0x40C387F999999999u, 0x40F869F7FFFFFFFFu, 0x3F1A36E20F35445Du, 0x3F50624D49814ABAu, 0x3F847AE09BE19D69u,
+        0x3FB99998C2DA04C3u, 0x3FEFFFFEF39085F4u, 0x4023FFFF583A53B8u, 0x4058FFFF2E48E8A7u, 0x408F3FFEF9DB22D0u,
+        0x40C387FF5C28F5C2u, 0x40F869FF33333333u, 0x412E847EFFFFFFFFu, 0x3F1A36E2D51EC34Bu, 0x3F50624DC5333A0Eu,
+        0x3F847AE136800892u, 0x3FB9999984200AB7u, 0x3FEFFFFFE5280D65u, 0x4023FFFFEF39085Fu, 0x4058FFFFEB074A77u,
+        0x408F3FFFE5C91D14u, 0x40C387FFEF9DB22Du, 0x40F869FFEB851EB8u, 0x412E847FE6666666u, 0x416312CFEFFFFFFFu,
+        0x3F1A36E2E8E94FFCu, 0x3F50624DD191D1FDu, 0x3F847AE145F6467Du, 0x3FB999999773D81Cu, 0x3FEFFFFFFD50CE23u,
+        0x4023FFFFFE5280D6u, 0x4058FFFFFDE7210Bu, 0x408F3FFFFD60E94Eu, 0x40C387FFFE5C91D1u, 0x40F869FFFDF3B645u,
+        0x412E847FFD70A3D7u, 0x416312CFFE666666u, 0x4197D783FDFFFFFFu, 0x3F1A36E2EAE3F7A7u, 0x3F50624DD2CE7AC8u,
+        0x3F847AE14782197Bu, 0x3FB9999999629FD9u, 0x3FEFFFFFFFBB47D0u, 0x4023FFFFFFD50CE2u, 0x4058FFFFFFCA501Au,
+        0x408F3FFFFFBCE421u, 0x40C387FFFFD60E94u, 0x40F869FFFFCB923Au, 0x412E847FFFBE76C8u, 0x416312CFFFD70A3Du,
+        0x4197D783FFCCCCCCu, 0x41CDCD64FFBFFFFFu, 0x3F1A36E2EB16A205u, 0x3F50624DD2EE2543u, 0x3F847AE147A9AE94u,
+        0x3FB9999999941A39u, 0x3FEFFFFFFFF920C8u, 0x4023FFFFFFFBB47Du, 0x4058FFFFFFFAA19Cu, 0x408F3FFFFFF94A03u,
+        0x40C387FFFFFBCE42u, 0x40F869FFFFFAC1D2u, 0x412E847FFFF97247u, 0x416312CFFFFBE76Cu, 0x4197D783FFFAE147u,
+        0x41CDCD64FFF99999u, 0x4202A05F1FFBFFFFu, 0x3F1A36E2EB1BB30Fu, 0x3F50624DD2F14FE9u, 0x3F847AE147ADA3E3u,
+        0x3FB9999999990CDCu, 0x3FEFFFFFFFFF5014u, 0x4023FFFFFFFF920Cu, 0x4058FFFFFFFF768Fu, 0x408F3FFFFFFF5433u,
+        0x40C387FFFFFF94A0u, 0x40F869FFFFFF79C8u, 0x412E847FFFFF583Au, 0x416312CFFFFF9724u, 0x4197D783FFFF7CEDu,
+        0x41CDCD64FFFF5C28u, 0x4202A05F1FFF9999u, 0x42374876E7FF7FFFu, 0x3F1A36E2EB1C34C3u, 0x3F50624DD2F1A0FAu,
+        0x3F847AE147AE0938u, 0x3FB9999999998B86u, 0x3FEFFFFFFFFFEE68u, 0x4023FFFFFFFFF501u, 0x4058FFFFFFFFF241u,
+        0x408F3FFFFFFFEED1u, 0x40C387FFFFFFF543u, 0x40F869FFFFFFF294u, 0x412E847FFFFFEF39u, 0x416312CFFFFFF583u,
+        0x4197D783FFFFF2E4u, 0x41CDCD64FFFFEF9Du, 0x4202A05F1FFFF5C2u, 0x42374876E7FFF333u, 0x426D1A94A1FFEFFFu,
+        0x3F1A36E2EB1C41BBu, 0x3F50624DD2F1A915u, 0x3F847AE147AE135Au, 0x3FB9999999999831u, 0x3FEFFFFFFFFFFE3Du,
+        0x4023FFFFFFFFFEE6u, 0x4058FFFFFFFFFEA0u, 0x408F3FFFFFFFFE48u, 0x40C387FFFFFFFEEDu, 0x40F869FFFFFFFEA8u,
+        0x412E847FFFFFFE52u, 0x416312CFFFFFFEF3u, 0x4197D783FFFFFEB0u, 0x41CDCD64FFFFFE5Cu, 0x4202A05F1FFFFEF9u,
+        0x42374876E7FFFEB8u, 0x426D1A94A1FFFE66u, 0x42A2309CE53FFEFFu, 0x3F1A36E2EB1C4307u, 0x3F50624DD2F1A9E4u,
+        0x3F847AE147AE145Eu, 0x3FB9999999999975u, 0x3FEFFFFFFFFFFFD2u, 0x4023FFFFFFFFFFE3u, 0x4058FFFFFFFFFFDCu,
+        0x408F3FFFFFFFFFD4u, 0x40C387FFFFFFFFE4u, 0x40F869FFFFFFFFDDu, 0x412E847FFFFFFFD5u, 0x416312CFFFFFFFE5u,
+        0x4197D783FFFFFFDEu, 0x41CDCD64FFFFFFD6u, 0x4202A05F1FFFFFE5u, 0x42374876E7FFFFDFu, 0x426D1A94A1FFFFD7u,
+        0x42A2309CE53FFFE6u, 0x42D6BCC41E8FFFDFu, 0x3F1A36E2EB1C4328u, 0x3F50624DD2F1A9F9u, 0x3F847AE147AE1477u,
+        0x3FB9999999999995u, 0x3FEFFFFFFFFFFFFBu, 0x4023FFFFFFFFFFFDu, 0x4058FFFFFFFFFFFCu, 0x408F3FFFFFFFFFFBu,
+        0x40C387FFFFFFFFFDu, 0x40F869FFFFFFFFFCu, 0x412E847FFFFFFFFBu, 0x416312CFFFFFFFFDu, 0x4197D783FFFFFFFCu,
+        0x41CDCD64FFFFFFFBu, 0x4202A05F1FFFFFFDu, 0x42374876E7FFFFFCu, 0x426D1A94A1FFFFFBu, 0x42A2309CE53FFFFDu,
+        0x42D6BCC41E8FFFFCu, 0x430C6BF52633FFFBu};
+
+    static constexpr int _Max_P = 309;
+
+    static constexpr uint64_t _Ordinary_X_table[314] = {0x3F1A36E2EB1C432Cu, 0x3F50624DD2F1A9FBu, 0x3F847AE147AE147Au,
+        0x3FB9999999999999u, 0x3FEFFFFFFFFFFFFFu, 0x4023FFFFFFFFFFFFu, 0x4058FFFFFFFFFFFFu, 0x408F3FFFFFFFFFFFu,
+        0x40C387FFFFFFFFFFu, 0x40F869FFFFFFFFFFu, 0x412E847FFFFFFFFFu, 0x416312CFFFFFFFFFu, 0x4197D783FFFFFFFFu,
+        0x41CDCD64FFFFFFFFu, 0x4202A05F1FFFFFFFu, 0x42374876E7FFFFFFu, 0x426D1A94A1FFFFFFu, 0x42A2309CE53FFFFFu,
+        0x42D6BCC41E8FFFFFu, 0x430C6BF52633FFFFu, 0x4341C37937E07FFFu, 0x4376345785D89FFFu, 0x43ABC16D674EC7FFu,
+        0x43E158E460913CFFu, 0x4415AF1D78B58C3Fu, 0x444B1AE4D6E2EF4Fu, 0x4480F0CF064DD591u, 0x44B52D02C7E14AF6u,
+        0x44EA784379D99DB4u, 0x45208B2A2C280290u, 0x4554ADF4B7320334u, 0x4589D971E4FE8401u, 0x45C027E72F1F1281u,
+        0x45F431E0FAE6D721u, 0x46293E5939A08CE9u, 0x465F8DEF8808B024u, 0x4693B8B5B5056E16u, 0x46C8A6E32246C99Cu,
+        0x46FED09BEAD87C03u, 0x4733426172C74D82u, 0x476812F9CF7920E2u, 0x479E17B84357691Bu, 0x47D2CED32A16A1B1u,
+        0x48078287F49C4A1Du, 0x483D6329F1C35CA4u, 0x48725DFA371A19E6u, 0x48A6F578C4E0A060u, 0x48DCB2D6F618C878u,
+        0x4911EFC659CF7D4Bu, 0x49466BB7F0435C9Eu, 0x497C06A5EC5433C6u, 0x49B18427B3B4A05Bu, 0x49E5E531A0A1C872u,
+        0x4A1B5E7E08CA3A8Fu, 0x4A511B0EC57E6499u, 0x4A8561D276DDFDC0u, 0x4ABABA4714957D30u, 0x4AF0B46C6CDD6E3Eu,
+        0x4B24E1878814C9CDu, 0x4B5A19E96A19FC40u, 0x4B905031E2503DA8u, 0x4BC4643E5AE44D12u, 0x4BF97D4DF19D6057u,
+        0x4C2FDCA16E04B86Du, 0x4C63E9E4E4C2F344u, 0x4C98E45E1DF3B015u, 0x4CCF1D75A5709C1Au, 0x4D03726987666190u,
+        0x4D384F03E93FF9F4u, 0x4D6E62C4E38FF872u, 0x4DA2FDBB0E39FB47u, 0x4DD7BD29D1C87A19u, 0x4E0DAC74463A989Fu,
+        0x4E428BC8ABE49F63u, 0x4E772EBAD6DDC73Cu, 0x4EACFA698C95390Bu, 0x4EE21C81F7DD43A7u, 0x4F16A3A275D49491u,
+        0x4F4C4C8B1349B9B5u, 0x4F81AFD6EC0E1411u, 0x4FB61BCCA7119915u, 0x4FEBA2BFD0D5FF5Bu, 0x502145B7E285BF98u,
+        0x50559725DB272F7Fu, 0x508AFCEF51F0FB5Eu, 0x50C0DE1593369D1Bu, 0x50F5159AF8044462u, 0x512A5B01B605557Au,
+        0x516078E111C3556Cu, 0x5194971956342AC7u, 0x51C9BCDFABC13579u, 0x5200160BCB58C16Cu, 0x52341B8EBE2EF1C7u,
+        0x526922726DBAAE39u, 0x529F6B0F092959C7u, 0x52D3A2E965B9D81Cu, 0x53088BA3BF284E23u, 0x533EAE8CAEF261ACu,
+        0x53732D17ED577D0Bu, 0x53A7F85DE8AD5C4Eu, 0x53DDF67562D8B362u, 0x5412BA095DC7701Du, 0x5447688BB5394C25u,
+        0x547D42AEA2879F2Eu, 0x54B249AD2594C37Cu, 0x54E6DC186EF9F45Cu, 0x551C931E8AB87173u, 0x5551DBF316B346E7u,
+        0x558652EFDC6018A1u, 0x55BBE7ABD3781ECAu, 0x55F170CB642B133Eu, 0x5625CCFE3D35D80Eu, 0x565B403DCC834E11u,
+        0x569108269FD210CBu, 0x56C54A3047C694FDu, 0x56FA9CBC59B83A3Du, 0x5730A1F5B8132466u, 0x5764CA732617ED7Fu,
+        0x5799FD0FEF9DE8DFu, 0x57D03E29F5C2B18Bu, 0x58044DB473335DEEu, 0x583961219000356Au, 0x586FB969F40042C5u,
+        0x58A3D3E2388029BBu, 0x58D8C8DAC6A0342Au, 0x590EFB1178484134u, 0x59435CEAEB2D28C0u, 0x59783425A5F872F1u,
+        0x59AE412F0F768FADu, 0x59E2E8BD69AA19CCu, 0x5A17A2ECC414A03Fu, 0x5A4D8BA7F519C84Fu, 0x5A827748F9301D31u,
+        0x5AB7151B377C247Eu, 0x5AECDA62055B2D9Du, 0x5B22087D4358FC82u, 0x5B568A9C942F3BA3u, 0x5B8C2D43B93B0A8Bu,
+        0x5BC19C4A53C4E697u, 0x5BF6035CE8B6203Du, 0x5C2B843422E3A84Cu, 0x5C6132A095CE492Fu, 0x5C957F48BB41DB7Bu,
+        0x5CCADF1AEA12525Au, 0x5D00CB70D24B7378u, 0x5D34FE4D06DE5056u, 0x5D6A3DE04895E46Cu, 0x5DA066AC2D5DAEC3u,
+        0x5DD4805738B51A74u, 0x5E09A06D06E26112u, 0x5E400444244D7CABu, 0x5E7405552D60DBD6u, 0x5EA906AA78B912CBu,
+        0x5EDF485516E7577Eu, 0x5F138D352E5096AFu, 0x5F48708279E4BC5Au, 0x5F7E8CA3185DEB71u, 0x5FB317E5EF3AB327u,
+        0x5FE7DDDF6B095FF0u, 0x601DD55745CBB7ECu, 0x6052A5568B9F52F4u, 0x60874EAC2E8727B1u, 0x60BD22573A28F19Du,
+        0x60F2357684599702u, 0x6126C2D4256FFCC2u, 0x615C73892ECBFBF3u, 0x6191C835BD3F7D78u, 0x61C63A432C8F5CD6u,
+        0x61FBC8D3F7B3340Bu, 0x62315D847AD00087u, 0x6265B4E5998400A9u, 0x629B221EFFE500D3u, 0x62D0F5535FEF2084u,
+        0x630532A837EAE8A5u, 0x633A7F5245E5A2CEu, 0x63708F936BAF85C1u, 0x63A4B378469B6731u, 0x63D9E056584240FDu,
+        0x64102C35F729689Eu, 0x6444374374F3C2C6u, 0x647945145230B377u, 0x64AF965966BCE055u, 0x64E3BDF7E0360C35u,
+        0x6518AD75D8438F43u, 0x654ED8D34E547313u, 0x6583478410F4C7ECu, 0x65B819651531F9E7u, 0x65EE1FBE5A7E7861u,
+        0x6622D3D6F88F0B3Cu, 0x665788CCB6B2CE0Cu, 0x668D6AFFE45F818Fu, 0x66C262DFEEBBB0F9u, 0x66F6FB97EA6A9D37u,
+        0x672CBA7DE5054485u, 0x6761F48EAF234AD3u, 0x679671B25AEC1D88u, 0x67CC0E1EF1A724EAu, 0x680188D357087712u,
+        0x6835EB082CCA94D7u, 0x686B65CA37FD3A0Du, 0x68A11F9E62FE4448u, 0x68D56785FBBDD55Au, 0x690AC1677AAD4AB0u,
+        0x6940B8E0ACAC4EAEu, 0x6974E718D7D7625Au, 0x69AA20DF0DCD3AF0u, 0x69E0548B68A044D6u, 0x6A1469AE42C8560Cu,
+        0x6A498419D37A6B8Fu, 0x6A7FE52048590672u, 0x6AB3EF342D37A407u, 0x6AE8EB0138858D09u, 0x6B1F25C186A6F04Cu,
+        0x6B537798F428562Fu, 0x6B88557F31326BBBu, 0x6BBE6ADEFD7F06AAu, 0x6BF302CB5E6F642Au, 0x6C27C37E360B3D35u,
+        0x6C5DB45DC38E0C82u, 0x6C9290BA9A38C7D1u, 0x6CC734E940C6F9C5u, 0x6CFD022390F8B837u, 0x6D3221563A9B7322u,
+        0x6D66A9ABC9424FEBu, 0x6D9C5416BB92E3E6u, 0x6DD1B48E353BCE6Fu, 0x6E0621B1C28AC20Bu, 0x6E3BAA1E332D728Eu,
+        0x6E714A52DFFC6799u, 0x6EA59CE797FB817Fu, 0x6EDB04217DFA61DFu, 0x6F10E294EEBC7D2Bu, 0x6F451B3A2A6B9C76u,
+        0x6F7A6208B5068394u, 0x6FB07D457124123Cu, 0x6FE49C96CD6D16CBu, 0x7019C3BC80C85C7Eu, 0x70501A55D07D39CFu,
+        0x708420EB449C8842u, 0x70B9292615C3AA53u, 0x70EF736F9B3494E8u, 0x7123A825C100DD11u, 0x7158922F31411455u,
+        0x718EB6BAFD91596Bu, 0x71C33234DE7AD7E2u, 0x71F7FEC216198DDBu, 0x722DFE729B9FF152u, 0x7262BF07A143F6D3u,
+        0x72976EC98994F488u, 0x72CD4A7BEBFA31AAu, 0x73024E8D737C5F0Au, 0x7336E230D05B76CDu, 0x736C9ABD04725480u,
+        0x73A1E0B622C774D0u, 0x73D658E3AB795204u, 0x740BEF1C9657A685u, 0x74417571DDF6C813u, 0x7475D2CE55747A18u,
+        0x74AB4781EAD1989Eu, 0x74E10CB132C2FF63u, 0x75154FDD7F73BF3Bu, 0x754AA3D4DF50AF0Au, 0x7580A6650B926D66u,
+        0x75B4CFFE4E7708C0u, 0x75EA03FDE214CAF0u, 0x7620427EAD4CFED6u, 0x7654531E58A03E8Bu, 0x768967E5EEC84E2Eu,
+        0x76BFC1DF6A7A61BAu, 0x76F3D92BA28C7D14u, 0x7728CF768B2F9C59u, 0x775F03542DFB8370u, 0x779362149CBD3226u,
+        0x77C83A99C3EC7EAFu, 0x77FE494034E79E5Bu, 0x7832EDC82110C2F9u, 0x7867A93A2954F3B7u, 0x789D9388B3AA30A5u,
+        0x78D27C35704A5E67u, 0x79071B42CC5CF601u, 0x793CE2137F743381u, 0x79720D4C2FA8A030u, 0x79A6909F3B92C83Du,
+        0x79DC34C70A777A4Cu, 0x7A11A0FC668AAC6Fu, 0x7A46093B802D578Bu, 0x7A7B8B8A6038AD6Eu, 0x7AB137367C236C65u,
+        0x7AE585041B2C477Eu, 0x7B1AE64521F7595Eu, 0x7B50CFEB353A97DAu, 0x7B8503E602893DD1u, 0x7BBA44DF832B8D45u,
+        0x7BF06B0BB1FB384Bu, 0x7C2485CE9E7A065Eu, 0x7C59A742461887F6u, 0x7C9008896BCF54F9u, 0x7CC40AABC6C32A38u,
+        0x7CF90D56B873F4C6u, 0x7D2F50AC6690F1F8u, 0x7D63926BC01A973Bu, 0x7D987706B0213D09u, 0x7DCE94C85C298C4Cu,
+        0x7E031CFD3999F7AFu, 0x7E37E43C8800759Bu, 0x7E6DDD4BAA009302u, 0x7EA2AA4F4A405BE1u, 0x7ED754E31CD072D9u,
+        0x7F0D2A1BE4048F90u, 0x7F423A516E82D9BAu, 0x7F76C8E5CA239028u, 0x7FAC7B1F3CAC7433u, 0x7FE1CCF385EBC89Fu,
+        0x7FEFFFFFFFFFFFFFu};
+};
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars_general_precision(
+    char* _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+    using _Traits    = _Floating_type_traits<_Floating>;
+    using _Uint_type = typename _Traits::_Uint_type;
+
+    const _Uint_type _Uint_value = _VSTD::bit_cast<_Uint_type>(_Value);
+
+    if (_Uint_value == 0) { // zero detected; write "0" and return; _Precision is irrelevant due to zero-trimming
+        if (_First == _Last) {
+            return {_Last, errc::value_too_large};
+        }
+
+        *_First++ = '0';
+
+        return {_First, errc{}};
+    }
+
+    // C11 7.21.6.1 "The fprintf function"/5:
+    // "A negative precision argument is taken as if the precision were omitted."
+    // /8: "g,G [...] Let P equal the precision if nonzero, 6 if the precision is omitted,
+    // or 1 if the precision is zero."
+
+    // Performance note: It's possible to rewrite this for branchless codegen,
+    // but profiling will be necessary to determine whether that's faster.
+    if (_Precision < 0) {
+        _Precision = 6;
+    } else if (_Precision == 0) {
+        _Precision = 1;
+    } else if (_Precision < 1'000'000) {
+        // _Precision is ok.
+    } else {
+        // Avoid integer overflow.
+        // Due to general notation's zero-trimming behavior, we can simply clamp _Precision.
+        // This is further clamped below.
+        _Precision = 1'000'000;
+    }
+
+    // _Precision is now the Standard's P.
+
+    // /8: "Then, if a conversion with style E would have an exponent of X:
+    // - if P > X >= -4, the conversion is with style f (or F) and precision P - (X + 1).
+    // - otherwise, the conversion is with style e (or E) and precision P - 1."
+
+    // /8: "Finally, [...] any trailing zeros are removed from the fractional portion of the result
+    // and the decimal-point character is removed if there is no fractional portion remaining."
+
+    using _Tables = _General_precision_tables<_Floating>;
+
+    const _Uint_type* _Table_begin;
+    const _Uint_type* _Table_end;
+
+    if (_Precision <= _Tables::_Max_special_P) {
+        _Table_begin = _Tables::_Special_X_table + (_Precision - 1) * (_Precision + 10) / 2;
+        _Table_end   = _Table_begin + _Precision + 5;
+    } else {
+        _Table_begin = _Tables::_Ordinary_X_table;
+        _Table_end   = _Table_begin + _VSTD::min(_Precision, _Tables::_Max_P) + 5;
+    }
+
+    // Profiling indicates that linear search is faster than binary search for small tables.
+    // Performance note: lambda captures may have a small performance cost.
+    const _Uint_type* const _Table_lower_bound = [=] {
+        if constexpr (!_IsSame<_Floating, float>::value) {
+            if (_Precision > 155) { // threshold determined via profiling
+                return _VSTD::lower_bound(_Table_begin, _Table_end, _Uint_value, less{});
+            }
+        }
+
+        return _VSTD::find_if(_Table_begin, _Table_end, [=](const _Uint_type _Elem) { return _Uint_value <= _Elem; });
+    }();
+
+    const ptrdiff_t _Table_index     = _Table_lower_bound - _Table_begin;
+    const int _Scientific_exponent_X = static_cast<int>(_Table_index - 5);
+    const bool _Use_fixed_notation   = _Precision > _Scientific_exponent_X && _Scientific_exponent_X >= -4;
+
+    // Performance note: it might (or might not) be faster to modify Ryu Printf to perform zero-trimming.
+    // Such modifications would involve a fairly complicated state machine (notably, both '0' and '9' digits would
+    // need to be buffered, due to rounding), and that would have performance costs due to increased branching.
+    // Here, we're using a simpler approach: writing into a local buffer, manually zero-trimming, and then copying into
+    // the output range. The necessary buffer size is reasonably small, the zero-trimming logic is simple and fast,
+    // and the final copying is also fast.
+
+    constexpr int _Max_output_length =
+        _IsSame<_Floating, float>::value ? 117 : 773; // cases: 0x1.fffffep-126f and 0x1.fffffffffffffp-1022
+    constexpr int _Max_fixed_precision =
+        _IsSame<_Floating, float>::value ? 37 : 66; // cases: 0x1.fffffep-14f and 0x1.fffffffffffffp-14
+    constexpr int _Max_scientific_precision =
+        _IsSame<_Floating, float>::value ? 111 : 766; // cases: 0x1.fffffep-126f and 0x1.fffffffffffffp-1022
+
+    // Note that _Max_output_length is determined by scientific notation and is more than enough for fixed notation.
+    // 0x1.fffffep+127f is 39 digits, plus 1 for '.', plus _Max_fixed_precision for '0' digits, equals 77.
+    // 0x1.fffffffffffffp+1023 is 309 digits, plus 1 for '.', plus _Max_fixed_precision for '0' digits, equals 376.
+
+    char _Buffer[_Max_output_length];
+    const char* const _Significand_first = _Buffer; // e.g. "1.234"
+    const char* _Significand_last        = nullptr;
+    const char* _Exponent_first          = nullptr; // e.g. "e-05"
+    const char* _Exponent_last           = nullptr;
+    int _Effective_precision; // number of digits printed after the decimal point, before trimming
+
+    // Write into the local buffer.
+    // Clamping _Effective_precision allows _Buffer to be as small as possible, and increases efficiency.
+    if (_Use_fixed_notation) {
+        _Effective_precision = _VSTD::min(_Precision - (_Scientific_exponent_X + 1), _Max_fixed_precision);
+        const to_chars_result _Buf_result =
+            _Floating_to_chars_fixed_precision(_Buffer, _VSTD::end(_Buffer), _Value, _Effective_precision);
+        _LIBCPP_ASSERT(_Buf_result.ec == errc{}, "");
+        _Significand_last = _Buf_result.ptr;
+    } else {
+        _Effective_precision = _VSTD::min(_Precision - 1, _Max_scientific_precision);
+        const to_chars_result _Buf_result =
+            _Floating_to_chars_scientific_precision(_Buffer, _VSTD::end(_Buffer), _Value, _Effective_precision);
+        _LIBCPP_ASSERT(_Buf_result.ec == errc{}, "");
+        _Significand_last = _VSTD::find(_Buffer, _Buf_result.ptr, 'e');
+        _Exponent_first   = _Significand_last;
+        _Exponent_last    = _Buf_result.ptr;
+    }
+
+    // If we printed a decimal point followed by digits, perform zero-trimming.
+    if (_Effective_precision > 0) {
+        while (_Significand_last[-1] == '0') { // will stop at '.' or a nonzero digit
+            --_Significand_last;
+        }
+
+        if (_Significand_last[-1] == '.') {
+            --_Significand_last;
+        }
+    }
+
+    // Copy the significand to the output range.
+    const ptrdiff_t _Significand_distance = _Significand_last - _Significand_first;
+    if (_Last - _First < _Significand_distance) {
+        return {_Last, errc::value_too_large};
+    }
+    _VSTD::memcpy(_First, _Significand_first, static_cast<size_t>(_Significand_distance));
+    _First += _Significand_distance;
+
+    // Copy the exponent to the output range.
+    if (!_Use_fixed_notation) {
+        const ptrdiff_t _Exponent_distance = _Exponent_last - _Exponent_first;
+        if (_Last - _First < _Exponent_distance) {
+            return {_Last, errc::value_too_large};
+        }
+        _VSTD::memcpy(_First, _Exponent_first, static_cast<size_t>(_Exponent_distance));
+        _First += _Exponent_distance;
+    }
+
+    return {_First, errc{}};
+}
+
+enum class _Floating_to_chars_overload { _Plain, _Format_only, _Format_precision };
+
+template <_Floating_to_chars_overload _Overload, class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars(
+    char* _First, char* const _Last, _Floating _Value, const chars_format _Fmt, const int _Precision) noexcept {
+
+    if constexpr (_Overload == _Floating_to_chars_overload::_Plain) {
+        _LIBCPP_ASSERT(_Fmt == chars_format{}, ""); // plain overload must pass chars_format{} internally
+    } else {
+        _LIBCPP_ASSERT(_Fmt == chars_format::general || _Fmt == chars_format::scientific || _Fmt == chars_format::fixed
+                         || _Fmt == chars_format::hex,
+            "invalid format in to_chars()");
+    }
+
+    using _Traits    = _Floating_type_traits<_Floating>;
+    using _Uint_type = typename _Traits::_Uint_type;
+
+    _Uint_type _Uint_value = _VSTD::bit_cast<_Uint_type>(_Value);
+
+    const bool _Was_negative = (_Uint_value & _Traits::_Shifted_sign_mask) != 0;
+
+    if (_Was_negative) { // sign bit detected; write minus sign and clear sign bit
+        if (_First == _Last) {
+            return {_Last, errc::value_too_large};
+        }
+
+        *_First++ = '-';
+
+        _Uint_value &= ~_Traits::_Shifted_sign_mask;
+        _Value = _VSTD::bit_cast<_Floating>(_Uint_value);
+    }
+
+    if ((_Uint_value & _Traits::_Shifted_exponent_mask) == _Traits::_Shifted_exponent_mask) {
+        // inf/nan detected; write appropriate string and return
+        const char* _Str;
+        size_t _Len;
+
+        const _Uint_type _Mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
+
+        if (_Mantissa == 0) {
+            _Str = "inf";
+            _Len = 3;
+        } else if (_Was_negative && _Mantissa == _Traits::_Special_nan_mantissa_mask) {
+            // When a NaN value has the sign bit set, the quiet bit set, and all other mantissa bits cleared,
+            // the UCRT interprets it to mean "indeterminate", and indicates this by printing "-nan(ind)".
+            _Str = "nan(ind)";
+            _Len = 8;
+        } else if ((_Mantissa & _Traits::_Special_nan_mantissa_mask) != 0) {
+            _Str = "nan";
+            _Len = 3;
+        } else {
+            _Str = "nan(snan)";
+            _Len = 9;
+        }
+
+        if (_Last - _First < static_cast<ptrdiff_t>(_Len)) {
+            return {_Last, errc::value_too_large};
+        }
+
+        _VSTD::memcpy(_First, _Str, _Len);
+
+        return {_First + _Len, errc{}};
+    }
+
+    if constexpr (_Overload == _Floating_to_chars_overload::_Plain) {
+        return _Floating_to_chars_ryu(_First, _Last, _Value, chars_format{});
+    } else if constexpr (_Overload == _Floating_to_chars_overload::_Format_only) {
+        if (_Fmt == chars_format::hex) {
+            return _Floating_to_chars_hex_shortest(_First, _Last, _Value);
+        }
+
+        return _Floating_to_chars_ryu(_First, _Last, _Value, _Fmt);
+    } else if constexpr (_Overload == _Floating_to_chars_overload::_Format_precision) {
+        switch (_Fmt) {
+        case chars_format::scientific:
+            return _Floating_to_chars_scientific_precision(_First, _Last, _Value, _Precision);
+        case chars_format::fixed:
+            return _Floating_to_chars_fixed_precision(_First, _Last, _Value, _Precision);
+        case chars_format::general:
+            return _Floating_to_chars_general_precision(_First, _Last, _Value, _Precision);
+        case chars_format::hex:
+        default: // avoid MSVC warning C4715: not all control paths return a value
+            return _Floating_to_chars_hex_precision(_First, _Last, _Value, _Precision);
+        }
+    }
+}
+
+// clang-format on
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
lib/libcxx/src/ryu/d2fixed.cpp
@@ -0,0 +1,669 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+#include "charconv"
+#include "cstring"
+#include "system_error"
+
+#include "include/ryu/common.h"
+#include "include/ryu/d2fixed.h"
+#include "include/ryu/d2fixed_full_table.h"
+#include "include/ryu/d2s.h"
+#include "include/ryu/d2s_intrinsics.h"
+#include "include/ryu/digit_table.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __POW10_ADDITIONAL_BITS = 120;
+
+#ifdef _LIBCPP_INTRINSIC128
+// Returns the low 64 bits of the high 128 bits of the 256-bit product of a and b.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __umul256_hi128_lo64(
+  const uint64_t __aHi, const uint64_t __aLo, const uint64_t __bHi, const uint64_t __bLo) {
+  uint64_t __b00Hi;
+  const uint64_t __b00Lo = __ryu_umul128(__aLo, __bLo, &__b00Hi);
+  uint64_t __b01Hi;
+  const uint64_t __b01Lo = __ryu_umul128(__aLo, __bHi, &__b01Hi);
+  uint64_t __b10Hi;
+  const uint64_t __b10Lo = __ryu_umul128(__aHi, __bLo, &__b10Hi);
+  uint64_t __b11Hi;
+  const uint64_t __b11Lo = __ryu_umul128(__aHi, __bHi, &__b11Hi);
+  (void) __b00Lo; // unused
+  (void) __b11Hi; // unused
+  const uint64_t __temp1Lo = __b10Lo + __b00Hi;
+  const uint64_t __temp1Hi = __b10Hi + (__temp1Lo < __b10Lo);
+  const uint64_t __temp2Lo = __b01Lo + __temp1Lo;
+  const uint64_t __temp2Hi = __b01Hi + (__temp2Lo < __b01Lo);
+  return __b11Lo + __temp1Hi + __temp2Hi;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __uint128_mod1e9(const uint64_t __vHi, const uint64_t __vLo) {
+  // After multiplying, we're going to shift right by 29, then truncate to uint32_t.
+  // This means that we need only 29 + 32 = 61 bits, so we can truncate to uint64_t before shifting.
+  const uint64_t __multiplied = __umul256_hi128_lo64(__vHi, __vLo, 0x89705F4136B4A597u, 0x31680A88F8953031u);
+
+  // For uint32_t truncation, see the __mod1e9() comment in d2s_intrinsics.h.
+  const uint32_t __shifted = static_cast<uint32_t>(__multiplied >> 29);
+
+  return static_cast<uint32_t>(__vLo) - 1000000000 * __shifted;
+}
+#endif // ^^^ intrinsics available ^^^
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulShift_mod1e9(const uint64_t __m, const uint64_t* const __mul, const int32_t __j) {
+  uint64_t __high0;                                               // 64
+  const uint64_t __low0 = __ryu_umul128(__m, __mul[0], &__high0); // 0
+  uint64_t __high1;                                               // 128
+  const uint64_t __low1 = __ryu_umul128(__m, __mul[1], &__high1); // 64
+  uint64_t __high2;                                               // 192
+  const uint64_t __low2 = __ryu_umul128(__m, __mul[2], &__high2); // 128
+  const uint64_t __s0low = __low0;                  // 0
+  (void) __s0low; // unused
+  const uint64_t __s0high = __low1 + __high0;       // 64
+  const uint32_t __c1 = __s0high < __low1;
+  const uint64_t __s1low = __low2 + __high1 + __c1; // 128
+  const uint32_t __c2 = __s1low < __low2; // __high1 + __c1 can't overflow, so compare against __low2
+  const uint64_t __s1high = __high2 + __c2;         // 192
+  _LIBCPP_ASSERT(__j >= 128, "");
+  _LIBCPP_ASSERT(__j <= 180, "");
+#ifdef _LIBCPP_INTRINSIC128
+  const uint32_t __dist = static_cast<uint32_t>(__j - 128); // __dist: [0, 52]
+  const uint64_t __shiftedhigh = __s1high >> __dist;
+  const uint64_t __shiftedlow = __ryu_shiftright128(__s1low, __s1high, __dist);
+  return __uint128_mod1e9(__shiftedhigh, __shiftedlow);
+#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
+  if (__j < 160) { // __j: [128, 160)
+    const uint64_t __r0 = __mod1e9(__s1high);
+    const uint64_t __r1 = __mod1e9((__r0 << 32) | (__s1low >> 32));
+    const uint64_t __r2 = ((__r1 << 32) | (__s1low & 0xffffffff));
+    return __mod1e9(__r2 >> (__j - 128));
+  } else { // __j: [160, 192)
+    const uint64_t __r0 = __mod1e9(__s1high);
+    const uint64_t __r1 = ((__r0 << 32) | (__s1low >> 32));
+    return __mod1e9(__r1 >> (__j - 160));
+  }
+#endif // ^^^ intrinsics unavailable ^^^
+}
+
+void __append_n_digits(const uint32_t __olength, uint32_t __digits, char* const __result) {
+  uint32_t __i = 0;
+  while (__digits >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+    const uint32_t __c = __digits - 10000 * (__digits / 10000);
+#else
+    const uint32_t __c = __digits % 10000;
+#endif
+    __digits /= 10000;
+    const uint32_t __c0 = (__c % 100) << 1;
+    const uint32_t __c1 = (__c / 100) << 1;
+    _VSTD::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c0, 2);
+    _VSTD::memcpy(__result + __olength - __i - 4, __DIGIT_TABLE + __c1, 2);
+    __i += 4;
+  }
+  if (__digits >= 100) {
+    const uint32_t __c = (__digits % 100) << 1;
+    __digits /= 100;
+    _VSTD::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c, 2);
+    __i += 2;
+  }
+  if (__digits >= 10) {
+    const uint32_t __c = __digits << 1;
+    _VSTD::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c, 2);
+  } else {
+    __result[0] = static_cast<char>('0' + __digits);
+  }
+}
+
+_LIBCPP_HIDE_FROM_ABI inline void __append_d_digits(const uint32_t __olength, uint32_t __digits, char* const __result) {
+  uint32_t __i = 0;
+  while (__digits >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+    const uint32_t __c = __digits - 10000 * (__digits / 10000);
+#else
+    const uint32_t __c = __digits % 10000;
+#endif
+    __digits /= 10000;
+    const uint32_t __c0 = (__c % 100) << 1;
+    const uint32_t __c1 = (__c / 100) << 1;
+    _VSTD::memcpy(__result + __olength + 1 - __i - 2, __DIGIT_TABLE + __c0, 2);
+    _VSTD::memcpy(__result + __olength + 1 - __i - 4, __DIGIT_TABLE + __c1, 2);
+    __i += 4;
+  }
+  if (__digits >= 100) {
+    const uint32_t __c = (__digits % 100) << 1;
+    __digits /= 100;
+    _VSTD::memcpy(__result + __olength + 1 - __i - 2, __DIGIT_TABLE + __c, 2);
+    __i += 2;
+  }
+  if (__digits >= 10) {
+    const uint32_t __c = __digits << 1;
+    __result[2] = __DIGIT_TABLE[__c + 1];
+    __result[1] = '.';
+    __result[0] = __DIGIT_TABLE[__c];
+  } else {
+    __result[1] = '.';
+    __result[0] = static_cast<char>('0' + __digits);
+  }
+}
+
+_LIBCPP_HIDE_FROM_ABI inline void __append_c_digits(const uint32_t __count, uint32_t __digits, char* const __result) {
+  uint32_t __i = 0;
+  for (; __i < __count - 1; __i += 2) {
+    const uint32_t __c = (__digits % 100) << 1;
+    __digits /= 100;
+    _VSTD::memcpy(__result + __count - __i - 2, __DIGIT_TABLE + __c, 2);
+  }
+  if (__i < __count) {
+    const char __c = static_cast<char>('0' + (__digits % 10));
+    __result[__count - __i - 1] = __c;
+  }
+}
+
+void __append_nine_digits(uint32_t __digits, char* const __result) {
+  if (__digits == 0) {
+    _VSTD::memset(__result, '0', 9);
+    return;
+  }
+
+  for (uint32_t __i = 0; __i < 5; __i += 4) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+    const uint32_t __c = __digits - 10000 * (__digits / 10000);
+#else
+    const uint32_t __c = __digits % 10000;
+#endif
+    __digits /= 10000;
+    const uint32_t __c0 = (__c % 100) << 1;
+    const uint32_t __c1 = (__c / 100) << 1;
+    _VSTD::memcpy(__result + 7 - __i, __DIGIT_TABLE + __c0, 2);
+    _VSTD::memcpy(__result + 5 - __i, __DIGIT_TABLE + __c1, 2);
+  }
+  __result[0] = static_cast<char>('0' + __digits);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __indexForExponent(const uint32_t __e) {
+  return (__e + 15) / 16;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow10BitsForIndex(const uint32_t __idx) {
+  return 16 * __idx + __POW10_ADDITIONAL_BITS;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __lengthForIndex(const uint32_t __idx) {
+  // +1 for ceil, +16 for mantissa, +8 to round up when dividing by 9
+  return (__log10Pow2(16 * static_cast<int32_t>(__idx)) + 1 + 16 + 8) / 9;
+}
+
+[[nodiscard]] to_chars_result __d2fixed_buffered_n(char* _First, char* const _Last, const double __d,
+  const uint32_t __precision) {
+  char* const _Original_first = _First;
+
+  const uint64_t __bits = __double_to_bits(__d);
+
+  // Case distinction; exit early for the easy cases.
+  if (__bits == 0) {
+    const int32_t _Total_zero_length = 1 // leading zero
+      + static_cast<int32_t>(__precision != 0) // possible decimal point
+      + static_cast<int32_t>(__precision); // zeroes after decimal point
+
+    if (_Last - _First < _Total_zero_length) {
+      return { _Last, errc::value_too_large };
+    }
+
+    *_First++ = '0';
+    if (__precision > 0) {
+      *_First++ = '.';
+      _VSTD::memset(_First, '0', __precision);
+      _First += __precision;
+    }
+    return { _First, errc{} };
+  }
+
+  // Decode __bits into mantissa and exponent.
+  const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
+  const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
+
+  int32_t __e2;
+  uint64_t __m2;
+  if (__ieeeExponent == 0) {
+    __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+    __m2 = __ieeeMantissa;
+  } else {
+    __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+    __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+  }
+
+  bool __nonzero = false;
+  if (__e2 >= -52) {
+    const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
+    const uint32_t __p10bits = __pow10BitsForIndex(__idx);
+    const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
+    for (int32_t __i = __len - 1; __i >= 0; --__i) {
+      const uint32_t __j = __p10bits - __e2;
+      // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+      // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+      const uint32_t __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT[__POW10_OFFSET[__idx] + __i],
+        static_cast<int32_t>(__j + 8));
+      if (__nonzero) {
+        if (_Last - _First < 9) {
+          return { _Last, errc::value_too_large };
+        }
+        __append_nine_digits(__digits, _First);
+        _First += 9;
+      } else if (__digits != 0) {
+        const uint32_t __olength = __decimalLength9(__digits);
+        if (_Last - _First < static_cast<ptrdiff_t>(__olength)) {
+          return { _Last, errc::value_too_large };
+        }
+        __append_n_digits(__olength, __digits, _First);
+        _First += __olength;
+        __nonzero = true;
+      }
+    }
+  }
+  if (!__nonzero) {
+    if (_First == _Last) {
+      return { _Last, errc::value_too_large };
+    }
+    *_First++ = '0';
+  }
+  if (__precision > 0) {
+    if (_First == _Last) {
+      return { _Last, errc::value_too_large };
+    }
+    *_First++ = '.';
+  }
+  if (__e2 < 0) {
+    const int32_t __idx = -__e2 / 16;
+    const uint32_t __blocks = __precision / 9 + 1;
+    // 0 = don't round up; 1 = round up unconditionally; 2 = round up if odd.
+    int __roundUp = 0;
+    uint32_t __i = 0;
+    if (__blocks <= __MIN_BLOCK_2[__idx]) {
+      __i = __blocks;
+      if (_Last - _First < static_cast<ptrdiff_t>(__precision)) {
+        return { _Last, errc::value_too_large };
+      }
+      _VSTD::memset(_First, '0', __precision);
+      _First += __precision;
+    } else if (__i < __MIN_BLOCK_2[__idx]) {
+      __i = __MIN_BLOCK_2[__idx];
+      if (_Last - _First < static_cast<ptrdiff_t>(9 * __i)) {
+        return { _Last, errc::value_too_large };
+      }
+      _VSTD::memset(_First, '0', 9 * __i);
+      _First += 9 * __i;
+    }
+    for (; __i < __blocks; ++__i) {
+      const int32_t __j = __ADDITIONAL_BITS_2 + (-__e2 - 16 * __idx);
+      const uint32_t __p = __POW10_OFFSET_2[__idx] + __i - __MIN_BLOCK_2[__idx];
+      if (__p >= __POW10_OFFSET_2[__idx + 1]) {
+        // If the remaining digits are all 0, then we might as well use memset.
+        // No rounding required in this case.
+        const uint32_t __fill = __precision - 9 * __i;
+        if (_Last - _First < static_cast<ptrdiff_t>(__fill)) {
+          return { _Last, errc::value_too_large };
+        }
+        _VSTD::memset(_First, '0', __fill);
+        _First += __fill;
+        break;
+      }
+      // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+      // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+      uint32_t __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT_2[__p], __j + 8);
+      if (__i < __blocks - 1) {
+        if (_Last - _First < 9) {
+          return { _Last, errc::value_too_large };
+        }
+        __append_nine_digits(__digits, _First);
+        _First += 9;
+      } else {
+        const uint32_t __maximum = __precision - 9 * __i;
+        uint32_t __lastDigit = 0;
+        for (uint32_t __k = 0; __k < 9 - __maximum; ++__k) {
+          __lastDigit = __digits % 10;
+          __digits /= 10;
+        }
+        if (__lastDigit != 5) {
+          __roundUp = __lastDigit > 5;
+        } else {
+          // Is m * 10^(additionalDigits + 1) / 2^(-__e2) integer?
+          const int32_t __requiredTwos = -__e2 - static_cast<int32_t>(__precision) - 1;
+          const bool __trailingZeros = __requiredTwos <= 0
+            || (__requiredTwos < 60 && __multipleOfPowerOf2(__m2, static_cast<uint32_t>(__requiredTwos)));
+          __roundUp = __trailingZeros ? 2 : 1;
+        }
+        if (__maximum > 0) {
+          if (_Last - _First < static_cast<ptrdiff_t>(__maximum)) {
+            return { _Last, errc::value_too_large };
+          }
+          __append_c_digits(__maximum, __digits, _First);
+          _First += __maximum;
+        }
+        break;
+      }
+    }
+    if (__roundUp != 0) {
+      char* _Round = _First;
+      char* _Dot = _Last;
+      while (true) {
+        if (_Round == _Original_first) {
+          _Round[0] = '1';
+          if (_Dot != _Last) {
+            _Dot[0] = '0';
+            _Dot[1] = '.';
+          }
+          if (_First == _Last) {
+            return { _Last, errc::value_too_large };
+          }
+          *_First++ = '0';
+          break;
+        }
+        --_Round;
+        const char __c = _Round[0];
+        if (__c == '.') {
+          _Dot = _Round;
+        } else if (__c == '9') {
+          _Round[0] = '0';
+          __roundUp = 1;
+        } else {
+          if (__roundUp == 1 || __c % 2 != 0) {
+            _Round[0] = __c + 1;
+          }
+          break;
+        }
+      }
+    }
+  } else {
+    if (_Last - _First < static_cast<ptrdiff_t>(__precision)) {
+      return { _Last, errc::value_too_large };
+    }
+    _VSTD::memset(_First, '0', __precision);
+    _First += __precision;
+  }
+  return { _First, errc{} };
+}
+
+[[nodiscard]] to_chars_result __d2exp_buffered_n(char* _First, char* const _Last, const double __d,
+  uint32_t __precision) {
+  char* const _Original_first = _First;
+
+  const uint64_t __bits = __double_to_bits(__d);
+
+  // Case distinction; exit early for the easy cases.
+  if (__bits == 0) {
+    const int32_t _Total_zero_length = 1 // leading zero
+      + static_cast<int32_t>(__precision != 0) // possible decimal point
+      + static_cast<int32_t>(__precision) // zeroes after decimal point
+      + 4; // "e+00"
+    if (_Last - _First < _Total_zero_length) {
+      return { _Last, errc::value_too_large };
+    }
+    *_First++ = '0';
+    if (__precision > 0) {
+      *_First++ = '.';
+      _VSTD::memset(_First, '0', __precision);
+      _First += __precision;
+    }
+    _VSTD::memcpy(_First, "e+00", 4);
+    _First += 4;
+    return { _First, errc{} };
+  }
+
+  // Decode __bits into mantissa and exponent.
+  const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
+  const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
+
+  int32_t __e2;
+  uint64_t __m2;
+  if (__ieeeExponent == 0) {
+    __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+    __m2 = __ieeeMantissa;
+  } else {
+    __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+    __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+  }
+
+  const bool __printDecimalPoint = __precision > 0;
+  ++__precision;
+  uint32_t __digits = 0;
+  uint32_t __printedDigits = 0;
+  uint32_t __availableDigits = 0;
+  int32_t __exp = 0;
+  if (__e2 >= -52) {
+    const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
+    const uint32_t __p10bits = __pow10BitsForIndex(__idx);
+    const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
+    for (int32_t __i = __len - 1; __i >= 0; --__i) {
+      const uint32_t __j = __p10bits - __e2;
+      // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+      // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+      __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT[__POW10_OFFSET[__idx] + __i],
+        static_cast<int32_t>(__j + 8));
+      if (__printedDigits != 0) {
+        if (__printedDigits + 9 > __precision) {
+          __availableDigits = 9;
+          break;
+        }
+        if (_Last - _First < 9) {
+          return { _Last, errc::value_too_large };
+        }
+        __append_nine_digits(__digits, _First);
+        _First += 9;
+        __printedDigits += 9;
+      } else if (__digits != 0) {
+        __availableDigits = __decimalLength9(__digits);
+        __exp = __i * 9 + static_cast<int32_t>(__availableDigits) - 1;
+        if (__availableDigits > __precision) {
+          break;
+        }
+        if (__printDecimalPoint) {
+          if (_Last - _First < static_cast<ptrdiff_t>(__availableDigits + 1)) {
+            return { _Last, errc::value_too_large };
+          }
+          __append_d_digits(__availableDigits, __digits, _First);
+          _First += __availableDigits + 1; // +1 for decimal point
+        } else {
+          if (_First == _Last) {
+            return { _Last, errc::value_too_large };
+          }
+          *_First++ = static_cast<char>('0' + __digits);
+        }
+        __printedDigits = __availableDigits;
+        __availableDigits = 0;
+      }
+    }
+  }
+
+  if (__e2 < 0 && __availableDigits == 0) {
+    const int32_t __idx = -__e2 / 16;
+    for (int32_t __i = __MIN_BLOCK_2[__idx]; __i < 200; ++__i) {
+      const int32_t __j = __ADDITIONAL_BITS_2 + (-__e2 - 16 * __idx);
+      const uint32_t __p = __POW10_OFFSET_2[__idx] + static_cast<uint32_t>(__i) - __MIN_BLOCK_2[__idx];
+      // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+      // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+      __digits = (__p >= __POW10_OFFSET_2[__idx + 1]) ? 0 : __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT_2[__p], __j + 8);
+      if (__printedDigits != 0) {
+        if (__printedDigits + 9 > __precision) {
+          __availableDigits = 9;
+          break;
+        }
+        if (_Last - _First < 9) {
+          return { _Last, errc::value_too_large };
+        }
+        __append_nine_digits(__digits, _First);
+        _First += 9;
+        __printedDigits += 9;
+      } else if (__digits != 0) {
+        __availableDigits = __decimalLength9(__digits);
+        __exp = -(__i + 1) * 9 + static_cast<int32_t>(__availableDigits) - 1;
+        if (__availableDigits > __precision) {
+          break;
+        }
+        if (__printDecimalPoint) {
+          if (_Last - _First < static_cast<ptrdiff_t>(__availableDigits + 1)) {
+            return { _Last, errc::value_too_large };
+          }
+          __append_d_digits(__availableDigits, __digits, _First);
+          _First += __availableDigits + 1; // +1 for decimal point
+        } else {
+          if (_First == _Last) {
+            return { _Last, errc::value_too_large };
+          }
+          *_First++ = static_cast<char>('0' + __digits);
+        }
+        __printedDigits = __availableDigits;
+        __availableDigits = 0;
+      }
+    }
+  }
+
+  const uint32_t __maximum = __precision - __printedDigits;
+  if (__availableDigits == 0) {
+    __digits = 0;
+  }
+  uint32_t __lastDigit = 0;
+  if (__availableDigits > __maximum) {
+    for (uint32_t __k = 0; __k < __availableDigits - __maximum; ++__k) {
+      __lastDigit = __digits % 10;
+      __digits /= 10;
+    }
+  }
+  // 0 = don't round up; 1 = round up unconditionally; 2 = round up if odd.
+  int __roundUp = 0;
+  if (__lastDigit != 5) {
+    __roundUp = __lastDigit > 5;
+  } else {
+    // Is m * 2^__e2 * 10^(__precision + 1 - __exp) integer?
+    // __precision was already increased by 1, so we don't need to write + 1 here.
+    const int32_t __rexp = static_cast<int32_t>(__precision) - __exp;
+    const int32_t __requiredTwos = -__e2 - __rexp;
+    bool __trailingZeros = __requiredTwos <= 0
+      || (__requiredTwos < 60 && __multipleOfPowerOf2(__m2, static_cast<uint32_t>(__requiredTwos)));
+    if (__rexp < 0) {
+      const int32_t __requiredFives = -__rexp;
+      __trailingZeros = __trailingZeros && __multipleOfPowerOf5(__m2, static_cast<uint32_t>(__requiredFives));
+    }
+    __roundUp = __trailingZeros ? 2 : 1;
+  }
+  if (__printedDigits != 0) {
+    if (_Last - _First < static_cast<ptrdiff_t>(__maximum)) {
+      return { _Last, errc::value_too_large };
+    }
+    if (__digits == 0) {
+      _VSTD::memset(_First, '0', __maximum);
+    } else {
+      __append_c_digits(__maximum, __digits, _First);
+    }
+    _First += __maximum;
+  } else {
+    if (__printDecimalPoint) {
+      if (_Last - _First < static_cast<ptrdiff_t>(__maximum + 1)) {
+        return { _Last, errc::value_too_large };
+      }
+      __append_d_digits(__maximum, __digits, _First);
+      _First += __maximum + 1; // +1 for decimal point
+    } else {
+      if (_First == _Last) {
+        return { _Last, errc::value_too_large };
+      }
+      *_First++ = static_cast<char>('0' + __digits);
+    }
+  }
+  if (__roundUp != 0) {
+    char* _Round = _First;
+    while (true) {
+      if (_Round == _Original_first) {
+        _Round[0] = '1';
+        ++__exp;
+        break;
+      }
+      --_Round;
+      const char __c = _Round[0];
+      if (__c == '.') {
+        // Keep going.
+      } else if (__c == '9') {
+        _Round[0] = '0';
+        __roundUp = 1;
+      } else {
+        if (__roundUp == 1 || __c % 2 != 0) {
+          _Round[0] = __c + 1;
+        }
+        break;
+      }
+    }
+  }
+
+  char _Sign_character;
+
+  if (__exp < 0) {
+    _Sign_character = '-';
+    __exp = -__exp;
+  } else {
+    _Sign_character = '+';
+  }
+
+  const int _Exponent_part_length = __exp >= 100
+    ? 5 // "e+NNN"
+    : 4; // "e+NN"
+
+  if (_Last - _First < _Exponent_part_length) {
+    return { _Last, errc::value_too_large };
+  }
+
+  *_First++ = 'e';
+  *_First++ = _Sign_character;
+
+  if (__exp >= 100) {
+    const int32_t __c = __exp % 10;
+    _VSTD::memcpy(_First, __DIGIT_TABLE + 2 * (__exp / 10), 2);
+    _First[2] = static_cast<char>('0' + __c);
+    _First += 3;
+  } else {
+    _VSTD::memcpy(_First, __DIGIT_TABLE + 2 * __exp, 2);
+    _First += 2;
+  }
+
+  return { _First, errc{} };
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
lib/libcxx/src/ryu/d2s.cpp
@@ -0,0 +1,782 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+#include "charconv"
+
+#include "include/ryu/common.h"
+#include "include/ryu/d2fixed.h"
+#include "include/ryu/d2s.h"
+#include "include/ryu/d2s_full_table.h"
+#include "include/ryu/d2s_intrinsics.h"
+#include "include/ryu/digit_table.h"
+#include "include/ryu/ryu.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// We need a 64x128-bit multiplication and a subsequent 128-bit shift.
+// Multiplication:
+//   The 64-bit factor is variable and passed in, the 128-bit factor comes
+//   from a lookup table. We know that the 64-bit factor only has 55
+//   significant bits (i.e., the 9 topmost bits are zeros). The 128-bit
+//   factor only has 124 significant bits (i.e., the 4 topmost bits are
+//   zeros).
+// Shift:
+//   In principle, the multiplication result requires 55 + 124 = 179 bits to
+//   represent. However, we then shift this value to the right by __j, which is
+//   at least __j >= 115, so the result is guaranteed to fit into 179 - 115 = 64
+//   bits. This means that we only need the topmost 64 significant bits of
+//   the 64x128-bit multiplication.
+//
+// There are several ways to do this:
+// 1. Best case: the compiler exposes a 128-bit type.
+//    We perform two 64x64-bit multiplications, add the higher 64 bits of the
+//    lower result to the higher result, and shift by __j - 64 bits.
+//
+//    We explicitly cast from 64-bit to 128-bit, so the compiler can tell
+//    that these are only 64-bit inputs, and can map these to the best
+//    possible sequence of assembly instructions.
+//    x64 machines happen to have matching assembly instructions for
+//    64x64-bit multiplications and 128-bit shifts.
+//
+// 2. Second best case: the compiler exposes intrinsics for the x64 assembly
+//    instructions mentioned in 1.
+//
+// 3. We only have 64x64 bit instructions that return the lower 64 bits of
+//    the result, i.e., we have to use plain C.
+//    Our inputs are less than the full width, so we have three options:
+//    a. Ignore this fact and just implement the intrinsics manually.
+//    b. Split both into 31-bit pieces, which guarantees no internal overflow,
+//       but requires extra work upfront (unless we change the lookup table).
+//    c. Split only the first factor into 31-bit pieces, which also guarantees
+//       no internal overflow, but requires extra work since the intermediate
+//       results are not perfectly aligned.
+#ifdef _LIBCPP_INTRINSIC128
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __mulShift(const uint64_t __m, const uint64_t* const __mul, const int32_t __j) {
+  // __m is maximum 55 bits
+  uint64_t __high1;                                               // 128
+  const uint64_t __low1 = __ryu_umul128(__m, __mul[1], &__high1); // 64
+  uint64_t __high0;                                               // 64
+  (void) __ryu_umul128(__m, __mul[0], &__high0);                  // 0
+  const uint64_t __sum = __high0 + __low1;
+  if (__sum < __high0) {
+    ++__high1; // overflow into __high1
+  }
+  return __ryu_shiftright128(__sum, __high1, static_cast<uint32_t>(__j - 64));
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __mulShiftAll(const uint64_t __m, const uint64_t* const __mul, const int32_t __j,
+  uint64_t* const __vp, uint64_t* const __vm, const uint32_t __mmShift) {
+  *__vp = __mulShift(4 * __m + 2, __mul, __j);
+  *__vm = __mulShift(4 * __m - 1 - __mmShift, __mul, __j);
+  return __mulShift(4 * __m, __mul, __j);
+}
+
+#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_ALWAYS_INLINE uint64_t __mulShiftAll(uint64_t __m, const uint64_t* const __mul, const int32_t __j,
+  uint64_t* const __vp, uint64_t* const __vm, const uint32_t __mmShift) { // TRANSITION, VSO-634761
+  __m <<= 1;
+  // __m is maximum 55 bits
+  uint64_t __tmp;
+  const uint64_t __lo = __ryu_umul128(__m, __mul[0], &__tmp);
+  uint64_t __hi;
+  const uint64_t __mid = __tmp + __ryu_umul128(__m, __mul[1], &__hi);
+  __hi += __mid < __tmp; // overflow into __hi
+
+  const uint64_t __lo2 = __lo + __mul[0];
+  const uint64_t __mid2 = __mid + __mul[1] + (__lo2 < __lo);
+  const uint64_t __hi2 = __hi + (__mid2 < __mid);
+  *__vp = __ryu_shiftright128(__mid2, __hi2, static_cast<uint32_t>(__j - 64 - 1));
+
+  if (__mmShift == 1) {
+    const uint64_t __lo3 = __lo - __mul[0];
+    const uint64_t __mid3 = __mid - __mul[1] - (__lo3 > __lo);
+    const uint64_t __hi3 = __hi - (__mid3 > __mid);
+    *__vm = __ryu_shiftright128(__mid3, __hi3, static_cast<uint32_t>(__j - 64 - 1));
+  } else {
+    const uint64_t __lo3 = __lo + __lo;
+    const uint64_t __mid3 = __mid + __mid + (__lo3 < __lo);
+    const uint64_t __hi3 = __hi + __hi + (__mid3 < __mid);
+    const uint64_t __lo4 = __lo3 - __mul[0];
+    const uint64_t __mid4 = __mid3 - __mul[1] - (__lo4 > __lo3);
+    const uint64_t __hi4 = __hi3 - (__mid4 > __mid3);
+    *__vm = __ryu_shiftright128(__mid4, __hi4, static_cast<uint32_t>(__j - 64));
+  }
+
+  return __ryu_shiftright128(__mid, __hi, static_cast<uint32_t>(__j - 64 - 1));
+}
+
+#endif // ^^^ intrinsics unavailable ^^^
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __decimalLength17(const uint64_t __v) {
+  // This is slightly faster than a loop.
+  // The average output length is 16.38 digits, so we check high-to-low.
+  // Function precondition: __v is not an 18, 19, or 20-digit number.
+  // (17 digits are sufficient for round-tripping.)
+  _LIBCPP_ASSERT(__v < 100000000000000000u, "");
+  if (__v >= 10000000000000000u) { return 17; }
+  if (__v >= 1000000000000000u) { return 16; }
+  if (__v >= 100000000000000u) { return 15; }
+  if (__v >= 10000000000000u) { return 14; }
+  if (__v >= 1000000000000u) { return 13; }
+  if (__v >= 100000000000u) { return 12; }
+  if (__v >= 10000000000u) { return 11; }
+  if (__v >= 1000000000u) { return 10; }
+  if (__v >= 100000000u) { return 9; }
+  if (__v >= 10000000u) { return 8; }
+  if (__v >= 1000000u) { return 7; }
+  if (__v >= 100000u) { return 6; }
+  if (__v >= 10000u) { return 5; }
+  if (__v >= 1000u) { return 4; }
+  if (__v >= 100u) { return 3; }
+  if (__v >= 10u) { return 2; }
+  return 1;
+}
+
+// A floating decimal representing m * 10^e.
+struct __floating_decimal_64 {
+  uint64_t __mantissa;
+  int32_t __exponent;
+};
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline __floating_decimal_64 __d2d(const uint64_t __ieeeMantissa, const uint32_t __ieeeExponent) {
+  int32_t __e2;
+  uint64_t __m2;
+  if (__ieeeExponent == 0) {
+    // We subtract 2 so that the bounds computation has 2 additional bits.
+    __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS - 2;
+    __m2 = __ieeeMantissa;
+  } else {
+    __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS - 2;
+    __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+  }
+  const bool __even = (__m2 & 1) == 0;
+  const bool __acceptBounds = __even;
+
+  // Step 2: Determine the interval of valid decimal representations.
+  const uint64_t __mv = 4 * __m2;
+  // Implicit bool -> int conversion. True is 1, false is 0.
+  const uint32_t __mmShift = __ieeeMantissa != 0 || __ieeeExponent <= 1;
+  // We would compute __mp and __mm like this:
+  // uint64_t __mp = 4 * __m2 + 2;
+  // uint64_t __mm = __mv - 1 - __mmShift;
+
+  // Step 3: Convert to a decimal power base using 128-bit arithmetic.
+  uint64_t __vr, __vp, __vm;
+  int32_t __e10;
+  bool __vmIsTrailingZeros = false;
+  bool __vrIsTrailingZeros = false;
+  if (__e2 >= 0) {
+    // I tried special-casing __q == 0, but there was no effect on performance.
+    // This expression is slightly faster than max(0, __log10Pow2(__e2) - 1).
+    const uint32_t __q = __log10Pow2(__e2) - (__e2 > 3);
+    __e10 = static_cast<int32_t>(__q);
+    const int32_t __k = __DOUBLE_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q)) - 1;
+    const int32_t __i = -__e2 + static_cast<int32_t>(__q) + __k;
+    __vr = __mulShiftAll(__m2, __DOUBLE_POW5_INV_SPLIT[__q], __i, &__vp, &__vm, __mmShift);
+    if (__q <= 21) {
+      // This should use __q <= 22, but I think 21 is also safe. Smaller values
+      // may still be safe, but it's more difficult to reason about them.
+      // Only one of __mp, __mv, and __mm can be a multiple of 5, if any.
+      const uint32_t __mvMod5 = static_cast<uint32_t>(__mv) - 5 * static_cast<uint32_t>(__div5(__mv));
+      if (__mvMod5 == 0) {
+        __vrIsTrailingZeros = __multipleOfPowerOf5(__mv, __q);
+      } else if (__acceptBounds) {
+        // Same as min(__e2 + (~__mm & 1), __pow5Factor(__mm)) >= __q
+        // <=> __e2 + (~__mm & 1) >= __q && __pow5Factor(__mm) >= __q
+        // <=> true && __pow5Factor(__mm) >= __q, since __e2 >= __q.
+        __vmIsTrailingZeros = __multipleOfPowerOf5(__mv - 1 - __mmShift, __q);
+      } else {
+        // Same as min(__e2 + 1, __pow5Factor(__mp)) >= __q.
+        __vp -= __multipleOfPowerOf5(__mv + 2, __q);
+      }
+    }
+  } else {
+    // This expression is slightly faster than max(0, __log10Pow5(-__e2) - 1).
+    const uint32_t __q = __log10Pow5(-__e2) - (-__e2 > 1);
+    __e10 = static_cast<int32_t>(__q) + __e2;
+    const int32_t __i = -__e2 - static_cast<int32_t>(__q);
+    const int32_t __k = __pow5bits(__i) - __DOUBLE_POW5_BITCOUNT;
+    const int32_t __j = static_cast<int32_t>(__q) - __k;
+    __vr = __mulShiftAll(__m2, __DOUBLE_POW5_SPLIT[__i], __j, &__vp, &__vm, __mmShift);
+    if (__q <= 1) {
+      // {__vr,__vp,__vm} is trailing zeros if {__mv,__mp,__mm} has at least __q trailing 0 bits.
+      // __mv = 4 * __m2, so it always has at least two trailing 0 bits.
+      __vrIsTrailingZeros = true;
+      if (__acceptBounds) {
+        // __mm = __mv - 1 - __mmShift, so it has 1 trailing 0 bit iff __mmShift == 1.
+        __vmIsTrailingZeros = __mmShift == 1;
+      } else {
+        // __mp = __mv + 2, so it always has at least one trailing 0 bit.
+        --__vp;
+      }
+    } else if (__q < 63) { // TRANSITION(ulfjack): Use a tighter bound here.
+      // We need to compute min(ntz(__mv), __pow5Factor(__mv) - __e2) >= __q - 1
+      // <=> ntz(__mv) >= __q - 1 && __pow5Factor(__mv) - __e2 >= __q - 1
+      // <=> ntz(__mv) >= __q - 1 (__e2 is negative and -__e2 >= __q)
+      // <=> (__mv & ((1 << (__q - 1)) - 1)) == 0
+      // We also need to make sure that the left shift does not overflow.
+      __vrIsTrailingZeros = __multipleOfPowerOf2(__mv, __q - 1);
+    }
+  }
+
+  // Step 4: Find the shortest decimal representation in the interval of valid representations.
+  int32_t __removed = 0;
+  uint8_t __lastRemovedDigit = 0;
+  uint64_t _Output;
+  // On average, we remove ~2 digits.
+  if (__vmIsTrailingZeros || __vrIsTrailingZeros) {
+    // General case, which happens rarely (~0.7%).
+    for (;;) {
+      const uint64_t __vpDiv10 = __div10(__vp);
+      const uint64_t __vmDiv10 = __div10(__vm);
+      if (__vpDiv10 <= __vmDiv10) {
+        break;
+      }
+      const uint32_t __vmMod10 = static_cast<uint32_t>(__vm) - 10 * static_cast<uint32_t>(__vmDiv10);
+      const uint64_t __vrDiv10 = __div10(__vr);
+      const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
+      __vmIsTrailingZeros &= __vmMod10 == 0;
+      __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+      __lastRemovedDigit = static_cast<uint8_t>(__vrMod10);
+      __vr = __vrDiv10;
+      __vp = __vpDiv10;
+      __vm = __vmDiv10;
+      ++__removed;
+    }
+    if (__vmIsTrailingZeros) {
+      for (;;) {
+        const uint64_t __vmDiv10 = __div10(__vm);
+        const uint32_t __vmMod10 = static_cast<uint32_t>(__vm) - 10 * static_cast<uint32_t>(__vmDiv10);
+        if (__vmMod10 != 0) {
+          break;
+        }
+        const uint64_t __vpDiv10 = __div10(__vp);
+        const uint64_t __vrDiv10 = __div10(__vr);
+        const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
+        __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+        __lastRemovedDigit = static_cast<uint8_t>(__vrMod10);
+        __vr = __vrDiv10;
+        __vp = __vpDiv10;
+        __vm = __vmDiv10;
+        ++__removed;
+      }
+    }
+    if (__vrIsTrailingZeros && __lastRemovedDigit == 5 && __vr % 2 == 0) {
+      // Round even if the exact number is .....50..0.
+      __lastRemovedDigit = 4;
+    }
+    // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+    _Output = __vr + ((__vr == __vm && (!__acceptBounds || !__vmIsTrailingZeros)) || __lastRemovedDigit >= 5);
+  } else {
+    // Specialized for the common case (~99.3%). Percentages below are relative to this.
+    bool __roundUp = false;
+    const uint64_t __vpDiv100 = __div100(__vp);
+    const uint64_t __vmDiv100 = __div100(__vm);
+    if (__vpDiv100 > __vmDiv100) { // Optimization: remove two digits at a time (~86.2%).
+      const uint64_t __vrDiv100 = __div100(__vr);
+      const uint32_t __vrMod100 = static_cast<uint32_t>(__vr) - 100 * static_cast<uint32_t>(__vrDiv100);
+      __roundUp = __vrMod100 >= 50;
+      __vr = __vrDiv100;
+      __vp = __vpDiv100;
+      __vm = __vmDiv100;
+      __removed += 2;
+    }
+    // Loop iterations below (approximately), without optimization above:
+    // 0: 0.03%, 1: 13.8%, 2: 70.6%, 3: 14.0%, 4: 1.40%, 5: 0.14%, 6+: 0.02%
+    // Loop iterations below (approximately), with optimization above:
+    // 0: 70.6%, 1: 27.8%, 2: 1.40%, 3: 0.14%, 4+: 0.02%
+    for (;;) {
+      const uint64_t __vpDiv10 = __div10(__vp);
+      const uint64_t __vmDiv10 = __div10(__vm);
+      if (__vpDiv10 <= __vmDiv10) {
+        break;
+      }
+      const uint64_t __vrDiv10 = __div10(__vr);
+      const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
+      __roundUp = __vrMod10 >= 5;
+      __vr = __vrDiv10;
+      __vp = __vpDiv10;
+      __vm = __vmDiv10;
+      ++__removed;
+    }
+    // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+    _Output = __vr + (__vr == __vm || __roundUp);
+  }
+  const int32_t __exp = __e10 + __removed;
+
+  __floating_decimal_64 __fd;
+  __fd.__exponent = __exp;
+  __fd.__mantissa = _Output;
+  return __fd;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result __to_chars(char* const _First, char* const _Last, const __floating_decimal_64 __v,
+  chars_format _Fmt, const double __f) {
+  // Step 5: Print the decimal representation.
+  uint64_t _Output = __v.__mantissa;
+  int32_t _Ryu_exponent = __v.__exponent;
+  const uint32_t __olength = __decimalLength17(_Output);
+  int32_t _Scientific_exponent = _Ryu_exponent + static_cast<int32_t>(__olength) - 1;
+
+  if (_Fmt == chars_format{}) {
+    int32_t _Lower;
+    int32_t _Upper;
+
+    if (__olength == 1) {
+      // Value | Fixed   | Scientific
+      // 1e-3  | "0.001" | "1e-03"
+      // 1e4   | "10000" | "1e+04"
+      _Lower = -3;
+      _Upper = 4;
+    } else {
+      // Value   | Fixed       | Scientific
+      // 1234e-7 | "0.0001234" | "1.234e-04"
+      // 1234e5  | "123400000" | "1.234e+08"
+      _Lower = -static_cast<int32_t>(__olength + 3);
+      _Upper = 5;
+    }
+
+    if (_Lower <= _Ryu_exponent && _Ryu_exponent <= _Upper) {
+      _Fmt = chars_format::fixed;
+    } else {
+      _Fmt = chars_format::scientific;
+    }
+  } else if (_Fmt == chars_format::general) {
+    // C11 7.21.6.1 "The fprintf function"/8:
+    // "Let P equal [...] 6 if the precision is omitted [...].
+    // Then, if a conversion with style E would have an exponent of X:
+    // - if P > X >= -4, the conversion is with style f [...].
+    // - otherwise, the conversion is with style e [...]."
+    if (-4 <= _Scientific_exponent && _Scientific_exponent < 6) {
+      _Fmt = chars_format::fixed;
+    } else {
+      _Fmt = chars_format::scientific;
+    }
+  }
+
+  if (_Fmt == chars_format::fixed) {
+    // Example: _Output == 1729, __olength == 4
+
+    // _Ryu_exponent | Printed  | _Whole_digits | _Total_fixed_length  | Notes
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //             2 | 172900   |  6            | _Whole_digits        | Ryu can't be used for printing
+    //             1 | 17290    |  5            | (sometimes adjusted) | when the trimmed digits are nonzero.
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //             0 | 1729     |  4            | _Whole_digits        | Unified length cases.
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //            -1 | 172.9    |  3            | __olength + 1        | This case can't happen for
+    //            -2 | 17.29    |  2            |                      | __olength == 1, but no additional
+    //            -3 | 1.729    |  1            |                      | code is needed to avoid it.
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //            -4 | 0.1729   |  0            | 2 - _Ryu_exponent    | C11 7.21.6.1 "The fprintf function"/8:
+    //            -5 | 0.01729  | -1            |                      | "If a decimal-point character appears,
+    //            -6 | 0.001729 | -2            |                      | at least one digit appears before it."
+
+    const int32_t _Whole_digits = static_cast<int32_t>(__olength) + _Ryu_exponent;
+
+    uint32_t _Total_fixed_length;
+    if (_Ryu_exponent >= 0) { // cases "172900" and "1729"
+      _Total_fixed_length = static_cast<uint32_t>(_Whole_digits);
+      if (_Output == 1) {
+        // Rounding can affect the number of digits.
+        // For example, 1e23 is exactly "99999999999999991611392" which is 23 digits instead of 24.
+        // We can use a lookup table to detect this and adjust the total length.
+        static constexpr uint8_t _Adjustment[309] = {
+          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,
+          1,1,0,0,1,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,1,0,1,0,1,1,0,0,0,0,1,1,1,
+          1,0,0,0,0,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,1,
+          1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,
+          0,1,0,1,0,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,0,1,0,1,1,0,0,0,1,
+          1,1,0,1,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,1,0,0,1,1,1,0,0,0,1,0,1,0,0,0,0,0,1,1,0,
+          0,1,0,1,1,1,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0,0,0,0,0,1,1,0,1,0 };
+        _Total_fixed_length -= _Adjustment[_Ryu_exponent];
+        // _Whole_digits doesn't need to be adjusted because these cases won't refer to it later.
+      }
+    } else if (_Whole_digits > 0) { // case "17.29"
+      _Total_fixed_length = __olength + 1;
+    } else { // case "0.001729"
+      _Total_fixed_length = static_cast<uint32_t>(2 - _Ryu_exponent);
+    }
+
+    if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
+      return { _Last, errc::value_too_large };
+    }
+
+    char* _Mid;
+    if (_Ryu_exponent > 0) { // case "172900"
+      bool _Can_use_ryu;
+
+      if (_Ryu_exponent > 22) { // 10^22 is the largest power of 10 that's exactly representable as a double.
+        _Can_use_ryu = false;
+      } else {
+        // Ryu generated X: __v.__mantissa * 10^_Ryu_exponent
+        // __v.__mantissa == 2^_Trailing_zero_bits * (__v.__mantissa >> _Trailing_zero_bits)
+        // 10^_Ryu_exponent == 2^_Ryu_exponent * 5^_Ryu_exponent
+
+        // _Trailing_zero_bits is [0, 56] (aside: because 2^56 is the largest power of 2
+        // with 17 decimal digits, which is double's round-trip limit.)
+        // _Ryu_exponent is [1, 22].
+        // Normalization adds [2, 52] (aside: at least 2 because the pre-normalized mantissa is at least 5).
+        // This adds up to [3, 130], which is well below double's maximum binary exponent 1023.
+
+        // Therefore, we just need to consider (__v.__mantissa >> _Trailing_zero_bits) * 5^_Ryu_exponent.
+
+        // If that product would exceed 53 bits, then X can't be exactly represented as a double.
+        // (That's not a problem for round-tripping, because X is close enough to the original double,
+        // but X isn't mathematically equal to the original double.) This requires a high-precision fallback.
+
+        // If the product is 53 bits or smaller, then X can be exactly represented as a double (and we don't
+        // need to re-synthesize it; the original double must have been X, because Ryu wouldn't produce the
+        // same output for two different doubles X and Y). This allows Ryu's output to be used (zero-filled).
+
+        // (2^53 - 1) / 5^0 (for indexing), (2^53 - 1) / 5^1, ..., (2^53 - 1) / 5^22
+        static constexpr uint64_t _Max_shifted_mantissa[23] = {
+          9007199254740991u, 1801439850948198u, 360287970189639u, 72057594037927u, 14411518807585u,
+          2882303761517u, 576460752303u, 115292150460u, 23058430092u, 4611686018u, 922337203u, 184467440u,
+          36893488u, 7378697u, 1475739u, 295147u, 59029u, 11805u, 2361u, 472u, 94u, 18u, 3u };
+
+        unsigned long _Trailing_zero_bits;
+#ifdef _LIBCPP_HAS_BITSCAN64
+        (void) _BitScanForward64(&_Trailing_zero_bits, __v.__mantissa); // __v.__mantissa is guaranteed nonzero
+#else // ^^^ 64-bit ^^^ / vvv 32-bit vvv
+        const uint32_t _Low_mantissa = static_cast<uint32_t>(__v.__mantissa);
+        if (_Low_mantissa != 0) {
+          (void) _BitScanForward(&_Trailing_zero_bits, _Low_mantissa);
+        } else {
+          const uint32_t _High_mantissa = static_cast<uint32_t>(__v.__mantissa >> 32); // nonzero here
+          (void) _BitScanForward(&_Trailing_zero_bits, _High_mantissa);
+          _Trailing_zero_bits += 32;
+        }
+#endif // ^^^ 32-bit ^^^
+        const uint64_t _Shifted_mantissa = __v.__mantissa >> _Trailing_zero_bits;
+        _Can_use_ryu = _Shifted_mantissa <= _Max_shifted_mantissa[_Ryu_exponent];
+      }
+
+      if (!_Can_use_ryu) {
+        // Print the integer exactly.
+        // Performance note: This will redundantly perform bounds checking.
+        // Performance note: This will redundantly decompose the IEEE representation.
+        return __d2fixed_buffered_n(_First, _Last, __f, 0);
+      }
+
+      // _Can_use_ryu
+      // Print the decimal digits, left-aligned within [_First, _First + _Total_fixed_length).
+      _Mid = _First + __olength;
+    } else { // cases "1729", "17.29", and "0.001729"
+      // Print the decimal digits, right-aligned within [_First, _First + _Total_fixed_length).
+      _Mid = _First + _Total_fixed_length;
+    }
+
+    // We prefer 32-bit operations, even on 64-bit platforms.
+    // We have at most 17 digits, and uint32_t can store 9 digits.
+    // If _Output doesn't fit into uint32_t, we cut off 8 digits,
+    // so the rest will fit into uint32_t.
+    if ((_Output >> 32) != 0) {
+      // Expensive 64-bit division.
+      const uint64_t __q = __div1e8(_Output);
+      uint32_t __output2 = static_cast<uint32_t>(_Output - 100000000 * __q);
+      _Output = __q;
+
+      const uint32_t __c = __output2 % 10000;
+      __output2 /= 10000;
+      const uint32_t __d = __output2 % 10000;
+      const uint32_t __c0 = (__c % 100) << 1;
+      const uint32_t __c1 = (__c / 100) << 1;
+      const uint32_t __d0 = (__d % 100) << 1;
+      const uint32_t __d1 = (__d / 100) << 1;
+
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __d0, 2);
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __d1, 2);
+    }
+    uint32_t __output2 = static_cast<uint32_t>(_Output);
+    while (__output2 >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+      const uint32_t __c = __output2 - 10000 * (__output2 / 10000);
+#else
+      const uint32_t __c = __output2 % 10000;
+#endif
+      __output2 /= 10000;
+      const uint32_t __c0 = (__c % 100) << 1;
+      const uint32_t __c1 = (__c / 100) << 1;
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
+    }
+    if (__output2 >= 100) {
+      const uint32_t __c = (__output2 % 100) << 1;
+      __output2 /= 100;
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+    }
+    if (__output2 >= 10) {
+      const uint32_t __c = __output2 << 1;
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+    } else {
+      *--_Mid = static_cast<char>('0' + __output2);
+    }
+
+    if (_Ryu_exponent > 0) { // case "172900" with _Can_use_ryu
+      // Performance note: it might be more efficient to do this immediately after setting _Mid.
+      _VSTD::memset(_First + __olength, '0', static_cast<size_t>(_Ryu_exponent));
+    } else if (_Ryu_exponent == 0) { // case "1729"
+      // Done!
+    } else if (_Whole_digits > 0) { // case "17.29"
+      // Performance note: moving digits might not be optimal.
+      _VSTD::memmove(_First, _First + 1, static_cast<size_t>(_Whole_digits));
+      _First[_Whole_digits] = '.';
+    } else { // case "0.001729"
+      // Performance note: a larger memset() followed by overwriting '.' might be more efficient.
+      _First[0] = '0';
+      _First[1] = '.';
+      _VSTD::memset(_First + 2, '0', static_cast<size_t>(-_Whole_digits));
+    }
+
+    return { _First + _Total_fixed_length, errc{} };
+  }
+
+  const uint32_t _Total_scientific_length = __olength + (__olength > 1) // digits + possible decimal point
+    + (-100 < _Scientific_exponent && _Scientific_exponent < 100 ? 4 : 5); // + scientific exponent
+  if (_Last - _First < static_cast<ptrdiff_t>(_Total_scientific_length)) {
+    return { _Last, errc::value_too_large };
+  }
+  char* const __result = _First;
+
+  // Print the decimal digits.
+  uint32_t __i = 0;
+  // We prefer 32-bit operations, even on 64-bit platforms.
+  // We have at most 17 digits, and uint32_t can store 9 digits.
+  // If _Output doesn't fit into uint32_t, we cut off 8 digits,
+  // so the rest will fit into uint32_t.
+  if ((_Output >> 32) != 0) {
+    // Expensive 64-bit division.
+    const uint64_t __q = __div1e8(_Output);
+    uint32_t __output2 = static_cast<uint32_t>(_Output) - 100000000 * static_cast<uint32_t>(__q);
+    _Output = __q;
+
+    const uint32_t __c = __output2 % 10000;
+    __output2 /= 10000;
+    const uint32_t __d = __output2 % 10000;
+    const uint32_t __c0 = (__c % 100) << 1;
+    const uint32_t __c1 = (__c / 100) << 1;
+    const uint32_t __d0 = (__d % 100) << 1;
+    const uint32_t __d1 = (__d / 100) << 1;
+    _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
+    _VSTD::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
+    _VSTD::memcpy(__result + __olength - __i - 5, __DIGIT_TABLE + __d0, 2);
+    _VSTD::memcpy(__result + __olength - __i - 7, __DIGIT_TABLE + __d1, 2);
+    __i += 8;
+  }
+  uint32_t __output2 = static_cast<uint32_t>(_Output);
+  while (__output2 >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+    const uint32_t __c = __output2 - 10000 * (__output2 / 10000);
+#else
+    const uint32_t __c = __output2 % 10000;
+#endif
+    __output2 /= 10000;
+    const uint32_t __c0 = (__c % 100) << 1;
+    const uint32_t __c1 = (__c / 100) << 1;
+    _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
+    _VSTD::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
+    __i += 4;
+  }
+  if (__output2 >= 100) {
+    const uint32_t __c = (__output2 % 100) << 1;
+    __output2 /= 100;
+    _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c, 2);
+    __i += 2;
+  }
+  if (__output2 >= 10) {
+    const uint32_t __c = __output2 << 1;
+    // We can't use memcpy here: the decimal dot goes between these two digits.
+    __result[2] = __DIGIT_TABLE[__c + 1];
+    __result[0] = __DIGIT_TABLE[__c];
+  } else {
+    __result[0] = static_cast<char>('0' + __output2);
+  }
+
+  // Print decimal point if needed.
+  uint32_t __index;
+  if (__olength > 1) {
+    __result[1] = '.';
+    __index = __olength + 1;
+  } else {
+    __index = 1;
+  }
+
+  // Print the exponent.
+  __result[__index++] = 'e';
+  if (_Scientific_exponent < 0) {
+    __result[__index++] = '-';
+    _Scientific_exponent = -_Scientific_exponent;
+  } else {
+    __result[__index++] = '+';
+  }
+
+  if (_Scientific_exponent >= 100) {
+    const int32_t __c = _Scientific_exponent % 10;
+    _VSTD::memcpy(__result + __index, __DIGIT_TABLE + 2 * (_Scientific_exponent / 10), 2);
+    __result[__index + 2] = static_cast<char>('0' + __c);
+    __index += 3;
+  } else {
+    _VSTD::memcpy(__result + __index, __DIGIT_TABLE + 2 * _Scientific_exponent, 2);
+    __index += 2;
+  }
+
+  return { _First + _Total_scientific_length, errc{} };
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __d2d_small_int(const uint64_t __ieeeMantissa, const uint32_t __ieeeExponent,
+  __floating_decimal_64* const __v) {
+  const uint64_t __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+  const int32_t __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+
+  if (__e2 > 0) {
+    // f = __m2 * 2^__e2 >= 2^53 is an integer.
+    // Ignore this case for now.
+    return false;
+  }
+
+  if (__e2 < -52) {
+    // f < 1.
+    return false;
+  }
+
+  // Since 2^52 <= __m2 < 2^53 and 0 <= -__e2 <= 52: 1 <= f = __m2 / 2^-__e2 < 2^53.
+  // Test if the lower -__e2 bits of the significand are 0, i.e. whether the fraction is 0.
+  const uint64_t __mask = (1ull << -__e2) - 1;
+  const uint64_t __fraction = __m2 & __mask;
+  if (__fraction != 0) {
+    return false;
+  }
+
+  // f is an integer in the range [1, 2^53).
+  // Note: __mantissa might contain trailing (decimal) 0's.
+  // Note: since 2^53 < 10^16, there is no need to adjust __decimalLength17().
+  __v->__mantissa = __m2 >> -__e2;
+  __v->__exponent = 0;
+  return true;
+}
+
+[[nodiscard]] to_chars_result __d2s_buffered_n(char* const _First, char* const _Last, const double __f,
+  const chars_format _Fmt) {
+
+  // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
+  const uint64_t __bits = __double_to_bits(__f);
+
+  // Case distinction; exit early for the easy cases.
+  if (__bits == 0) {
+    if (_Fmt == chars_format::scientific) {
+      if (_Last - _First < 5) {
+        return { _Last, errc::value_too_large };
+      }
+
+      _VSTD::memcpy(_First, "0e+00", 5);
+
+      return { _First + 5, errc{} };
+    }
+
+    // Print "0" for chars_format::fixed, chars_format::general, and chars_format{}.
+    if (_First == _Last) {
+      return { _Last, errc::value_too_large };
+    }
+
+    *_First = '0';
+
+    return { _First + 1, errc{} };
+  }
+
+  // Decode __bits into mantissa and exponent.
+  const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
+  const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
+
+  if (_Fmt == chars_format::fixed) {
+    // const uint64_t _Mantissa2 = __ieeeMantissa | (1ull << __DOUBLE_MANTISSA_BITS); // restore implicit bit
+    const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
+      - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS; // bias and normalization
+
+    // Normal values are equal to _Mantissa2 * 2^_Exponent2.
+    // (Subnormals are different, but they'll be rejected by the _Exponent2 test here, so they can be ignored.)
+
+    // For nonzero integers, _Exponent2 >= -52. (The minimum value occurs when _Mantissa2 * 2^_Exponent2 is 1.
+    // In that case, _Mantissa2 is the implicit 1 bit followed by 52 zeros, so _Exponent2 is -52 to shift away
+    // the zeros.) The dense range of exactly representable integers has negative or zero exponents
+    // (as positive exponents make the range non-dense). For that dense range, Ryu will always be used:
+    // every digit is necessary to uniquely identify the value, so Ryu must print them all.
+
+    // Positive exponents are the non-dense range of exactly representable integers. This contains all of the values
+    // for which Ryu can't be used (and a few Ryu-friendly values). We can save time by detecting positive
+    // exponents here and skipping Ryu. Calling __d2fixed_buffered_n() with precision 0 is valid for all integers
+    // (so it's okay if we call it with a Ryu-friendly value).
+    if (_Exponent2 > 0) {
+      return __d2fixed_buffered_n(_First, _Last, __f, 0);
+    }
+  }
+
+  __floating_decimal_64 __v;
+  const bool __isSmallInt = __d2d_small_int(__ieeeMantissa, __ieeeExponent, &__v);
+  if (__isSmallInt) {
+    // For small integers in the range [1, 2^53), __v.__mantissa might contain trailing (decimal) zeros.
+    // For scientific notation we need to move these zeros into the exponent.
+    // (This is not needed for fixed-point notation, so it might be beneficial to trim
+    // trailing zeros in __to_chars only if needed - once fixed-point notation output is implemented.)
+    for (;;) {
+      const uint64_t __q = __div10(__v.__mantissa);
+      const uint32_t __r = static_cast<uint32_t>(__v.__mantissa) - 10 * static_cast<uint32_t>(__q);
+      if (__r != 0) {
+        break;
+      }
+      __v.__mantissa = __q;
+      ++__v.__exponent;
+    }
+  } else {
+    __v = __d2d(__ieeeMantissa, __ieeeExponent);
+  }
+
+  return __to_chars(_First, _Last, __v, _Fmt, __f);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
lib/libcxx/src/ryu/f2s.cpp
@@ -0,0 +1,715 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include "__config"
+#include "charconv"
+
+#include "include/ryu/common.h"
+#include "include/ryu/d2fixed.h"
+#include "include/ryu/d2s_intrinsics.h"
+#include "include/ryu/digit_table.h"
+#include "include/ryu/f2s.h"
+#include "include/ryu/ryu.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __FLOAT_MANTISSA_BITS = 23;
+inline constexpr int __FLOAT_EXPONENT_BITS = 8;
+inline constexpr int __FLOAT_BIAS = 127;
+
+inline constexpr int __FLOAT_POW5_INV_BITCOUNT = 59;
+inline constexpr uint64_t __FLOAT_POW5_INV_SPLIT[31] = {
+  576460752303423489u, 461168601842738791u, 368934881474191033u, 295147905179352826u,
+  472236648286964522u, 377789318629571618u, 302231454903657294u, 483570327845851670u,
+  386856262276681336u, 309485009821345069u, 495176015714152110u, 396140812571321688u,
+  316912650057057351u, 507060240091291761u, 405648192073033409u, 324518553658426727u,
+  519229685853482763u, 415383748682786211u, 332306998946228969u, 531691198313966350u,
+  425352958651173080u, 340282366920938464u, 544451787073501542u, 435561429658801234u,
+  348449143727040987u, 557518629963265579u, 446014903970612463u, 356811923176489971u,
+  570899077082383953u, 456719261665907162u, 365375409332725730u
+};
+inline constexpr int __FLOAT_POW5_BITCOUNT = 61;
+inline constexpr uint64_t __FLOAT_POW5_SPLIT[47] = {
+  1152921504606846976u, 1441151880758558720u, 1801439850948198400u, 2251799813685248000u,
+  1407374883553280000u, 1759218604441600000u, 2199023255552000000u, 1374389534720000000u,
+  1717986918400000000u, 2147483648000000000u, 1342177280000000000u, 1677721600000000000u,
+  2097152000000000000u, 1310720000000000000u, 1638400000000000000u, 2048000000000000000u,
+  1280000000000000000u, 1600000000000000000u, 2000000000000000000u, 1250000000000000000u,
+  1562500000000000000u, 1953125000000000000u, 1220703125000000000u, 1525878906250000000u,
+  1907348632812500000u, 1192092895507812500u, 1490116119384765625u, 1862645149230957031u,
+  1164153218269348144u, 1455191522836685180u, 1818989403545856475u, 2273736754432320594u,
+  1421085471520200371u, 1776356839400250464u, 2220446049250313080u, 1387778780781445675u,
+  1734723475976807094u, 2168404344971008868u, 1355252715606880542u, 1694065894508600678u,
+  2117582368135750847u, 1323488980084844279u, 1654361225106055349u, 2067951531382569187u,
+  1292469707114105741u, 1615587133892632177u, 2019483917365790221u
+};
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow5Factor(uint32_t __value) {
+  uint32_t __count = 0;
+  for (;;) {
+    _LIBCPP_ASSERT(__value != 0, "");
+    const uint32_t __q = __value / 5;
+    const uint32_t __r = __value % 5;
+    if (__r != 0) {
+      break;
+    }
+    __value = __q;
+    ++__count;
+  }
+  return __count;
+}
+
+// Returns true if __value is divisible by 5^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf5(const uint32_t __value, const uint32_t __p) {
+  return __pow5Factor(__value) >= __p;
+}
+
+// Returns true if __value is divisible by 2^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint32_t __value, const uint32_t __p) {
+  _LIBCPP_ASSERT(__value != 0, "");
+  _LIBCPP_ASSERT(__p < 32, "");
+  // __builtin_ctz doesn't appear to be faster here.
+  return (__value & ((1u << __p) - 1)) == 0;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulShift(const uint32_t __m, const uint64_t __factor, const int32_t __shift) {
+  _LIBCPP_ASSERT(__shift > 32, "");
+
+  // The casts here help MSVC to avoid calls to the __allmul library
+  // function.
+  const uint32_t __factorLo = static_cast<uint32_t>(__factor);
+  const uint32_t __factorHi = static_cast<uint32_t>(__factor >> 32);
+  const uint64_t __bits0 = static_cast<uint64_t>(__m) * __factorLo;
+  const uint64_t __bits1 = static_cast<uint64_t>(__m) * __factorHi;
+
+#ifndef _LIBCPP_64_BIT
+  // On 32-bit platforms we can avoid a 64-bit shift-right since we only
+  // need the upper 32 bits of the result and the shift value is > 32.
+  const uint32_t __bits0Hi = static_cast<uint32_t>(__bits0 >> 32);
+  uint32_t __bits1Lo = static_cast<uint32_t>(__bits1);
+  uint32_t __bits1Hi = static_cast<uint32_t>(__bits1 >> 32);
+  __bits1Lo += __bits0Hi;
+  __bits1Hi += (__bits1Lo < __bits0Hi);
+  const int32_t __s = __shift - 32;
+  return (__bits1Hi << (32 - __s)) | (__bits1Lo >> __s);
+#else // ^^^ 32-bit ^^^ / vvv 64-bit vvv
+  const uint64_t __sum = (__bits0 >> 32) + __bits1;
+  const uint64_t __shiftedSum = __sum >> (__shift - 32);
+  _LIBCPP_ASSERT(__shiftedSum <= UINT32_MAX, "");
+  return static_cast<uint32_t>(__shiftedSum);
+#endif // ^^^ 64-bit ^^^
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulPow5InvDivPow2(const uint32_t __m, const uint32_t __q, const int32_t __j) {
+  return __mulShift(__m, __FLOAT_POW5_INV_SPLIT[__q], __j);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulPow5divPow2(const uint32_t __m, const uint32_t __i, const int32_t __j) {
+  return __mulShift(__m, __FLOAT_POW5_SPLIT[__i], __j);
+}
+
+// A floating decimal representing m * 10^e.
+struct __floating_decimal_32 {
+  uint32_t __mantissa;
+  int32_t __exponent;
+};
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline __floating_decimal_32 __f2d(const uint32_t __ieeeMantissa, const uint32_t __ieeeExponent) {
+  int32_t __e2;
+  uint32_t __m2;
+  if (__ieeeExponent == 0) {
+    // We subtract 2 so that the bounds computation has 2 additional bits.
+    __e2 = 1 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
+    __m2 = __ieeeMantissa;
+  } else {
+    __e2 = static_cast<int32_t>(__ieeeExponent) - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
+    __m2 = (1u << __FLOAT_MANTISSA_BITS) | __ieeeMantissa;
+  }
+  const bool __even = (__m2 & 1) == 0;
+  const bool __acceptBounds = __even;
+
+  // Step 2: Determine the interval of valid decimal representations.
+  const uint32_t __mv = 4 * __m2;
+  const uint32_t __mp = 4 * __m2 + 2;
+  // Implicit bool -> int conversion. True is 1, false is 0.
+  const uint32_t __mmShift = __ieeeMantissa != 0 || __ieeeExponent <= 1;
+  const uint32_t __mm = 4 * __m2 - 1 - __mmShift;
+
+  // Step 3: Convert to a decimal power base using 64-bit arithmetic.
+  uint32_t __vr, __vp, __vm;
+  int32_t __e10;
+  bool __vmIsTrailingZeros = false;
+  bool __vrIsTrailingZeros = false;
+  uint8_t __lastRemovedDigit = 0;
+  if (__e2 >= 0) {
+    const uint32_t __q = __log10Pow2(__e2);
+    __e10 = static_cast<int32_t>(__q);
+    const int32_t __k = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q)) - 1;
+    const int32_t __i = -__e2 + static_cast<int32_t>(__q) + __k;
+    __vr = __mulPow5InvDivPow2(__mv, __q, __i);
+    __vp = __mulPow5InvDivPow2(__mp, __q, __i);
+    __vm = __mulPow5InvDivPow2(__mm, __q, __i);
+    if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
+      // We need to know one removed digit even if we are not going to loop below. We could use
+      // __q = X - 1 above, except that would require 33 bits for the result, and we've found that
+      // 32-bit arithmetic is faster even on 64-bit machines.
+      const int32_t __l = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q - 1)) - 1;
+      __lastRemovedDigit = static_cast<uint8_t>(__mulPow5InvDivPow2(__mv, __q - 1,
+        -__e2 + static_cast<int32_t>(__q) - 1 + __l) % 10);
+    }
+    if (__q <= 9) {
+      // The largest power of 5 that fits in 24 bits is 5^10, but __q <= 9 seems to be safe as well.
+      // Only one of __mp, __mv, and __mm can be a multiple of 5, if any.
+      if (__mv % 5 == 0) {
+        __vrIsTrailingZeros = __multipleOfPowerOf5(__mv, __q);
+      } else if (__acceptBounds) {
+        __vmIsTrailingZeros = __multipleOfPowerOf5(__mm, __q);
+      } else {
+        __vp -= __multipleOfPowerOf5(__mp, __q);
+      }
+    }
+  } else {
+    const uint32_t __q = __log10Pow5(-__e2);
+    __e10 = static_cast<int32_t>(__q) + __e2;
+    const int32_t __i = -__e2 - static_cast<int32_t>(__q);
+    const int32_t __k = __pow5bits(__i) - __FLOAT_POW5_BITCOUNT;
+    int32_t __j = static_cast<int32_t>(__q) - __k;
+    __vr = __mulPow5divPow2(__mv, static_cast<uint32_t>(__i), __j);
+    __vp = __mulPow5divPow2(__mp, static_cast<uint32_t>(__i), __j);
+    __vm = __mulPow5divPow2(__mm, static_cast<uint32_t>(__i), __j);
+    if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
+      __j = static_cast<int32_t>(__q) - 1 - (__pow5bits(__i + 1) - __FLOAT_POW5_BITCOUNT);
+      __lastRemovedDigit = static_cast<uint8_t>(__mulPow5divPow2(__mv, static_cast<uint32_t>(__i + 1), __j) % 10);
+    }
+    if (__q <= 1) {
+      // {__vr,__vp,__vm} is trailing zeros if {__mv,__mp,__mm} has at least __q trailing 0 bits.
+      // __mv = 4 * __m2, so it always has at least two trailing 0 bits.
+      __vrIsTrailingZeros = true;
+      if (__acceptBounds) {
+        // __mm = __mv - 1 - __mmShift, so it has 1 trailing 0 bit iff __mmShift == 1.
+        __vmIsTrailingZeros = __mmShift == 1;
+      } else {
+        // __mp = __mv + 2, so it always has at least one trailing 0 bit.
+        --__vp;
+      }
+    } else if (__q < 31) { // TRANSITION(ulfjack): Use a tighter bound here.
+      __vrIsTrailingZeros = __multipleOfPowerOf2(__mv, __q - 1);
+    }
+  }
+
+  // Step 4: Find the shortest decimal representation in the interval of valid representations.
+  int32_t __removed = 0;
+  uint32_t _Output;
+  if (__vmIsTrailingZeros || __vrIsTrailingZeros) {
+    // General case, which happens rarely (~4.0%).
+    while (__vp / 10 > __vm / 10) {
+#ifdef __clang__ // TRANSITION, LLVM-23106
+      __vmIsTrailingZeros &= __vm - (__vm / 10) * 10 == 0;
+#else
+      __vmIsTrailingZeros &= __vm % 10 == 0;
+#endif
+      __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+      __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
+      __vr /= 10;
+      __vp /= 10;
+      __vm /= 10;
+      ++__removed;
+    }
+    if (__vmIsTrailingZeros) {
+      while (__vm % 10 == 0) {
+        __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+        __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
+        __vr /= 10;
+        __vp /= 10;
+        __vm /= 10;
+        ++__removed;
+      }
+    }
+    if (__vrIsTrailingZeros && __lastRemovedDigit == 5 && __vr % 2 == 0) {
+      // Round even if the exact number is .....50..0.
+      __lastRemovedDigit = 4;
+    }
+    // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+    _Output = __vr + ((__vr == __vm && (!__acceptBounds || !__vmIsTrailingZeros)) || __lastRemovedDigit >= 5);
+  } else {
+    // Specialized for the common case (~96.0%). Percentages below are relative to this.
+    // Loop iterations below (approximately):
+    // 0: 13.6%, 1: 70.7%, 2: 14.1%, 3: 1.39%, 4: 0.14%, 5+: 0.01%
+    while (__vp / 10 > __vm / 10) {
+      __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
+      __vr /= 10;
+      __vp /= 10;
+      __vm /= 10;
+      ++__removed;
+    }
+    // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+    _Output = __vr + (__vr == __vm || __lastRemovedDigit >= 5);
+  }
+  const int32_t __exp = __e10 + __removed;
+
+  __floating_decimal_32 __fd;
+  __fd.__exponent = __exp;
+  __fd.__mantissa = _Output;
+  return __fd;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result _Large_integer_to_chars(char* const _First, char* const _Last,
+  const uint32_t _Mantissa2, const int32_t _Exponent2) {
+
+  // Print the integer _Mantissa2 * 2^_Exponent2 exactly.
+
+  // For nonzero integers, _Exponent2 >= -23. (The minimum value occurs when _Mantissa2 * 2^_Exponent2 is 1.
+  // In that case, _Mantissa2 is the implicit 1 bit followed by 23 zeros, so _Exponent2 is -23 to shift away
+  // the zeros.) The dense range of exactly representable integers has negative or zero exponents
+  // (as positive exponents make the range non-dense). For that dense range, Ryu will always be used:
+  // every digit is necessary to uniquely identify the value, so Ryu must print them all.
+
+  // Positive exponents are the non-dense range of exactly representable integers.
+  // This contains all of the values for which Ryu can't be used (and a few Ryu-friendly values).
+
+  // Performance note: Long division appears to be faster than losslessly widening float to double and calling
+  // __d2fixed_buffered_n(). If __f2fixed_buffered_n() is implemented, it might be faster than long division.
+
+  _LIBCPP_ASSERT(_Exponent2 > 0, "");
+  _LIBCPP_ASSERT(_Exponent2 <= 104, ""); // because __ieeeExponent <= 254
+
+  // Manually represent _Mantissa2 * 2^_Exponent2 as a large integer. _Mantissa2 is always 24 bits
+  // (due to the implicit bit), while _Exponent2 indicates a shift of at most 104 bits.
+  // 24 + 104 equals 128 equals 4 * 32, so we need exactly 4 32-bit elements.
+  // We use a little-endian representation, visualized like this:
+
+  // << left shift <<
+  // most significant
+  // _Data[3] _Data[2] _Data[1] _Data[0]
+  //                   least significant
+  //                   >> right shift >>
+
+  constexpr uint32_t _Data_size = 4;
+  uint32_t _Data[_Data_size]{};
+
+  // _Maxidx is the index of the most significant nonzero element.
+  uint32_t _Maxidx = ((24 + static_cast<uint32_t>(_Exponent2) + 31) / 32) - 1;
+  _LIBCPP_ASSERT(_Maxidx < _Data_size, "");
+
+  const uint32_t _Bit_shift = static_cast<uint32_t>(_Exponent2) % 32;
+  if (_Bit_shift <= 8) { // _Mantissa2's 24 bits don't cross an element boundary
+    _Data[_Maxidx] = _Mantissa2 << _Bit_shift;
+  } else { // _Mantissa2's 24 bits cross an element boundary
+    _Data[_Maxidx - 1] = _Mantissa2 << _Bit_shift;
+    _Data[_Maxidx] = _Mantissa2 >> (32 - _Bit_shift);
+  }
+
+  // If Ryu hasn't determined the total output length, we need to buffer the digits generated from right to left
+  // by long division. The largest possible float is: 340'282346638'528859811'704183484'516925440
+  uint32_t _Blocks[4];
+  int32_t _Filled_blocks = 0;
+  // From left to right, we're going to print:
+  // _Data[0] will be [1, 10] digits.
+  // Then if _Filled_blocks > 0:
+  // _Blocks[_Filled_blocks - 1], ..., _Blocks[0] will be 0-filled 9-digit blocks.
+
+  if (_Maxidx != 0) { // If the integer is actually large, perform long division.
+                      // Otherwise, skip to printing _Data[0].
+    for (;;) {
+      // Loop invariant: _Maxidx != 0 (i.e. the integer is actually large)
+
+      const uint32_t _Most_significant_elem = _Data[_Maxidx];
+      const uint32_t _Initial_remainder = _Most_significant_elem % 1000000000;
+      const uint32_t _Initial_quotient = _Most_significant_elem / 1000000000;
+      _Data[_Maxidx] = _Initial_quotient;
+      uint64_t _Remainder = _Initial_remainder;
+
+      // Process less significant elements.
+      uint32_t _Idx = _Maxidx;
+      do {
+        --_Idx; // Initially, _Remainder is at most 10^9 - 1.
+
+        // Now, _Remainder is at most (10^9 - 1) * 2^32 + 2^32 - 1, simplified to 10^9 * 2^32 - 1.
+        _Remainder = (_Remainder << 32) | _Data[_Idx];
+
+        // floor((10^9 * 2^32 - 1) / 10^9) == 2^32 - 1, so uint32_t _Quotient is lossless.
+        const uint32_t _Quotient = static_cast<uint32_t>(__div1e9(_Remainder));
+
+        // _Remainder is at most 10^9 - 1 again.
+        // For uint32_t truncation, see the __mod1e9() comment in d2s_intrinsics.h.
+        _Remainder = static_cast<uint32_t>(_Remainder) - 1000000000u * _Quotient;
+
+        _Data[_Idx] = _Quotient;
+      } while (_Idx != 0);
+
+      // Store a 0-filled 9-digit block.
+      _Blocks[_Filled_blocks++] = static_cast<uint32_t>(_Remainder);
+
+      if (_Initial_quotient == 0) { // Is the large integer shrinking?
+        --_Maxidx; // log2(10^9) is 29.9, so we can't shrink by more than one element.
+        if (_Maxidx == 0) {
+          break; // We've finished long division. Now we need to print _Data[0].
+        }
+      }
+    }
+  }
+
+  _LIBCPP_ASSERT(_Data[0] != 0, "");
+  for (uint32_t _Idx = 1; _Idx < _Data_size; ++_Idx) {
+    _LIBCPP_ASSERT(_Data[_Idx] == 0, "");
+  }
+
+  const uint32_t _Data_olength = _Data[0] >= 1000000000 ? 10 : __decimalLength9(_Data[0]);
+  const uint32_t _Total_fixed_length = _Data_olength + 9 * _Filled_blocks;
+
+  if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
+    return { _Last, errc::value_too_large };
+  }
+
+  char* _Result = _First;
+
+  // Print _Data[0]. While it's up to 10 digits,
+  // which is more than Ryu generates, the code below can handle this.
+  __append_n_digits(_Data_olength, _Data[0], _Result);
+  _Result += _Data_olength;
+
+  // Print 0-filled 9-digit blocks.
+  for (int32_t _Idx = _Filled_blocks - 1; _Idx >= 0; --_Idx) {
+    __append_nine_digits(_Blocks[_Idx], _Result);
+    _Result += 9;
+  }
+
+  return { _Result, errc{} };
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result __to_chars(char* const _First, char* const _Last, const __floating_decimal_32 __v,
+  chars_format _Fmt, const uint32_t __ieeeMantissa, const uint32_t __ieeeExponent) {
+  // Step 5: Print the decimal representation.
+  uint32_t _Output = __v.__mantissa;
+  int32_t _Ryu_exponent = __v.__exponent;
+  const uint32_t __olength = __decimalLength9(_Output);
+  int32_t _Scientific_exponent = _Ryu_exponent + static_cast<int32_t>(__olength) - 1;
+
+  if (_Fmt == chars_format{}) {
+    int32_t _Lower;
+    int32_t _Upper;
+
+    if (__olength == 1) {
+      // Value | Fixed   | Scientific
+      // 1e-3  | "0.001" | "1e-03"
+      // 1e4   | "10000" | "1e+04"
+      _Lower = -3;
+      _Upper = 4;
+    } else {
+      // Value   | Fixed       | Scientific
+      // 1234e-7 | "0.0001234" | "1.234e-04"
+      // 1234e5  | "123400000" | "1.234e+08"
+      _Lower = -static_cast<int32_t>(__olength + 3);
+      _Upper = 5;
+    }
+
+    if (_Lower <= _Ryu_exponent && _Ryu_exponent <= _Upper) {
+      _Fmt = chars_format::fixed;
+    } else {
+      _Fmt = chars_format::scientific;
+    }
+  } else if (_Fmt == chars_format::general) {
+    // C11 7.21.6.1 "The fprintf function"/8:
+    // "Let P equal [...] 6 if the precision is omitted [...].
+    // Then, if a conversion with style E would have an exponent of X:
+    // - if P > X >= -4, the conversion is with style f [...].
+    // - otherwise, the conversion is with style e [...]."
+    if (-4 <= _Scientific_exponent && _Scientific_exponent < 6) {
+      _Fmt = chars_format::fixed;
+    } else {
+      _Fmt = chars_format::scientific;
+    }
+  }
+
+  if (_Fmt == chars_format::fixed) {
+    // Example: _Output == 1729, __olength == 4
+
+    // _Ryu_exponent | Printed  | _Whole_digits | _Total_fixed_length  | Notes
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //             2 | 172900   |  6            | _Whole_digits        | Ryu can't be used for printing
+    //             1 | 17290    |  5            | (sometimes adjusted) | when the trimmed digits are nonzero.
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //             0 | 1729     |  4            | _Whole_digits        | Unified length cases.
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //            -1 | 172.9    |  3            | __olength + 1        | This case can't happen for
+    //            -2 | 17.29    |  2            |                      | __olength == 1, but no additional
+    //            -3 | 1.729    |  1            |                      | code is needed to avoid it.
+    // --------------|----------|---------------|----------------------|---------------------------------------
+    //            -4 | 0.1729   |  0            | 2 - _Ryu_exponent    | C11 7.21.6.1 "The fprintf function"/8:
+    //            -5 | 0.01729  | -1            |                      | "If a decimal-point character appears,
+    //            -6 | 0.001729 | -2            |                      | at least one digit appears before it."
+
+    const int32_t _Whole_digits = static_cast<int32_t>(__olength) + _Ryu_exponent;
+
+    uint32_t _Total_fixed_length;
+    if (_Ryu_exponent >= 0) { // cases "172900" and "1729"
+      _Total_fixed_length = static_cast<uint32_t>(_Whole_digits);
+      if (_Output == 1) {
+        // Rounding can affect the number of digits.
+        // For example, 1e11f is exactly "99999997952" which is 11 digits instead of 12.
+        // We can use a lookup table to detect this and adjust the total length.
+        static constexpr uint8_t _Adjustment[39] = {
+          0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1,0,1,1,1 };
+        _Total_fixed_length -= _Adjustment[_Ryu_exponent];
+        // _Whole_digits doesn't need to be adjusted because these cases won't refer to it later.
+      }
+    } else if (_Whole_digits > 0) { // case "17.29"
+      _Total_fixed_length = __olength + 1;
+    } else { // case "0.001729"
+      _Total_fixed_length = static_cast<uint32_t>(2 - _Ryu_exponent);
+    }
+
+    if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
+      return { _Last, errc::value_too_large };
+    }
+
+    char* _Mid;
+    if (_Ryu_exponent > 0) { // case "172900"
+      bool _Can_use_ryu;
+
+      if (_Ryu_exponent > 10) { // 10^10 is the largest power of 10 that's exactly representable as a float.
+        _Can_use_ryu = false;
+      } else {
+        // Ryu generated X: __v.__mantissa * 10^_Ryu_exponent
+        // __v.__mantissa == 2^_Trailing_zero_bits * (__v.__mantissa >> _Trailing_zero_bits)
+        // 10^_Ryu_exponent == 2^_Ryu_exponent * 5^_Ryu_exponent
+
+        // _Trailing_zero_bits is [0, 29] (aside: because 2^29 is the largest power of 2
+        // with 9 decimal digits, which is float's round-trip limit.)
+        // _Ryu_exponent is [1, 10].
+        // Normalization adds [2, 23] (aside: at least 2 because the pre-normalized mantissa is at least 5).
+        // This adds up to [3, 62], which is well below float's maximum binary exponent 127.
+
+        // Therefore, we just need to consider (__v.__mantissa >> _Trailing_zero_bits) * 5^_Ryu_exponent.
+
+        // If that product would exceed 24 bits, then X can't be exactly represented as a float.
+        // (That's not a problem for round-tripping, because X is close enough to the original float,
+        // but X isn't mathematically equal to the original float.) This requires a high-precision fallback.
+
+        // If the product is 24 bits or smaller, then X can be exactly represented as a float (and we don't
+        // need to re-synthesize it; the original float must have been X, because Ryu wouldn't produce the
+        // same output for two different floats X and Y). This allows Ryu's output to be used (zero-filled).
+
+        // (2^24 - 1) / 5^0 (for indexing), (2^24 - 1) / 5^1, ..., (2^24 - 1) / 5^10
+        static constexpr uint32_t _Max_shifted_mantissa[11] = {
+          16777215, 3355443, 671088, 134217, 26843, 5368, 1073, 214, 42, 8, 1 };
+
+        unsigned long _Trailing_zero_bits;
+        (void) _BitScanForward(&_Trailing_zero_bits, __v.__mantissa); // __v.__mantissa is guaranteed nonzero
+        const uint32_t _Shifted_mantissa = __v.__mantissa >> _Trailing_zero_bits;
+        _Can_use_ryu = _Shifted_mantissa <= _Max_shifted_mantissa[_Ryu_exponent];
+      }
+
+      if (!_Can_use_ryu) {
+        const uint32_t _Mantissa2 = __ieeeMantissa | (1u << __FLOAT_MANTISSA_BITS); // restore implicit bit
+        const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
+          - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
+
+        // Performance note: We've already called Ryu, so this will redundantly perform buffering and bounds checking.
+        return _Large_integer_to_chars(_First, _Last, _Mantissa2, _Exponent2);
+      }
+
+      // _Can_use_ryu
+      // Print the decimal digits, left-aligned within [_First, _First + _Total_fixed_length).
+      _Mid = _First + __olength;
+    } else { // cases "1729", "17.29", and "0.001729"
+      // Print the decimal digits, right-aligned within [_First, _First + _Total_fixed_length).
+      _Mid = _First + _Total_fixed_length;
+    }
+
+    while (_Output >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+      const uint32_t __c = _Output - 10000 * (_Output / 10000);
+#else
+      const uint32_t __c = _Output % 10000;
+#endif
+      _Output /= 10000;
+      const uint32_t __c0 = (__c % 100) << 1;
+      const uint32_t __c1 = (__c / 100) << 1;
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
+    }
+    if (_Output >= 100) {
+      const uint32_t __c = (_Output % 100) << 1;
+      _Output /= 100;
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+    }
+    if (_Output >= 10) {
+      const uint32_t __c = _Output << 1;
+      _VSTD::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+    } else {
+      *--_Mid = static_cast<char>('0' + _Output);
+    }
+
+    if (_Ryu_exponent > 0) { // case "172900" with _Can_use_ryu
+      // Performance note: it might be more efficient to do this immediately after setting _Mid.
+      _VSTD::memset(_First + __olength, '0', static_cast<size_t>(_Ryu_exponent));
+    } else if (_Ryu_exponent == 0) { // case "1729"
+      // Done!
+    } else if (_Whole_digits > 0) { // case "17.29"
+      // Performance note: moving digits might not be optimal.
+      _VSTD::memmove(_First, _First + 1, static_cast<size_t>(_Whole_digits));
+      _First[_Whole_digits] = '.';
+    } else { // case "0.001729"
+      // Performance note: a larger memset() followed by overwriting '.' might be more efficient.
+      _First[0] = '0';
+      _First[1] = '.';
+      _VSTD::memset(_First + 2, '0', static_cast<size_t>(-_Whole_digits));
+    }
+
+    return { _First + _Total_fixed_length, errc{} };
+  }
+
+  const uint32_t _Total_scientific_length =
+    __olength + (__olength > 1) + 4; // digits + possible decimal point + scientific exponent
+  if (_Last - _First < static_cast<ptrdiff_t>(_Total_scientific_length)) {
+    return { _Last, errc::value_too_large };
+  }
+  char* const __result = _First;
+
+  // Print the decimal digits.
+  uint32_t __i = 0;
+  while (_Output >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+    const uint32_t __c = _Output - 10000 * (_Output / 10000);
+#else
+    const uint32_t __c = _Output % 10000;
+#endif
+    _Output /= 10000;
+    const uint32_t __c0 = (__c % 100) << 1;
+    const uint32_t __c1 = (__c / 100) << 1;
+    _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
+    _VSTD::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
+    __i += 4;
+  }
+  if (_Output >= 100) {
+    const uint32_t __c = (_Output % 100) << 1;
+    _Output /= 100;
+    _VSTD::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c, 2);
+    __i += 2;
+  }
+  if (_Output >= 10) {
+    const uint32_t __c = _Output << 1;
+    // We can't use memcpy here: the decimal dot goes between these two digits.
+    __result[2] = __DIGIT_TABLE[__c + 1];
+    __result[0] = __DIGIT_TABLE[__c];
+  } else {
+    __result[0] = static_cast<char>('0' + _Output);
+  }
+
+  // Print decimal point if needed.
+  uint32_t __index;
+  if (__olength > 1) {
+    __result[1] = '.';
+    __index = __olength + 1;
+  } else {
+    __index = 1;
+  }
+
+  // Print the exponent.
+  __result[__index++] = 'e';
+  if (_Scientific_exponent < 0) {
+    __result[__index++] = '-';
+    _Scientific_exponent = -_Scientific_exponent;
+  } else {
+    __result[__index++] = '+';
+  }
+
+  _VSTD::memcpy(__result + __index, __DIGIT_TABLE + 2 * _Scientific_exponent, 2);
+  __index += 2;
+
+  return { _First + _Total_scientific_length, errc{} };
+}
+
+[[nodiscard]] to_chars_result __f2s_buffered_n(char* const _First, char* const _Last, const float __f,
+  const chars_format _Fmt) {
+
+  // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
+  const uint32_t __bits = __float_to_bits(__f);
+
+  // Case distinction; exit early for the easy cases.
+  if (__bits == 0) {
+    if (_Fmt == chars_format::scientific) {
+      if (_Last - _First < 5) {
+        return { _Last, errc::value_too_large };
+      }
+
+      _VSTD::memcpy(_First, "0e+00", 5);
+
+      return { _First + 5, errc{} };
+    }
+
+    // Print "0" for chars_format::fixed, chars_format::general, and chars_format{}.
+    if (_First == _Last) {
+      return { _Last, errc::value_too_large };
+    }
+
+    *_First = '0';
+
+    return { _First + 1, errc{} };
+  }
+
+  // Decode __bits into mantissa and exponent.
+  const uint32_t __ieeeMantissa = __bits & ((1u << __FLOAT_MANTISSA_BITS) - 1);
+  const uint32_t __ieeeExponent = __bits >> __FLOAT_MANTISSA_BITS;
+
+  // When _Fmt == chars_format::fixed and the floating-point number is a large integer,
+  // it's faster to skip Ryu and immediately print the integer exactly.
+  if (_Fmt == chars_format::fixed) {
+    const uint32_t _Mantissa2 = __ieeeMantissa | (1u << __FLOAT_MANTISSA_BITS); // restore implicit bit
+    const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
+      - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
+
+    // Normal values are equal to _Mantissa2 * 2^_Exponent2.
+    // (Subnormals are different, but they'll be rejected by the _Exponent2 test here, so they can be ignored.)
+
+    if (_Exponent2 > 0) {
+      return _Large_integer_to_chars(_First, _Last, _Mantissa2, _Exponent2);
+    }
+  }
+
+  const __floating_decimal_32 __v = __f2d(__ieeeMantissa, __ieeeExponent);
+  return __to_chars(_First, _Last, __v, _Fmt, __ieeeMantissa, __ieeeExponent);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
lib/libcxx/src/support/ibm/mbsnrtowcs.cpp
@@ -0,0 +1,95 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <cstddef> // size_t
+#include <cwchar>  // mbstate_t
+#include <limits.h> // MB_LEN_MAX
+#include <string.h> // wmemcpy
+
+// Returns the number of wide characters found in the multi byte sequence `src`
+// (of `src_size_bytes`), that fit in the buffer `dst` (of `max_dest_chars`
+// elements size). The count returned excludes the null terminator.
+// When `dst` is NULL, no characters are copied to `dst`.
+// Returns (size_t) -1 when an invalid sequence is encountered.
+// Leaves *`src` pointing to the next character to convert or NULL
+// if a null character was converted from *`src`.
+_LIBCPP_FUNC_VIS
+size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
+                   size_t src_size_bytes, size_t max_dest_chars,
+                   mbstate_t *__restrict ps) {
+  const size_t terminated_sequence = static_cast<size_t>(0);
+  const size_t invalid_sequence = static_cast<size_t>(-1);
+  const size_t incomplete_sequence = static_cast<size_t>(-2);
+
+  size_t source_converted;
+  size_t dest_converted;
+  size_t result = 0;
+
+  // If `dst` is null then `max_dest_chars` should be ignored according to the
+  // standard. Setting `max_dest_chars` to a large value has this effect.
+  if (dst == nullptr)
+    max_dest_chars = static_cast<size_t>(-1);
+
+  for (dest_converted = source_converted = 0;
+       source_converted < src_size_bytes && (!dst || dest_converted < max_dest_chars);
+       ++dest_converted, source_converted += result) {
+    // Converts one multi byte character.
+    // If result (char_size) is greater than 0, it's the size in bytes of that character.
+    // If result (char_size) is zero, it indicates that the null character has been found.
+    // Otherwise, it's an error and errno may be set.
+    size_t source_remaining = src_size_bytes - source_converted;
+    size_t dest_remaining = max_dest_chars - dest_converted;
+
+    if (dst == nullptr) {
+      result = mbrtowc(NULL, *src + source_converted, source_remaining, ps);
+    } else if (dest_remaining >= source_remaining) {
+      // dst has enough space to translate in-place.
+      result = mbrtowc(dst + dest_converted, *src + source_converted, source_remaining, ps);
+    } else {
+      /*
+      * dst may not have enough space, so use a temporary buffer.
+      *
+      * We need to save a copy of the conversion state
+      * here so we can restore it if the multibyte
+      * character is too long for the buffer.
+      */
+      wchar_t buff[MB_LEN_MAX];
+      mbstate_t mbstate_tmp;
+
+      if (ps != nullptr)
+        mbstate_tmp = *ps;
+      result = mbrtowc(buff, *src + source_converted, source_remaining, ps);
+
+      if (result > dest_remaining) {
+        // Multi-byte sequence for character won't fit.
+        if (ps != nullptr)
+          *ps = mbstate_tmp;
+        break;
+      } else {
+        // The buffer was used, so we need copy the translation to dst.
+        wmemcpy(dst, buff, result);
+      }
+    }
+
+    // Don't do anything to change errno from here on.
+    if (result == invalid_sequence || result == terminated_sequence || result == incomplete_sequence) {
+      break;
+    }
+  }
+
+  if (dst) {
+    if (result == terminated_sequence)
+      *src = NULL;
+    else
+      *src += source_converted;
+  }
+  if (result == invalid_sequence)
+    return invalid_sequence;
+
+  return dest_converted;
+}
lib/libcxx/src/support/ibm/wcsnrtombs.cpp
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <cwchar>  // mbstate_t
+#include <limits.h> // MB_LEN_MAX
+#include <stdlib.h> // MB_CUR_MAX, size_t
+#include <string.h> // memcpy
+
+// Converts `max_source_chars` from the wide character buffer pointer to by *`src`,
+// into the multi byte character sequence buffer stored at `dst`, which must be
+// `dst_size_bytes` bytes in size. Returns the number of bytes in the sequence
+// converted from *src, excluding the null terminator. 
+// Returns (size_t) -1 if an error occurs and sets errno.
+// If `dst` is NULL, `dst_size_bytes` is ignored and no bytes are copied to `dst`.
+_LIBCPP_FUNC_VIS
+size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
+                   size_t max_source_chars, size_t dst_size_bytes,
+                   mbstate_t *__restrict ps) {
+
+  const size_t invalid_wchar = static_cast<size_t>(-1);
+
+  size_t source_converted;
+  size_t dest_converted;
+  size_t result = 0;
+
+  // If `dst` is null then `dst_size_bytes` should be ignored according to the
+  // standard. Setting dst_size_bytes to a large value has this effect.
+  if (dst == nullptr)
+    dst_size_bytes = static_cast<size_t>(-1);
+
+  for (dest_converted = source_converted = 0;
+       source_converted < max_source_chars && (!dst || dest_converted < dst_size_bytes);
+       ++source_converted, dest_converted += result) {
+    wchar_t c = (*src)[source_converted];
+    size_t dest_remaining = dst_size_bytes - dest_converted;
+
+    if (dst == nullptr) {
+      result = wcrtomb(NULL, c, ps);
+    } else if (dest_remaining >= static_cast<size_t>(MB_CUR_MAX)) {
+      // dst has enough space to translate in-place.
+      result = wcrtomb(dst + dest_converted, c, ps);
+    } else {
+      /*
+      * dst may not have enough space, so use a temporary buffer.
+      *
+      * We need to save a copy of the conversion state
+      * here so we can restore it if the multibyte
+      * character is too long for the buffer.
+      */
+      char buff[MB_LEN_MAX];
+      mbstate_t mbstate_tmp;
+
+      if (ps != nullptr)
+        mbstate_tmp = *ps;
+      result = wcrtomb(buff, c, ps);
+
+      if (result > dest_remaining) {
+        // Multi-byte sequence for character won't fit.
+        if (ps != nullptr)
+          *ps = mbstate_tmp;
+        if (result != invalid_wchar)
+          break;
+      } else {
+        // The buffer was used, so we need copy the translation to dst.
+        memcpy(dst, buff, result);
+      }
+    }
+
+    // result (char_size) contains the size of the multi-byte-sequence converted.
+    // Otherwise, result (char_size) is (size_t) -1 and wcrtomb() sets the errno.
+    if (result == invalid_wchar) {
+      if (dst)
+        *src = *src + source_converted;
+      return invalid_wchar;
+    }
+
+    if (c == L'\0') {
+      if (dst)
+        *src = NULL;
+      return dest_converted;
+    }
+  }
+
+  if (dst)
+    *src = *src + source_converted;
+
+  return dest_converted;
+}
lib/libcxx/src/support/runtime/stdexcept_default.ipp
@@ -1,4 +1,4 @@
-//===--------------------- stdexcept_default.ipp --------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/support/runtime/stdexcept_vcruntime.ipp
@@ -1,4 +1,4 @@
-//===------------------- stdexcept_vcruntime.ipp --------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/support/win32/locale_win32.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 //===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -98,7 +97,10 @@ int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
         ret, n, format, loc, ap);
 #else
     __libcpp_locale_guard __current(loc);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
     int result = vsnprintf( ret, n, format, ap );
+#pragma clang diagnostic pop
 #endif
     va_end(ap);
     return result;
lib/libcxx/src/support/win32/support.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 //===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -24,7 +23,10 @@ int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap )
     // Query the count required.
     va_list ap_copy;
     va_copy(ap_copy, ap);
-    int count = _vsnprintf( NULL, 0, format, ap_copy );
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+    int count = vsnprintf( NULL, 0, format, ap_copy );
+#pragma clang diagnostic pop
     va_end(ap_copy);
     if (count < 0)
         return count;
@@ -34,7 +36,10 @@ int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap )
         return -1;
     // If we haven't used exactly what was required, something is wrong.
     // Maybe bug in vsnprintf. Report the error and return.
-    if (_vsnprintf(p, buffer_size, format, ap) != count) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+    if (vsnprintf(p, buffer_size, format, ap) != count) {
+#pragma clang diagnostic pop
         free(p);
         return -1;
     }
lib/libcxx/src/support/win32/thread_win32.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 //===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -39,9 +38,6 @@ static_assert(alignof(__libcpp_thread_t) == alignof(HANDLE), "");
 static_assert(sizeof(__libcpp_tls_key) == sizeof(DWORD), "");
 static_assert(alignof(__libcpp_tls_key) == alignof(DWORD), "");
 
-static_assert(sizeof(__libcpp_semaphore_t) == sizeof(HANDLE), "");
-static_assert(alignof(__libcpp_semaphore_t) == alignof(HANDLE), "");
-
 // Mutex
 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
 {
@@ -275,37 +271,4 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
   return 0;
 }
 
-// Semaphores
-bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init)
-{
-  *(PHANDLE)__sem = CreateSemaphoreEx(nullptr, __init, _LIBCPP_SEMAPHORE_MAX,
-                                      nullptr, 0, SEMAPHORE_ALL_ACCESS);
-  return *__sem != nullptr;
-}
-
-bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem)
-{
-  CloseHandle(*(PHANDLE)__sem);
-  return true;
-}
-
-bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem)
-{
-  return ReleaseSemaphore(*(PHANDLE)__sem, 1, nullptr);
-}
-
-bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem)
-{
-  return WaitForSingleObjectEx(*(PHANDLE)__sem, INFINITE, false) ==
-         WAIT_OBJECT_0;
-}
-
-bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem,
-                                   chrono::nanoseconds const& __ns)
-{
-  chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__ns);
-  return WaitForSingleObjectEx(*(PHANDLE)__sem, __ms.count(), false) ==
-         WAIT_OBJECT_0;
-}
-
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/algorithm.cpp
@@ -1,4 +1,4 @@
-//===----------------------- algorithm.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,9 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
+#endif
 template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
 template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
 template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
@@ -27,7 +29,9 @@ template void __sort<__less<double>&, double*>(double*, double*, __less<double>&
 template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
 
 template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
+#endif
 template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
 template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
 template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
lib/libcxx/src/any.cpp
@@ -1,4 +1,4 @@
-//===---------------------------- any.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/atomic.cpp
@@ -1,4 +1,4 @@
-//===------------------------- atomic.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,9 +9,10 @@
 #include <__config>
 #ifndef _LIBCPP_HAS_NO_THREADS
 
-#include <climits>
 #include <atomic>
+#include <climits>
 #include <functional>
+#include <thread>
 
 #ifdef __linux__
 
lib/libcxx/src/barrier.cpp
@@ -1,4 +1,4 @@
-//===------------------------- barrier.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -15,14 +15,14 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER > 11)
+#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER)
 
 class __barrier_algorithm_base {
 public:
     struct alignas(64) /* naturally-align the heap state */ __state_t
     {
         struct {
-            __atomic_base<__barrier_phase_t> __phase = ATOMIC_VAR_INIT(0);
+          __atomic_base<__barrier_phase_t> __phase{0};
         } __tickets[64];
     };
 
@@ -90,7 +90,7 @@ void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier)
     delete __barrier;
 }
 
-#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER >= 11)
+#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER)
 
 _LIBCPP_END_NAMESPACE_STD
 
lib/libcxx/src/bind.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- bind.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/charconv.cpp
@@ -1,4 +1,4 @@
-//===------------------------- charconv.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,27 +9,14 @@
 #include "charconv"
 #include <string.h>
 
+#include "include/ryu/digit_table.h"
+#include "include/to_chars_floating_point.h"
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace __itoa
 {
 
-static constexpr char cDigitsLut[200] = {
-    '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0',
-    '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
-    '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2',
-    '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
-    '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3',
-    '7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
-    '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5',
-    '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
-    '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6',
-    '7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
-    '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8',
-    '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
-    '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9',
-    '7', '9', '8', '9', '9'};
-
 template <typename T>
 inline _LIBCPP_INLINE_VISIBILITY char*
 append1(char* buffer, T i) noexcept
@@ -42,7 +29,7 @@ template <typename T>
 inline _LIBCPP_INLINE_VISIBILITY char*
 append2(char* buffer, T i) noexcept
 {
-    memcpy(buffer, &cDigitsLut[(i)*2], 2);
+    memcpy(buffer, &__DIGIT_TABLE[(i)*2], 2);
     return buffer + 2;
 }
 
@@ -157,4 +144,53 @@ __u64toa(uint64_t value, char* buffer) noexcept
 
 }  // namespace __itoa
 
+// The original version of floating-point to_chars was written by Microsoft and
+// contributed with the following license.
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// This implementation is dedicated to the memory of Mary and Thavatchai.
+
+to_chars_result to_chars(char* __first, char* __last, float __value) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
+}
+
+to_chars_result to_chars(char* __first, char* __last, double __value) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
+}
+
+to_chars_result to_chars(char* __first, char* __last, long double __value) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, static_cast<double>(__value),
+                                                                 chars_format{}, 0);
+}
+
+to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
+}
+
+to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
+}
+
+to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, static_cast<double>(__value),
+                                                                       __fmt, 0);
+}
+
+to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt,
+                                                                            __precision);
+}
+
+to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(__first, __last, __value, __fmt,
+                                                                            __precision);
+}
+
+to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
+  return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
+      __first, __last, static_cast<double>(__value), __fmt, __precision);
+}
+
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/chrono.cpp
@@ -1,4 +1,4 @@
-//===------------------------- chrono.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -44,6 +44,10 @@
 #  endif
 #endif // defined(_LIBCPP_WIN32API)
 
+#if defined(__Fuchsia__)
+#  include <zircon/syscalls.h>
+#endif
+
 #if __has_include(<mach/mach_time.h>)
 # include <mach/mach_time.h>
 #endif
@@ -63,6 +67,30 @@ namespace chrono
 
 #if defined(_LIBCPP_WIN32API)
 
+#if _WIN32_WINNT < _WIN32_WINNT_WIN8
+
+namespace {
+
+typedef void(WINAPI *GetSystemTimeAsFileTimePtr)(LPFILETIME);
+
+class GetSystemTimeInit {
+public:
+  GetSystemTimeInit() {
+    fp = (GetSystemTimeAsFileTimePtr)GetProcAddress(
+        GetModuleHandleW(L"kernel32.dll"), "GetSystemTimePreciseAsFileTime");
+    if (fp == nullptr)
+      fp = GetSystemTimeAsFileTime;
+  }
+  GetSystemTimeAsFileTimePtr fp;
+};
+
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "chrono_system_time_init.h"
+} // namespace
+
+#endif
+
 static system_clock::time_point __libcpp_system_clock_now() {
   // FILETIME is in 100ns units
   using filetime_duration =
@@ -74,10 +102,13 @@ static system_clock::time_point __libcpp_system_clock_now() {
   static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600};
 
   FILETIME ft;
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) || \
+    (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
   GetSystemTimePreciseAsFileTime(&ft);
-#else
+#elif !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
   GetSystemTimeAsFileTime(&ft);
+#else
+  GetSystemTimeAsFileTimeFunc.fp(&ft);
 #endif
 
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
@@ -239,7 +270,18 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
   return steady_clock::time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
 }
 
-#elif defined(CLOCK_MONOTONIC)
+#  elif defined(__Fuchsia__)
+
+static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
+  // Implicitly link against the vDSO system call ABI without
+  // requiring the final link to specify -lzircon explicitly when
+  // statically linking libc++.
+#    pragma comment(lib, "zircon")
+
+  return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic()));
+}
+
+#  elif defined(CLOCK_MONOTONIC)
 
 static steady_clock::time_point __libcpp_steady_clock_now() {
     struct timespec tp;
@@ -248,9 +290,9 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
     return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
 }
 
-#else
-#   error "Monotonic clock not implemented on this platform"
-#endif
+#  else
+#    error "Monotonic clock not implemented on this platform"
+#  endif
 
 const bool steady_clock::is_steady;
 
lib/libcxx/src/chrono_system_time_init.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+GetSystemTimeInit GetSystemTimeAsFileTimeFunc _LIBCPP_INIT_PRIORITY_MAX;
lib/libcxx/src/condition_variable.cpp
@@ -1,4 +1,4 @@
-//===-------------------- condition_variable.cpp --------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/condition_variable_destructor.cpp
@@ -1,4 +1,4 @@
-//===---------------- condition_variable_destructor.cpp ------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/debug.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- debug.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/exception.cpp
@@ -1,4 +1,4 @@
-//===------------------------ exception.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/format.cpp
@@ -1,4 +1,4 @@
-//===------------------------- format.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,10 +10,6 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER > 17
-
 format_error::~format_error() noexcept = default;
 
-#endif //_LIBCPP_STD_VER > 17
-
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/functional.cpp
@@ -1,4 +1,4 @@
-//===----------------------- functional.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -14,7 +14,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 bad_function_call::~bad_function_call() noexcept
 {
 }
+#endif
 
+#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
 const char*
 bad_function_call::what() const noexcept
 {
lib/libcxx/src/future.cpp
@@ -1,4 +1,4 @@
-//===------------------------- future.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/hash.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- hash.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/ios.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- ios.cpp -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -137,7 +137,7 @@ ios_base::getloc() const
 
 // xalloc
 #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
-atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
+atomic<int> ios_base::__xindex_{0};
 #else
 int ios_base::__xindex_ = 0;
 #endif
lib/libcxx/src/ios.instantiations.cpp
@@ -19,15 +19,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // Original explicit instantiations provided in the library
 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_iostream<char>;
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
+#endif
+
 // Additional instantiations added later. Whether programs rely on these being
 // available is protected by _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1.
 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringbuf<char>;
lib/libcxx/src/iostream.cpp
@@ -1,4 +1,4 @@
-//===------------------------ iostream.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -17,7 +17,6 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#ifndef _LIBCPP_HAS_NO_STDIN
 _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
 __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
@@ -25,6 +24,8 @@ __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_trai
 ;
 _ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
 static mbstate_t mb_cin;
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
 __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
@@ -32,9 +33,8 @@ __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_tr
 ;
 _ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
 static mbstate_t mb_wcin;
-#endif
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
-#ifndef _LIBCPP_HAS_NO_STDOUT
 _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
 __asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
@@ -42,6 +42,8 @@ __asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_tra
 ;
 _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
 static mbstate_t mb_cout;
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
 __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
@@ -49,7 +51,7 @@ __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t
 ;
 _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
 static mbstate_t mb_wcout;
-#endif
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
@@ -58,6 +60,8 @@ __asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_tra
 ;
 _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
 static mbstate_t mb_cerr;
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
 __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
@@ -65,19 +69,25 @@ __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t
 ;
 _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
 static mbstate_t mb_wcerr;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
 __asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
 #endif
 ;
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
 __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
 #endif
 ;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
-_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "iostream_init.h"
 
 // On Windows the TLS storage for locales needs to be initialized before we create
 // the standard streams, otherwise it may not be alive during program termination
@@ -107,44 +117,39 @@ DoIOSInit::DoIOSInit()
 {
     force_locale_initialization();
 
-#ifndef _LIBCPP_HAS_NO_STDIN
     istream* cin_ptr  = ::new(cin)  istream(::new(__cin)  __stdinbuf <char>(stdin, &mb_cin));
-    wistream* wcin_ptr  = ::new(wcin)  wistream(::new(__wcin)  __stdinbuf <wchar_t>(stdin, &mb_wcin));
-#endif
-#ifndef _LIBCPP_HAS_NO_STDOUT
     ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout));
-    wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
-#endif
     ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
                         ::new(clog) ostream(cerr_ptr->rdbuf());
+    cin_ptr->tie(cout_ptr);
+    _VSTD::unitbuf(*cerr_ptr);
+    cerr_ptr->tie(cout_ptr);
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+    wistream* wcin_ptr  = ::new(wcin)  wistream(::new(__wcin)  __stdinbuf <wchar_t>(stdin, &mb_wcin));
+    wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
     wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
                           ::new(wclog) wostream(wcerr_ptr->rdbuf());
 
-#if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
-    cin_ptr->tie(cout_ptr);
     wcin_ptr->tie(wcout_ptr);
-#endif
-    _VSTD::unitbuf(*cerr_ptr);
     _VSTD::unitbuf(*wcerr_ptr);
-#ifndef _LIBCPP_HAS_NO_STDOUT
-    cerr_ptr->tie(cout_ptr);
     wcerr_ptr->tie(wcout_ptr);
 #endif
 }
 
 DoIOSInit::~DoIOSInit()
 {
-#ifndef _LIBCPP_HAS_NO_STDOUT
     ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
-    wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
     cout_ptr->flush();
-    wcout_ptr->flush();
-#endif
-
     ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
-    wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
     clog_ptr->flush();
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+    wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
+    wcout_ptr->flush();
+    wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
     wclog_ptr->flush();
+#endif
 }
 
 ios_base::Init::Init()
lib/libcxx/src/iostream_init.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
lib/libcxx/src/legacy_pointer_safety.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "__config"
+#include <memory>
+
+// Support for garbage collection was removed in C++23 by https://wg21.link/P2186R2. Libc++ implements
+// that removal as an extension in all Standard versions. However, we still define the functions that
+// were once part of the library's ABI for backwards compatibility.
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+_LIBCPP_FUNC_VIS void declare_reachable(void*) {}
+_LIBCPP_FUNC_VIS void declare_no_pointers(char*, size_t) {}
+_LIBCPP_FUNC_VIS void undeclare_no_pointers(char*, size_t) {}
+_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* p) { return p; }
+
+_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/locale.cpp
@@ -1,4 +1,4 @@
-//===------------------------- locale.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -12,28 +12,36 @@
 #define _LCONV_C99
 #endif
 
-#include "string"
-#include "locale"
-#include "codecvt"
-#include "vector"
 #include "algorithm"
-#include "typeinfo"
-#ifndef _LIBCPP_NO_EXCEPTIONS
-#  include "type_traits"
-#endif
 #include "clocale"
+#include "codecvt"
+#include "cstdio"
+#include "cstdlib"
 #include "cstring"
+#include "locale"
+#include "string"
+#include "type_traits"
+#include "typeinfo"
+#include "vector"
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#   include "cwctype"
+#endif
+
+#if defined(_AIX)
+#   include <sys/localedef.h> // for __lc_ctype_ptr
+#endif
+
 #if defined(_LIBCPP_MSVCRT)
-#define _CTYPE_DISABLE_MACROS
+#   define _CTYPE_DISABLE_MACROS
 #endif
-#include "cwctype"
+
 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
-#include "__support/win32/locale_win32.h"
+#   include "__support/win32/locale_win32.h"
 #elif !defined(__BIONIC__) && !defined(__NuttX__)
-#include <langinfo.h>
+#   include <langinfo.h>
 #endif
-#include <stdlib.h>
-#include <stdio.h>
+
 #include "include/atomic_support.h"
 #include "include/sso_allocator.h"
 #include "__undef_macros"
@@ -81,33 +89,11 @@ struct release
     void operator()(locale::facet* p) {p->__release_shared();}
 };
 
-template <class T, class A0>
-inline
-T&
-make(A0 a0)
+template <class T, class ...Args>
+T& make(Args ...args)
 {
     static typename aligned_storage<sizeof(T)>::type buf;
-    auto *obj = ::new (&buf) T(a0);
-    return *obj;
-}
-
-template <class T, class A0, class A1>
-inline
-T&
-make(A0 a0, A1 a1)
-{
-    static typename aligned_storage<sizeof(T)>::type buf;
-    ::new (&buf) T(a0, a1);
-    return *reinterpret_cast<T*>(&buf);
-}
-
-template <class T, class A0, class A1, class A2>
-inline
-T&
-make(A0 a0, A1 a1, A2 a2)
-{
-    static typename aligned_storage<sizeof(T)>::type buf;
-    auto *obj = ::new (&buf) T(a0, a1, a2);
+    auto *obj = ::new (&buf) T(args...);
     return *obj;
 }
 
@@ -197,11 +183,17 @@ locale::__imp::__imp(size_t refs)
 {
     facets_.clear();
     install(&make<_VSTD::collate<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<_VSTD::collate<wchar_t> >(1u));
+#endif
     install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<_VSTD::ctype<wchar_t> >(1u));
+#endif
     install(&make<codecvt<char, char, mbstate_t> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
+#endif
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
     install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
     install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
@@ -211,25 +203,43 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
     install(&make<codecvt<char32_t, char8_t, mbstate_t> >(1u));
 #endif
     install(&make<numpunct<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<numpunct<wchar_t> >(1u));
+#endif
     install(&make<num_get<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<num_get<wchar_t> >(1u));
+#endif
     install(&make<num_put<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<num_put<wchar_t> >(1u));
+#endif
     install(&make<moneypunct<char, false> >(1u));
     install(&make<moneypunct<char, true> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<moneypunct<wchar_t, false> >(1u));
     install(&make<moneypunct<wchar_t, true> >(1u));
+#endif
     install(&make<money_get<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<money_get<wchar_t> >(1u));
+#endif
     install(&make<money_put<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<money_put<wchar_t> >(1u));
+#endif
     install(&make<time_get<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<time_get<wchar_t> >(1u));
+#endif
     install(&make<time_put<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<time_put<wchar_t> >(1u));
+#endif
     install(&make<_VSTD::messages<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     install(&make<_VSTD::messages<wchar_t> >(1u));
+#endif
 }
 
 locale::__imp::__imp(const string& name, size_t refs)
@@ -246,11 +256,17 @@ locale::__imp::__imp(const string& name, size_t refs)
             if (facets_[i])
                 facets_[i]->__add_shared();
         install(new collate_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new collate_byname<wchar_t>(name_));
+#endif
         install(new ctype_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new ctype_byname<wchar_t>(name_));
+#endif
         install(new codecvt_byname<char, char, mbstate_t>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
+#endif
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
         install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
         install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
@@ -260,17 +276,27 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
         install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_));
 #endif
         install(new numpunct_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new numpunct_byname<wchar_t>(name_));
+#endif
         install(new moneypunct_byname<char, false>(name_));
         install(new moneypunct_byname<char, true>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new moneypunct_byname<wchar_t, false>(name_));
         install(new moneypunct_byname<wchar_t, true>(name_));
+#endif
         install(new time_get_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new time_get_byname<wchar_t>(name_));
+#endif
         install(new time_put_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new time_put_byname<wchar_t>(name_));
+#endif
         install(new messages_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
         install(new messages_byname<wchar_t>(name_));
+#endif
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
@@ -283,13 +309,6 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
 #endif // _LIBCPP_NO_EXCEPTIONS
 }
 
-// NOTE avoid the `base class should be explicitly initialized in the
-// copy constructor` warning emitted by GCC
-#if defined(__clang__) || _GNUC_VER >= 406
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wextra"
-#endif
-
 locale::__imp::__imp(const __imp& other)
     : facets_(max<size_t>(N, other.facets_.size())),
       name_(other.name_)
@@ -300,10 +319,6 @@ locale::__imp::__imp(const __imp& other)
             facets_[i]->__add_shared();
 }
 
-#if defined(__clang__) || _GNUC_VER >= 406
-#pragma GCC diagnostic pop
-#endif
-
 locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
     : facets_(N),
       name_("*")
@@ -319,14 +334,20 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
         if (c & locale::collate)
         {
             install(new collate_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new collate_byname<wchar_t>(name));
+#endif
         }
         if (c & locale::ctype)
         {
             install(new ctype_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new ctype_byname<wchar_t>(name));
+#endif
             install(new codecvt_byname<char, char, mbstate_t>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
+#endif
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
             install(new codecvt_byname<char16_t, char, mbstate_t>(name));
             install(new codecvt_byname<char32_t, char, mbstate_t>(name));
@@ -340,25 +361,35 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
         {
             install(new moneypunct_byname<char, false>(name));
             install(new moneypunct_byname<char, true>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new moneypunct_byname<wchar_t, false>(name));
             install(new moneypunct_byname<wchar_t, true>(name));
+#endif
         }
         if (c & locale::numeric)
         {
             install(new numpunct_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new numpunct_byname<wchar_t>(name));
+#endif
         }
         if (c & locale::time)
         {
             install(new time_get_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new time_get_byname<wchar_t>(name));
+#endif
             install(new time_put_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new time_put_byname<wchar_t>(name));
+#endif
         }
         if (c & locale::messages)
         {
             install(new messages_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install(new messages_byname<wchar_t>(name));
+#endif
         }
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
@@ -396,12 +427,16 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
         if (c & locale::collate)
         {
             install_from<_VSTD::collate<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<_VSTD::collate<wchar_t> >(one);
+#endif
         }
         if (c & locale::ctype)
         {
             install_from<_VSTD::ctype<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<_VSTD::ctype<wchar_t> >(one);
+#endif
             install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
             install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
@@ -411,39 +446,59 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
             install_from<_VSTD::codecvt<char16_t, char8_t, mbstate_t> >(one);
             install_from<_VSTD::codecvt<char32_t, char8_t, mbstate_t> >(one);
 #endif
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
+#endif
         }
         if (c & locale::monetary)
         {
             install_from<moneypunct<char, false> >(one);
             install_from<moneypunct<char, true> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<moneypunct<wchar_t, false> >(one);
             install_from<moneypunct<wchar_t, true> >(one);
+#endif
             install_from<money_get<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<money_get<wchar_t> >(one);
+#endif
             install_from<money_put<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<money_put<wchar_t> >(one);
+#endif
         }
         if (c & locale::numeric)
         {
             install_from<numpunct<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<numpunct<wchar_t> >(one);
+#endif
             install_from<num_get<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<num_get<wchar_t> >(one);
+#endif
             install_from<num_put<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<num_put<wchar_t> >(one);
+#endif
         }
         if (c & locale::time)
         {
             install_from<time_get<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<time_get<wchar_t> >(one);
+#endif
             install_from<time_put<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<time_put<wchar_t> >(one);
+#endif
         }
         if (c & locale::messages)
         {
             install_from<_VSTD::messages<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
             install_from<_VSTD::messages<wchar_t> >(one);
+#endif
         }
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
@@ -734,6 +789,7 @@ collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) con
 
 // template <> class collate_byname<wchar_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
     : collate<wchar_t>(refs),
       __l(newlocale(LC_ALL_MASK, n, 0))
@@ -779,8 +835,7 @@ collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi)
     wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
     return out;
 }
-
-// template <> class ctype<wchar_t>;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 const ctype_base::mask ctype_base::space;
 const ctype_base::mask ctype_base::print;
@@ -795,6 +850,9 @@ const ctype_base::mask ctype_base::blank;
 const ctype_base::mask ctype_base::alnum;
 const ctype_base::mask ctype_base::graph;
 
+// template <> class ctype<wchar_t>;
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 locale::id ctype<wchar_t>::id;
 
 ctype<wchar_t>::~ctype()
@@ -840,7 +898,7 @@ ctype<wchar_t>::do_toupper(char_type c) const
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
     return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
-      defined(__NetBSD__)
+      defined(__NetBSD__) || defined(__MVS__)
     return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
 #else
     return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c;
@@ -854,7 +912,7 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
         *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
-      defined(__NetBSD__)
+      defined(__NetBSD__) || defined(__MVS__)
         *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
                              : *low;
 #else
@@ -869,7 +927,7 @@ ctype<wchar_t>::do_tolower(char_type c) const
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
     return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
-      defined(__NetBSD__)
+      defined(__NetBSD__) || defined(__MVS__)
     return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
 #else
     return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c;
@@ -883,7 +941,7 @@ ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
         *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
-      defined(__NetBSD__)
+      defined(__NetBSD__) || defined(__MVS__)
         *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
                              : *low;
 #else
@@ -924,11 +982,14 @@ ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfau
             *dest = dfault;
     return low;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // template <> class ctype<char>;
 
 locale::id ctype<char>::id;
 
+const size_t ctype<char>::table_size;
+
 ctype<char>::ctype(const mask* tab, bool del, size_t refs)
     : locale::facet(refs),
       __tab_(tab),
@@ -952,7 +1013,7 @@ ctype<char>::do_toupper(char_type c) const
       static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
 #elif defined(__NetBSD__)
     return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
     return isascii(c) ?
       static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
 #else
@@ -969,7 +1030,7 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
           static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
 #elif defined(__NetBSD__)
         *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
         *low = isascii(*low) ?
           static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
 #else
@@ -986,7 +1047,7 @@ ctype<char>::do_tolower(char_type c) const
       static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
 #elif defined(__NetBSD__)
     return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
     return isascii(c) ?
       static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
 #else
@@ -1002,7 +1063,7 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
         *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
 #elif defined(__NetBSD__)
         *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
         *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
 #else
         *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low;
@@ -1133,7 +1194,7 @@ ctype<char>::classic_table() noexcept
 const ctype<char>::mask*
 ctype<char>::classic_table() noexcept
 {
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
     return _DefaultRuneLocale.__runetype;
 #elif defined(__NetBSD__)
     return _C_ctype_tab_ + 1;
@@ -1150,6 +1211,12 @@ ctype<char>::classic_table() noexcept
     return _ctype_ + 1;
 #elif defined(_AIX)
     return (const unsigned int *)__lc_ctype_ptr->obj->mask;
+#elif defined(__MVS__)
+# if defined(__NATIVE_ASCII_F)
+    return const_cast<const ctype<char>::mask*> (__OBJ_DATA(__lc_ctype_a)->mask);
+# else
+    return const_cast<const ctype<char>::mask*> (__ctypec);
+# endif
 #else
     // Platform not supported: abort so the person doing the port knows what to
     // fix
@@ -1198,7 +1265,26 @@ ctype<char>::__classic_upper_table() noexcept
 {
     return *__ctype_toupper_loc();
 }
-#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__
+#elif defined(__MVS__)
+const unsigned short*
+ctype<char>::__classic_lower_table() _NOEXCEPT
+{
+# if defined(__NATIVE_ASCII_F)
+  return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->lower);
+# else
+  return const_cast<const unsigned short*>(__ctype + __TOLOWER_INDEX);
+# endif
+}
+const unsigned short *
+ctype<char>::__classic_upper_table() _NOEXCEPT
+{
+# if defined(__NATIVE_ASCII_F)
+  return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->upper);
+# else
+  return const_cast<const unsigned short*>(__ctype + __TOUPPER_INDEX);
+# endif
+}
+#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__ || __MVS__
 
 // template <> class ctype_byname<char>
 
@@ -1255,6 +1341,7 @@ ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
 
 // template <> class ctype_byname<wchar_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
     : ctype<wchar_t>(refs),
       __l(newlocale(LC_ALL_MASK, name, 0))
@@ -1454,6 +1541,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch
     }
     return low;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // template <> class codecvt<char, char, mbstate_t>
 
@@ -1518,6 +1606,7 @@ codecvt<char, char, mbstate_t>::do_max_length() const noexcept
 
 // template <> class codecvt<wchar_t, char, mbstate_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 locale::id codecvt<wchar_t, char, mbstate_t>::id;
 
 codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
@@ -1730,6 +1819,7 @@ codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept
 {
     return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l));
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 //                                     Valid UTF ranges
 //     UTF-32               UTF-16                          UTF-8               # of code points
@@ -3436,6 +3526,7 @@ codecvt<char32_t, char8_t, mbstate_t>::do_max_length() const noexcept
 
 // __codecvt_utf8<wchar_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 __codecvt_utf8<wchar_t>::result
 __codecvt_utf8<wchar_t>::do_out(state_type&,
     const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
@@ -3517,16 +3608,27 @@ __codecvt_utf8<wchar_t>::do_length(state_type&,
 {
     const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
     const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+#if defined(_LIBCPP_SHORT_WCHAR)
+    return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+#else
     return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+#endif
 }
 
 int
 __codecvt_utf8<wchar_t>::do_max_length() const noexcept
 {
+#if defined(_LIBCPP_SHORT_WCHAR)
+    if (_Mode_ & consume_header)
+        return 6;
+    return 3;
+#else
     if (_Mode_ & consume_header)
         return 7;
     return 4;
+#endif
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // __codecvt_utf8<char16_t>
 
@@ -3680,19 +3782,31 @@ __codecvt_utf8<char32_t>::do_max_length() const noexcept
 
 // __codecvt_utf16<wchar_t, false>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 __codecvt_utf16<wchar_t, false>::result
 __codecvt_utf16<wchar_t, false>::do_out(state_type&,
     const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
     extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
 {
+#if defined(_LIBCPP_SHORT_WCHAR)
+    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+    const uint16_t* _frm_nxt = _frm;
+#else
     const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
     const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
     const uint32_t* _frm_nxt = _frm;
+#endif
     uint8_t* _to = reinterpret_cast<uint8_t*>(to);
     uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
     uint8_t* _to_nxt = _to;
+#if defined(_LIBCPP_SHORT_WCHAR)
+    result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
+                               _Maxcode_, _Mode_);
+#else
     result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
                                _Maxcode_, _Mode_);
+#endif
     frm_nxt = frm + (_frm_nxt - _frm);
     to_nxt = to + (_to_nxt - _to);
     return r;
@@ -3706,11 +3820,19 @@ __codecvt_utf16<wchar_t, false>::do_in(state_type&,
     const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
     const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
     const uint8_t* _frm_nxt = _frm;
+#if defined(_LIBCPP_SHORT_WCHAR)
+    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+    uint16_t* _to_nxt = _to;
+    result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
+                               _Maxcode_, _Mode_);
+#else
     uint32_t* _to = reinterpret_cast<uint32_t*>(to);
     uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
     uint32_t* _to_nxt = _to;
     result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
                                _Maxcode_, _Mode_);
+#endif
     frm_nxt = frm + (_frm_nxt - _frm);
     to_nxt = to + (_to_nxt - _to);
     return r;
@@ -3742,15 +3864,25 @@ __codecvt_utf16<wchar_t, false>::do_length(state_type&,
 {
     const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
     const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+#if defined(_LIBCPP_SHORT_WCHAR)
+    return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+#else
     return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+#endif
 }
 
 int
 __codecvt_utf16<wchar_t, false>::do_max_length() const noexcept
 {
+#if defined(_LIBCPP_SHORT_WCHAR)
+    if (_Mode_ & consume_header)
+        return 4;
+    return 2;
+#else
     if (_Mode_ & consume_header)
         return 6;
     return 4;
+#endif
 }
 
 // __codecvt_utf16<wchar_t, true>
@@ -3760,14 +3892,25 @@ __codecvt_utf16<wchar_t, true>::do_out(state_type&,
     const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
     extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
 {
+#if defined(_LIBCPP_SHORT_WCHAR)
+    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+    const uint16_t* _frm_nxt = _frm;
+#else
     const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
     const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
     const uint32_t* _frm_nxt = _frm;
+#endif
     uint8_t* _to = reinterpret_cast<uint8_t*>(to);
     uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
     uint8_t* _to_nxt = _to;
+#if defined(_LIBCPP_SHORT_WCHAR)
+    result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
+                               _Maxcode_, _Mode_);
+#else
     result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
                                _Maxcode_, _Mode_);
+#endif
     frm_nxt = frm + (_frm_nxt - _frm);
     to_nxt = to + (_to_nxt - _to);
     return r;
@@ -3781,11 +3924,19 @@ __codecvt_utf16<wchar_t, true>::do_in(state_type&,
     const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
     const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
     const uint8_t* _frm_nxt = _frm;
+#if defined(_LIBCPP_SHORT_WCHAR)
+    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+    uint16_t* _to_nxt = _to;
+    result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
+                               _Maxcode_, _Mode_);
+#else
     uint32_t* _to = reinterpret_cast<uint32_t*>(to);
     uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
     uint32_t* _to_nxt = _to;
     result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
                                _Maxcode_, _Mode_);
+#endif
     frm_nxt = frm + (_frm_nxt - _frm);
     to_nxt = to + (_to_nxt - _to);
     return r;
@@ -3817,16 +3968,27 @@ __codecvt_utf16<wchar_t, true>::do_length(state_type&,
 {
     const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
     const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+#if defined(_LIBCPP_SHORT_WCHAR)
+    return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+#else
     return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+#endif
 }
 
 int
 __codecvt_utf16<wchar_t, true>::do_max_length() const noexcept
 {
+#if defined(_LIBCPP_SHORT_WCHAR)
+    if (_Mode_ & consume_header)
+        return 4;
+    return 2;
+#else
     if (_Mode_ & consume_header)
         return 6;
     return 4;
+#endif
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // __codecvt_utf16<char16_t, false>
 
@@ -4130,14 +4292,21 @@ __codecvt_utf16<char32_t, true>::do_max_length() const noexcept
 
 // __codecvt_utf8_utf16<wchar_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 __codecvt_utf8_utf16<wchar_t>::result
 __codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
     const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
     extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
 {
+#if defined(_LIBCPP_SHORT_WCHAR)
+    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+    const uint16_t* _frm_nxt = _frm;
+#else
     const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
     const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
     const uint32_t* _frm_nxt = _frm;
+#endif
     uint8_t* _to = reinterpret_cast<uint8_t*>(to);
     uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
     uint8_t* _to_nxt = _to;
@@ -4156,9 +4325,15 @@ __codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
     const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
     const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
     const uint8_t* _frm_nxt = _frm;
+#if defined(_LIBCPP_SHORT_WCHAR)
+    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+    uint16_t* _to_nxt = _to;
+#else
     uint32_t* _to = reinterpret_cast<uint32_t*>(to);
     uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
     uint32_t* _to_nxt = _to;
+#endif
     result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
                              _Maxcode_, _Mode_);
     frm_nxt = frm + (_frm_nxt - _frm);
@@ -4202,6 +4377,7 @@ __codecvt_utf8_utf16<wchar_t>::do_max_length() const noexcept
         return 7;
     return 4;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // __codecvt_utf8_utf16<char16_t>
 
@@ -4377,7 +4553,7 @@ __widen_from_utf8<32>::~__widen_from_utf8()
 {
 }
 
-
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 static bool checked_string_to_wchar_convert(wchar_t& dest,
                                             const char* ptr,
                                             locale_t loc) {
@@ -4392,6 +4568,19 @@ static bool checked_string_to_wchar_convert(wchar_t& dest,
   dest = out;
   return true;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+
+#ifdef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+static bool is_narrow_non_breaking_space(const char* ptr) {
+  // https://www.fileformat.info/info/unicode/char/202f/index.htm
+  return ptr[0] == '\xe2' && ptr[1] == '\x80' && ptr[2] == '\xaf';
+}
+
+static bool is_non_breaking_space(const char* ptr) {
+  // https://www.fileformat.info/info/unicode/char/0a/index.htm
+  return ptr[0] == '\xc2' && ptr[1] == '\xa0';
+}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 static bool checked_string_to_char_convert(char& dest,
                                            const char* ptr,
@@ -4402,6 +4591,8 @@ static bool checked_string_to_char_convert(char& dest,
     dest = *ptr;
     return true;
   }
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   // First convert the MBS into a wide char then attempt to narrow it using
   // wctob_l.
   wchar_t wout;
@@ -4412,7 +4603,7 @@ static bool checked_string_to_char_convert(char& dest,
     dest = res;
     return true;
   }
-  // FIXME: Work around specific multibyte sequences that we can reasonable
+  // FIXME: Work around specific multibyte sequences that we can reasonably
   // translate into a different single byte.
   switch (wout) {
   case L'\u202F': // narrow non-breaking space
@@ -4422,6 +4613,16 @@ static bool checked_string_to_char_convert(char& dest,
   default:
     return false;
   }
+#else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+  // FIXME: Work around specific multibyte sequences that we can reasonably
+  // translate into a different single byte.
+  if (is_narrow_non_breaking_space(ptr) || is_non_breaking_space(ptr)) {
+    dest = ' ';
+    return true;
+  }
+
+  return false;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
   _LIBCPP_UNREACHABLE();
 }
 
@@ -4429,7 +4630,9 @@ static bool checked_string_to_char_convert(char& dest,
 // numpunct<char> && numpunct<wchar_t>
 
 locale::id numpunct< char  >::id;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 locale::id numpunct<wchar_t>::id;
+#endif
 
 numpunct<char>::numpunct(size_t refs)
     : locale::facet(refs),
@@ -4438,35 +4641,49 @@ numpunct<char>::numpunct(size_t refs)
 {
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 numpunct<wchar_t>::numpunct(size_t refs)
     : locale::facet(refs),
       __decimal_point_(L'.'),
       __thousands_sep_(L',')
 {
 }
+#endif
 
 numpunct<char>::~numpunct()
 {
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 numpunct<wchar_t>::~numpunct()
 {
 }
+#endif
 
  char   numpunct< char  >::do_decimal_point() const {return __decimal_point_;}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
+#endif
 
  char   numpunct< char  >::do_thousands_sep() const {return __thousands_sep_;}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
+#endif
 
 string numpunct< char  >::do_grouping() const {return __grouping_;}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
+#endif
 
  string numpunct< char  >::do_truename() const {return "true";}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 wstring numpunct<wchar_t>::do_truename() const {return L"true";}
+#endif
 
  string numpunct< char  >::do_falsename() const {return "false";}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
+#endif
 
 // numpunct_byname<char>
 
@@ -4489,6 +4706,7 @@ numpunct_byname<char>::~numpunct_byname()
 void
 numpunct_byname<char>::__init(const char* nm)
 {
+    typedef numpunct<char> base;
     if (strcmp(nm, "C") != 0)
     {
         __libcpp_unique_locale loc(nm);
@@ -4497,10 +4715,12 @@ numpunct_byname<char>::__init(const char* nm)
                                 " failed to construct for " + string(nm));
 
         lconv* lc = __libcpp_localeconv_l(loc.get());
-        checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
-                                       loc.get());
-        checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep,
-                                       loc.get());
+        if (!checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
+                                            loc.get()))
+            __decimal_point_ = base::do_decimal_point();
+        if (!checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep,
+                                            loc.get()))
+            __thousands_sep_ = base::do_thousands_sep();
         __grouping_ = lc->grouping;
         // localization for truename and falsename is not available
     }
@@ -4508,6 +4728,7 @@ numpunct_byname<char>::__init(const char* nm)
 
 // numpunct_byname<wchar_t>
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
     : numpunct<wchar_t>(refs)
 {
@@ -4543,6 +4764,7 @@ numpunct_byname<wchar_t>::__init(const char* nm)
         // localization for truename and falsename is not available
     }
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // num_get helpers
 
@@ -4718,6 +4940,7 @@ init_weeks()
     return weeks;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 static
 wstring*
 init_wweeks()
@@ -4739,6 +4962,7 @@ init_wweeks()
     weeks[13] = L"Sat";
     return weeks;
 }
+#endif
 
 template <>
 const string*
@@ -4748,6 +4972,7 @@ __time_get_c_storage<char>::__weeks() const
     return weeks;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 const wstring*
 __time_get_c_storage<wchar_t>::__weeks() const
@@ -4755,6 +4980,7 @@ __time_get_c_storage<wchar_t>::__weeks() const
     static const wstring* weeks = init_wweeks();
     return weeks;
 }
+#endif
 
 static
 string*
@@ -4788,6 +5014,7 @@ init_months()
     return months;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 static
 wstring*
 init_wmonths()
@@ -4819,6 +5046,7 @@ init_wmonths()
     months[23] = L"Dec";
     return months;
 }
+#endif
 
 template <>
 const string*
@@ -4828,6 +5056,7 @@ __time_get_c_storage<char>::__months() const
     return months;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 const wstring*
 __time_get_c_storage<wchar_t>::__months() const
@@ -4835,6 +5064,7 @@ __time_get_c_storage<wchar_t>::__months() const
     static const wstring* months = init_wmonths();
     return months;
 }
+#endif
 
 static
 string*
@@ -4846,6 +5076,7 @@ init_am_pm()
     return am_pm;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 static
 wstring*
 init_wam_pm()
@@ -4855,6 +5086,7 @@ init_wam_pm()
     am_pm[1]  = L"PM";
     return am_pm;
 }
+#endif
 
 template <>
 const string*
@@ -4864,6 +5096,7 @@ __time_get_c_storage<char>::__am_pm() const
     return am_pm;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 const wstring*
 __time_get_c_storage<wchar_t>::__am_pm() const
@@ -4871,6 +5104,7 @@ __time_get_c_storage<wchar_t>::__am_pm() const
     static const wstring* am_pm = init_wam_pm();
     return am_pm;
 }
+#endif
 
 template <>
 const string&
@@ -4880,6 +5114,7 @@ __time_get_c_storage<char>::__x() const
     return s;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 const wstring&
 __time_get_c_storage<wchar_t>::__x() const
@@ -4887,6 +5122,7 @@ __time_get_c_storage<wchar_t>::__x() const
     static wstring s(L"%m/%d/%y");
     return s;
 }
+#endif
 
 template <>
 const string&
@@ -4896,6 +5132,7 @@ __time_get_c_storage<char>::__X() const
     return s;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 const wstring&
 __time_get_c_storage<wchar_t>::__X() const
@@ -4903,6 +5140,7 @@ __time_get_c_storage<wchar_t>::__X() const
     static wstring s(L"%H:%M:%S");
     return s;
 }
+#endif
 
 template <>
 const string&
@@ -4912,6 +5150,7 @@ __time_get_c_storage<char>::__c() const
     return s;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 const wstring&
 __time_get_c_storage<wchar_t>::__c() const
@@ -4919,6 +5158,7 @@ __time_get_c_storage<wchar_t>::__c() const
     static wstring s(L"%a %b %d %H:%M:%S %Y");
     return s;
 }
+#endif
 
 template <>
 const string&
@@ -4928,6 +5168,7 @@ __time_get_c_storage<char>::__r() const
     return s;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 const wstring&
 __time_get_c_storage<wchar_t>::__r() const
@@ -4935,6 +5176,7 @@ __time_get_c_storage<wchar_t>::__r() const
     static wstring s(L"%I:%M:%S %p");
     return s;
 }
+#endif
 
 // time_get_byname
 
@@ -5113,6 +5355,7 @@ __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
 #pragma clang diagnostic ignored "-Wmissing-braces"
 #endif
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 wstring
 __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
@@ -5262,6 +5505,7 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
     }
     return result;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template <>
 void
@@ -5300,6 +5544,7 @@ __time_get_storage<char>::init(const ctype<char>& ct)
     __X_ = __analyze('X', ct);
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 void
 __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
@@ -5375,6 +5620,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
     __x_ = __analyze('x', ct);
     __X_ = __analyze('X', ct);
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template <class CharT>
 struct _LIBCPP_HIDDEN __time_get_temp
@@ -5402,6 +5648,7 @@ __time_get_storage<char>::__time_get_storage(const string& __nm)
     init(ct);
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 __time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
     : __time_get(__nm)
@@ -5417,6 +5664,7 @@ __time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
     const __time_get_temp<wchar_t> ct(__nm);
     init(ct);
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template <>
 time_base::dateorder
@@ -5505,6 +5753,7 @@ __time_get_storage<char>::__do_date_order() const
     return time_base::no_order;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 time_base::dateorder
 __time_get_storage<wchar_t>::__do_date_order() const
@@ -5591,6 +5840,7 @@ __time_get_storage<wchar_t>::__do_date_order() const
     }
     return time_base::no_order;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // time_put
 
@@ -5627,6 +5877,7 @@ __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
     __ne = __nb + n;
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 void
 __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
                      char __fmt, char __mod) const
@@ -5641,6 +5892,7 @@ __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
         __throw_runtime_error("locale not supported");
     __we = __wb + j;
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // moneypunct_byname
 
@@ -6120,6 +6372,7 @@ moneypunct_byname<char, true>::init(const char* nm)
 #endif // !_LIBCPP_MSVCRT
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template<>
 void
 moneypunct_byname<wchar_t, false>::init(const char* nm)
@@ -6267,6 +6520,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
                lc->int_n_sign_posn, L' ');
 #endif // !_LIBCPP_MSVCRT
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 void __do_nothing(void*) {}
 
@@ -6280,63 +6534,63 @@ void __throw_runtime_error(const char* msg)
 #endif
 }
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;)
 
-template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;
-template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;
+                           template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;)
 
-template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
-template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;
+                           template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;)
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;)
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;)
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;
+                           template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;)
 template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char, mbstate_t>;
 template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char, mbstate_t>;
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
lib/libcxx/src/memory.cpp
@@ -1,4 +1,4 @@
-//===------------------------ memory.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,11 +8,11 @@
 
 #include "memory"
 #ifndef _LIBCPP_HAS_NO_THREADS
-#include "mutex"
-#include "thread"
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
-#endif
+#   include "mutex"
+#   include "thread"
+#   if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+#       pragma comment(lib, "pthread")
+#   endif
 #endif
 #include "include/atomic_support.h"
 
@@ -130,7 +130,7 @@ __shared_weak_count::__get_deleter(const type_info&) const noexcept
     return nullptr;
 }
 
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+#if !defined(_LIBCPP_HAS_NO_THREADS)
 
 _LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
 _LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
@@ -181,28 +181,7 @@ __get_sp_mut(const void* p)
     return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
 }
 
-#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
-
-void
-declare_reachable(void*)
-{
-}
-
-void
-declare_no_pointers(char*, size_t)
-{
-}
-
-void
-undeclare_no_pointers(char*, size_t)
-{
-}
-
-void*
-__undeclare_reachable(void* p)
-{
-    return p;
-}
+#endif // !defined(_LIBCPP_HAS_NO_THREADS)
 
 void*
 align(size_t alignment, size_t size, void*& ptr, size_t& space)
lib/libcxx/src/mutex.cpp
@@ -1,4 +1,4 @@
-//===------------------------- mutex.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/mutex_destructor.cpp
@@ -1,4 +1,4 @@
-//===--------------------- mutex_destructor.cpp ---------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/new.cpp
@@ -1,4 +1,4 @@
-//===--------------------------- new.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/optional.cpp
@@ -1,4 +1,4 @@
-//===------------------------ optional.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/random.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- random.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,8 +9,8 @@
 #include <__config>
 
 #if defined(_LIBCPP_USING_WIN32_RANDOM)
-// Must be defined before including stdlib.h to enable rand_s().
-#define _CRT_RAND_S
+    // Must be defined before including stdlib.h to enable rand_s().
+#   define _CRT_RAND_S
 #endif // defined(_LIBCPP_USING_WIN32_RANDOM)
 
 #include "limits"
@@ -18,7 +18,7 @@
 #include "system_error"
 
 #if defined(__sun__)
-#define rename solaris_headers_are_broken
+#   define rename solaris_headers_are_broken
 #endif // defined(__sun__)
 
 #include <errno.h>
@@ -26,16 +26,18 @@
 #include <stdlib.h>
 
 #if defined(_LIBCPP_USING_GETENTROPY)
-#include <sys/random.h>
+#   include <sys/random.h>
 #elif defined(_LIBCPP_USING_DEV_RANDOM)
-#include <fcntl.h>
-#include <unistd.h>
-#if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>)
-#include <sys/ioctl.h>
-#include <linux/random.h>
-#endif
+#   include <fcntl.h>
+#   include <unistd.h>
+#   if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>)
+#       include <sys/ioctl.h>
+#       include <linux/random.h>
+#   endif
 #elif defined(_LIBCPP_USING_NACL_RANDOM)
-#include <nacl/nacl_random.h>
+#   include <nacl/nacl_random.h>
+#elif defined(_LIBCPP_USING_FUCHSIA_CPRNG)
+#  include <zircon/syscalls.h>
 #endif
 
 
@@ -66,10 +68,8 @@ random_device::operator()()
 
 #elif defined(_LIBCPP_USING_ARC4_RANDOM)
 
-random_device::random_device(const string& __token)
+random_device::random_device(const string&)
 {
-    if (__token != "/dev/urandom")
-        __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
 }
 
 random_device::~random_device()
@@ -170,6 +170,27 @@ random_device::operator()()
     return r;
 }
 
+#elif defined(_LIBCPP_USING_FUCHSIA_CPRNG)
+
+random_device::random_device(const string& __token) {
+  if (__token != "/dev/urandom")
+    __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
+}
+
+random_device::~random_device() {}
+
+unsigned random_device::operator()() {
+  // Implicitly link against the vDSO system call ABI without
+  // requiring the final link to specify -lzircon explicitly when
+  // statically linking libc++.
+#  pragma comment(lib, "zircon")
+
+  // The system call cannot fail.  It returns only when the bits are ready.
+  unsigned r;
+  _zx_cprng_draw(&r, sizeof(r));
+  return r;
+}
+
 #else
 #error "Random device not implemented for this architecture"
 #endif
@@ -189,7 +210,7 @@ random_device::entropy() const noexcept
     return std::numeric_limits<result_type>::digits;
 
   return ent;
-#elif defined(__OpenBSD__)
+#elif defined(_LIBCPP_USING_ARC4_RANDOM) || defined(_LIBCPP_USING_FUCHSIA_CPRNG)
   return std::numeric_limits<result_type>::digits;
 #else
   return 0;
lib/libcxx/src/random_shuffle.cpp
@@ -1,4 +1,4 @@
-//===----------------------- random_shuffle.cpp ---------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/regex.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- regex.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -76,6 +76,125 @@ struct collationnames
     char char_;
 };
 
+#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
+// EBCDIC IBM-1047
+// Sorted via the EBCDIC collating sequence
+const collationnames collatenames[] =
+{
+    {"a", 0x81},
+    {"alert", 0x2f},
+    {"ampersand", 0x50},
+    {"apostrophe", 0x7d},
+    {"asterisk", 0x5c},
+    {"b", 0x82},
+    {"backslash", 0xe0},
+    {"backspace", 0x16},
+    {"c", 0x83},
+    {"carriage-return", 0xd},
+    {"circumflex", 0x5f},
+    {"circumflex-accent", 0x5f},
+    {"colon", 0x7a},
+    {"comma", 0x6b},
+    {"commercial-at", 0x7c},
+    {"d", 0x84},
+    {"dollar-sign", 0x5b},
+    {"e", 0x85},
+    {"eight", 0xf8},
+    {"equals-sign", 0x7e},
+    {"exclamation-mark", 0x5a},
+    {"f", 0x86},
+    {"five", 0xf5},
+    {"form-feed", 0xc},
+    {"four", 0xf4},
+    {"full-stop", 0x4b},
+    {"g", 0x87},
+    {"grave-accent", 0x79},
+    {"greater-than-sign", 0x6e},
+    {"h", 0x88},
+    {"hyphen", 0x60},
+    {"hyphen-minus", 0x60},
+    {"i", 0x89},
+    {"j", 0x91},
+    {"k", 0x92},
+    {"l", 0x93},
+    {"left-brace", 0xc0},
+    {"left-curly-bracket", 0xc0},
+    {"left-parenthesis", 0x4d},
+    {"left-square-bracket", 0xad},
+    {"less-than-sign", 0x4c},
+    {"low-line", 0x6d},
+    {"m", 0x94},
+    {"n", 0x95},
+    {"newline", 0x15},
+    {"nine", 0xf9},
+    {"number-sign", 0x7b},
+    {"o", 0x96},
+    {"one", 0xf1},
+    {"p", 0x97},
+    {"percent-sign", 0x6c},
+    {"period", 0x4b},
+    {"plus-sign", 0x4e},
+    {"q", 0x98},
+    {"question-mark", 0x6f},
+    {"quotation-mark", 0x7f},
+    {"r", 0x99},
+    {"reverse-solidus", 0xe0},
+    {"right-brace", 0xd0},
+    {"right-curly-bracket", 0xd0},
+    {"right-parenthesis", 0x5d},
+    {"right-square-bracket", 0xbd},
+    {"s", 0xa2},
+    {"semicolon", 0x5e},
+    {"seven", 0xf7},
+    {"six", 0xf6},
+    {"slash", 0x61},
+    {"solidus", 0x61},
+    {"space", 0x40},
+    {"t", 0xa3},
+    {"tab", 0x5},
+    {"three", 0xf3},
+    {"tilde", 0xa1},
+    {"two", 0xf2},
+    {"u", 0xa4},
+    {"underscore", 0x6d},
+    {"v", 0xa5},
+    {"vertical-line", 0x4f},
+    {"vertical-tab", 0xb},
+    {"w", 0xa6},
+    {"x", 0xa7},
+    {"y", 0xa8},
+    {"z", 0xa9},
+    {"zero", 0xf0},
+    {"A", 0xc1},
+    {"B", 0xc2},
+    {"C", 0xc3},
+    {"D", 0xc4},
+    {"E", 0xc5},
+    {"F", 0xc6},
+    {"G", 0xc7},
+    {"H", 0xc8},
+    {"I", 0xc9},
+    {"J", 0xd1},
+    {"K", 0xd2},
+    {"L", 0xd3},
+    {"M", 0xd4},
+    {"N", 0xd5},
+    {"NUL", 0},
+    {"O", 0xd6},
+    {"P", 0xd7},
+    {"Q", 0xd8},
+    {"R", 0xd9},
+    {"S", 0xe2},
+    {"T", 0xe3},
+    {"U", 0xe4},
+    {"V", 0xe5},
+    {"W", 0xe6},
+    {"X", 0xe7},
+    {"Y", 0xe8},
+    {"Z", 0xe9}
+};
+#else
+// ASCII
 const collationnames collatenames[] =
 {
     {"A", 0x41},
@@ -190,6 +309,7 @@ const collationnames collatenames[] =
     {"z", 0x7a},
     {"zero", 0x30}
 };
+#endif
 
 struct classnames
 {
lib/libcxx/src/shared_mutex.cpp
@@ -1,4 +1,4 @@
-//===---------------------- shared_mutex.cpp ------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/stdexcept.cpp
@@ -1,4 +1,4 @@
-//===------------------------ stdexcept.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/string.cpp
@@ -1,4 +1,4 @@
-//===------------------------- string.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,24 +9,50 @@
 #include "string"
 #include "charconv"
 #include "cstdlib"
-#include "cwchar"
 #include "cerrno"
 #include "limits"
 #include "stdexcept"
 #include <stdio.h>
 #include "__debug"
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+#   include "cwchar"
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __basic_string_common<true>;
+#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
+
+template <bool>
+struct __basic_string_common;
+
+// The struct isn't declared anymore in the headers. It's only here for ABI compatibility.
+template <>
+struct __basic_string_common<true> {
+    _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
+    _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
+};
+
+void __basic_string_common<true>::__throw_length_error() const {
+    std::__throw_length_error("basic_string");
+}
+void __basic_string_common<true>::__throw_out_of_range() const {
+    std::__throw_out_of_range("basic_string");
+}
+
+#endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
 
 #define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
 #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
-_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
-_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
+    _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
+#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+        _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
+#   endif
 #else
-_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
-_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
+    _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
+#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+        _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
+#   endif
 #endif
 #undef _LIBCPP_EXTERN_TEMPLATE_DEFINE
 
@@ -131,6 +157,7 @@ as_integer( const string& func, const string& s, size_t* idx, int base )
     return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 // wstring
 template<>
 inline
@@ -175,6 +202,7 @@ as_integer( const string& func, const wstring& s, size_t* idx, int base )
 {
     return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 // as_float
 
@@ -226,6 +254,7 @@ as_float( const string& func, const string& s, size_t* idx )
     return as_float_helper<long double>( func, s, idx, strtold );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template<>
 inline
 float
@@ -249,6 +278,7 @@ as_float( const string& func, const wstring& s, size_t* idx )
 {
     return as_float_helper<long double>( func, s, idx, wcstold );
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 }  // unnamed namespace
 
@@ -258,11 +288,13 @@ stoi(const string& str, size_t* idx, int base)
     return as_integer<int>( "stoi", str, idx, base );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 int
 stoi(const wstring& str, size_t* idx, int base)
 {
     return as_integer<int>( "stoi", str, idx, base );
 }
+#endif
 
 long
 stol(const string& str, size_t* idx, int base)
@@ -270,11 +302,13 @@ stol(const string& str, size_t* idx, int base)
     return as_integer<long>( "stol", str, idx, base );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 long
 stol(const wstring& str, size_t* idx, int base)
 {
     return as_integer<long>( "stol", str, idx, base );
 }
+#endif
 
 unsigned long
 stoul(const string& str, size_t* idx, int base)
@@ -282,11 +316,13 @@ stoul(const string& str, size_t* idx, int base)
     return as_integer<unsigned long>( "stoul", str, idx, base );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 unsigned long
 stoul(const wstring& str, size_t* idx, int base)
 {
     return as_integer<unsigned long>( "stoul", str, idx, base );
 }
+#endif
 
 long long
 stoll(const string& str, size_t* idx, int base)
@@ -294,11 +330,13 @@ stoll(const string& str, size_t* idx, int base)
     return as_integer<long long>( "stoll", str, idx, base );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 long long
 stoll(const wstring& str, size_t* idx, int base)
 {
     return as_integer<long long>( "stoll", str, idx, base );
 }
+#endif
 
 unsigned long long
 stoull(const string& str, size_t* idx, int base)
@@ -306,11 +344,13 @@ stoull(const string& str, size_t* idx, int base)
     return as_integer<unsigned long long>( "stoull", str, idx, base );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 unsigned long long
 stoull(const wstring& str, size_t* idx, int base)
 {
     return as_integer<unsigned long long>( "stoull", str, idx, base );
 }
+#endif
 
 float
 stof(const string& str, size_t* idx)
@@ -318,11 +358,13 @@ stof(const string& str, size_t* idx)
     return as_float<float>( "stof", str, idx );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 float
 stof(const wstring& str, size_t* idx)
 {
     return as_float<float>( "stof", str, idx );
 }
+#endif
 
 double
 stod(const string& str, size_t* idx)
@@ -330,11 +372,13 @@ stod(const string& str, size_t* idx)
     return as_float<double>( "stod", str, idx );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 double
 stod(const wstring& str, size_t* idx)
 {
     return as_float<double>( "stod", str, idx );
 }
+#endif
 
 long double
 stold(const string& str, size_t* idx)
@@ -342,11 +386,13 @@ stold(const string& str, size_t* idx)
     return as_float<long double>( "stold", str, idx );
 }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 long double
 stold(const wstring& str, size_t* idx)
 {
     return as_float<long double>( "stold", str, idx );
 }
+#endif
 
 // to_string
 
@@ -397,6 +443,7 @@ struct initial_string<string>
     }
 };
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 template <>
 struct initial_string<wstring>
 {
@@ -421,6 +468,7 @@ get_swprintf()
     return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
 #endif
 }
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
 template <typename S, typename V>
 S i_to_string(V v)
@@ -444,20 +492,23 @@ string  to_string (unsigned val)           { return i_to_string< string>(val); }
 string  to_string (unsigned long val)      { return i_to_string< string>(val); }
 string  to_string (unsigned long long val) { return i_to_string< string>(val); }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 wstring to_wstring(int val)                { return i_to_string<wstring>(val); }
 wstring to_wstring(long val)               { return i_to_string<wstring>(val); }
 wstring to_wstring(long long val)          { return i_to_string<wstring>(val); }
 wstring to_wstring(unsigned val)           { return i_to_string<wstring>(val); }
 wstring to_wstring(unsigned long val)      { return i_to_string<wstring>(val); }
 wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); }
-
+#endif
 
 string  to_string (float val)       { return as_string(snprintf,       initial_string< string>()(),   "%f", val); }
 string  to_string (double val)      { return as_string(snprintf,       initial_string< string>()(),   "%f", val); }
 string  to_string (long double val) { return as_string(snprintf,       initial_string< string>()(),  "%Lf", val); }
 
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
 wstring to_wstring(float val)       { return as_string(get_swprintf(), initial_string<wstring>()(),  L"%f", val); }
 wstring to_wstring(double val)      { return as_string(get_swprintf(), initial_string<wstring>()(),  L"%f", val); }
 wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); }
+#endif
 
 _LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/strstream.cpp
@@ -1,4 +1,4 @@
-//===------------------------ strstream.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/system_error.cpp
@@ -1,4 +1,4 @@
-//===---------------------- system_error.cpp ------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/typeinfo.cpp
@@ -1,4 +1,4 @@
-//===------------------------- typeinfo.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/utility.cpp
@@ -1,4 +1,4 @@
-//===------------------------ utility.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/valarray.cpp
@@ -1,4 +1,4 @@
-//===------------------------ valarray.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/variant.cpp
@@ -1,4 +1,4 @@
-//===------------------------ variant.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
lib/libcxx/src/vector.cpp
@@ -1,4 +1,4 @@
-//===------------------------- vector.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,6 +10,25 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __vector_base_common<true>;
+#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
+
+template <bool>
+struct __vector_base_common;
+
+template <>
+struct __vector_base_common<true> {
+  _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
+  _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
+};
+
+void __vector_base_common<true>::__throw_length_error() const {
+  _VSTD::__throw_length_error("vector");
+}
+
+void __vector_base_common<true>::__throw_out_of_range() const {
+  _VSTD::__throw_out_of_range("vector");
+}
+
+#endif // _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
 
 _LIBCPP_END_NAMESPACE_STD
src/libcxx.zig
@@ -54,6 +54,7 @@ const libcxx_files = [_][]const u8{
     "src/ios.cpp",
     "src/ios.instantiations.cpp",
     "src/iostream.cpp",
+    "src/legacy_pointer_safety.cpp",
     "src/locale.cpp",
     "src/memory.cpp",
     "src/mutex.cpp",
@@ -63,10 +64,15 @@ const libcxx_files = [_][]const u8{
     "src/random.cpp",
     "src/random_shuffle.cpp",
     "src/regex.cpp",
+    "src/ryu/d2fixed.cpp",
+    "src/ryu/d2s.cpp",
+    "src/ryu/f2s.cpp",
     "src/shared_mutex.cpp",
     "src/stdexcept.cpp",
     "src/string.cpp",
     "src/strstream.cpp",
+    "src/support/ibm/mbsnrtowcs.cpp",
+    "src/support/ibm/wcsnrtombs.cpp",
     "src/support/ibm/xlocale_zos.cpp",
     "src/support/solaris/xlocale.cpp",
     "src/support/win32/locale_win32.cpp",