fixed emplace()

This commit is contained in:
Patrick 2024-07-29 16:53:38 +02:00
parent 0350b33087
commit 6ebec36b2d
1 changed files with 11 additions and 10 deletions

View File

@ -467,19 +467,20 @@ namespace cc {
}
template<typename T, std::size_t N>
template<class... Args>
template<typename... Args>
constexpr const_vector<T, N>::iterator const_vector<T, N>::emplace(const_vector::const_iterator pos, Args &&... args)
{
if (_size == N) throw std::exception();
if (_size == N) throw std::length_error("No space left in vector");
T obj(std::forward<Args>(args)...);
ptrdiff_t i = pos - _arr;
std::move(_arr + i, _arr + _size, _arr + i + 1);
_erase_no_move(pos);
_arr[i] = std::move(obj);
return pos;
auto it = const_cast<iterator>(pos);
if (it != end()) {
std::move_backward(it, end(), end() + 1);
}
*it = T(std::forward<Args>(args)...);
++_size;
return it;
}
template<typename T, std::size_t N>