Ignore:
Timestamp:
Apr 7, 2017, 2:32:03 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
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
Message:

Expand benchmarks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/evaluation/cpp-stack.h

    r4cfcf41 r122aecd  
    66                node* next;
    77
     8                node( T& v ) : value(v), next(nullptr) {}
    89                node( T&& v, node* n ) : value(std::move(v)), next(n) {}
    910        };
     
    1112        node* head;
    1213
     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
    1325public:
    14         stack() : head(nullptr) {}
    15 
    16         ~stack() {
     26        void clear() {
    1727                node* next = head;
    1828                while ( next ) {
     
    2131                        delete crnt;
    2232                }
     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;
    2355        }
    2456
Note: See TracChangeset for help on using the changeset viewer.