diff libcxx/include/vector @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 5f17cb93ff66
children 1f2b6ac9f198
line wrap: on
line diff
--- a/libcxx/include/vector	Wed Jul 21 10:27:27 2021 +0900
+++ b/libcxx/include/vector	Wed Nov 09 17:45:10 2022 +0900
@@ -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 @@
 
 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,27 +271,61 @@
 
 */
 
+#include <__algorithm/copy.h>
+#include <__algorithm/equal.h>
+#include <__algorithm/fill_n.h>
+#include <__algorithm/lexicographical_compare.h>
+#include <__algorithm/remove.h>
+#include <__algorithm/remove_if.h>
+#include <__algorithm/rotate.h>
+#include <__algorithm/unwrap_iter.h>
+#include <__assert> // all public C++ headers provide the assertion handler
+#include <__bit_reference>
 #include <__config>
-#include <__bit_reference>
 #include <__debug>
-#include <__functional_base>
+#include <__format/enable_insertable.h>
+#include <__functional/hash.h>
+#include <__functional/unary_function.h>
+#include <__iterator/advance.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/reverse_iterator.h>
 #include <__iterator/wrap_iter.h>
+#include <__memory/allocate_at_least.h>
+#include <__memory/pointer_traits.h>
+#include <__memory/swap_allocator.h>
+#include <__memory/temp_value.h>
+#include <__memory/uninitialized_algorithms.h>
+#include <__memory_resource/polymorphic_allocator.h>
 #include <__split_buffer>
+#include <__type_traits/is_allocator.h>
+#include <__type_traits/noexcept_move_assign_container.h>
 #include <__utility/forward.h>
-#include <algorithm>
+#include <__utility/move.h>
+#include <__utility/swap.h>
 #include <climits>
-#include <compare>
+#include <cstdlib>
 #include <cstring>
-#include <initializer_list>
 #include <iosfwd> // for forward declaration of vector
 #include <limits>
-#include <memory>
 #include <stdexcept>
 #include <type_traits>
 #include <version>
 
+// standard-mandated includes
+
+// [iterator.range]
+#include <__iterator/access.h>
+#include <__iterator/data.h>
+#include <__iterator/empty.h>
+#include <__iterator/reverse_access.h>
+#include <__iterator/size.h>
+
+// [vector.syn]
+#include <compare>
+#include <initializer_list>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
+#  pragma GCC system_header
 #endif
 
 _LIBCPP_PUSH_MACROS
@@ -300,488 +334,301 @@
 
 _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>());}
-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 std::reverse_iterator<iterator>               reverse_iterator;
+    typedef std::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
+    static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
+                  "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
+                  "original allocator");
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
-        {
-#if _LIBCPP_DEBUG_LEVEL == 2
-            __get_db()->__insert_c(this);
-#endif
-        }
-    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
+    {
+        std::__debug_db_insert_c(this);
+    }
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 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
+        std::__debug_db_insert_c(this);
     }
-    explicit vector(size_type __n);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n);
 #if _LIBCPP_STD_VER > 11
-    explicit vector(size_type __n, const allocator_type& __a);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 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 _InputIterator>
-        vector(_InputIterator __first,
-               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                                 !__is_cpp17_forward_iterator<_InputIterator>::value &&
-                                 is_constructible<
-                                    value_type,
-                                    typename iterator_traits<_InputIterator>::reference>::value,
-                                 _InputIterator>::type __last);
-    template <class _InputIterator>
-        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
-               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                                 !__is_cpp17_forward_iterator<_InputIterator>::value &&
-                                 is_constructible<
-                                    value_type,
-                                    typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
-    template <class _ForwardIterator>
-        vector(_ForwardIterator __first,
-               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
-                                 is_constructible<
-                                    value_type,
-                                    typename iterator_traits<_ForwardIterator>::reference>::value,
-                                 _ForwardIterator>::type __last);
-    template <class _ForwardIterator>
-        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
-               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
-                                 is_constructible<
-                                    value_type,
-                                    typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
-
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x);
+
+    template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+    vector(size_type __n, const value_type& __x, const allocator_type& __a)
+        : __end_cap_(nullptr, __a)
+    {
+      std::__debug_db_insert_c(this);
+      if (__n > 0)
+      {
+          __vallocate(__n);
+          __construct_at_end(__n, __x);
+      }
+    }
+
+  template <class _InputIterator,
+            __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last);
+  template <class _InputIterator,
+            __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
+
+  template <
+      class _ForwardIterator,
+      __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last);
+
+  template <class _ForwardIterator,
+      __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     ~vector()
     {
-        __annotate_delete();
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__erase_c(this);
-#endif
+      __annotate_delete();
+      std::__debug_db_erase_c(this);
+
+      if (this->__begin_ != nullptr)
+      {
+        __clear();
+        __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
+      }
     }
 
-    vector(const vector& __x);
-    vector(const vector& __x, const __identity_t<allocator_type>& __a);
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     vector& operator=(const vector& __x);
 
 #ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     vector(initializer_list<value_type> __il);
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     vector(initializer_list<value_type> __il, const allocator_type& __a);
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+    vector& operator=(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end()); return *this;}
+#endif // !_LIBCPP_CXX03_LANG
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     vector(vector&& __x)
 #if _LIBCPP_STD_VER > 14
-        _NOEXCEPT;
+        noexcept;
 #else
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY
-    vector(vector&& __x, const __identity_t<allocator_type>& __a);
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+    vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     vector& operator=(vector&& __x)
         _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
 
-    _LIBCPP_INLINE_VISIBILITY
-    vector& operator=(initializer_list<value_type> __il)
-        {assign(__il.begin(), __il.end()); return *this;}
-
-#endif // !_LIBCPP_CXX03_LANG
-
-    template <class _InputIterator>
-        typename enable_if
-        <
-             __is_cpp17_input_iterator  <_InputIterator>::value &&
-            !__is_cpp17_forward_iterator<_InputIterator>::value &&
-            is_constructible<
-                 value_type,
-                 typename iterator_traits<_InputIterator>::reference>::value,
-            void
-        >::type
-        assign(_InputIterator __first, _InputIterator __last);
-    template <class _ForwardIterator>
-        typename enable_if
-        <
-            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
-            is_constructible<
-                 value_type,
-                 typename iterator_traits<_ForwardIterator>::reference>::value,
-            void
-        >::type
-        assign(_ForwardIterator __first, _ForwardIterator __last);
-
-    void assign(size_type __n, const_reference __u);
+  template <class _InputIterator,
+            __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last);
+  template <
+      class _ForwardIterator,
+      __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);
 
 #ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void assign(initializer_list<value_type> __il)
         {assign(__il.begin(), __il.end());}
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     allocator_type get_allocator() const _NOEXCEPT
         {return this->__alloc();}
 
