aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 33e22da was
a381b46,
checked in by Aaron Moss <a3moss@…>, 6 years ago
|
Minor cleanup, also filled in benchmark source appendix
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | #include "cpp-vstack.hpp" |
---|
2 | #include <utility> |
---|
3 | |
---|
4 | stack::node::node( const object& v ) : value( v.new_copy() ), next( nullptr ) {} |
---|
5 | stack::node::node( ptr<object>&& v, node* n ) : value( std::move(v) ), next( n ) {} |
---|
6 | |
---|
7 | void stack::copy(const stack& o) { |
---|
8 | node** crnt = &head; |
---|
9 | node* next = o.head; |
---|
10 | while ( next ) { |
---|
11 | *crnt = new node{ *next->value }; |
---|
12 | crnt = &(*crnt)->next; |
---|
13 | next = next->next; |
---|
14 | } |
---|
15 | *crnt = nullptr; |
---|
16 | } |
---|
17 | |
---|
18 | stack::stack() : head(nullptr) {} |
---|
19 | stack::stack(const stack& o) { copy(o); } |
---|
20 | stack::stack(stack&& o) : head(o.head) { o.head = nullptr; } |
---|
21 | stack::~stack() { clear(); } |
---|
22 | |
---|
23 | stack& stack::operator= (const stack& o) { |
---|
24 | if ( this == &o ) return *this; |
---|
25 | clear(); |
---|
26 | copy(o); |
---|
27 | return *this; |
---|
28 | } |
---|
29 | |
---|
30 | stack& stack::operator= (stack&& o) { |
---|
31 | if ( this == &o ) return *this; |
---|
32 | head = o.head; |
---|
33 | o.head = nullptr; |
---|
34 | return *this; |
---|
35 | } |
---|
36 | |
---|
37 | void stack::clear() { |
---|
38 | node* next = head; |
---|
39 | while ( next ) { |
---|
40 | node* crnt = next; |
---|
41 | next = crnt->next; |
---|
42 | delete crnt; |
---|
43 | } |
---|
44 | head = nullptr; |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | bool stack::empty() const { return head == nullptr; } |
---|
49 | |
---|
50 | void stack::push(ptr<object>&& value) { head = new node{ std::move(value), head }; /***/ } |
---|
51 | |
---|
52 | ptr<object> stack::pop() { |
---|
53 | node* n = head; |
---|
54 | head = n->next; |
---|
55 | ptr<object> x = std::move(n->value); |
---|
56 | delete n; |
---|
57 | return x; |
---|
58 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.