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

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since f86c8e5 was f86c8e5, checked in by Aaron Moss <a3moss@…>, 4 years ago

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

  • Property mode set to 100644
File size: 956 bytes
RevLine 
[604e76d]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 ) {
[fb2ce27]9                *crnt = new node{ *next->value }; /***/
[604e76d]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.