-    _LIBCPP_INLINE_VISIBILITY iterator               begin() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY const_iterator         begin()   const _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY iterator               end() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY const_iterator         end()     const _NOEXCEPT;
-
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator               begin() _NOEXCEPT;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator         begin()   const _NOEXCEPT;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator               end() _NOEXCEPT;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator         end()     const _NOEXCEPT;
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     reverse_iterator       rbegin() _NOEXCEPT
         {return       reverse_iterator(end());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const_reverse_iterator rbegin()  const _NOEXCEPT
         {return const_reverse_iterator(end());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     reverse_iterator       rend() _NOEXCEPT
         {return       reverse_iterator(begin());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const_reverse_iterator rend()    const _NOEXCEPT
         {return const_reverse_iterator(begin());}
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const_iterator         cbegin()  const _NOEXCEPT
         {return begin();}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const_iterator         cend()    const _NOEXCEPT
         {return end();}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const_reverse_iterator crbegin() const _NOEXCEPT
         {return rbegin();}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const_reverse_iterator crend()   const _NOEXCEPT
         {return rend();}
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     size_type size() const _NOEXCEPT
         {return static_cast<size_type>(this->__end_ - this->__begin_);}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     size_type capacity() const _NOEXCEPT
-        {return __base::capacity();}
-    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
+        {return static_cast<size_type>(__end_cap() - this->__begin_);}
+    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     bool empty() const _NOEXCEPT
         {return this->__begin_ == this->__end_;}
-    size_type max_size() const _NOEXCEPT;
-    void reserve(size_type __n);
-    void shrink_to_fit() _NOEXCEPT;
-
-    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
-    reference       at(size_type __n);
-    const_reference at(size_type __n) const;
-
-    _LIBCPP_INLINE_VISIBILITY reference       front() _NOEXCEPT
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       operator[](size_type __n) _NOEXCEPT;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       at(size_type __n);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       front() _NOEXCEPT
     {
         _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
         return *this->__begin_;
     }
-    _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT
     {
         _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
         return *this->__begin_;
     }
-    _LIBCPP_INLINE_VISIBILITY reference       back() _NOEXCEPT
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       back() _NOEXCEPT
     {
         _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
         return *(this->__end_ - 1);
     }
-    _LIBCPP_INLINE_VISIBILITY const_reference back()  const _NOEXCEPT
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back()  const _NOEXCEPT
     {
         _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
         return *(this->__end_ - 1);
     }
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     value_type*       data() _NOEXCEPT
-        {return _VSTD::__to_address(this->__begin_);}
-    _LIBCPP_INLINE_VISIBILITY
+        {return std::__to_address(this->__begin_);}
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const value_type* data() const _NOEXCEPT
-        {return _VSTD::__to_address(this->__begin_);}
-
-#ifdef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    void __emplace_back(const value_type& __x) { push_back(__x); }
-#else
-    template <class _Arg>
-    _LIBCPP_INLINE_VISIBILITY
-    void __emplace_back(_Arg&& __arg) {
-      emplace_back(_VSTD::forward<_Arg>(__arg));
-    }
-#endif
-
-    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
-
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
+        {return std::__to_address(this->__begin_);}
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
 
     template <class... _Args>
-        _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
 #if _LIBCPP_STD_VER > 14
         reference emplace_back(_Args&&... __args);
 #else
         void      emplace_back(_Args&&... __args);
 #endif
-#endif // !_LIBCPP_CXX03_LANG
-
-    _LIBCPP_INLINE_VISIBILITY
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void pop_back();
 
-    iterator insert(const_iterator __position, const_reference __x);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);
+    template <class... _Args>
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+    iterator insert(const_iterator __position, size_type __n, const_reference __x);
+
+  template <class _InputIterator,
+            __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
+  insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
+
+  template <
+      class _ForwardIterator,
+      __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
+  insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
 
 #ifndef _LIBCPP_CXX03_LANG
-    iterator insert(const_iterator __position, value_type&& __x);
-    template <class... _Args>
-        iterator emplace(const_iterator __position, _Args&&... __args);
-#endif // !_LIBCPP_CXX03_LANG
-
-    iterator insert(const_iterator __position, size_type __n, const_reference __x);
-    template <class _InputIterator>
-        typename enable_if
-        <
-             __is_cpp17_input_iterator  <_InputIterator>::value &&
-            !__is_cpp17_forward_iterator<_InputIterator>::value &&
-            is_constructible<
-                 value_type,
-                 typename iterator_traits<_InputIterator>::reference>::value,
-            iterator
-        >::type
-        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
-    template <class _ForwardIterator>
-        typename enable_if
-        <
-            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
-            is_constructible<
-                 value_type,
-                 typename iterator_traits<_ForwardIterator>::reference>::value,
-            iterator
-        >::type
-        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
-
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     iterator insert(const_iterator __position, initializer_list<value_type> __il)
         {return insert(__position, __il.begin(), __il.end());}
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
-    iterator erase(const_iterator __first, const_iterator __last);
-
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void clear() _NOEXCEPT
     {
         size_type __old_size = size();
-        __base::clear();
+        __clear();
         __annotate_shrink(__old_size);
-        __invalidate_all_iterators();
+        std::__debug_db_invalidate_all(this);
     }
 
-    void resize(size_type __sz);
-    void resize(size_type __sz, const_reference __x);
-
-    void swap(vector&)
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&)
 #if _LIBCPP_STD_VER >= 14
         _NOEXCEPT;
 #else
@@ -789,107 +636,122 @@
                     __is_nothrow_swappable<allocator_type>::value);
 #endif
 
-    bool __invariants() const;
-
-#if _LIBCPP_DEBUG_LEVEL == 2
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
+
+#ifdef _LIBCPP_ENABLE_DEBUG_MODE
 
     bool __dereferenceable(const const_iterator* __i) const;
     bool __decrementable(const const_iterator* __i) const;
     bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
     bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
 
-#endif // _LIBCPP_DEBUG_LEVEL == 2
+#endif // _LIBCPP_ENABLE_DEBUG_MODE
 
 private:
-    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
-    _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
-    void __vallocate(size_type __n);
-    void __vdeallocate() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
-    void __construct_at_end(size_type __n);
-    _LIBCPP_INLINE_VISIBILITY
+    pointer __begin_ = nullptr;
+    pointer __end_ = nullptr;
+    __compressed_pair<pointer, allocator_type> __end_cap_ =
+        __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
+
+    _LIBCPP_HIDE_FROM_ABI void __invalidate_iterators_past(pointer __new_last);
+
+    //  Allocate space for __n objects
+    //  throws length_error if __n > max_size()
+    //  throws (probably bad_alloc) if memory run out
+    //  Precondition:  __begin_ == __end_ == __end_cap() == 0
+    //  Precondition:  __n > 0
+    //  Postcondition:  capacity() >= __n
+    //  Postcondition:  size() == 0
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
+        if (__n > max_size())
+            __throw_length_error();
+        auto __allocation = std::__allocate_at_least(__alloc(), __n);
+        __begin_ = __allocation.ptr;
+        __end_ = __allocation.ptr;
+        __end_cap() = __begin_ + __allocation.count;
+        __annotate_new(0);
+    }
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void __construct_at_end(size_type __n, const_reference __x);
-    template <class _ForwardIterator>
-        typename enable_if
-        <
-            __is_cpp17_forward_iterator<_ForwardIterator>::value,
-            void
-        >::type
-        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
-    void __append(size_type __n);
-    void __append(size_type __n, const_reference __x);
-    _LIBCPP_INLINE_VISIBILITY
+
+  template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value, int> = 0>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
+  __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
+
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     iterator       __make_iter(pointer __p) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
-    void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
-    pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
-    void __move_range(pointer __from_s, pointer __from_e, pointer __to);
-    void __move_assign(vector& __c, true_type)
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_range(pointer __from_s, pointer __from_e, pointer __to);
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type)
         _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
-    void __move_assign(vector& __c, false_type)
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)
         _NOEXCEPT_(__alloc_traits::is_always_equal::value);
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void __destruct_at_end(pointer __new_last) _NOEXCEPT
     {
-        __invalidate_iterators_past(__new_last);
+        if (!__libcpp_is_constant_evaluated())
+            __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);
     }
 
-#ifndef _LIBCPP_CXX03_LANG
     template <class _Up>
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     inline void __push_back_slow_path(_Up&& __x);
 
     template <class... _Args>
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     inline void __emplace_back_slow_path(_Args&&... __args);
-#else
-    template <class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    inline void __push_back_slow_path(_Up& __x);
-#endif
 
     // The following functions are no-ops outside of AddressSanitizer mode.
     // We call annotatations only for the default Allocator because other allocators
     // may not meet the AddressSanitizer alignment constraints.
     // See the documentation for __sanitizer_annotate_contiguous_container for more details.
 #ifndef _LIBCPP_HAS_NO_ASAN
+    _LIBCPP_CONSTEXPR_SINCE_CXX20
     void __annotate_contiguous_container(const void *__beg, const void *__end,
                                          const void *__old_mid,
                                          const void *__new_mid) const
     {
 
-      if (__beg && is_same<allocator_type, __default_allocator_type>::value)
+      if (!__libcpp_is_constant_evaluated() && __beg && is_same<allocator_type, __default_allocator_type>::value)
         __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
     }
 #else
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void __annotate_contiguous_container(const void*, const void*, const void*,
                                          const void*) const _NOEXCEPT {}
 #endif
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void __annotate_new(size_type __current_size) const _NOEXCEPT {
       __annotate_contiguous_container(data(), data() + capacity(),
                                       data() + capacity(), data() + __current_size);
     }
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void __annotate_delete() const _NOEXCEPT {
       __annotate_contiguous_container(data(), data() + capacity(),
                                       data() + size(), data() + capacity());
     }
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void __annotate_increase(size_type __n) const _NOEXCEPT
     {
       __annotate_contiguous_container(data(), data() + capacity(),
                                       data() + size(), data() + size() + __n);
     }
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     void __annotate_shrink(size_type __old_size) const _NOEXCEPT
     {
       __annotate_contiguous_container(data(), data() + capacity(),
@@ -897,13 +759,14 @@
     }
 
   struct _ConstructTransaction {
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
     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
     }
-    ~_ConstructTransaction() {
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
       __v_.__end_ = __pos_;
 #ifndef _LIBCPP_HAS_NO_ASAN
       if (__pos_ != __new_end_) {
@@ -922,82 +785,149 @@
   };
 
   template <class ..._Args>
-  _LIBCPP_INLINE_VISIBILITY
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
   void __construct_one_at_end(_Args&& ...__args) {
     _ConstructTransaction __tx(*this, 1);
-    __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_),
-        _VSTD::forward<_Args>(__args)...);
+    __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_),
+        std::forward<_Args>(__args)...);
     ++__tx.__pos_;
   }
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  allocator_type& __alloc() _NOEXCEPT
+      {return this->__end_cap_.second();}
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  const allocator_type& __alloc() const _NOEXCEPT
+      {return this->__end_cap_.second();}
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  pointer& __end_cap() _NOEXCEPT
+      {return this->__end_cap_.first();}
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  const pointer& __end_cap() const _NOEXCEPT
+      {return this->__end_cap_.first();}
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  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(), std::__to_address(--__soon_to_be_end));
+    this->__end_ = __new_last;
+  }
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  void __copy_assign_alloc(const vector& __c)
+      {__copy_assign_alloc(__c, integral_constant<bool,
+                    __alloc_traits::propagate_on_container_copy_assignment::value>());}
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  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 {
+      std::__throw_length_error("vector");
+  }
+
+  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+  void __throw_out_of_range() const {
+      std::__throw_out_of_range("vector");
+  }
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  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_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  void __copy_assign_alloc(const vector&, false_type)
+  {}
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  void __move_assign_alloc(vector& __c, true_type)
+      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
+  {
+    __alloc() = std::move(__c.__alloc());
+  }
+
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
+  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>;
 #endif
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
 {
-
     __annotate_delete();
-    _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
-    _VSTD::swap(this->__begin_, __v.__begin_);
-    _VSTD::swap(this->__end_, __v.__end_);
-    _VSTD::swap(this->__end_cap(), __v.__end_cap());
+    using _RevIter = std::reverse_iterator<pointer>;
+    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
+                       __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_))
+                       .base();
+    std::swap(this->__begin_, __v.__begin_);
+    std::swap(this->__end_, __v.__end_);
+    std::swap(this->__end_cap(), __v.__end_cap());
     __v.__first_ = __v.__begin_;
     __annotate_new(size());
