util/StaticVector: push_back(), emplace_back() return reference

Imitating std::vector since C++17.
This commit is contained in:
Max Kellermann 2023-08-14 15:23:55 +02:00 committed by Max Kellermann
parent d5b1ca1a52
commit b2acf02af9
1 changed files with 6 additions and 6 deletions

View File

@ -191,20 +191,20 @@ public:
return Launder(array.data());
}
constexpr void push_back(const_reference value) {
emplace_back(value);
constexpr reference push_back(const_reference value) {
return emplace_back(value);
}
constexpr void push_back(T &&value) {
emplace_back(std::move(value));
constexpr reference push_back(T &&value) {
return emplace_back(std::move(value));
}
template<typename... Args>
constexpr void emplace_back(Args&&... args) {
constexpr reference emplace_back(Args&&... args) {
if (full())
throw std::bad_alloc{};
::new(&array[the_size]) T(std::forward<Args>(args)...);
++the_size;
return *Launder(&array[the_size++]);
}
};