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<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) 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)...); auto it = const_cast<iterator>(pos);
ptrdiff_t i = pos - _arr; if (it != end()) {
std::move(_arr + i, _arr + _size, _arr + i + 1); std::move_backward(it, end(), end() + 1);
_erase_no_move(pos); }
_arr[i] = std::move(obj); *it = T(std::forward<Args>(args)...);
return pos; ++_size;
return it;
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>