1 module appbase.utils.container.stack;
2 
3 import std.container.dlist;
4 
5 struct Stack(T)
6 {
7     @property bool empty() const
8     {
9         return _data.empty();
10     }
11 
12     @property ref T front()
13     {
14         return _data.front();
15     }
16 
17     @property ref T back()
18     {
19         return _data.back();
20     }
21 
22     @property size_t length()
23     {
24         return _size;
25     }
26 
27     void push(T value)
28     {
29         _data.insertBack(value);
30         _size++;
31     }
32 
33     T pop()
34     {
35         assert(!_data.empty(), "Stack is empty.");
36 
37         T value = _data.back();
38         _data.removeBack();
39         _size--;
40 
41         return value;
42     }
43 
44     void clear()
45     {
46         _data.clear();
47         _size = 0;
48     }
49 
50     @property ref auto range()
51     {
52         return _data[];
53     }
54 
55 private:
56 
57     DList!T _data;
58     size_t  _size = 0;
59 }