OLD | NEW |
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 Loading... |
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 // Deprecated: Use v.data() instead. | |
102 template<typename T> | |
103 inline T* vector_as_array(std::vector<T>* v) { | |
104 return v->data(); | |
105 } | |
106 | |
107 template<typename T> | |
108 inline const T* vector_as_array(const std::vector<T>* v) { | |
109 return v->data(); | |
110 } | |
111 | |
112 // Return a mutable char* pointing to a string's internal buffer, | 101 // Return a mutable char* pointing to a string's internal buffer, |
113 // which may not be null-terminated. Writing through this pointer will | 102 // which may not be null-terminated. Writing through this pointer will |
114 // modify the string. | 103 // modify the string. |
115 // | 104 // |
116 // string_as_array(&str)[i] is valid for 0 <= i < str.size() until the | 105 // string_as_array(&str)[i] is valid for 0 <= i < str.size() until the |
117 // next call to a string method that invalidates iterators. | 106 // next call to a string method that invalidates iterators. |
118 // | 107 // |
119 // As of 2006-04, there is no standard-blessed way of getting a | 108 // As of 2006-04, there is no standard-blessed way of getting a |
120 // mutable reference to a string's internal buffer. However, issue 530 | 109 // mutable reference to a string's internal buffer. However, issue 530 |
121 // (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) | 110 // (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 bool STLIncludes(const Arg1& a1, const Arg2& a2) { | 253 bool STLIncludes(const Arg1& a1, const Arg2& a2) { |
265 DCHECK(STLIsSorted(a1)); | 254 DCHECK(STLIsSorted(a1)); |
266 DCHECK(STLIsSorted(a2)); | 255 DCHECK(STLIsSorted(a2)); |
267 return std::includes(a1.begin(), a1.end(), | 256 return std::includes(a1.begin(), a1.end(), |
268 a2.begin(), a2.end()); | 257 a2.begin(), a2.end()); |
269 } | 258 } |
270 | 259 |
271 } // namespace base | 260 } // namespace base |
272 | 261 |
273 #endif // BASE_STL_UTIL_H_ | 262 #endif // BASE_STL_UTIL_H_ |
OLD | NEW |