forked from Bananymous/banan-os
BAN: Add Queue::Emplace()
This commit is contained in:
parent
1340e26148
commit
59fa4055a6
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue