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