fixed emplace()
This commit is contained in:
parent
0350b33087
commit
6ebec36b2d
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue