- Timestamp:
- Mar 10, 2024, 11:21:18 AM (4 months ago)
- Branches:
- master
- Children:
- 9398177
- Parents:
- b64d0f4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction.hpp
rb64d0f4 r5546f50b 100 100 template<typename El> 101 101 class list { 102 103 104 105 106 107 102 struct node { 103 LIST_ENTRY(node) links; 104 El elem; 105 }; 106 LIST_HEAD(Impl, node); 107 Impl impl; 108 108 public: 109 110 111 112 113 114 115 116 117 109 list() { 110 LIST_INIT(&impl); 111 } 112 void push_front( const El & src ) { 113 node * n = new node(); 114 n->elem = src; 115 LIST_INSERT_HEAD(&impl, n, links); 116 } 117 // ... `emplace` elided 118 118 119 119 … … 129 129 130 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 131 template<typename... CtorArgs> 132 void emplace_front( CtorArgs... args ) { 133 El tempEl{args...}; // (mock: avoid real emplacing to keep `struct node` simple; disucssion is about allocation, not copying) 134 push_front(tempEl); 135 } 136 class IType { 137 node* p; 138 public: 139 IType(node* p) : p(p) {} 140 bool operator!=(IType rhs) {return p != rhs.p;} 141 const El& operator*() {return p->elem;} 142 void operator++() { p = LIST_NEXT(p, links); } 143 }; 144 IType begin() {return IType(LIST_FIRST(&impl)); } 145 IType end() {return IType(NULL); } 146 146 147 147
Note: See TracChangeset
for help on using the changeset viewer.