|
Celeritas 0.7+972e6cd
|
Stack "view" that keeps the top element in a local scalar. More...
#include <IdStack.hh>
Public Types | |
| using | value_type = T |
| using | size_type = S |
Public Member Functions | |
| IdStack (Span< T, Extent > storage) | |
| Construct with underlying spill storage. | |
| void | push (T element) |
| Push an element onto the top of the stack. | |
| void | pop () |
| Remove the top element. | |
| T | top () const |
| Get the top element. | |
| bool | empty () const |
| Whether there are any elements in the container. | |
| size_type | size () const |
| Get the number of elements. | |
| constexpr size_type | capacity () const |
| Get the number of elements that can fit in the allocated storage. | |
Static Public Attributes | |
| static constexpr std::size_t | spill_extent = Extent |
| Capacity (may be dynamic) | |
Stack "view" that keeps the top element in a local scalar.
| T | value type |
| E | extent for spill (dynamic or fixed) |
This particular stack requires OpaqueId as its element type, because the default value must evaluate to "false" and is never a valid stack value. Without this restriction it would need an extra boolean in addition to the top item.
The most recently pushed value is always stored in top_. Older values are spilled into the underlying storage. This increases the effective stack capacity by one: for storage size N, the stack capacity is N + 1. The internal size_ tracks only the number of spilled elements in underlying storage. The logical size reported by size() is therefore size_ + !this->empty().