-    __invalidate_all_iterators();
+    std::__debug_db_invalidate_all(this);
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<_Tp, _Allocator>::pointer
 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
 {
     __annotate_delete();
     pointer __r = __v.__begin_;
-    _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_);
-    _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_);
-    _VSTD::swap(this->__begin_, __v.__begin_);
-    _VSTD::swap(this->__end_, __v.__end_);
-    _VSTD::swap(this->__end_cap(), __v.__end_cap());
+    using _RevIter = std::reverse_iterator<pointer>;
+    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
+                       __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_))
+                       .base();
+    __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_);
+    std::swap(this->__begin_, __v.__begin_);
+    std::swap(this->__end_, __v.__end_);
+    std::swap(this->__end_cap(), __v.__end_cap());
     __v.__first_ = __v.__begin_;
     __annotate_new(size());
-    __invalidate_all_iterators();
+    std::__debug_db_invalidate_all(this);
     return __r;
 }
 
-//  Allocate space for __n objects
-//  throws length_error if __n > max_size()
-//  throws (probably bad_alloc) if memory run out
-//  Precondition:  __begin_ == __end_ == __end_cap() == 0
-//  Precondition:  __n > 0
-//  Postcondition:  capacity() == __n
-//  Postcondition:  size() == 0
-template <class _Tp, class _Allocator>
-void
-vector<_Tp, _Allocator>::__vallocate(size_type __n)
-{
-    if (__n > max_size())
-        this->__throw_length_error();
-    this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
-    this->__end_cap() = this->__begin_ + __n;
-    __annotate_new(0);
-}
-
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
 {
@@ -1010,16 +940,18 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<_Tp, _Allocator>::size_type
 vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
 {
-    return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
+    return std::min<size_type>(__alloc_traits::max_size(this->__alloc()),
                                  numeric_limits<difference_type>::max());
 }
 
 //  Precondition:  __new_size > capacity()
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 typename vector<_Tp, _Allocator>::size_type
 vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
 {
@@ -1029,7 +961,7 @@
     const size_type __cap = capacity();
     if (__cap >= __ms / 2)
         return __ms;
-    return _VSTD::max<size_type>(2*__cap, __new_size);
+    return std::max<size_type>(2 * __cap, __new_size);
 }
 
 //  Default constructs __n objects starting at __end_
@@ -1038,13 +970,14 @@
 //  Precondition:  size() + __n <= capacity()
 //  Postcondition:  size() == size() + __n
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 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) {
-        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
+    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
+        __alloc_traits::construct(this->__alloc(), std::__to_address(__pos));
     }
 }
 
@@ -1055,28 +988,25 @@
 //  Postcondition:  size() == old size() + __n
 //  Postcondition:  [i] == __x for all i in [size() - __n, __n)
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 inline
 void
 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) {
-        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
+    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
+        __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x);
     }
 }
 
 template <class _Tp, class _Allocator>
-template <class _ForwardIterator>
-typename enable_if
-<
-    __is_cpp17_forward_iterator<_ForwardIterator>::value,
-    void
->::type
+template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value, int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
 {
-    _ConstructTransaction __tx(*this, __n);
-    _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
+  _ConstructTransaction __tx(*this, __n);
+  __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
 }
 
 //  Default constructs __n objects starting at __end_
@@ -1084,6 +1014,7 @@
 //  Postcondition:  size() == size() + __n
 //  Exception safety: strong.
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::__append(size_type __n)
 {
@@ -1103,6 +1034,7 @@
 //  Postcondition:  size() == size() + __n
 //  Exception safety: strong.
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
 {
@@ -1118,11 +1050,10 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<_Tp, _Allocator>::vector(size_type __n)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    std::__debug_db_insert_c(this);
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1132,12 +1063,11 @@
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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
+    std::__debug_db_insert_c(this);
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1147,25 +1077,10 @@
 #endif
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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
+    std::__debug_db_insert_c(this);
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1174,52 +1089,39 @@
 }
 
 template <class _Tp, class _Allocator>
-template <class _InputIterator>
-vector<_Tp, _Allocator>::vector(_InputIterator __first,
-       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                         !__is_cpp17_forward_iterator<_InputIterator>::value &&
-                         is_constructible<
-                            value_type,
-                            typename iterator_traits<_InputIterator>::reference>::value,
-                          _InputIterator>::type __last)
+template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    std::__debug_db_insert_c(this);
     for (; __first != __last; ++__first)
-        __emplace_back(*__first);
+        emplace_back(*__first);
 }
 
 template <class _Tp, class _Allocator>
-template <class _InputIterator>
-vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
-       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                         !__is_cpp17_forward_iterator<_InputIterator>::value &&
-                         is_constructible<
-                            value_type,
-                            typename iterator_traits<_InputIterator>::reference>::value>::type*)
-    : __base(__a)
+template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    std::__debug_db_insert_c(this);
     for (; __first != __last; ++__first)
-        __emplace_back(*__first);
+        emplace_back(*__first);
 }
 
 template <class _Tp, class _Allocator>
-template <class _ForwardIterator>
-vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
-                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
-                                is_constructible<
-                                   value_type,
-                                   typename iterator_traits<_ForwardIterator>::reference>::value,
-                                                   _ForwardIterator>::type __last)
+template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
-    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
+    std::__debug_db_insert_c(this);
+    size_type __n = static_cast<size_type>(std::distance(__first, __last));
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1228,18 +1130,15 @@
 }
 
 template <class _Tp, class _Allocator>
-template <class _ForwardIterator>
-vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
-                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
-                                is_constructible<
-                                   value_type,
-                                   typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
-    : __base(__a)
+template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
-    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
+    std::__debug_db_insert_c(this);
+    size_type __n = static_cast<size_type>(std::distance(__first, __last));
     if (__n > 0)
     {
         __vallocate(__n);
@@ -1248,12 +1147,11 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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
+    std::__debug_db_insert_c(this);
     size_type __n = __x.size();
     if (__n > 0)
     {
@@ -1263,12 +1161,11 @@
 }
 
 template <class _Tp, class _Allocator>
-vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
-    : __base(__a)
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    std::__debug_db_insert_c(this);
     size_type __n = __x.size();
     if (__n > 0)
     {
@@ -1277,22 +1174,19 @@
     }
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 vector<_Tp, _Allocator>::vector(vector&& __x)
 #if _LIBCPP_STD_VER > 14
-        _NOEXCEPT
+        noexcept
 #else
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
 #endif
-    : __base(_VSTD::move(__x.__alloc()))
+    : __end_cap_(nullptr, std::move(__x.__alloc()))
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-    __get_db()->swap(this, &__x);
-#endif
+    std::__debug_db_insert_c(this);
+    std::__debug_db_swap(this, std::addressof(__x));
     this->__begin_ = __x.__begin_;
     this->__end_ = __x.__end_;
     this->__end_cap() = __x.__end_cap();
@@ -1300,22 +1194,19 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
-    : __base(__a)
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
+vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
+    : __end_cap_(nullptr, __a)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    std::__debug_db_insert_c(this);
     if (__a == __x.__alloc())
     {
         this->__begin_ = __x.__begin_;
         this->__end_ = __x.__end_;
         this->__end_cap() = __x.__end_cap();
         __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
-#if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->swap(this, &__x);
-#endif
+        std::__debug_db_swap(this, std::addressof(__x));
     }
     else
     {
@@ -1324,13 +1215,14 @@
     }
 }
 
+#ifndef _LIBCPP_CXX03_LANG
+
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__insert_c(this);
-#endif
+    std::__debug_db_insert_c(this);
     if (__il.size() > 0)
     {
         __vallocate(__il.size());
@@ -1339,13 +1231,12 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 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
+    std::__debug_db_insert_c(this);
     if (__il.size() > 0)
     {
         __vallocate(__il.size());
@@ -1353,8 +1244,11 @@
     }
 }
 
+#endif // _LIBCPP_CXX03_LANG
+
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 vector<_Tp, _Allocator>&
 vector<_Tp, _Allocator>::operator=(vector&& __x)
     _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
@@ -1365,11 +1259,12 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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()));
@@ -1379,67 +1274,54 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 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);
-#endif
+    std::__debug_db_swap(this, std::addressof(__c));
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 vector<_Tp, _Allocator>&
 vector<_Tp, _Allocator>::operator=(const vector& __x)
 {
-    if (this != &__x)
+    if (this != std::addressof(__x))
     {
-        __base::__copy_assign_alloc(__x);
+        __copy_assign_alloc(__x);
         assign(__x.__begin_, __x.__end_);
     }
     return *this;
 }
 
 template <class _Tp, class _Allocator>
-template <class _InputIterator>
-typename enable_if
-<
-     __is_cpp17_input_iterator  <_InputIterator>::value &&
-    !__is_cpp17_forward_iterator<_InputIterator>::value &&
-    is_constructible<
-       _Tp,
-       typename iterator_traits<_InputIterator>::reference>::value,
-    void
->::type
+template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
 {
     clear();
     for (; __first != __last; ++__first)
-        __emplace_back(*__first);
+        emplace_back(*__first);
 }
 
 template <class _Tp, class _Allocator>
-template <class _ForwardIterator>
-typename enable_if
-<
-    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
-    is_constructible<
-       _Tp,
-       typename iterator_traits<_ForwardIterator>::reference>::value,
-    void
->::type
+template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
 {
-    size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
+    size_type __new_size = static_cast<size_type>(std::distance(__first, __last));
     if (__new_size <= capacity())
     {
         _ForwardIterator __mid = __last;
@@ -1448,9 +1330,9 @@
         {
             __growing = true;
             __mid =  __first;
-            _VSTD::advance(__mid, size());
+            std::advance(__mid, size());
         }
-        pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
+        pointer __m = std::copy(__first, __mid, this->__begin_);
         if (__growing)
             __construct_at_end(__mid, __last, __new_size - size());
         else
@@ -1462,17 +1344,18 @@
         __vallocate(__recommend(__new_size));
         __construct_at_end(__first, __last, __new_size);
     }
-    __invalidate_all_iterators();
+    std::__debug_db_invalidate_all(this);
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
 {
     if (__n <= capacity())
     {
         size_type __s = size();
-        _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
+        std::fill_n(this->__begin_, std::min(__n, __s), __u);
         if (__n > __s)
             __construct_at_end(__n - __s, __u);
         else
@@ -1484,67 +1367,48 @@
         __vallocate(__recommend(static_cast<size_type>(__n)));
         __construct_at_end(__n, __u);
     }
-    __invalidate_all_iterators();
+    std::__debug_db_invalidate_all(this);
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 typename vector<_Tp, _Allocator>::iterator
-vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
+vector<_Tp, _Allocator>::begin() _NOEXCEPT
 {
-#if _LIBCPP_DEBUG_LEVEL == 2
-    return iterator(this, __p);
-#else
-    return iterator(__p);
-#endif
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-typename vector<_Tp, _Allocator>::const_iterator
-vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
-    return const_iterator(this, __p);
-#else
-    return const_iterator(__p);
-#endif
+    return iterator(this, this->__begin_);
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-typename vector<_Tp, _Allocator>::iterator
-vector<_Tp, _Allocator>::begin() _NOEXCEPT
-{
-    return __make_iter(this->__begin_);
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 typename vector<_Tp, _Allocator>::const_iterator
 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
 {
-    return __make_iter(this->__begin_);
+    return const_iterator(this, this->__begin_);
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 typename vector<_Tp, _Allocator>::iterator
 vector<_Tp, _Allocator>::end() _NOEXCEPT
 {
-    return __make_iter(this->__end_);
+    return iterator(this, this->__end_);
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 typename vector<_Tp, _Allocator>::const_iterator
 vector<_Tp, _Allocator>::end() const _NOEXCEPT
 {
-    return __make_iter(this->__end_);
+    return const_iterator(this, this->__end_);
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 typename vector<_Tp, _Allocator>::reference
 vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
 {
@@ -1553,7 +1417,8 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 typename vector<_Tp, _Allocator>::const_reference
 vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
 {
@@ -1562,6 +1427,7 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<_Tp, _Allocator>::reference
 vector<_Tp, _Allocator>::at(size_type __n)
 {
@@ -1571,6 +1437,7 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<_Tp, _Allocator>::const_reference
 vector<_Tp, _Allocator>::at(size_type __n) const
 {
@@ -1580,11 +1447,14 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 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);
@@ -1592,6 +1462,7 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
 {
@@ -1615,23 +1486,21 @@
 
 template <class _Tp, class _Allocator>
 template <class _Up>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
-#ifndef _LIBCPP_CXX03_LANG
 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
-#else
-vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
-#endif
 {
     allocator_type& __a = this->__alloc();
     __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
-    // __v.push_back(_VSTD::forward<_Up>(__x));
-    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x));
+    // __v.push_back(std::forward<_Up>(__x));
+    __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));
     __v.__end_++;
     __swap_out_circular_buffer(__v);
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 void
 vector<_Tp, _Allocator>::push_back(const_reference __x)
 {
@@ -1643,36 +1512,37 @@
         __push_back_slow_path(__x);
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 void
 vector<_Tp, _Allocator>::push_back(value_type&& __x)
 {
     if (this->__end_ < this->__end_cap())
     {
-        __construct_one_at_end(_VSTD::move(__x));
+        __construct_one_at_end(std::move(__x));
     }
     else
-        __push_back_slow_path(_VSTD::move(__x));
+        __push_back_slow_path(std::move(__x));
 }
 
 template <class _Tp, class _Allocator>
 template <class... _Args>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
 {
     allocator_type& __a = this->__alloc();
     __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
-//    __v.emplace_back(_VSTD::forward<_Args>(__args)...);
-    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...);
+//    __v.emplace_back(std::forward<_Args>(__args)...);
+    __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
     __v.__end_++;
     __swap_out_circular_buffer(__v);
 }
 
 template <class _Tp, class _Allocator>
 template <class... _Args>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 inline
 #if _LIBCPP_STD_VER > 14
 typename vector<_Tp, _Allocator>::reference
@@ -1683,18 +1553,17 @@
 {
     if (this->__end_ < this->__end_cap())
     {
-        __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
+        __construct_one_at_end(std::forward<_Args>(__args)...);
     }
     else
-        __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
+        __emplace_back_slow_path(std::forward<_Args>(__args)...);
 #if _LIBCPP_STD_VER > 14
     return this->back();
 #endif
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 inline
 void
 vector<_Tp, _Allocator>::pop_back()
@@ -1704,48 +1573,47 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 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(std::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();
     pointer __p = this->__begin_ + __ps;
-    this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
-    this->__invalidate_iterators_past(__p-1);
-    iterator __r = __make_iter(__p);
+    this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));
+    if (!__libcpp_is_constant_evaluated())
+        this->__invalidate_iterators_past(__p - 1);
+    iterator __r = iterator(this, __p);
     return __r;
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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(std::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(std::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) {
-        this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
-        this->__invalidate_iterators_past(__p - 1);
+        this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));
+        if (!__libcpp_is_constant_evaluated())
+            this->__invalidate_iterators_past(__p - 1);
     }
-    iterator __r = __make_iter(__p);
+    iterator __r = iterator(this, __p);
     return __r;
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
 {
@@ -1755,26 +1623,25 @@
       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));
+                                    std::__to_address(__pos),
+                                    std::move(*__i));
       }
     }
-    _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
+    std::move_backward(__from_s, __from_s + __n, __old_last);
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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(std::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())
+    // We can't compare unrelated pointers inside constant expressions
+    if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap())
     {
         if (__p == this->__end_)
         {
@@ -1796,92 +1663,83 @@
         __v.push_back(__x);
         __p = __swap_out_circular_buffer(__v, __p);
     }
-    return __make_iter(__p);
+    return iterator(this, __p);
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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(std::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())
     {
         if (__p == this->__end_)
         {
-            __construct_one_at_end(_VSTD::move(__x));
+            __construct_one_at_end(std::move(__x));
         }
         else
         {
             __move_range(__p, this->__end_, __p + 1);
-            *__p = _VSTD::move(__x);
+            *__p = std::move(__x);
         }
     }
     else
     {
         allocator_type& __a = this->__alloc();
         __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
-        __v.push_back(_VSTD::move(__x));
+        __v.push_back(std::move(__x));
         __p = __swap_out_circular_buffer(__v, __p);
     }
-    return __make_iter(__p);
+    return iterator(this, __p);
 }
 
 template <class _Tp, class _Allocator>
 template <class... _Args>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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(std::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())
     {
         if (__p == this->__end_)
         {
-            __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
+            __construct_one_at_end(std::forward<_Args>(__args)...);
         }
         else
         {
-            __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
+            __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...);
             __move_range(__p, this->__end_, __p + 1);
-            *__p = _VSTD::move(__tmp.get());
+            *__p = std::move(__tmp.get());
         }
     }
     else
     {
         allocator_type& __a = this->__alloc();
         __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
-        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
+        __v.emplace_back(std::forward<_Args>(__args)...);
         __p = __swap_out_circular_buffer(__v, __p);
     }
-    return __make_iter(__p);
+    return iterator(this, __p);
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 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(std::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)
     {
-        if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
+        // We can't compare unrelated pointers inside constant expressions
+        if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_))
         {
             size_type __old_n = __n;
             pointer __old_last = this->__end_;
@@ -1897,7 +1755,7 @@
                 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
                 if (__p <= __xr && __xr < this->__end_)
                     __xr += __old_n;
-                _VSTD::fill_n(__p, __n, *__xr);
+                std::fill_n(__p, __n, *__xr);
             }
         }
         else
