2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
#ifndef _LIBCPP_SPLIT_BUFFER
|
|
|
|
#define _LIBCPP_SPLIT_BUFFER
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-12 03:42:16 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
template <bool>
|
|
|
|
class __split_buffer_common
|
|
|
|
{
|
|
|
|
protected:
|
2021-02-24 03:17:29 +08:00
|
|
|
_LIBCPP_NORETURN void __throw_length_error() const;
|
|
|
|
_LIBCPP_NORETURN void __throw_out_of_range() const;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-07-08 03:14:52 +08:00
|
|
|
template <class _Tp, class _Allocator = allocator<_Tp> >
|
2010-05-12 03:42:16 +08:00
|
|
|
struct __split_buffer
|
|
|
|
: private __split_buffer_common<true>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
__split_buffer(const __split_buffer&);
|
|
|
|
__split_buffer& operator=(const __split_buffer&);
|
|
|
|
public:
|
2010-08-22 08:02:43 +08:00
|
|
|
typedef _Tp value_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef _Allocator allocator_type;
|
|
|
|
typedef typename remove_reference<allocator_type>::type __alloc_rr;
|
|
|
|
typedef allocator_traits<__alloc_rr> __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 pointer iterator;
|
|
|
|
typedef const_pointer const_iterator;
|
|
|
|
|
|
|
|
pointer __first_;
|
|
|
|
pointer __begin_;
|
|
|
|
pointer __end_;
|
|
|
|
__compressed_pair<pointer, allocator_type> __end_cap_;
|
|
|
|
|
|
|
|
typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref;
|
|
|
|
typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref;
|
|
|
|
|
2011-06-03 04:00:14 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const __alloc_rr& __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();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 23:16:49 +08:00
|
|
|
__split_buffer()
|
|
|
|
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __split_buffer(__alloc_rr& __a);
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit __split_buffer(const __alloc_rr& __a);
|
|
|
|
__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
|
|
|
|
~__split_buffer();
|
|
|
|
|
2011-06-03 04:00:14 +08:00
|
|
|
__split_buffer(__split_buffer&& __c)
|
|
|
|
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer(__split_buffer&& __c, const __alloc_rr& __a);
|
2011-06-03 04:00:14 +08:00
|
|
|
__split_buffer& operator=(__split_buffer&& __c)
|
|
|
|
_NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
|
|
|
|
is_nothrow_move_assignable<allocator_type>::value) ||
|
|
|
|
!__alloc_traits::propagate_on_container_move_assignment::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-03 04:00:14 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-03 04:00:14 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void clear() _NOEXCEPT
|
|
|
|
{__destruct_at_end(__begin_);}
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);}
|
|
|
|
|
|
|
|
void reserve(size_type __n);
|
2011-06-03 04:00:14 +08:00
|
|
|
void shrink_to_fit() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
void push_front(const_reference __x);
|
2012-02-15 08:41:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
|
2010-05-12 03:42:16 +08:00
|
|
|
void push_front(value_type&& __x);
|
|
|
|
void push_back(value_type&& __x);
|
|
|
|
template <class... _Args>
|
|
|
|
void emplace_back(_Args&&... __args);
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);}
|
|
|
|
|
|
|
|
void __construct_at_end(size_type __n);
|
|
|
|
void __construct_at_end(size_type __n, const_reference __x);
|
|
|
|
template <class _InputIter>
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIter>::value &&
|
|
|
|
!__is_cpp17_forward_iterator<_InputIter>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
>::type
|
|
|
|
__construct_at_end(_InputIter __first, _InputIter __last);
|
|
|
|
template <class _ForwardIterator>
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_forward_iterator<_ForwardIterator>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
>::type
|
|
|
|
__construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin)
|
2010-11-20 06:17:28 +08:00
|
|
|
{__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());}
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __destruct_at_begin(pointer __new_begin, false_type);
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __destruct_at_begin(pointer __new_begin, true_type);
|
|
|
|
|
2011-06-03 04:00:14 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __destruct_at_end(pointer __new_last) _NOEXCEPT
|
2012-02-15 08:41:34 +08:00
|
|
|
{__destruct_at_end(__new_last, false_type());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 04:00:14 +08:00
|
|
|
void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT;
|
2012-02-15 08:41:34 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 04:00:14 +08:00
|
|
|
void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-03 04:00:14 +08:00
|
|
|
void swap(__split_buffer& __x)
|
|
|
|
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
|
|
|
|
__is_nothrow_swappable<__alloc_rr>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
bool __invariants() const;
|
|
|
|
|
|
|
|
private:
|
2010-09-22 04:16:37 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-09-03 04:42:31 +08:00
|
|
|
void __move_assign_alloc(__split_buffer& __c, true_type)
|
2011-06-03 04:00:14 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
__alloc() = _VSTD::move(__c.__alloc());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2010-09-22 04:16:37 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-12-02 04:21:04 +08:00
|
|
|
void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{}
|
2019-08-12 15:51:05 +08:00
|
|
|
|
|
|
|
struct _ConstructTransaction {
|
|
|
|
explicit _ConstructTransaction(pointer* __p, size_type __n) _NOEXCEPT
|
|
|
|
: __pos_(*__p), __end_(*__p + __n), __dest_(__p) {
|
|
|
|
}
|
|
|
|
~_ConstructTransaction() {
|
|
|
|
*__dest_ = __pos_;
|
|
|
|
}
|
|
|
|
pointer __pos_;
|
|
|
|
const pointer __end_;
|
|
|
|
private:
|
|
|
|
pointer *__dest_;
|
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
bool
|
|
|
|
__split_buffer<_Tp, _Allocator>::__invariants() const
|
|
|
|
{
|
|
|
|
if (__first_ == nullptr)
|
|
|
|
{
|
|
|
|
if (__begin_ != nullptr)
|
|
|
|
return false;
|
|
|
|
if (__end_ != nullptr)
|
|
|
|
return false;
|
|
|
|
if (__end_cap() != nullptr)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (__begin_ < __first_)
|
|
|
|
return false;
|
|
|
|
if (__end_ < __begin_)
|
|
|
|
return false;
|
|
|
|
if (__end_cap() < __end_)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default constructs __n objects starting at __end_
|
|
|
|
// throws if construction throws
|
|
|
|
// Precondition: __n > 0
|
|
|
|
// Precondition: size() + __n <= capacity()
|
|
|
|
// Postcondition: size() == size() + __n
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n)
|
|
|
|
{
|
2019-08-12 15:51:05 +08:00
|
|
|
_ConstructTransaction __tx(&this->__end_, __n);
|
|
|
|
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
|
2019-11-17 06:13:26 +08:00
|
|
|
__alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_));
|
2019-08-12 15:51:05 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy constructs __n objects starting at __end_ from __x
|
|
|
|
// throws if construction throws
|
|
|
|
// Precondition: __n > 0
|
|
|
|
// Precondition: size() + __n <= capacity()
|
|
|
|
// Postcondition: size() == old size() + __n
|
|
|
|
// Postcondition: [i] == __x for all i in [size() - __n, __n)
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
|
|
|
|
{
|
2019-08-12 15:51:05 +08:00
|
|
|
_ConstructTransaction __tx(&this->__end_, __n);
|
|
|
|
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
|
|
|
|
__alloc_traits::construct(this->__alloc(),
|
2019-11-17 06:13:26 +08:00
|
|
|
_VSTD::__to_address(__tx.__pos_), __x);
|
2019-08-12 15:51:05 +08:00
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
template <class _InputIter>
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIter>::value &&
|
|
|
|
!__is_cpp17_forward_iterator<_InputIter>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
>::type
|
|
|
|
__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last)
|
|
|
|
{
|
|
|
|
__alloc_rr& __a = this->__alloc();
|
|
|
|
for (; __first != __last; ++__first)
|
|
|
|
{
|
|
|
|
if (__end_ == __end_cap())
|
|
|
|
{
|
|
|
|
size_type __old_cap = __end_cap() - __first_;
|
2011-07-01 05:18:19 +08:00
|
|
|
size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8);
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer __buf(__new_cap, 0, __a);
|
|
|
|
for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_)
|
|
|
|
__alloc_traits::construct(__buf.__alloc(),
|
2019-11-17 06:13:26 +08:00
|
|
|
_VSTD::__to_address(__buf.__end_), _VSTD::move(*__p));
|
2010-05-12 03:42:16 +08:00
|
|
|
swap(__buf);
|
|
|
|
}
|
2019-11-17 06:13:26 +08:00
|
|
|
__alloc_traits::construct(__a, _VSTD::__to_address(this->__end_), *__first);
|
2010-05-12 03:42:16 +08:00
|
|
|
++this->__end_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
template <class _ForwardIterator>
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_forward_iterator<_ForwardIterator>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
>::type
|
|
|
|
__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
|
|
|
|
{
|
[libc++] Consistently replace `std::` qualification with `_VSTD::` or nothing. NFCI.
I used a lot of `git grep` to find places where `std::` was being used
outside of comments and assert-messages. There were three outcomes:
- Qualified function calls, e.g. `std::move` becomes `_VSTD::move`.
This is the most common case.
- Typenames that don't need qualification, e.g. `std::allocator` becomes `allocator`.
Leaving these as `_VSTD::allocator` would also be fine, but I decided
that removing the qualification is more consistent with existing practice.
- Names that specifically need un-versioned `std::` qualification,
or that I wasn't sure about. For example, I didn't touch any code in
<atomic>, <math.h>, <new>, or any ext/ or experimental/ headers;
and I didn't touch any instances of `std::type_info`.
In some deduction guides, we were accidentally using `class Alloc = typename std::allocator<T>`,
despite `std::allocator<T>`'s type-ness not being template-dependent.
Because `std::allocator` is a qualified name, this did parse as we intended;
but what we meant was simply `class Alloc = allocator<T>`.
Differential Revision: https://reviews.llvm.org/D92250
2020-11-28 00:02:06 +08:00
|
|
|
_ConstructTransaction __tx(&this->__end_, _VSTD::distance(__first, __last));
|
2019-08-12 15:51:05 +08:00
|
|
|
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, ++__first) {
|
|
|
|
__alloc_traits::construct(this->__alloc(),
|
2019-11-17 06:13:26 +08:00
|
|
|
_VSTD::__to_address(__tx.__pos_), *__first);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
|
|
|
|
{
|
2012-02-15 08:41:34 +08:00
|
|
|
while (__begin_ != __new_begin)
|
2020-11-19 07:54:38 +08:00
|
|
|
__alloc_traits::destroy(__alloc(), _VSTD::__to_address(__begin_++));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type)
|
|
|
|
{
|
|
|
|
__begin_ = __new_begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
2011-06-03 04:00:14 +08:00
|
|
|
__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2012-02-15 08:41:34 +08:00
|
|
|
while (__new_last != __end_)
|
2020-11-19 07:54:38 +08:00
|
|
|
__alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__end_));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
2011-06-03 04:00:14 +08:00
|
|
|
__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__end_ = __new_last;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a)
|
2013-06-24 05:17:24 +08:00
|
|
|
: __end_cap_(nullptr, __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr;
|
|
|
|
__begin_ = __end_ = __first_ + __start;
|
|
|
|
__end_cap() = __first_ + __cap;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer<_Tp, _Allocator>::__split_buffer()
|
2011-06-03 23:16:49 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
|
2019-12-17 07:23:39 +08:00
|
|
|
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __default_init_tag())
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a)
|
2013-06-24 05:17:24 +08:00
|
|
|
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
|
2013-06-24 05:17:24 +08:00
|
|
|
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
__split_buffer<_Tp, _Allocator>::~__split_buffer()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
if (__first_)
|
|
|
|
__alloc_traits::deallocate(__alloc(), __first_, capacity());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)
|
2011-06-03 04:00:14 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
|
2011-07-01 05:18:19 +08:00
|
|
|
: __first_(_VSTD::move(__c.__first_)),
|
|
|
|
__begin_(_VSTD::move(__c.__begin_)),
|
|
|
|
__end_(_VSTD::move(__c.__end_)),
|
|
|
|
__end_cap_(_VSTD::move(__c.__end_cap_))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__c.__first_ = nullptr;
|
|
|
|
__c.__begin_ = nullptr;
|
|
|
|
__c.__end_ = nullptr;
|
|
|
|
__c.__end_cap() = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a)
|
2019-12-17 07:23:39 +08:00
|
|
|
: __end_cap_(nullptr, __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (__a == __c.__alloc())
|
|
|
|
{
|
|
|
|
__first_ = __c.__first_;
|
|
|
|
__begin_ = __c.__begin_;
|
|
|
|
__end_ = __c.__end_;
|
|
|
|
__end_cap() = __c.__end_cap();
|
|
|
|
__c.__first_ = nullptr;
|
|
|
|
__c.__begin_ = nullptr;
|
|
|
|
__c.__end_ = nullptr;
|
|
|
|
__c.__end_cap() = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_type __cap = __c.size();
|
|
|
|
__first_ = __alloc_traits::allocate(__alloc(), __cap);
|
|
|
|
__begin_ = __end_ = __first_;
|
|
|
|
__end_cap() = __first_ + __cap;
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef move_iterator<iterator> _Ip;
|
|
|
|
__construct_at_end(_Ip(__c.begin()), _Ip(__c.end()));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
__split_buffer<_Tp, _Allocator>&
|
|
|
|
__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
|
2011-06-03 04:00:14 +08:00
|
|
|
_NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
|
|
|
|
is_nothrow_move_assignable<allocator_type>::value) ||
|
|
|
|
!__alloc_traits::propagate_on_container_move_assignment::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
shrink_to_fit();
|
|
|
|
__first_ = __c.__first_;
|
|
|
|
__begin_ = __c.__begin_;
|
|
|
|
__end_ = __c.__end_;
|
|
|
|
__end_cap() = __c.__end_cap();
|
|
|
|
__move_assign_alloc(__c,
|
|
|
|
integral_constant<bool,
|
|
|
|
__alloc_traits::propagate_on_container_move_assignment::value>());
|
|
|
|
__c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
|
2011-06-03 04:00:14 +08:00
|
|
|
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
|
|
|
|
__is_nothrow_swappable<__alloc_rr>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __x.__first_);
|
|
|
|
_VSTD::swap(__begin_, __x.__begin_);
|
|
|
|
_VSTD::swap(__end_, __x.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __x.__end_cap());
|
2020-11-19 07:54:38 +08:00
|
|
|
_VSTD::__swap_allocator(__alloc(), __x.__alloc());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::reserve(size_type __n)
|
|
|
|
{
|
|
|
|
if (__n < capacity())
|
|
|
|
{
|
|
|
|
__split_buffer<value_type, __alloc_rr&> __t(__n, 0, __alloc());
|
|
|
|
__t.__construct_at_end(move_iterator<pointer>(__begin_),
|
|
|
|
move_iterator<pointer>(__end_));
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __t.__first_);
|
|
|
|
_VSTD::swap(__begin_, __t.__begin_);
|
|
|
|
_VSTD::swap(__end_, __t.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __t.__end_cap());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
2011-06-03 04:00:14 +08:00
|
|
|
__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (capacity() > size())
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc());
|
|
|
|
__t.__construct_at_end(move_iterator<pointer>(__begin_),
|
|
|
|
move_iterator<pointer>(__end_));
|
|
|
|
__t.__end_ = __t.__begin_ + (__end_ - __begin_);
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __t.__first_);
|
|
|
|
_VSTD::swap(__begin_, __t.__begin_);
|
|
|
|
_VSTD::swap(__end_, __t.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __t.__end_cap());
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
}
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::push_front(const_reference __x)
|
|
|
|
{
|
|
|
|
if (__begin_ == __first_)
|
|
|
|
{
|
|
|
|
if (__end_ < __end_cap())
|
|
|
|
{
|
|
|
|
difference_type __d = __end_cap() - __end_;
|
|
|
|
__d = (__d + 1) / 2;
|
2011-07-01 05:18:19 +08:00
|
|
|
__begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d);
|
2010-05-12 03:42:16 +08:00
|
|
|
__end_ += __d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-02 04:21:04 +08:00
|
|
|
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
|
2010-07-08 03:14:52 +08:00
|
|
|
__split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
|
2010-05-12 03:42:16 +08:00
|
|
|
__t.__construct_at_end(move_iterator<pointer>(__begin_),
|
|
|
|
move_iterator<pointer>(__end_));
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __t.__first_);
|
|
|
|
_VSTD::swap(__begin_, __t.__begin_);
|
|
|
|
_VSTD::swap(__end_, __t.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __t.__end_cap());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-17 06:13:26 +08:00
|
|
|
__alloc_traits::construct(__alloc(), _VSTD::__to_address(__begin_-1), __x);
|
2010-05-12 03:42:16 +08:00
|
|
|
--__begin_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x)
|
|
|
|
{
|
|
|
|
if (__begin_ == __first_)
|
|
|
|
{
|
|
|
|
if (__end_ < __end_cap())
|
|
|
|
{
|
|
|
|
difference_type __d = __end_cap() - __end_;
|
|
|
|
__d = (__d + 1) / 2;
|
2011-07-01 05:18:19 +08:00
|
|
|
__begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d);
|
2010-05-12 03:42:16 +08:00
|
|
|
__end_ += __d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-02 04:21:04 +08:00
|
|
|
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
|
2010-07-08 03:14:52 +08:00
|
|
|
__split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
|
2010-05-12 03:42:16 +08:00
|
|
|
__t.__construct_at_end(move_iterator<pointer>(__begin_),
|
|
|
|
move_iterator<pointer>(__end_));
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __t.__first_);
|
|
|
|
_VSTD::swap(__begin_, __t.__begin_);
|
|
|
|
_VSTD::swap(__end_, __t.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __t.__end_cap());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-17 06:13:26 +08:00
|
|
|
__alloc_traits::construct(__alloc(), _VSTD::__to_address(__begin_-1),
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::move(__x));
|
2010-05-12 03:42:16 +08:00
|
|
|
--__begin_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::push_back(const_reference __x)
|
|
|
|
{
|
|
|
|
if (__end_ == __end_cap())
|
|
|
|
{
|
|
|
|
if (__begin_ > __first_)
|
|
|
|
{
|
|
|
|
difference_type __d = __begin_ - __first_;
|
|
|
|
__d = (__d + 1) / 2;
|
2011-07-01 05:18:19 +08:00
|
|
|
__end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
|
2010-05-12 03:42:16 +08:00
|
|
|
__begin_ -= __d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-02 04:21:04 +08:00
|
|
|
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
|
|
|
|
__t.__construct_at_end(move_iterator<pointer>(__begin_),
|
|
|
|
move_iterator<pointer>(__end_));
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __t.__first_);
|
|
|
|
_VSTD::swap(__begin_, __t.__begin_);
|
|
|
|
_VSTD::swap(__end_, __t.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __t.__end_cap());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-17 06:13:26 +08:00
|
|
|
__alloc_traits::construct(__alloc(), _VSTD::__to_address(__end_), __x);
|
2010-05-12 03:42:16 +08:00
|
|
|
++__end_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x)
|
|
|
|
{
|
|
|
|
if (__end_ == __end_cap())
|
|
|
|
{
|
|
|
|
if (__begin_ > __first_)
|
|
|
|
{
|
|
|
|
difference_type __d = __begin_ - __first_;
|
|
|
|
__d = (__d + 1) / 2;
|
2011-07-01 05:18:19 +08:00
|
|
|
__end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
|
2010-05-12 03:42:16 +08:00
|
|
|
__begin_ -= __d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-02 04:21:04 +08:00
|
|
|
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
|
|
|
|
__t.__construct_at_end(move_iterator<pointer>(__begin_),
|
|
|
|
move_iterator<pointer>(__end_));
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __t.__first_);
|
|
|
|
_VSTD::swap(__begin_, __t.__begin_);
|
|
|
|
_VSTD::swap(__end_, __t.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __t.__end_cap());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-17 06:13:26 +08:00
|
|
|
__alloc_traits::construct(__alloc(), _VSTD::__to_address(__end_),
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::move(__x));
|
2010-05-12 03:42:16 +08:00
|
|
|
++__end_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Allocator>
|
|
|
|
template <class... _Args>
|
|
|
|
void
|
|
|
|
__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args)
|
|
|
|
{
|
|
|
|
if (__end_ == __end_cap())
|
|
|
|
{
|
|
|
|
if (__begin_ > __first_)
|
|
|
|
{
|
|
|
|
difference_type __d = __begin_ - __first_;
|
|
|
|
__d = (__d + 1) / 2;
|
2011-07-01 05:18:19 +08:00
|
|
|
__end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
|
2010-05-12 03:42:16 +08:00
|
|
|
__begin_ -= __d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-02 04:21:04 +08:00
|
|
|
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
|
2010-05-12 03:42:16 +08:00
|
|
|
__split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
|
|
|
|
__t.__construct_at_end(move_iterator<pointer>(__begin_),
|
|
|
|
move_iterator<pointer>(__end_));
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__first_, __t.__first_);
|
|
|
|
_VSTD::swap(__begin_, __t.__begin_);
|
|
|
|
_VSTD::swap(__end_, __t.__end_);
|
|
|
|
_VSTD::swap(__end_cap(), __t.__end_cap());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-17 06:13:26 +08:00
|
|
|
__alloc_traits::construct(__alloc(), _VSTD::__to_address(__end_),
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
++__end_;
|
|
|
|
}
|
|
|
|
|
2011-06-03 04:00:14 +08:00
|
|
|
template <class _Tp, class _Allocator>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-06-03 04:00:14 +08:00
|
|
|
void
|
|
|
|
swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y)
|
|
|
|
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
|
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_SPLIT_BUFFER
|