Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/__split_buffer is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___SPLIT_BUFFER
0011 #define _LIBCPP___SPLIT_BUFFER
0012 
0013 #include <__algorithm/max.h>
0014 #include <__algorithm/move.h>
0015 #include <__algorithm/move_backward.h>
0016 #include <__config>
0017 #include <__iterator/distance.h>
0018 #include <__iterator/iterator_traits.h>
0019 #include <__iterator/move_iterator.h>
0020 #include <__memory/allocate_at_least.h>
0021 #include <__memory/allocator.h>
0022 #include <__memory/allocator_traits.h>
0023 #include <__memory/compressed_pair.h>
0024 #include <__memory/pointer_traits.h>
0025 #include <__memory/swap_allocator.h>
0026 #include <__type_traits/conditional.h>
0027 #include <__type_traits/enable_if.h>
0028 #include <__type_traits/integral_constant.h>
0029 #include <__type_traits/is_nothrow_assignable.h>
0030 #include <__type_traits/is_nothrow_constructible.h>
0031 #include <__type_traits/is_swappable.h>
0032 #include <__type_traits/is_trivially_destructible.h>
0033 #include <__type_traits/is_trivially_relocatable.h>
0034 #include <__type_traits/remove_reference.h>
0035 #include <__utility/forward.h>
0036 #include <__utility/move.h>
0037 
0038 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0039 #  pragma GCC system_header
0040 #endif
0041 
0042 _LIBCPP_PUSH_MACROS
0043 #include <__undef_macros>
0044 
0045 _LIBCPP_BEGIN_NAMESPACE_STD
0046 
0047 // __split_buffer allocates a contiguous chunk of memory and stores objects in the range [__begin_, __end_).
0048 // It has uninitialized memory in the ranges  [__first_, __begin_) and [__end_, __cap_). That allows
0049 // it to grow both in the front and back without having to move the data.
0050 
0051 template <class _Tp, class _Allocator = allocator<_Tp> >
0052 struct __split_buffer {
0053 public:
0054   using value_type                     = _Tp;
0055   using allocator_type                 = _Allocator;
0056   using __alloc_rr _LIBCPP_NODEBUG     = __libcpp_remove_reference_t<allocator_type>;
0057   using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<__alloc_rr>;
0058   using reference                      = value_type&;
0059   using const_reference                = const value_type&;
0060   using size_type                      = typename __alloc_traits::size_type;
0061   using difference_type                = typename __alloc_traits::difference_type;
0062   using pointer                        = typename __alloc_traits::pointer;
0063   using const_pointer                  = typename __alloc_traits::const_pointer;
0064   using iterator                       = pointer;
0065   using const_iterator                 = const_pointer;
0066 
0067   // A __split_buffer contains the following members which may be trivially relocatable:
0068   // - pointer: may be trivially relocatable, so it's checked
0069   // - allocator_type: may be trivially relocatable, so it's checked
0070   // __split_buffer doesn't have any self-references, so it's trivially relocatable if its members are.
0071   using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
0072       __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
0073       __split_buffer,
0074       void>;
0075 
0076   pointer __first_;
0077   pointer __begin_;
0078   pointer __end_;
0079   _LIBCPP_COMPRESSED_PAIR(pointer, __cap_, allocator_type, __alloc_);
0080 
0081   __split_buffer(const __split_buffer&)            = delete;
0082   __split_buffer& operator=(const __split_buffer&) = delete;
0083 
0084   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __split_buffer()
0085       _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
0086       : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __cap_(nullptr) {}
0087 
0088   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit __split_buffer(__alloc_rr& __a)
0089       : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __cap_(nullptr), __alloc_(__a) {}
0090 
0091   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit __split_buffer(const __alloc_rr& __a)
0092       : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __cap_(nullptr), __alloc_(__a) {}
0093 
0094   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
0095   __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
0096 
0097   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __split_buffer(__split_buffer&& __c)
0098       _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
0099 
0100   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __split_buffer(__split_buffer&& __c, const __alloc_rr& __a);
0101 
0102   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __split_buffer& operator=(__split_buffer&& __c)
0103       _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
0104                   is_nothrow_move_assignable<allocator_type>::value) ||
0105                  !__alloc_traits::propagate_on_container_move_assignment::value);
0106 
0107   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~__split_buffer();
0108 
0109   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __begin_; }
0110   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __begin_; }
0111 
0112   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __end_; }
0113   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __end_; }
0114 
0115   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __destruct_at_end(__begin_); }
0116 
0117   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type size() const {
0118     return static_cast<size_type>(__end_ - __begin_);
0119   }
0120 
0121   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool empty() const { return __end_ == __begin_; }
0122 
0123   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type capacity() const {
0124     return static_cast<size_type>(__cap_ - __first_);
0125   }
0126 
0127   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __front_spare() const {
0128     return static_cast<size_type>(__begin_ - __first_);
0129   }
0130 
0131   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __back_spare() const {
0132     return static_cast<size_type>(__cap_ - __end_);
0133   }
0134 
0135   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() { return *__begin_; }
0136   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const { return *__begin_; }
0137   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() { return *(__end_ - 1); }
0138   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const { return *(__end_ - 1); }
0139 
0140   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
0141 
0142   template <class... _Args>
0143   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
0144   template <class... _Args>
0145   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
0146 
0147   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_front() { __destruct_at_begin(__begin_ + 1); }
0148   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_back() { __destruct_at_end(__end_ - 1); }
0149 
0150   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
0151   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x);
0152 
0153   template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
0154   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
0155   __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
0156 
0157   template <class _Iterator, class _Sentinel>
0158   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
0159   __construct_at_end_with_sentinel(_Iterator __first, _Sentinel __last);
0160 
0161   template <class _Iterator>
0162   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
0163   __construct_at_end_with_size(_Iterator __first, size_type __n);
0164 
0165   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_begin(pointer __new_begin) {
0166     __destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());
0167   }
0168 
0169   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_begin(pointer __new_begin, false_type);
0170   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_begin(pointer __new_begin, true_type);
0171 
0172   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT {
0173     __destruct_at_end(__new_last, false_type());
0174   }
0175 
0176   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT;
0177   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT;
0178 
0179   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(__split_buffer& __x)
0180       _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__alloc_rr>);
0181 
0182   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
0183 
0184 private:
0185   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__split_buffer& __c, true_type)
0186       _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
0187     __alloc_ = std::move(__c.__alloc_);
0188   }
0189 
0190   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT {}
0191 
0192   struct _ConstructTransaction {
0193     _LIBCPP_CONSTEXPR_SINCE_CXX20
0194     _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(pointer* __p, size_type __n) _NOEXCEPT
0195         : __pos_(*__p),
0196           __end_(*__p + __n),
0197           __dest_(__p) {}
0198 
0199     _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() { *__dest_ = __pos_; }
0200 
0201     pointer __pos_;
0202     const pointer __end_;
0203 
0204   private:
0205     pointer* __dest_;
0206   };
0207 };
0208 
0209 template <class _Tp, class _Allocator>
0210 _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __split_buffer<_Tp, _Allocator>::__invariants() const {
0211   if (__first_ == nullptr) {
0212     if (__begin_ != nullptr)
0213       return false;
0214     if (__end_ != nullptr)
0215       return false;
0216     if (__cap_ != nullptr)
0217       return false;
0218   } else {
0219     if (__begin_ < __first_)
0220       return false;
0221     if (__end_ < __begin_)
0222       return false;
0223     if (__cap_ < __end_)
0224       return false;
0225   }
0226   return true;
0227 }
0228 
0229 //  Default constructs __n objects starting at __end_
0230 //  throws if construction throws
0231 //  Precondition:  __n > 0
0232 //  Precondition:  size() + __n <= capacity()
0233 //  Postcondition:  size() == size() + __n
0234 template <class _Tp, class _Allocator>
0235 _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n) {
0236   _ConstructTransaction __tx(&this->__end_, __n);
0237   for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
0238     __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_));
0239   }
0240 }
0241 
0242 //  Copy constructs __n objects starting at __end_ from __x
0243 //  throws if construction throws
0244 //  Precondition:  __n > 0
0245 //  Precondition:  size() + __n <= capacity()
0246 //  Postcondition:  size() == old size() + __n
0247 //  Postcondition:  [i] == __x for all i in [size() - __n, __n)
0248 template <class _Tp, class _Allocator>
0249 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0250 __split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
0251   _ConstructTransaction __tx(&this->__end_, __n);
0252   for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
0253     __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_), __x);
0254   }
0255 }
0256 
0257 template <class _Tp, class _Allocator>
0258 template <class _Iterator, class _Sentinel>
0259 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0260 __split_buffer<_Tp, _Allocator>::__construct_at_end_with_sentinel(_Iterator __first, _Sentinel __last) {
0261   __alloc_rr& __a = __alloc_;
0262   for (; __first != __last; ++__first) {
0263     if (__end_ == __cap_) {
0264       size_type __old_cap = __cap_ - __first_;
0265       size_type __new_cap = std::max<size_type>(2 * __old_cap, 8);
0266       __split_buffer __buf(__new_cap, 0, __a);
0267       for (pointer __p = __begin_; __p != __end_; ++__p, (void)++__buf.__end_)
0268         __alloc_traits::construct(__buf.__alloc_, std::__to_address(__buf.__end_), std::move(*__p));
0269       swap(__buf);
0270     }
0271     __alloc_traits::construct(__a, std::__to_address(this->__end_), *__first);
0272     ++this->__end_;
0273   }
0274 }
0275 template <class _Tp, class _Allocator>
0276 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
0277 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0278 __split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) {
0279   __construct_at_end_with_size(__first, std::distance(__first, __last));
0280 }
0281 
0282 template <class _Tp, class _Allocator>
0283 template <class _ForwardIterator>
0284 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0285 __split_buffer<_Tp, _Allocator>::__construct_at_end_with_size(_ForwardIterator __first, size_type __n) {
0286   _ConstructTransaction __tx(&this->__end_, __n);
0287   for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__first) {
0288     __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_), *__first);
0289   }
0290 }
0291 
0292 template <class _Tp, class _Allocator>
0293 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
0294 __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) {
0295   while (__begin_ != __new_begin)
0296     __alloc_traits::destroy(__alloc_, std::__to_address(__begin_++));
0297 }
0298 
0299 template <class _Tp, class _Allocator>
0300 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
0301 __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type) {
0302   __begin_ = __new_begin;
0303 }
0304 
0305 template <class _Tp, class _Allocator>
0306 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
0307 __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT {
0308   while (__new_last != __end_)
0309     __alloc_traits::destroy(__alloc_, std::__to_address(--__end_));
0310 }
0311 
0312 template <class _Tp, class _Allocator>
0313 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
0314 __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT {
0315   __end_ = __new_last;
0316 }
0317 
0318 template <class _Tp, class _Allocator>
0319 _LIBCPP_CONSTEXPR_SINCE_CXX20
0320 __split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a)
0321     : __cap_(nullptr), __alloc_(__a) {
0322   if (__cap == 0) {
0323     __first_ = nullptr;
0324   } else {
0325     auto __allocation = std::__allocate_at_least(__alloc_, __cap);
0326     __first_          = __allocation.ptr;
0327     __cap             = __allocation.count;
0328   }
0329   __begin_ = __end_ = __first_ + __start;
0330   __cap_            = __first_ + __cap;
0331 }
0332 
0333 template <class _Tp, class _Allocator>
0334 _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::~__split_buffer() {
0335   clear();
0336   if (__first_)
0337     __alloc_traits::deallocate(__alloc_, __first_, capacity());
0338 }
0339 
0340 template <class _Tp, class _Allocator>
0341 _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)
0342     _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
0343     : __first_(std::move(__c.__first_)),
0344       __begin_(std::move(__c.__begin_)),
0345       __end_(std::move(__c.__end_)),
0346       __cap_(std::move(__c.__cap_)),
0347       __alloc_(std::move(__c.__alloc_)) {
0348   __c.__first_ = nullptr;
0349   __c.__begin_ = nullptr;
0350   __c.__end_   = nullptr;
0351   __c.__cap_   = nullptr;
0352 }
0353 
0354 template <class _Tp, class _Allocator>
0355 _LIBCPP_CONSTEXPR_SINCE_CXX20
0356 __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a)
0357     : __cap_(nullptr), __alloc_(__a) {
0358   if (__a == __c.__alloc_) {
0359     __first_     = __c.__first_;
0360     __begin_     = __c.__begin_;
0361     __end_       = __c.__end_;
0362     __cap_       = __c.__cap_;
0363     __c.__first_ = nullptr;
0364     __c.__begin_ = nullptr;
0365     __c.__end_   = nullptr;
0366     __c.__cap_   = nullptr;
0367   } else {
0368     auto __allocation = std::__allocate_at_least(__alloc_, __c.size());
0369     __first_          = __allocation.ptr;
0370     __begin_ = __end_ = __first_;
0371     __cap_            = __first_ + __allocation.count;
0372     typedef move_iterator<iterator> _Ip;
0373     __construct_at_end(_Ip(__c.begin()), _Ip(__c.end()));
0374   }
0375 }
0376 
0377 template <class _Tp, class _Allocator>
0378 _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>&
0379 __split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
0380     _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
0381                 is_nothrow_move_assignable<allocator_type>::value) ||
0382                !__alloc_traits::propagate_on_container_move_assignment::value) {
0383   clear();
0384   shrink_to_fit();
0385   __first_ = __c.__first_;
0386   __begin_ = __c.__begin_;
0387   __end_   = __c.__end_;
0388   __cap_   = __c.__cap_;
0389   __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
0390   __c.__first_ = __c.__begin_ = __c.__end_ = __c.__cap_ = nullptr;
0391   return *this;
0392 }
0393 
0394 template <class _Tp, class _Allocator>
0395 _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
0396     _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__alloc_rr>) {
0397   std::swap(__first_, __x.__first_);
0398   std::swap(__begin_, __x.__begin_);
0399   std::swap(__end_, __x.__end_);
0400   std::swap(__cap_, __x.__cap_);
0401   std::__swap_allocator(__alloc_, __x.__alloc_);
0402 }
0403 
0404 template <class _Tp, class _Allocator>
0405 _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {
0406   if (capacity() > size()) {
0407 #if _LIBCPP_HAS_EXCEPTIONS
0408     try {
0409 #endif // _LIBCPP_HAS_EXCEPTIONS
0410       __split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc_);
0411       if (__t.capacity() < capacity()) {
0412         __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
0413         __t.__end_ = __t.__begin_ + (__end_ - __begin_);
0414         std::swap(__first_, __t.__first_);
0415         std::swap(__begin_, __t.__begin_);
0416         std::swap(__end_, __t.__end_);
0417         std::swap(__cap_, __t.__cap_);
0418       }
0419 #if _LIBCPP_HAS_EXCEPTIONS
0420     } catch (...) {
0421     }
0422 #endif // _LIBCPP_HAS_EXCEPTIONS
0423   }
0424 }
0425 
0426 template <class _Tp, class _Allocator>
0427 template <class... _Args>
0428 _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::emplace_front(_Args&&... __args) {
0429   if (__begin_ == __first_) {
0430     if (__end_ < __cap_) {
0431       difference_type __d = __cap_ - __end_;
0432       __d                 = (__d + 1) / 2;
0433       __begin_            = std::move_backward(__begin_, __end_, __end_ + __d);
0434       __end_ += __d;
0435     } else {
0436       size_type __c = std::max<size_type>(2 * static_cast<size_type>(__cap_ - __first_), 1);
0437       __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc_);
0438       __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
0439       std::swap(__first_, __t.__first_);
0440       std::swap(__begin_, __t.__begin_);
0441       std::swap(__end_, __t.__end_);
0442       std::swap(__cap_, __t.__cap_);
0443     }
0444   }
0445   __alloc_traits::construct(__alloc_, std::__to_address(__begin_ - 1), std::forward<_Args>(__args)...);
0446   --__begin_;
0447 }
0448 
0449 template <class _Tp, class _Allocator>
0450 template <class... _Args>
0451 _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
0452   if (__end_ == __cap_) {
0453     if (__begin_ > __first_) {
0454       difference_type __d = __begin_ - __first_;
0455       __d                 = (__d + 1) / 2;
0456       __end_              = std::move(__begin_, __end_, __begin_ - __d);
0457       __begin_ -= __d;
0458     } else {
0459       size_type __c = std::max<size_type>(2 * static_cast<size_type>(__cap_ - __first_), 1);
0460       __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc_);
0461       __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
0462       std::swap(__first_, __t.__first_);
0463       std::swap(__begin_, __t.__begin_);
0464       std::swap(__end_, __t.__end_);
0465       std::swap(__cap_, __t.__cap_);
0466     }
0467   }
0468   __alloc_traits::construct(__alloc_, std::__to_address(__end_), std::forward<_Args>(__args)...);
0469   ++__end_;
0470 }
0471 
0472 template <class _Tp, class _Allocator>
0473 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
0474 swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
0475   __x.swap(__y);
0476 }
0477 
0478 _LIBCPP_END_NAMESPACE_STD
0479 
0480 _LIBCPP_POP_MACROS
0481 
0482 #endif // _LIBCPP___SPLIT_BUFFER