util/StaticVector: push_back(), emplace_back() return reference
Imitating std::vector since C++17.
This commit is contained in:
parent
d5b1ca1a52
commit
b2acf02af9
|
@ -191,20 +191,20 @@ public:
|
||||||
return Launder(array.data());
|
return Launder(array.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void push_back(const_reference value) {
|
constexpr reference push_back(const_reference value) {
|
||||||
emplace_back(value);
|
return emplace_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void push_back(T &&value) {
|
constexpr reference push_back(T &&value) {
|
||||||
emplace_back(std::move(value));
|
return emplace_back(std::move(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
constexpr void emplace_back(Args&&... args) {
|
constexpr reference emplace_back(Args&&... args) {
|
||||||
if (full())
|
if (full())
|
||||||
throw std::bad_alloc{};
|
throw std::bad_alloc{};
|
||||||
|
|
||||||
::new(&array[the_size]) T(std::forward<Args>(args)...);
|
::new(&array[the_size]) T(std::forward<Args>(args)...);
|
||||||
++the_size;
|
return *Launder(&array[the_size++]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue