20 #ifndef PSTORE_CORE_ARRAY_STACK_HPP 21 #define PSTORE_CORE_ARRAY_STACK_HPP 38 template <
class Ty, std::
size_t Size>
41 using container_type = std::array<Ty, Size>;
42 using value_type =
typename container_type::value_type;
43 using reference =
typename container_type::reference;
44 using const_reference =
typename container_type::const_reference;
45 using size_type =
typename container_type::size_type;
50 return elements_ == other.elements_ && std::equal (
begin (),
end (), other.
begin ());
52 bool operator!= (
array_stack const & other)
const {
return !operator== (other); }
55 typename container_type::const_iterator
begin ()
const {
return std::begin (c_); }
57 typename container_type::const_iterator
end ()
const {
return std::begin (c_) + elements_; }
63 constexpr
bool empty () const noexcept {
return elements_ == 0; }
66 constexpr size_type
size () const noexcept {
return elements_; }
70 constexpr
size_t max_size () const noexcept {
return Size; }
78 reference
top () noexcept {
79 PSTORE_ASSERT (elements_ > 0);
80 return c_[elements_ - 1];
83 const_reference
top () const noexcept {
84 PSTORE_ASSERT (elements_ > 0);
85 return c_[elements_ - 1];
93 void push (value_type
const & value) {
94 PSTORE_ASSERT (elements_ < Size);
95 c_[elements_++] = value;
99 void push (value_type && value) {
100 PSTORE_ASSERT (elements_ < Size);
101 c_[elements_++] = std::move (value);
106 PSTORE_ASSERT (elements_ > 0);
115 std::size_t elements_{0};
119 #endif // PSTORE_CORE_ARRAY_STACK_HPP void pop()
Remove the top element from the stack.
Definition: array_stack.hpp:105
const_reference top() const noexcept
Acceses the top element.
Definition: array_stack.hpp:83
constexpr size_type size() const noexcept
Returns the number of elements stored on the stack.
Definition: array_stack.hpp:66
container_type::const_iterator begin() const
Returns an iterator pointing to the first element in the stack.
Definition: array_stack.hpp:55
A simple wrapper for std::array which provides the functionality of a stack, specifically a FILO (fir...
Definition: array_stack.hpp:39
Definition: nonpod2.cpp:40
constexpr size_t max_size() const noexcept
Returns the maximum number of elements that the stack is able to hold.
Definition: array_stack.hpp:70
An implementation of the standard assert() macro with the exception that it will, on failure...
constexpr bool empty() const noexcept
Checks whether the stack is empty.
Definition: array_stack.hpp:63
void push(value_type const &value)
Inserts an element at the top of the container.
Definition: array_stack.hpp:93
container_type::const_iterator end() const
Returns an iterator pointing to the past-the-end element in the array container.
Definition: array_stack.hpp:57
reference top() noexcept
Acceses the top element.
Definition: array_stack.hpp:78
void push(value_type &&value)
Inserts an element at the top of the container.
Definition: array_stack.hpp:99