[libc++] Remove vector base class

Remove the vector base class as suggested by @ldionne

Reviewed By: ldionne, Quuxplusone, #libc

Spies: libcxx-commits, ldionne

Differential Revision: https://reviews.llvm.org/D117108
This commit is contained in:
Nikolas Klauser 2022-02-03 23:09:37 +01:00
parent 06f3ef6626
commit b82da8b555
3 changed files with 44 additions and 68 deletions

View File

@ -116,6 +116,8 @@
# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
// Remove basic_string common base
# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
// Remove vector base class
# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
#elif _LIBCPP_ABI_VERSION == 1
# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
// Enable compiling copies of now inline methods into the dylib to support

View File

@ -302,55 +302,10 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <bool>
struct __vector_base_common;
template <>
struct __vector_base_common<true> {
// Both are defined in vector.cpp
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
};
template <class _Tp, class _Allocator>
class __vector_base
: protected __vector_base_common<true> // This base class is historical, but it needs to remain for ABI compatibility
{
typedef _Allocator allocator_type;
typedef typename allocator_traits<allocator_type>::pointer pointer;
protected:
pointer __begin_;
pointer __end_;
__compressed_pair<pointer, allocator_type> __end_cap_;
_LIBCPP_INLINE_VISIBILITY
__vector_base()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __begin_(nullptr),
__end_(nullptr),
__end_cap_(nullptr, __default_init_tag()) {}
_LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a)
: __begin_(nullptr),
__end_(nullptr),
__end_cap_(nullptr, __a) {}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT
: __begin_(nullptr),
__end_(nullptr),
__end_cap_(nullptr, _VSTD::move(__a)) {}
#endif
};
template <class _Tp, class _Allocator /* = allocator<_Tp> */>
class _LIBCPP_TEMPLATE_VIS vector
// This base class is historical, but it needs to remain for ABI compatibility.
: private __vector_base<_Tp, _Allocator>
{
private:
typedef __vector_base<_Tp, _Allocator> __base;
typedef allocator<_Tp> __default_allocator_type;
public:
typedef vector __self;
@ -382,7 +337,7 @@ public:
#else
_NOEXCEPT
#endif
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
}
@ -394,7 +349,7 @@ public:
template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
vector(size_type __n, const value_type& __x, const allocator_type& __a)
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__n > 0)
@ -691,6 +646,11 @@ public:
#endif // _LIBCPP_DEBUG_LEVEL == 2
private:
pointer __begin_ = nullptr;
pointer __end_ = nullptr;
__compressed_pair<pointer, allocator_type> __end_cap_ =
__compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
_LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
void __vallocate(size_type __n);
@ -859,20 +819,12 @@ private:
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
void __throw_length_error() const {
#ifndef _LIBCPP_NO_EXCEPTIONS
__vector_base_common<true>::__throw_length_error();
#else
_VSTD::abort();
#endif
_VSTD::__throw_length_error("vector");
}
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
void __throw_out_of_range() const {
#ifndef _LIBCPP_NO_EXCEPTIONS
__vector_base_common<true>::__throw_out_of_range();
#else
_VSTD::abort();
#endif
_VSTD::__throw_out_of_range("vector");
}
_LIBCPP_INLINE_VISIBILITY
@ -1106,7 +1058,7 @@ vector<_Tp, _Allocator>::vector(size_type __n)
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__n > 0)
@ -1151,7 +1103,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value>::type*)
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
for (; __first != __last; ++__first)
@ -1183,7 +1135,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
@ -1196,7 +1148,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(const vector& __x)
: __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
: __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
{
_VSTD::__debug_db_insert_c(this);
size_type __n = __x.size();
@ -1209,7 +1161,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
size_type __n = __x.size();
@ -1230,7 +1182,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
#endif
: __base(_VSTD::move(__x.__alloc()))
: __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
@ -1245,7 +1197,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__a == __x.__alloc())
@ -1280,7 +1232,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
: __base(__a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
if (__il.size() > 0)
@ -2079,7 +2031,6 @@ struct __has_storage_type<vector<bool, _Allocator> >
template <class _Allocator>
class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
: private __vector_base_common<true>
{
public:
typedef vector __self;
@ -2348,6 +2299,16 @@ public:
bool __invariants() const;
private:
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
void __throw_length_error() const {
_VSTD::__throw_length_error("vector");
}
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
void __throw_out_of_range() const {
_VSTD::__throw_out_of_range("vector");
}
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
void __vallocate(size_type __n);
void __vdeallocate() _NOEXCEPT;

View File

@ -10,12 +10,25 @@
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
template <bool>
struct __vector_base_common;
template <>
struct __vector_base_common<true> {
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
};
void __vector_base_common<true>::__throw_length_error() const {
_VSTD::__throw_length_error("vector");
_VSTD::__throw_length_error("vector");
}
void __vector_base_common<true>::__throw_out_of_range() const {
_VSTD::__throw_out_of_range("vector");
_VSTD::__throw_out_of_range("vector");
}
#endif // _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
_LIBCPP_END_NAMESPACE_STD