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 c87cd93 was
c87cd93,
checked in by Aaron Moss <a3moss@…>, 6 years ago
|
Final version of the benchmark code
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[b276be5] | 1 | #include "cpp-vstack.hpp" |
---|
| 2 | #include <utility> |
---|
| 3 | |
---|
[c87cd93] | 4 | stack::node::node( const object& v, node* n ) : value( v.new_copy() ), next( n ) {} |
---|
[b276be5] | 5 | |
---|
| 6 | void stack::copy(const stack& o) { |
---|
| 7 | node** crnt = &head; |
---|
| 8 | node* next = o.head; |
---|
| 9 | while ( next ) { |
---|
| 10 | *crnt = new node{ *next->value }; |
---|
| 11 | crnt = &(*crnt)->next; |
---|
| 12 | next = next->next; |
---|
| 13 | } |
---|
| 14 | *crnt = nullptr; |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | stack::stack() : head(nullptr) {} |
---|
| 18 | stack::stack(const stack& o) { copy(o); } |
---|
| 19 | stack::stack(stack&& o) : head(o.head) { o.head = nullptr; } |
---|
| 20 | stack::~stack() { clear(); } |
---|
| 21 | |
---|
| 22 | stack& stack::operator= (const stack& o) { |
---|
| 23 | if ( this == &o ) return *this; |
---|
| 24 | clear(); |
---|
| 25 | copy(o); |
---|
| 26 | return *this; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | stack& stack::operator= (stack&& o) { |
---|
| 30 | if ( this == &o ) return *this; |
---|
| 31 | head = o.head; |
---|
| 32 | o.head = nullptr; |
---|
| 33 | return *this; |
---|
| 34 | } |
---|
| 35 | |
---|
[a381b46] | 36 | void stack::clear() { |
---|
| 37 | node* next = head; |
---|
| 38 | while ( next ) { |
---|
| 39 | node* crnt = next; |
---|
| 40 | next = crnt->next; |
---|
| 41 | delete crnt; |
---|
| 42 | } |
---|
| 43 | head = nullptr; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
[79b8dc3] | 47 | bool stack::empty() const { return head == nullptr; } |
---|
[b276be5] | 48 | |
---|
[c87cd93] | 49 | void stack::push(const object& value) { head = new node{ value, head }; /***/ } |
---|
[b276be5] | 50 | |
---|
[79b8dc3] | 51 | ptr<object> stack::pop() { |
---|
[b276be5] | 52 | node* n = head; |
---|
| 53 | head = n->next; |
---|
[79b8dc3] | 54 | ptr<object> x = std::move(n->value); |
---|
[b276be5] | 55 | delete n; |
---|
| 56 | return x; |
---|
| 57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.