[libc++] Introduce helper functions __make_iter in vector and string

This prepares the terrain for introducing a new type of bounded iterator
that can't be constructed like __wrap_iter. This reverts part of the
changes made to std::vector in 4eab04f84.

Differential Revision: https://reviews.llvm.org/D138036
This commit is contained in:
Louis Dionne 2022-11-14 11:01:05 -10:00
parent d1da6f23a6
commit 5ed6dc4681
2 changed files with 28 additions and 22 deletions

View File

@ -813,6 +813,14 @@ private:
std::__debug_db_insert_c(this);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iterator(pointer __p) {
return iterator(this, __p);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_const_iterator(const_pointer __p) const {
return const_iterator(this, __p);
}
public:
_LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1;
@ -1029,16 +1037,16 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
iterator begin() _NOEXCEPT
{return iterator(this, __get_pointer());}
{return __make_iterator(__get_pointer());}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
const_iterator begin() const _NOEXCEPT
{return const_iterator(this, __get_pointer());}
{return __make_const_iterator(__get_pointer());}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
iterator end() _NOEXCEPT
{return iterator(this, __get_pointer() + size());}
{return __make_iterator(__get_pointer() + size());}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
const_iterator end() const _NOEXCEPT
{return const_iterator(this, __get_pointer() + size());}
{return __make_const_iterator(__get_pointer() + size());}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
reverse_iterator rbegin() _NOEXCEPT

View File

@ -686,9 +686,9 @@ private:
_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;
iterator __make_iter(pointer __p) _NOEXCEPT { return iterator(this, __p); }
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
const_iterator __make_iter(const_pointer __p) const _NOEXCEPT { return const_iterator(this, __p); }
_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);
@ -1377,7 +1377,7 @@ inline _LIBCPP_HIDE_FROM_ABI
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::begin() _NOEXCEPT
{
return iterator(this, this->__begin_);
return __make_iter(this->__begin_);
}
template <class _Tp, class _Allocator>
@ -1386,7 +1386,7 @@ inline _LIBCPP_HIDE_FROM_ABI
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::begin() const _NOEXCEPT
{
return const_iterator(this, this->__begin_);
return __make_iter(this->__begin_);
}
template <class _Tp, class _Allocator>
@ -1395,7 +1395,7 @@ inline _LIBCPP_HIDE_FROM_ABI
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::end() _NOEXCEPT
{
return iterator(this, this->__end_);
return __make_iter(this->__end_);
}
template <class _Tp, class _Allocator>
@ -1404,7 +1404,7 @@ inline _LIBCPP_HIDE_FROM_ABI
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::end() const _NOEXCEPT
{
return const_iterator(this, this->__end_);
return __make_iter(this->__end_);
}
template <class _Tp, class _Allocator>
@ -1588,8 +1588,7 @@ vector<_Tp, _Allocator>::erase(const_iterator __position)
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;
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
@ -1609,8 +1608,7 @@ vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
if (!__libcpp_is_constant_evaluated())
this->__invalidate_iterators_past(__p - 1);
}
iterator __r = iterator(this, __p);
return __r;
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
@ -1664,7 +1662,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
__v.push_back(__x);
__p = __swap_out_circular_buffer(__v, __p);
}
return iterator(this, __p);
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
@ -1694,7 +1692,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
__v.push_back(std::move(__x));
__p = __swap_out_circular_buffer(__v, __p);
}
return iterator(this, __p);
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
@ -1726,7 +1724,7 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
__v.emplace_back(std::forward<_Args>(__args)...);
__p = __swap_out_circular_buffer(__v, __p);
}
return iterator(this, __p);
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
@ -1767,7 +1765,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
__p = __swap_out_circular_buffer(__v, __p);
}
}
return iterator(this, __p);
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
@ -1804,14 +1802,14 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __firs
}
catch (...)
{
erase(iterator(this, __old_last), end());
erase(__make_iter(__old_last), end());
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
__p = std::rotate(__p, __old_last, this->__end_);
insert(iterator(this, __p), std::make_move_iterator(__v.begin()),
std::make_move_iterator(__v.end()));
insert(__make_iter(__p), std::make_move_iterator(__v.begin()),
std::make_move_iterator(__v.end()));
return begin() + __off;
}
@ -1856,7 +1854,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __fi
__p = __swap_out_circular_buffer(__v, __p);
}
}
return iterator(this, __p);
return __make_iter(__p);
}
template <class _Tp, class _Allocator>