source: doc/generic_types/evaluation/cpp-stack.h@ 309be81

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new stuck-waitfor-destruct with_gc
Last change on this file since 309be81 was 309be81, checked in by Aaron Moss <a3moss@…>, 9 years ago

Started evaluation benchmarks for paper (CFA version doesn't compile yet)

  • Property mode set to 100644
File size: 563 bytes
Line 
1#include <utility>
2
3template<typename T> class stack {
4 struct node {
5 T value;
6 node* next;
7
8 node( T&& v, node* n ) : value(std::move(v)), next(n) {}
9 };
10
11 node* head;
12
13public:
14 stack() : head(nullptr) {}
15
16 ~stack() {
17 node* next = head;
18 while ( next ) {
19 node* crnt = next;
20 next = crnt->next;
21 delete crnt;
22 }
23 }
24
25 bool empty() const {
26 return head == nullptr;
27 }
28
29 void push(T&& value) {
30 head = new node{ std::move(value), head };
31 }
32
33 T pop() {
34 node* n = head;
35 head = n->next;
36 T x = std::move(n->value);
37 delete n;
38 return x;
39 }
40};
Note: See TracBrowser for help on using the repository browser.