9 #ifndef CPPCOMMON_CONTAINERS_STACK_H
10 #define CPPCOMMON_CONTAINERS_STACK_H
21 class StackConstIterator;
104 template <
typename T>
127 Stack() noexcept : _size(0), _top(
nullptr) {}
128 template <
class InputIterator>
129 Stack(InputIterator first, InputIterator last) noexcept;
138 explicit operator
bool() const noexcept {
return !
empty(); }
141 bool empty() const noexcept {
return _top ==
nullptr; }
144 size_t size() const noexcept {
return _size; }
147 T*
top() noexcept {
return _top; }
148 const T*
top() const noexcept {
return _top; }
163 void push(T& item) noexcept;
175 void clear() noexcept;
179 template <typename U>
191 template <typename T>
217 {
return it1._node == it2._node; }
219 {
return it1._node != it2._node; }
228 explicit operator
bool() const noexcept {
return _node !=
nullptr; }
232 template <
typename U>
243 template <
typename T>
265 { _node = it._node;
return *
this; }
270 {
return it1._node == it2._node; }
272 {
return it1._node != it2._node; }
281 explicit operator
bool() const noexcept {
return _node !=
nullptr; }
285 template <
typename U>
Intrusive stack constant iterator.
StackConstIterator & operator=(const StackConstIterator &it) noexcept=default
StackConstIterator & operator=(StackConstIterator &&it) noexcept=default
const value_type & const_reference
friend bool operator==(const StackConstIterator &it1, const StackConstIterator &it2) noexcept
StackConstIterator(const StackConstIterator &it) noexcept=default
const value_type * const_pointer
ptrdiff_t difference_type
StackConstIterator(const StackIterator< T > &it) noexcept
StackConstIterator(const T *node) noexcept
StackConstIterator() noexcept
StackConstIterator(StackConstIterator &&it) noexcept=default
friend void swap(StackConstIterator< U > &it1, StackConstIterator< U > &it2) noexcept
~StackConstIterator() noexcept=default
friend bool operator!=(const StackConstIterator &it1, const StackConstIterator &it2) noexcept
std::forward_iterator_tag iterator_category
Intrusive stack container.
void push(T &item) noexcept
Push a new item into the top of the stack.
Stack(const Stack &) noexcept=default
void reverse() noexcept
Reverse the stack.
ptrdiff_t difference_type
const_iterator cend() const noexcept
Stack(Stack &&) noexcept=default
T * top() noexcept
Get the top stack item.
T * pop() noexcept
Pop the item from the top of the stack.
StackIterator< T > iterator
iterator end() noexcept
Get the end stack iterator.
size_t size() const noexcept
Get the stack size.
const T * top() const noexcept
StackConstIterator< T > const_iterator
void swap(Stack &stack) noexcept
Swap two instances.
const_iterator cbegin() const noexcept
iterator begin() noexcept
Get the begin stack iterator.
void clear() noexcept
Clear the stack.
bool empty() const noexcept
Is the stack empty?
const value_type & const_reference
const value_type * const_pointer
Intrusive stack iterator.
StackIterator(T *node) noexcept
StackIterator(StackIterator &&it) noexcept=default
friend void swap(StackIterator< U > &it1, StackIterator< U > &it2) noexcept
const value_type * const_pointer
ptrdiff_t difference_type
const value_type & const_reference
~StackIterator() noexcept=default
StackIterator(const StackIterator &it) noexcept=default
friend bool operator!=(const StackIterator &it1, const StackIterator &it2) noexcept
std::forward_iterator_tag iterator_category
C++ Common project definitions.
Intrusive stack container inline implementation.
T * next
Pointer to the next stack node.