source: doc/papers/general/evaluation/cpp-vstack.cpp @ b51e5fdb

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@…>, 6 years ago

Remove move-operators from C++, C++obj benchmarks for parity

  • Property mode set to 100644
File size: 956 bytes
Line 
1#include "cpp-vstack.hpp"
2#include <utility>
3
4stack::node::node( const object& v, node* n ) : value( v.new_copy() ), next( n ) {}
5
6void 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
15stack::stack() : head(nullptr) {}
16stack::stack(const stack& o) { copy(o); }
17stack::~stack() { clear(); }
18
19stack& stack::operator= (const stack& o) {
20        if ( this == &o ) return *this;
21        clear();
22        copy(o);
23        return *this;
24}
25
26void 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
36bool stack::empty() const { return head == nullptr; }
37
38void stack::push(const object& value) { head = new node{ value, head }; /***/ }
39
40ptr<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.