Changeset 32cab5b for doc/papers/general/evaluation/cpp-vstack.cpp
- Timestamp:
- Apr 17, 2018, 12:01:09 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 3265399
- Parents:
- b2fe1c9 (diff), 81bb114 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/cpp-vstack.cpp
rb2fe1c9 r32cab5b 2 2 #include <utility> 3 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 ) { 9 *crnt = new node{ *next->value }; 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(stack&& o) : head(o.head) { o.head = nullptr; } 18 stack::~stack() { clear(); } 19 20 stack& stack::operator= (const stack& o) { 21 if ( this == &o ) return *this; 22 clear(); 23 copy(o); 24 return *this; 25 } 26 27 stack& stack::operator= (stack&& o) { 28 if ( this == &o ) return *this; 29 head = o.head; 30 o.head = nullptr; 31 return *this; 32 } 4 stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {} 33 5 34 6 void stack::clear() { 35 for ( node* next = head; next; ) {36 node * crnt = next;7 for ( node * next = head; next; ) { 8 node * crnt = next; 37 9 next = crnt->next; 38 10 delete crnt; … … 41 13 } 42 14 15 void stack::copy( const stack & o ) { 16 node ** crnt = &head; 17 for ( node * next = o.head; next; next = next->next ) { 18 *crnt = new node{ *next->value }; /***/ 19 crnt = &(*crnt)->next; 20 } 21 *crnt = nullptr; 22 } 23 24 stack::stack() : head( nullptr ) {} 25 stack::stack( const stack & o ) { copy( o ); } 26 stack::~stack() { clear(); } 27 28 stack & stack::operator=( const stack & o ) { 29 if ( this == &o ) return *this; 30 clear(); 31 copy( o ); 32 return *this; 33 } 43 34 44 35 bool stack::empty() const { return head == nullptr; } 45 36 46 void stack::push( const object& value) { head = new node{ value, head }; /***/ }37 void stack::push( const object & value ) { head = new node{ value, head }; /***/ } 47 38 48 39 ptr<object> stack::pop() { 49 node * n = head;40 node * n = head; 50 41 head = n->next; 51 ptr<object> x = std::move(n->value);42 ptr<object> v = std::move( n->value ); 52 43 delete n; 53 return x;44 return v; 54 45 }
Note:
See TracChangeset
for help on using the changeset viewer.