@@ -1908,27 +1766,18 @@
             __p = __swap_out_circular_buffer(__v, __p);
         }
     }
-    return __make_iter(__p);
+    return iterator(this, __p);
 }
 
 template <class _Tp, class _Allocator>
-template <class _InputIterator>
-typename enable_if
-<
-     __is_cpp17_input_iterator  <_InputIterator>::value &&
-    !__is_cpp17_forward_iterator<_InputIterator>::value &&
-    is_constructible<
-       _Tp,
-       typename iterator_traits<_InputIterator>::reference>::value,
-    typename vector<_Tp, _Allocator>::iterator
->::type
+template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
+                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
+                          int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
 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(std::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();
@@ -1954,36 +1803,28 @@
         }
         catch (...)
         {
-            erase(__make_iter(__old_last), end());
+            erase(iterator(this, __old_last), end());
             throw;
         }
 #endif // _LIBCPP_NO_EXCEPTIONS
     }
-    __p = _VSTD::rotate(__p, __old_last, this->__end_);
-    insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()),
-                             _VSTD::make_move_iterator(__v.end()));
+    __p = std::rotate(__p, __old_last, this->__end_);
+    insert(iterator(this, __p), std::make_move_iterator(__v.begin()),
+                                std::make_move_iterator(__v.end()));
     return begin() + __off;
 }
 
 template <class _Tp, class _Allocator>
-template <class _ForwardIterator>
-typename enable_if
-<
-    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
-    is_constructible<
-       _Tp,
-       typename iterator_traits<_ForwardIterator>::reference>::value,
-    typename vector<_Tp, _Allocator>::iterator
->::type
+template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
+                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
+                    int> >
+_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
 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(std::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);
+    difference_type __n = std::distance(__first, __last);
     if (__n > 0)
     {
         if (__n <= this->__end_cap() - this->__end_)
@@ -1996,14 +1837,14 @@
             {
                 __m = __first;
                 difference_type __diff = this->__end_ - __p;
-                _VSTD::advance(__m, __diff);
+                std::advance(__m, __diff);
                 __construct_at_end(__m, __last, __n - __diff);
                 __n = __dx;
             }
             if (__n > 0)
             {
                 __move_range(__p, __old_last, __p + __old_n);
-                _VSTD::copy(__first, __m, __p);
+                std::copy(__first, __m, __p);
             }
         }
         else
@@ -2014,10 +1855,11 @@
             __p = __swap_out_circular_buffer(__v, __p);
         }
     }
-    return __make_iter(__p);
+    return iterator(this, __p);
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::resize(size_type __sz)
 {
@@ -2029,6 +1871,7 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
 {
@@ -2040,6 +1883,7 @@
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<_Tp, _Allocator>::swap(vector& __x)
 #if _LIBCPP_STD_VER >= 14
@@ -2053,17 +1897,16 @@
                    this->__alloc() == __x.__alloc(),
                    "vector::swap: Either propagate_on_container_swap must be true"
                    " or the allocators must compare equal");
-    _VSTD::swap(this->__begin_, __x.__begin_);
-    _VSTD::swap(this->__end_, __x.__end_);
-    _VSTD::swap(this->__end_cap(), __x.__end_cap());
-    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
+    std::swap(this->__begin_, __x.__begin_);
+    std::swap(this->__end_, __x.__end_);
+    std::swap(this->__end_cap(), __x.__end_cap());
+    std::__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);
-#endif
+    std::__debug_db_swap(this, std::addressof(__x));
 }
 
 template <class _Tp, class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 bool
 vector<_Tp, _Allocator>::__invariants() const
 {
@@ -2084,7 +1927,7 @@
     return true;
 }
 
-#if _LIBCPP_DEBUG_LEVEL == 2
+#ifdef _LIBCPP_ENABLE_DEBUG_MODE
 
 template <class _Tp, class _Allocator>
 bool
@@ -2116,24 +1959,13 @@
     return this->__begin_ <= __p && __p < this->__end_;
 }
 
-#endif // _LIBCPP_DEBUG_LEVEL == 2
+#endif // _LIBCPP_ENABLE_DEBUG_MODE
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-void
-vector<_Tp, _Allocator>::__invalidate_all_iterators()
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
-    __get_db()->__invalidate_all(this);
-#endif
-}
-
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI
 void
 vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
-#if _LIBCPP_DEBUG_LEVEL == 2
+#ifdef _LIBCPP_ENABLE_DEBUG_MODE
   __c_node* __c = __get_db()->__find_c_and_lock(this);
   for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
     --__p;
@@ -2141,7 +1973,7 @@
     if (__i->base() > __new_last) {
       (*__p)->__c_ = nullptr;
       if (--__c->end_ != __p)
-        _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
+        std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
     }
   }
   __get_db()->unlock();
@@ -2164,7 +1996,6 @@
 
 template <class _Allocator>
 class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
-    : private __vector_base_common<true>
 {
 public:
     typedef vector                                   __self;
@@ -2178,11 +2009,11 @@
     typedef __bit_iterator<vector, true>             const_pointer;
     typedef pointer                                  iterator;
     typedef const_pointer                            const_iterator;
-    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
-    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
+    typedef std::reverse_iterator<iterator>         reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>   const_reverse_iterator;
 
 private:
-    typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
+    typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
     typedef allocator_traits<__storage_allocator>    __storage_traits;
     typedef typename __storage_traits::pointer       __storage_pointer;
     typedef typename __storage_traits::const_pointer __const_storage_pointer;
@@ -2192,284 +2023,309 @@
     __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
 public:
     typedef __bit_reference<vector>                  reference;
+#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
+    using const_reference = bool;
+#else
     typedef __bit_const_reference<vector>            const_reference;
+#endif
 private:
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     size_type& __cap() _NOEXCEPT
         {return __cap_alloc_.first();}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const size_type& __cap() const _NOEXCEPT
         {return __cap_alloc_.first();}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     __storage_allocator& __alloc() _NOEXCEPT
         {return __cap_alloc_.second();}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const __storage_allocator& __alloc() const _NOEXCEPT
         {return __cap_alloc_.second();}
 
     static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
         {return __n * __bits_per_word;}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
         {return (__n - 1) / __bits_per_word + 1;}
 
 public:
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
 
-    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a)
 #if _LIBCPP_STD_VER <= 14
         _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
 #else
         _NOEXCEPT;
 #endif
-    ~vector();
-    explicit vector(size_type __n);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector();
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n);
 #if _LIBCPP_STD_VER > 11
-    explicit vector(size_type __n, const allocator_type& __a);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a);
 #endif
-    vector(size_type __n, const value_type& __v);
-    vector(size_type __n, const value_type& __v, const allocator_type& __a);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v, const allocator_type& __a);
     template <class _InputIterator>
-        vector(_InputIterator __first, _InputIterator __last,
-               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                                 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last,
+               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
     template <class _InputIterator>
-        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
-               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                                 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
+               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
     template <class _ForwardIterator>
-        vector(_ForwardIterator __first, _ForwardIterator __last,
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last,
                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
     template <class _ForwardIterator>
-        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
 
-    vector(const vector& __v);
-    vector(const vector& __v, const allocator_type& __a);
-    vector& operator=(const vector& __v);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v);
 
 #ifndef _LIBCPP_CXX03_LANG
-    vector(initializer_list<value_type> __il);
-    vector(initializer_list<value_type> __il, const allocator_type& __a);
-
-    _LIBCPP_INLINE_VISIBILITY
-    vector(vector&& __v)
-#if _LIBCPP_STD_VER > 14
-        _NOEXCEPT;
-#else
-        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
-#endif
-    vector(vector&& __v, const __identity_t<allocator_type>& __a);
-    _LIBCPP_INLINE_VISIBILITY
-    vector& operator=(vector&& __v)
-        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
-
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il, const allocator_type& __a);
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     vector& operator=(initializer_list<value_type> __il)
         {assign(__il.begin(), __il.end()); return *this;}
 
 #endif // !_LIBCPP_CXX03_LANG
 
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+    vector(vector&& __v)
+#if _LIBCPP_STD_VER > 14
+        noexcept;
+#else
+        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
+#endif
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+    vector& operator=(vector&& __v)
+        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
+
     template <class _InputIterator>
-        typename enable_if
-        <
-            __is_cpp17_input_iterator<_InputIterator>::value &&
-           !__is_cpp17_forward_iterator<_InputIterator>::value,
+        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
            void
         >::type
-        assign(_InputIterator __first, _InputIterator __last);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
     template <class _ForwardIterator>
         typename enable_if
         <
             __is_cpp17_forward_iterator<_ForwardIterator>::value,
            void
         >::type
-        assign(_ForwardIterator __first, _ForwardIterator __last);
-
-    void assign(size_type __n, const value_type& __x);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x);
 
 #ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void assign(initializer_list<value_type> __il)
         {assign(__il.begin(), __il.end());}
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT
         {return allocator_type(this->__alloc());}
 
-    size_type max_size() const _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     size_type capacity() const _NOEXCEPT
         {return __internal_cap_to_external(__cap());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     size_type size() const _NOEXCEPT
         {return __size_;}
-    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     bool empty() const _NOEXCEPT
         {return __size_ == 0;}
-    void reserve(size_type __n);
-    void shrink_to_fit() _NOEXCEPT;
-
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     iterator begin() _NOEXCEPT
         {return __make_iter(0);}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_iterator begin() const _NOEXCEPT
         {return __make_iter(0);}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     iterator end() _NOEXCEPT
         {return __make_iter(__size_);}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_iterator end()   const _NOEXCEPT
         {return __make_iter(__size_);}
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     reverse_iterator rbegin() _NOEXCEPT
         {return       reverse_iterator(end());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_reverse_iterator rbegin() const _NOEXCEPT
         {return const_reverse_iterator(end());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     reverse_iterator rend() _NOEXCEPT
         {return       reverse_iterator(begin());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_reverse_iterator rend()   const _NOEXCEPT
         {return const_reverse_iterator(begin());}
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_iterator         cbegin()  const _NOEXCEPT
         {return __make_iter(0);}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_iterator         cend()    const _NOEXCEPT
         {return __make_iter(__size_);}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_reverse_iterator crbegin() const _NOEXCEPT
         {return rbegin();}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_reverse_iterator crend()   const _NOEXCEPT
         {return rend();}
 
-    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n)       {return __make_ref(__n);}
-    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
-    reference       at(size_type __n);
-    const_reference at(size_type __n) const;
-
-    _LIBCPP_INLINE_VISIBILITY reference       front()       {return __make_ref(0);}
-    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
-    _LIBCPP_INLINE_VISIBILITY reference       back()        {return __make_ref(__size_ - 1);}
-    _LIBCPP_INLINE_VISIBILITY const_reference back()  const {return __make_ref(__size_ - 1);}
-
-    void push_back(const value_type& __x);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference       operator[](size_type __n)       {return __make_ref(__n);}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {return __make_ref(__n);}
+    _LIBCPP_HIDE_FROM_ABI reference       at(size_type __n);
+    _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference       front()       {return __make_ref(0);}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const {return __make_ref(0);}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference       back()        {return __make_ref(__size_ - 1);}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back()  const {return __make_ref(__size_ - 1);}
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
 #if _LIBCPP_STD_VER > 11
     template <class... _Args>
 #if _LIBCPP_STD_VER > 14
-    _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
 #else
-    _LIBCPP_INLINE_VISIBILITY void      emplace_back(_Args&&... __args)
+    _LIBCPP_HIDE_FROM_ABI void      emplace_back(_Args&&... __args)
 #endif
     {
-        push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
+        push_back ( value_type ( std::forward<_Args>(__args)... ));
 #if _LIBCPP_STD_VER > 14
         return this->back();
 #endif
     }
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() {--__size_;}
 
 #if _LIBCPP_STD_VER > 11
     template <class... _Args>
-   _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
-        { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
+   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args)
+        { return insert ( __position, value_type ( std::forward<_Args>(__args)... )); }
 #endif
 
-    iterator insert(const_iterator __position, const value_type& __x);
-    iterator insert(const_iterator __position, size_type __n, const value_type& __x);
-    iterator insert(const_iterator __position, size_type __n, const_reference __x);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
     template <class _InputIterator>
-        typename enable_if
-        <
-             __is_cpp17_input_iterator  <_InputIterator>::value &&
-            !__is_cpp17_forward_iterator<_InputIterator>::value,
+        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
             iterator
         >::type
-        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
+        _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
     template <class _ForwardIterator>
         typename enable_if
         <
             __is_cpp17_forward_iterator<_ForwardIterator>::value,
             iterator
         >::type
-        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
+        _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
 
 #ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     iterator insert(const_iterator __position, initializer_list<value_type> __il)
         {return insert(__position, __il.begin(), __il.end());}
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
-    iterator erase(const_iterator __first, const_iterator __last);
-
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last);
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void clear() _NOEXCEPT {__size_ = 0;}
 
-    void swap(vector&)
+    _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&)
 #if _LIBCPP_STD_VER >= 14
         _NOEXCEPT;
 #else
         _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
                     __is_nothrow_swappable<allocator_type>::value);
 #endif
-    static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
-
-    void resize(size_type __sz, value_type __x = false);
-    void flip() _NOEXCEPT;
-
-    bool __invariants() const;
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT { std::swap(__x, __y); }
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT;
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
 
 private:
