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

Side by Side Diff: base/stl_util.h

Issue 2361953003: Remove stl_util's STLDeleteContainerPairSecondPointers. (Closed)
Patch Set: dependency Created 4 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
« 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Derived from google3/util/gtl/stl_util.h 5 // Derived from google3/util/gtl/stl_util.h
6 6
7 #ifndef BASE_STL_UTIL_H_ 7 #ifndef BASE_STL_UTIL_H_
8 #define BASE_STL_UTIL_H_ 8 #define BASE_STL_UTIL_H_
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 29 matching lines...) Expand all
40 // stale pointer. 40 // stale pointer.
41 template <class ForwardIterator> 41 template <class ForwardIterator>
42 void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { 42 void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) {
43 while (begin != end) { 43 while (begin != end) {
44 ForwardIterator temp = begin; 44 ForwardIterator temp = begin;
45 ++begin; 45 ++begin;
46 delete *temp; 46 delete *temp;
47 } 47 }
48 } 48 }
49 49
50 // For a range within a container of pairs, calls delete.
51 // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator.
52 // Deleting the value does not always invalidate the iterator, but it may
53 // do so if the key is a pointer into the value object.
54 template <class ForwardIterator>
55 void STLDeleteContainerPairSecondPointers(ForwardIterator begin,
56 ForwardIterator end) {
57 while (begin != end) {
58 ForwardIterator temp = begin;
59 ++begin;
60 delete temp->second;
61 }
62 }
63
64 // Counts the number of instances of val in a container. 50 // Counts the number of instances of val in a container.
65 template <typename Container, typename T> 51 template <typename Container, typename T>
66 typename std::iterator_traits< 52 typename std::iterator_traits<
67 typename Container::const_iterator>::difference_type 53 typename Container::const_iterator>::difference_type
68 STLCount(const Container& container, const T& val) { 54 STLCount(const Container& container, const T& val) {
69 return std::count(container.begin(), container.end(), val); 55 return std::count(container.begin(), container.end(), val);
70 } 56 }
71 57
72 // Return a mutable char* pointing to a string's internal buffer, 58 // Return a mutable char* pointing to a string's internal buffer,
73 // which may not be null-terminated. Writing through this pointer will 59 // which may not be null-terminated. Writing through this pointer will
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bool STLIncludes(const Arg1& a1, const Arg2& a2) { 175 bool STLIncludes(const Arg1& a1, const Arg2& a2) {
190 DCHECK(STLIsSorted(a1)); 176 DCHECK(STLIsSorted(a1));
191 DCHECK(STLIsSorted(a2)); 177 DCHECK(STLIsSorted(a2));
192 return std::includes(a1.begin(), a1.end(), 178 return std::includes(a1.begin(), a1.end(),
193 a2.begin(), a2.end()); 179 a2.begin(), a2.end());
194 } 180 }
195 181
196 } // namespace base 182 } // namespace base
197 183
198 #endif // BASE_STL_UTIL_H_ 184 #endif // BASE_STL_UTIL_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