Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: base/linked_list.h

Issue 10933014: clang: Remove an ancient workaround. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_LINKED_LIST_H_ 5 #ifndef BASE_LINKED_LIST_H_
6 #define BASE_LINKED_LIST_H_ 6 #define BASE_LINKED_LIST_H_
7 7
8 // Simple LinkedList type. (See the Q&A section to understand how this 8 // Simple LinkedList type. (See the Q&A section to understand how this
9 // differs from std::list). 9 // differs from std::list).
10 // 10 //
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 // Cast from the node-type to the value type. 119 // Cast from the node-type to the value type.
120 const T* value() const { 120 const T* value() const {
121 return static_cast<const T*>(this); 121 return static_cast<const T*>(this);
122 } 122 }
123 123
124 T* value() { 124 T* value() {
125 return static_cast<T*>(this); 125 return static_cast<T*>(this);
126 } 126 }
127 127
128 // Work around a Clang bug reported upstream:
129 // http://llvm.org/bugs/show_bug.cgi?id=7974
130 // TODO(evanm): remove this and its sole caller.
131 void set(LinkNode<T>* prev, LinkNode<T>* next) {
132 previous_ = prev; next_ = next;
133 }
134
135 private: 128 private:
136 LinkNode<T>* previous_; 129 LinkNode<T>* previous_;
137 LinkNode<T>* next_; 130 LinkNode<T>* next_;
138 }; 131 };
139 132
140 template <typename T> 133 template <typename T>
141 class LinkedList { 134 class LinkedList {
142 public: 135 public:
143 // The "root" node is self-referential, and forms the basis of a circular 136 // The "root" node is self-referential, and forms the basis of a circular
144 // list (root_.next() will point back to the start of the list, 137 // list (root_.next() will point back to the start of the list,
145 // and root_->previous() wraps around to the end of the list). 138 // and root_->previous() wraps around to the end of the list).
146 LinkedList() { root_.set(&root_, &root_); } 139 LinkedList() : root_(&root_, &root_) {}
147 140
148 // Appends |e| to the end of the linked list. 141 // Appends |e| to the end of the linked list.
149 void Append(LinkNode<T>* e) { 142 void Append(LinkNode<T>* e) {
150 e->InsertBefore(&root_); 143 e->InsertBefore(&root_);
151 } 144 }
152 145
153 LinkNode<T>* head() const { 146 LinkNode<T>* head() const {
154 return root_.next(); 147 return root_.next();
155 } 148 }
156 149
157 LinkNode<T>* tail() const { 150 LinkNode<T>* tail() const {
158 return root_.previous(); 151 return root_.previous();
159 } 152 }
160 153
161 const LinkNode<T>* end() const { 154 const LinkNode<T>* end() const {
162 return &root_; 155 return &root_;
163 } 156 }
164 157
165 private: 158 private:
166 LinkNode<T> root_; 159 LinkNode<T> root_;
167 }; 160 };
168 161
169 } // namespace base 162 } // namespace base
170 163
171 #endif // BASE_LINKED_LIST_H_ 164 #endif // BASE_LINKED_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698