mirror of https://github.com/AxioDL/metaforce.git
rstl: Return reference to emplaced element in emplace_back()
Follows the behavior of the C++17 variant of emplace_back, which returns a reference to the emplaced element. This allows eliminating cases like: container.emplace_back(some, things, arguments); container.back().blah(); ... // subsequent modifications to the element given we can just retrieve the reference from the emplace_back call.
This commit is contained in:
parent
6a3eba0091
commit
15e856404d
|
@ -385,15 +385,18 @@ public:
|
|||
}
|
||||
|
||||
template <class... _Args>
|
||||
void emplace_back(_Args&&... args) {
|
||||
T& emplace_back(_Args&&... args) {
|
||||
#ifndef NDEBUG
|
||||
if (x0_size == N) {
|
||||
Log.report(logvisor::Fatal, fmt("emplace_back() called on full rstl::reserved_vector."));
|
||||
}
|
||||
#endif
|
||||
|
||||
::new (static_cast<void*>(std::addressof(_value(x0_size)))) T(std::forward<_Args>(args)...);
|
||||
T& element = _value(x0_size);
|
||||
::new (static_cast<void*>(std::addressof(element))) T(std::forward<_Args>(args)...);
|
||||
|
||||
++x0_size;
|
||||
return element;
|
||||
}
|
||||
|
||||
void pop_back() {
|
||||
|
|
Loading…
Reference in New Issue