-    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
-    void __vallocate(size_type __n);
-    void __vdeallocate() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+    void __throw_length_error() const {
+        std::__throw_length_error("vector");
+    }
+
+    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
+    void __throw_out_of_range() const {
+        std::__throw_out_of_range("vector");
+    }
+
+    //  Allocate space for __n objects
+    //  throws length_error if __n > max_size()
+    //  throws (probably bad_alloc) if memory run out
+    //  Precondition:  __begin_ == __end_ == __cap() == 0
+    //  Precondition:  __n > 0
+    //  Postcondition:  capacity() >= __n
+    //  Postcondition:  size() == 0
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
+        if (__n > max_size())
+            __throw_length_error();
+        auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
+        __begin_ = __allocation.ptr;
+        __size_ = 0;
+        __cap() = __allocation.count;
+        if (__libcpp_is_constant_evaluated()) {
+            for (size_type __i = 0; __i != __cap(); ++__i)
+                std::__construct_at(std::__to_address(__begin_) + __i);
+        }
+    }
+
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT;
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     static size_type __align_it(size_type __new_size) _NOEXCEPT
-        {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);}
-    _LIBCPP_INLINE_VISIBILITY  size_type __recommend(size_type __new_size) const;
-    _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
+        {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20  size_type __recommend(size_type __new_size) const;
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
     template <class _ForwardIterator>
         typename enable_if
         <
             __is_cpp17_forward_iterator<_ForwardIterator>::value,
             void
         >::type
-        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
-    void __append(size_type __n, const_reference __x);
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     reference __make_ref(size_type __pos) _NOEXCEPT
         {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
-    _LIBCPP_INLINE_VISIBILITY
-    const_reference __make_ref(size_type __pos) const _NOEXCEPT
-        {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+    const_reference __make_ref(size_type __pos) const _NOEXCEPT {
+        return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
+                                             __storage_type(1) << __pos % __bits_per_word);
+    }
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     iterator __make_iter(size_type __pos) _NOEXCEPT
         {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     const_iterator __make_iter(size_type __pos) const _NOEXCEPT
         {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
         {return begin() + (__p - cbegin());}
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void __copy_assign_alloc(const vector& __v)
         {__copy_assign_alloc(__v, integral_constant<bool,
                       __storage_traits::propagate_on_container_copy_assignment::value>());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void __copy_assign_alloc(const vector& __c, true_type)
         {
             if (__alloc() != __c.__alloc())
@@ -2477,33 +2333,33 @@
             __alloc() = __c.__alloc();
         }
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void __copy_assign_alloc(const vector&, false_type)
         {}
 
-    void __move_assign(vector& __c, false_type);
-    void __move_assign(vector& __c, true_type)
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type);
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type)
         _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void __move_assign_alloc(vector& __c)
         _NOEXCEPT_(
             !__storage_traits::propagate_on_container_move_assignment::value ||
             is_nothrow_move_assignable<allocator_type>::value)
         {__move_assign_alloc(__c, integral_constant<bool,
                       __storage_traits::propagate_on_container_move_assignment::value>());}
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void __move_assign_alloc(vector& __c, true_type)
         _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
         {
-            __alloc() = _VSTD::move(__c.__alloc());
+            __alloc() = std::move(__c.__alloc());
         }
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     void __move_assign_alloc(vector&, false_type)
         _NOEXCEPT
         {}
 
-    size_t __hash_code() const _NOEXCEPT;
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
 
     friend class __bit_reference<vector>;
     friend class __bit_const_reference<vector>;
@@ -2514,45 +2370,20 @@
 };
 
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-void
-vector<bool, _Allocator>::__invalidate_all_iterators()
-{
-}
-
-//  Allocate space for __n objects
-//  throws length_error if __n > max_size()
-//  throws (probably bad_alloc) if memory run out
-//  Precondition:  __begin_ == __end_ == __cap() == 0
-//  Precondition:  __n > 0
-//  Postcondition:  capacity() == __n
-//  Postcondition:  size() == 0
-template <class _Allocator>
-void
-vector<bool, _Allocator>::__vallocate(size_type __n)
-{
-    if (__n > max_size())
-        this->__throw_length_error();
-    __n = __external_cap_to_internal(__n);
-    this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
-    this->__size_ = 0;
-    this->__cap() = __n;
-}
-
-template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
 {
     if (this->__begin_ != nullptr)
     {
         __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
-        __invalidate_all_iterators();
+        std::__debug_db_invalidate_all(this);
         this->__begin_ = nullptr;
         this->__size_ = this->__cap() = 0;
     }
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<bool, _Allocator>::size_type
 vector<bool, _Allocator>::max_size() const _NOEXCEPT
 {
@@ -2565,7 +2396,7 @@
 
 //  Precondition:  __new_size > capacity()
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<bool, _Allocator>::size_type
 vector<bool, _Allocator>::__recommend(size_type __new_size) const
 {
@@ -2575,7 +2406,7 @@
     const size_type __cap = capacity();
     if (__cap >= __ms / 2)
         return __ms;
-    return _VSTD::max(2*__cap, __align_it(__new_size));
+    return std::max(2 * __cap, __align_it(__new_size));
 }
 
 //  Default constructs __n objects starting at __end_
@@ -2583,7 +2414,7 @@
 //  Precondition:  size() + __n <= capacity()
 //  Postcondition:  size() == size() + __n
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
 void
 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
 {
@@ -2596,11 +2427,12 @@
         else
             this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
     }
-    _VSTD::fill_n(__make_iter(__old_size), __n, __x);
+    std::fill_n(__make_iter(__old_size), __n, __x);
 }
 
 template <class _Allocator>
 template <class _ForwardIterator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename enable_if
 <
     __is_cpp17_forward_iterator<_ForwardIterator>::value,
@@ -2609,7 +2441,7 @@
 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
 {
     size_type __old_size = this->__size_;
-    this->__size_ += _VSTD::distance(__first, __last);
+    this->__size_ += std::distance(__first, __last);
     if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
     {
         if (this->__size_ <= __bits_per_word)
@@ -2617,11 +2449,11 @@
         else
             this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
     }
-    _VSTD::copy(__first, __last, __make_iter(__old_size));
+    std::copy(__first, __last, __make_iter(__old_size));
 }
 
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector()
     _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
     : __begin_(nullptr),
@@ -2631,7 +2463,7 @@
 }
 
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(const allocator_type& __a)
 #if _LIBCPP_STD_VER <= 14
         _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
@@ -2645,6 +2477,7 @@
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(size_type __n)
     : __begin_(nullptr),
       __size_(0),
@@ -2659,6 +2492,7 @@
 
 #if _LIBCPP_STD_VER > 11
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
     : __begin_(nullptr),
       __size_(0),
@@ -2673,6 +2507,7 @@
 #endif
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
     : __begin_(nullptr),
       __size_(0),
@@ -2686,6 +2521,7 @@
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
     : __begin_(nullptr),
       __size_(0),
@@ -2700,9 +2536,9 @@
 
 template <class _Allocator>
 template <class _InputIterator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
-       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                         !__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
+       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
     : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, __default_init_tag())
@@ -2719,7 +2555,7 @@
     {
         if (__begin_ != nullptr)
             __storage_traits::deallocate(__alloc(), __begin_, __cap());
-        __invalidate_all_iterators();
+        std::__debug_db_invalidate_all(this);
         throw;
     }
 #endif // _LIBCPP_NO_EXCEPTIONS
@@ -2727,9 +2563,9 @@
 
 template <class _Allocator>
 template <class _InputIterator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
-       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
-                         !__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
+       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
     : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, static_cast<__storage_allocator>(__a))
@@ -2746,7 +2582,7 @@
     {
         if (__begin_ != nullptr)
             __storage_traits::deallocate(__alloc(), __begin_, __cap());
-        __invalidate_all_iterators();
+        std::__debug_db_invalidate_all(this);
         throw;
     }
 #endif // _LIBCPP_NO_EXCEPTIONS
@@ -2754,13 +2590,14 @@
 
 template <class _Allocator>
 template <class _ForwardIterator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
                                 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
     : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, __default_init_tag())
 {
-    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
+    size_type __n = static_cast<size_type>(std::distance(__first, __last));
     if (__n > 0)
     {
         __vallocate(__n);
@@ -2770,13 +2607,14 @@
 
 template <class _Allocator>
 template <class _ForwardIterator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
                                 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
     : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, static_cast<__storage_allocator>(__a))
 {
-    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
+    size_type __n = static_cast<size_type>(std::distance(__first, __last));
     if (__n > 0)
     {
         __vallocate(__n);
@@ -2787,6 +2625,7 @@
 #ifndef _LIBCPP_CXX03_LANG
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
     : __begin_(nullptr),
       __size_(0),
@@ -2801,6 +2640,7 @@
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
     : __begin_(nullptr),
       __size_(0),
@@ -2817,14 +2657,16 @@
 #endif // _LIBCPP_CXX03_LANG
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::~vector()
 {
     if (__begin_ != nullptr)
         __storage_traits::deallocate(__alloc(), __begin_, __cap());
-    __invalidate_all_iterators();
+    std::__debug_db_invalidate_all(this);
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(const vector& __v)
     : __begin_(nullptr),
       __size_(0),
@@ -2838,6 +2680,7 @@
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
     : __begin_(nullptr),
       __size_(0),
@@ -2851,10 +2694,11 @@
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>&
 vector<bool, _Allocator>::operator=(const vector& __v)
 {
-    if (this != &__v)
+    if (this != std::addressof(__v))
     {
         __copy_assign_alloc(__v);
         if (__v.__size_)
@@ -2864,17 +2708,15 @@
                 __vdeallocate();
                 __vallocate(__v.__size_);
             }
-            _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
+            std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
         }
         __size_ = __v.__size_;
     }
     return *this;
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v)
 #if _LIBCPP_STD_VER > 14
     _NOEXCEPT
 #else
@@ -2882,14 +2724,15 @@
 #endif
     : __begin_(__v.__begin_),
       __size_(__v.__size_),
-      __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) {
+      __cap_alloc_(std::move(__v.__cap_alloc_)) {
     __v.__begin_ = nullptr;
     __v.__size_ = 0;
     __v.__cap() = 0;
 }
 
 template <class _Allocator>
-vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a)
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
     : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, __a)
@@ -2910,7 +2753,7 @@
 }
 
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
 vector<bool, _Allocator>&
 vector<bool, _Allocator>::operator=(vector&& __v)
     _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
@@ -2921,7 +2764,7 @@
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
 {
     if (__alloc() != __c.__alloc())
@@ -2931,7 +2774,7 @@
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
     _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
 {
@@ -2944,10 +2787,8 @@
     __c.__cap() = __c.__size_ = 0;
 }
 
-#endif // !_LIBCPP_CXX03_LANG
-
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
 {
     __size_ = 0;
@@ -2958,22 +2799,19 @@
             __size_ = __n;
         else
         {
-            vector __v(__alloc());
+            vector __v(get_allocator());
             __v.reserve(__recommend(__n));
             __v.__size_ = __n;
             swap(__v);
         }
-        _VSTD::fill_n(begin(), __n, __x);
+        std::fill_n(begin(), __n, __x);
     }
-  __invalidate_all_iterators();
+    std::__debug_db_invalidate_all(this);
 }
 
 template <class _Allocator>
 template <class _InputIterator>
-typename enable_if
-<
-    __is_cpp17_input_iterator<_InputIterator>::value &&
-   !__is_cpp17_forward_iterator<_InputIterator>::value,
+_LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
    void
 >::type
 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
@@ -2985,6 +2823,7 @@
 
 template <class _Allocator>
 template <class _ForwardIterator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename enable_if
 <
     __is_cpp17_forward_iterator<_ForwardIterator>::value,
@@ -2993,7 +2832,7 @@
 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
 {
     clear();
-    difference_type __ns = _VSTD::distance(__first, __last);
+    difference_type __ns = std::distance(__first, __last);
     _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
     const size_t __n = static_cast<size_type>(__ns);
     if (__n)
@@ -3008,21 +2847,23 @@
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 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);
-        __invalidate_all_iterators();
+        std::__debug_db_invalidate_all(this);
     }
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
 {
     if (__external_cap_to_internal(size()) > __cap())
@@ -3060,7 +2901,7 @@
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::push_back(const value_type& __x)
 {
     if (this->__size_ == this->capacity())
@@ -3070,7 +2911,7 @@
 }
 
 template <class _Allocator>
-typename vector<bool, _Allocator>::iterator
+_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
 {
     iterator __r;
@@ -3078,16 +2919,16 @@
     {
         const_iterator __old_end = end();
         ++__size_;
-        _VSTD::copy_backward(__position, __old_end, end());
+        std::copy_backward(__position, __old_end, end());
         __r = __const_iterator_cast(__position);
     }
     else
     {
-        vector __v(__alloc());
+        vector __v(get_allocator());
         __v.reserve(__recommend(__size_ + 1));
         __v.__size_ = __size_ + 1;
-        __r = _VSTD::copy(cbegin(), __position, __v.begin());
-        _VSTD::copy_backward(__position, cend(), __v.end());
+        __r = std::copy(cbegin(), __position, __v.begin());
+        std::copy_backward(__position, cend(), __v.end());
         swap(__v);
     }
     *__r = __x;
@@ -3095,7 +2936,7 @@
 }
 
 template <class _Allocator>
-typename vector<bool, _Allocator>::iterator
+_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
 {
     iterator __r;
@@ -3104,28 +2945,25 @@
     {
         const_iterator __old_end = end();
         __size_ += __n;
-        _VSTD::copy_backward(__position, __old_end, end());
+        std::copy_backward(__position, __old_end, end());
         __r = __const_iterator_cast(__position);
     }
     else
     {
-        vector __v(__alloc());
+        vector __v(get_allocator());
         __v.reserve(__recommend(__size_ + __n));
         __v.__size_ = __size_ + __n;
-        __r = _VSTD::copy(cbegin(), __position, __v.begin());
-        _VSTD::copy_backward(__position, cend(), __v.end());
+        __r = std::copy(cbegin(), __position, __v.begin());
+        std::copy_backward(__position, cend(), __v.end());
         swap(__v);
     }
-    _VSTD::fill_n(__r, __n, __x);
+    std::fill_n(__r, __n, __x);
     return __r;
 }
 
 template <class _Allocator>
 template <class _InputIterator>
-typename enable_if
-<
-     __is_cpp17_input_iterator  <_InputIterator>::value &&
-    !__is_cpp17_forward_iterator<_InputIterator>::value,
+_LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
     typename vector<bool, _Allocator>::iterator
 >::type
 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
@@ -3138,7 +2976,7 @@
         ++this->__size_;
         back() = *__first;
     }
-    vector __v(__alloc());
+    vector __v(get_allocator());
     if (__first != __last)
     {
 #ifndef _LIBCPP_NO_EXCEPTIONS
@@ -3160,13 +2998,14 @@
         }
 #endif // _LIBCPP_NO_EXCEPTIONS
     }
-    __p = _VSTD::rotate(__p, __old_end, end());
+    __p = std::rotate(__p, __old_end, end());
     insert(__p, __v.begin(), __v.end());
     return begin() + __off;
 }
 
 template <class _Allocator>
 template <class _ForwardIterator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename enable_if
 <
     __is_cpp17_forward_iterator<_ForwardIterator>::value,
@@ -3174,7 +3013,7 @@
 >::type
 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
 {
-    const difference_type __n_signed = _VSTD::distance(__first, __last);
+    const difference_type __n_signed = std::distance(__first, __last);
     _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
     const size_type __n = static_cast<size_type>(__n_signed);
     iterator __r;
@@ -3183,46 +3022,47 @@
     {
         const_iterator __old_end = end();
         __size_ += __n;
-        _VSTD::copy_backward(__position, __old_end, end());
+        std::copy_backward(__position, __old_end, end());
         __r = __const_iterator_cast(__position);
     }
     else
     {
-        vector __v(__alloc());
+        vector __v(get_allocator());
         __v.reserve(__recommend(__size_ + __n));
         __v.__size_ = __size_ + __n;
-        __r = _VSTD::copy(cbegin(), __position, __v.begin());
-        _VSTD::copy_backward(__position, cend(), __v.end());
+        __r = std::copy(cbegin(), __position, __v.begin());
+        std::copy_backward(__position, cend(), __v.end());
         swap(__v);
     }
-    _VSTD::copy(__first, __last, __r);
+    std::copy(__first, __last, __r);
     return __r;
 }
 
 template <class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<bool, _Allocator>::iterator
 vector<bool, _Allocator>::erase(const_iterator __position)
 {
     iterator __r = __const_iterator_cast(__position);
-    _VSTD::copy(__position + 1, this->cend(), __r);
+    std::copy(__position + 1, this->cend(), __r);
     --__size_;
     return __r;
 }
 
 template <class _Allocator>
+_LIBCPP_CONSTEXPR_SINCE_CXX20
 typename vector<bool, _Allocator>::iterator
 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
 {
     iterator __r = __const_iterator_cast(__first);
     difference_type __d = __last - __first;
-    _VSTD::copy(__last, this->cend(), __r);
+    std::copy(__last, this->cend(), __r);
     __size_ -= __d;
     return __r;
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::swap(vector& __x)
 #if _LIBCPP_STD_VER >= 14
     _NOEXCEPT
@@ -3231,15 +3071,15 @@
                 __is_nothrow_swappable<allocator_type>::value)
 #endif
 {
-    _VSTD::swap(this->__begin_, __x.__begin_);
-    _VSTD::swap(this->__size_, __x.__size_);
-    _VSTD::swap(this->__cap(), __x.__cap());
-    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
+    std::swap(this->__begin_, __x.__begin_);
+    std::swap(this->__size_, __x.__size_);
+    std::swap(this->__cap(), __x.__cap());
+    std::__swap_allocator(this->__alloc(), __x.__alloc(),
         integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
 {
     size_type __cs = size();
@@ -3255,20 +3095,20 @@
         }
         else
         {
-            vector __v(__alloc());
+            vector __v(get_allocator());
             __v.reserve(__recommend(__size_ + __n));
             __v.__size_ = __size_ + __n;
-            __r = _VSTD::copy(cbegin(), cend(), __v.begin());
+            __r = std::copy(cbegin(), cend(), __v.begin());
             swap(__v);
         }
-        _VSTD::fill_n(__r, __n, __x);
+        std::fill_n(__r, __n, __x);
     }
     else
         __size_ = __sz;
 }
 
 template <class _Allocator>
-void
+_LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<bool, _Allocator>::flip() _NOEXCEPT
 {
     // do middle whole words
@@ -3287,7 +3127,7 @@
 }
 
 template <class _Allocator>
-bool
+_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
 vector<bool, _Allocator>::__invariants() const
 {
     if (this->__begin_ == nullptr)
@@ -3306,7 +3146,7 @@
 }
 
 template <class _Allocator>
-size_t
+_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
 {
     size_t __h = 0;
@@ -3326,24 +3166,26 @@
 
 template <class _Allocator>
 struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
-    : public unary_function<vector<bool, _Allocator>, size_t>
+    : public __unary_function<vector<bool, _Allocator>, size_t>
 {
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
     size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
         {return __vec.__hash_code();}
 };
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 bool
 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
 {
     const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
-    return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
+    return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 bool
 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
 {
@@ -3351,15 +3193,17 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 bool
 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
 {
-    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+    return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 bool
 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
 {
@@ -3367,7 +3211,8 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 bool
 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
 {
@@ -3375,7 +3220,8 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 bool
 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
 {
@@ -3383,7 +3229,8 @@
 }
 
 template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI
 void
 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
     _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
@@ -3393,24 +3240,49 @@
 
 #if _LIBCPP_STD_VER > 17
 template <class _Tp, class _Allocator, class _Up>
-inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
 erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
   auto __old_size = __c.size();
-  __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end());
+  __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
   return __old_size - __c.size();
 }
 
 template <class _Tp, class _Allocator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
+_LIBCPP_CONSTEXPR_SINCE_CXX20
+inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
 erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
   auto __old_size = __c.size();
-  __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
+  __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
   return __old_size - __c.size();
 }
+
+template <>
+inline constexpr bool __format::__enable_insertable<std::vector<char>> = true;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+inline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true;
 #endif
 
+#endif // _LIBCPP_STD_VER > 17
+
 _LIBCPP_END_NAMESPACE_STD
 
+#if _LIBCPP_STD_VER > 14
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace pmr {
+template <class _ValueT>
+using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
+} // namespace pmr
+_LIBCPP_END_NAMESPACE_STD
+#endif
+
 _LIBCPP_POP_MACROS
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <algorithm>
+#  include <typeinfo>
+#  include <utility>
+#endif
+
 #endif // _LIBCPP_VECTOR