diff --git a/include/const_vector.hpp b/include/const_vector.hpp index 3fecbcb..94b6f90 100644 --- a/include/const_vector.hpp +++ b/include/const_vector.hpp @@ -467,19 +467,20 @@ namespace cc { } template - template + template constexpr const_vector::iterator const_vector::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)...); - - 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(pos); + + if (it != end()) { + std::move_backward(it, end(), end() + 1); + } + *it = T(std::forward(args)...); + + ++_size; + return it; } template