18namespace sequoia::data_structures
25 template<
class T, std::
size_t MaxDepth>
30 : m_Queue{utilities::to_array<T, MaxDepth>(l)}
31 , m_Front{l.size() ? 0 : MaxDepth}
32 , m_Back{l.size() ? l.size() - 1 : MaxDepth}
43 constexpr void push(
const T& val)
45 if constexpr(MaxDepth > 0)
47 if(size() == MaxDepth)
49 throw std::logic_error(
"Attempting to exceed maximum queue depth");
51 else if(m_Front == MaxDepth)
58 m_Back = (m_Back + 1) % MaxDepth;
61 m_Queue[m_Back] = val;
65 throw std::logic_error(
"Attempting to exceed maximum queue depth");
70 constexpr const T& back()
const noexcept
72 return m_Queue[m_Back];
76 constexpr const T& front()
const noexcept
78 return m_Queue[m_Front];
81 constexpr void pop()
noexcept
90 m_Front = (m_Front + 1) % MaxDepth;
95 constexpr bool empty()
const noexcept
97 return m_Front == MaxDepth;
101 constexpr std::size_t size()
const noexcept
107 else if(m_Front <= m_Back)
109 return m_Back + 1 - m_Front;
113 return MaxDepth + 1 - (m_Front - m_Back);
120 if constexpr(MaxDepth > 0)
122 const auto sz{lhs.size()};
123 if(sz != rhs.size())
return false;
125 for(std::size_t i{}, l{lhs.m_Front}, r{rhs.m_Front}; i<sz; ++i)
128 if(lhs.m_Queue[l] != rhs.m_Queue[r])
return false;
130 l = (l+1) % MaxDepth;
131 r = (r+1) % MaxDepth;
142 std::array<T, MaxDepth> m_Queue{};
144 std::size_t m_Front{MaxDepth}, m_Back{MaxDepth};
A collection of constexpr algorithms.
Utility to convert an initializer_list into an array, potentially transforming the initializer_list i...
A queue suitable for constexpr contexts.
Definition: StaticQueue.hpp:27