fixed erase()

This commit is contained in:
Patrick 2024-07-29 17:22:47 +02:00
parent cfb82ca1fe
commit 9cbeacef21
1 changed files with 14 additions and 7 deletions

View File

@ -486,22 +486,29 @@ namespace cc {
template<typename T, std::size_t N>
constexpr const_vector<T, N>::iterator const_vector<T, N>::erase(const_vector::const_iterator pos)
{
_erase_no_move(pos);
std::move(pos + 1, end(), pos);
auto it = const_cast<iterator>(pos);
std::destroy_n(it, 1);
std::move(it + 1, end(), it);
--_size;
return pos;
return it;
}
template<typename T, std::size_t N>
constexpr const_vector<T, N>::iterator
const_vector<T, N>::erase(const_vector::const_iterator first, const_vector::const_iterator last)
{
_erase_no_move(first, last);
std::move(last + 1, end(), first);
_size -= (last - first);
auto _first = const_cast<iterator>(first);
auto _last = const_cast<iterator>(last);
if (_first == _last) return _last;
std::destroy(_first, _last);
std::move(_last, end(), _first);
_size -= std::distance(_first, _last);
return first;
return _first;
}
template<typename T, std::size_t N>