BAN: Add Queue::Emplace()

This commit is contained in:
Bananymous 2023-01-17 12:02:59 +02:00
parent 1340e26148
commit 59fa4055a6
1 changed files with 12 additions and 0 deletions

View File

@ -26,6 +26,8 @@ namespace BAN
[[nodiscard]] ErrorOr<void> Push(T&&);
[[nodiscard]] ErrorOr<void> Push(const T&);
template<typename... Args>
[[nodiscard]] ErrorOr<void> Emplace(Args...);
void Pop();
void Clear();
@ -116,6 +118,16 @@ namespace BAN
return Push(Move(T(value)));
}
template<typename T>
template<typename... Args>
ErrorOr<void> Queue<T>::Emplace(Args... args)
{
TRY(EnsureCapacity(m_size + 1));
new (AddressOf(m_size)) T(Forward<Args>(args)...);
m_size++;
return {};
}
template<typename T>
void Queue<T>::Pop()
{