ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since b51e5fdb was
f86c8e5,
checked in by Aaron Moss <a3moss@…>, 7 years ago
|
Remove move-operators from C++, C++obj benchmarks for parity
|
-
Property mode set to
100644
|
File size:
956 bytes
|
Rev | Line | |
---|
[604e76d] | 1 | #include "cpp-vstack.hpp" |
---|
| 2 | #include <utility> |
---|
| 3 | |
---|
| 4 | stack::node::node( const object& v, node* n ) : value( v.new_copy() ), next( n ) {} |
---|
| 5 | |
---|
| 6 | void stack::copy(const stack& o) { |
---|
| 7 | node** crnt = &head; |
---|
| 8 | for ( node* next = o.head; next; next = next->next ) { |
---|
[fb2ce27] | 9 | *crnt = new node{ *next->value }; /***/ |
---|
[604e76d] | 10 | crnt = &(*crnt)->next; |
---|
| 11 | } |
---|
| 12 | *crnt = nullptr; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | stack::stack() : head(nullptr) {} |
---|
| 16 | stack::stack(const stack& o) { copy(o); } |
---|
| 17 | stack::~stack() { clear(); } |
---|
| 18 | |
---|
| 19 | stack& stack::operator= (const stack& o) { |
---|
| 20 | if ( this == &o ) return *this; |
---|
| 21 | clear(); |
---|
| 22 | copy(o); |
---|
| 23 | return *this; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | void stack::clear() { |
---|
| 27 | for ( node* next = head; next; ) { |
---|
| 28 | node* crnt = next; |
---|
| 29 | next = crnt->next; |
---|
| 30 | delete crnt; |
---|
| 31 | } |
---|
| 32 | head = nullptr; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | bool stack::empty() const { return head == nullptr; } |
---|
| 37 | |
---|
| 38 | void stack::push(const object& value) { head = new node{ value, head }; /***/ } |
---|
| 39 | |
---|
| 40 | ptr<object> stack::pop() { |
---|
| 41 | node* n = head; |
---|
| 42 | head = n->next; |
---|
| 43 | ptr<object> x = std::move(n->value); |
---|
| 44 | delete n; |
---|
| 45 | return x; |
---|
| 46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.