Changeset 122aecd for doc/generic_types/evaluation/cpp-stack.h
- Timestamp:
- Apr 7, 2017, 2:32:03 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, resolv-new, with_gc
- Children:
- 3a48e283
- Parents:
- 4cfcf41
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/evaluation/cpp-stack.h
r4cfcf41 r122aecd 6 6 node* next; 7 7 8 node( T& v ) : value(v), next(nullptr) {} 8 9 node( T&& v, node* n ) : value(std::move(v)), next(n) {} 9 10 }; … … 11 12 node* head; 12 13 14 void copy(const stack<T>& o) { 15 node** crnt = &head; 16 node* next = o.head; 17 while ( next ) { 18 *crnt = new node{ next->value }; 19 crnt = &(*crnt)->next; 20 next = next->next; 21 } 22 *crnt = nullptr; 23 } 24 13 25 public: 14 stack() : head(nullptr) {} 15 16 ~stack() { 26 void clear() { 17 27 node* next = head; 18 28 while ( next ) { … … 21 31 delete crnt; 22 32 } 33 } 34 35 stack() : head(nullptr) {} 36 37 stack(const stack<T>& o) { copy(o); } 38 39 stack(stack<T>&& o) : head(o.head) { o.head = nullptr; } 40 41 ~stack() { clear(); } 42 43 stack& operator= (const stack<T>& o) { 44 if ( this == &o ) return *this; 45 clear(); 46 copy(o); 47 return *this;if ( this == &o ) return *this; 48 } 49 50 stack& operator= (stack<T>&& o) { 51 if ( this == &o ) return *this; 52 head = o.head; 53 o.head = nullptr; 54 return *this; 23 55 } 24 56
Note: See TracChangeset
for help on using the changeset viewer.