The stack is a container that supports the same set of operations as the deque, but has two key differences:
- Thanks to using a simpler stack structure to represent the chunks, the stack offers faster access to the back of the container and faster indexing operations than deque.
- Unlike deque, the stack cannot guarantee fast updates to the front of the container: each update operation performed on the front position can require at most
Chunk_capacity
items to be shifted toward to back.
The template interface of the stack constructor is the same as that of the deque constructor, except that the chunk structure is not needed.
4 namespace bootstrapped {
8 int Chunk_capacity = 512,
9 class Cache = cachedmeasure::trivial<Item, size_t>,
10 class Item_alloc = std::allocator<Item>
Example
#include <iostream>
#include <string>
#include <assert.h>
int main(
int argc,
const char * argv[]) {
mystack_type
mystack = { 0, 1, 2, 3, 4 };
std::cout << "mystack contains:";
while (! mystack.empty())
std::cout << std::endl;
return 0;
}
Output
mystack contains: 4 3 2 1 0