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

Side by Side Diff: base/stl_util.h

Issue 1441543002: Make vector_as_array use std::vector::data and switch a few directories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU fix Created 5 years, 1 month 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 | base/trace_event/process_memory_dump.cc » ('j') | base/win/registry.h » ('J')
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 // Counts the number of instances of val in a container. 93 // Counts the number of instances of val in a container.
94 template <typename Container, typename T> 94 template <typename Container, typename T>
95 typename std::iterator_traits< 95 typename std::iterator_traits<
96 typename Container::const_iterator>::difference_type 96 typename Container::const_iterator>::difference_type
97 STLCount(const Container& container, const T& val) { 97 STLCount(const Container& container, const T& val) {
98 return std::count(container.begin(), container.end(), val); 98 return std::count(container.begin(), container.end(), val);
99 } 99 }
100 100
101 // To treat a possibly-empty vector as an array, use these functions. 101 // Deprecated: Use v.data() instead.
danakj 2015/11/14 00:39:01 Can you just delete this in this CL?
davidben 2015/11/16 21:27:38 There's a lot more consumers. I only did a few for
102 // If you know the array will never be empty, you can use &*v.begin()
103 // directly, but that is undefined behaviour if |v| is empty.
104 template<typename T> 102 template<typename T>
105 inline T* vector_as_array(std::vector<T>* v) { 103 inline T* vector_as_array(std::vector<T>* v) {
106 return v->empty() ? NULL : &*v->begin(); 104 return v->data();
107 } 105 }
108 106
109 template<typename T> 107 template<typename T>
110 inline const T* vector_as_array(const std::vector<T>* v) { 108 inline const T* vector_as_array(const std::vector<T>* v) {
111 return v->empty() ? NULL : &*v->begin(); 109 return v->data();
112 } 110 }
113 111
114 // Return a mutable char* pointing to a string's internal buffer, 112 // Return a mutable char* pointing to a string's internal buffer,
115 // which may not be null-terminated. Writing through this pointer will 113 // which may not be null-terminated. Writing through this pointer will
116 // modify the string. 114 // modify the string.
117 // 115 //
118 // string_as_array(&str)[i] is valid for 0 <= i < str.size() until the 116 // string_as_array(&str)[i] is valid for 0 <= i < str.size() until the
119 // next call to a string method that invalidates iterators. 117 // next call to a string method that invalidates iterators.
120 // 118 //
121 // As of 2006-04, there is no standard-blessed way of getting a 119 // As of 2006-04, there is no standard-blessed way of getting a
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 bool STLIncludes(const Arg1& a1, const Arg2& a2) { 264 bool STLIncludes(const Arg1& a1, const Arg2& a2) {
267 DCHECK(STLIsSorted(a1)); 265 DCHECK(STLIsSorted(a1));
268 DCHECK(STLIsSorted(a2)); 266 DCHECK(STLIsSorted(a2));
269 return std::includes(a1.begin(), a1.end(), 267 return std::includes(a1.begin(), a1.end(),
270 a2.begin(), a2.end()); 268 a2.begin(), a2.end());
271 } 269 }
272 270
273 } // namespace base 271 } // namespace base
274 272
275 #endif // BASE_STL_UTIL_H_ 273 #endif // BASE_STL_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/process_memory_dump.cc » ('j') | base/win/registry.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698