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 2b8a897 was
c87cd93,
checked in by Aaron Moss <a3moss@…>, 7 years ago
|
Final version of the benchmark code
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | #include "cpp-vstack.hpp" |
---|
2 | #include <utility> |
---|
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 | node* next = o.head; |
---|
9 | while ( next ) { |
---|
10 | *crnt = new node{ *next->value }; |
---|
11 | crnt = &(*crnt)->next; |
---|
12 | next = next->next; |
---|
13 | } |
---|
14 | *crnt = nullptr; |
---|
15 | } |
---|
16 | |
---|
17 | stack::stack() : head(nullptr) {} |
---|
18 | stack::stack(const stack& o) { copy(o); } |
---|
19 | stack::stack(stack&& o) : head(o.head) { o.head = nullptr; } |
---|
20 | stack::~stack() { clear(); } |
---|
21 | |
---|
22 | stack& stack::operator= (const stack& o) { |
---|
23 | if ( this == &o ) return *this; |
---|
24 | clear(); |
---|
25 | copy(o); |
---|
26 | return *this; |
---|
27 | } |
---|
28 | |
---|
29 | stack& stack::operator= (stack&& o) { |
---|
30 | if ( this == &o ) return *this; |
---|
31 | head = o.head; |
---|
32 | o.head = nullptr; |
---|
33 | return *this; |
---|
34 | } |
---|
35 | |
---|
36 | void stack::clear() { |
---|
37 | node* next = head; |
---|
38 | while ( next ) { |
---|
39 | node* crnt = next; |
---|
40 | next = crnt->next; |
---|
41 | delete crnt; |
---|
42 | } |
---|
43 | head = nullptr; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | bool stack::empty() const { return head == nullptr; } |
---|
48 | |
---|
49 | void stack::push(const object& value) { head = new node{ value, head }; /***/ } |
---|
50 | |
---|
51 | ptr<object> stack::pop() { |
---|
52 | node* n = head; |
---|
53 | head = n->next; |
---|
54 | ptr<object> x = std::move(n->value); |
---|
55 | delete n; |
---|
56 | return x; |
---|
57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.