diff options
Diffstat (limited to 'libcxx/include/vector')
-rw-r--r-- | libcxx/include/vector | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/libcxx/include/vector b/libcxx/include/vector index 8366bb5d11e8..1007beeaafd0 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -261,9 +261,11 @@ void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) noexcept(noexcept(x.swap(y))); template <class T, class Allocator, class U> - void erase(vector<T, Allocator>& c, const U& value); // C++20 +typename vector<T, Allocator>::size_type +erase(vector<T, Allocator>& c, const U& value); // C++20 template <class T, class Allocator, class Predicate> - void erase_if(vector<T, Allocator>& c, Predicate pred); // C++20 +typename vector<T, Allocator>::size_type +erase_if(vector<T, Allocator>& c, Predicate pred); // C++20 } // std @@ -1041,8 +1043,9 @@ void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) { _ConstructTransaction __tx(*this, __n); - for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) { - __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_)); + 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)); } } @@ -1058,8 +1061,9 @@ void vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) { _ConstructTransaction __tx(*this, __n); - for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) { - __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), __x); + 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); } } @@ -1751,9 +1755,10 @@ vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointe { pointer __i = __from_s + __n; _ConstructTransaction __tx(*this, __from_e - __i); - for (; __i < __from_e; ++__i, ++__tx.__pos_) { + for (pointer __pos = __tx.__pos_; __i < __from_e; + ++__i, ++__pos, __tx.__pos_ = __pos) { __alloc_traits::construct(this->__alloc(), - _VSTD::__to_address(__tx.__pos_), + _VSTD::__to_address(__pos), _VSTD::move(*__i)); } } @@ -1956,8 +1961,8 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __firs #endif // _LIBCPP_NO_EXCEPTIONS } __p = _VSTD::rotate(__p, __old_last, this->__end_); - insert(__make_iter(__p), make_move_iterator(__v.begin()), - make_move_iterator(__v.end())); + insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()), + _VSTD::make_move_iterator(__v.end())); return begin() + __off; } @@ -3389,14 +3394,20 @@ swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) #if _LIBCPP_STD_VER > 17 template <class _Tp, class _Allocator, class _Up> -inline _LIBCPP_INLINE_VISIBILITY -void erase(vector<_Tp, _Allocator>& __c, const _Up& __v) -{ __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); } +inline _LIBCPP_INLINE_VISIBILITY 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()); + return __old_size - __c.size(); +} template <class _Tp, class _Allocator, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY -void erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) -{ __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); } +inline _LIBCPP_INLINE_VISIBILITY 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()); + return __old_size - __c.size(); +} #endif _LIBCPP_END_NAMESPACE_STD |