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 <string> | 11 #include <string> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 // Clears internal memory of an STL object. | 14 // Clears internal memory of an STL object. |
14 // STL clear()/reserve(0) does not always free internal memory allocated | 15 // STL clear()/reserve(0) does not always free internal memory allocated |
15 // This function uses swap/destructor to ensure the internal memory is freed. | 16 // This function uses swap/destructor to ensure the internal memory is freed. |
16 template<class T> | 17 template<class T> |
17 void STLClearObject(T* obj) { | 18 void STLClearObject(T* obj) { |
18 T tmp; | 19 T tmp; |
19 tmp.swap(*obj); | 20 tmp.swap(*obj); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 private: | 184 private: |
184 T* container_; | 185 T* container_; |
185 }; | 186 }; |
186 | 187 |
187 // Test to see if a set, map, hash_set or hash_map contains a particular key. | 188 // Test to see if a set, map, hash_set or hash_map contains a particular key. |
188 // Returns true if the key is in the collection. | 189 // Returns true if the key is in the collection. |
189 template <typename Collection, typename Key> | 190 template <typename Collection, typename Key> |
190 bool ContainsKey(const Collection& collection, const Key& key) { | 191 bool ContainsKey(const Collection& collection, const Key& key) { |
191 return collection.find(key) != collection.end(); | 192 return collection.find(key) != collection.end(); |
192 } | 193 } |
193 | 194 |
willchan no longer on Chromium
2012/12/01 17:22:13
New code should go into the base namespace. I know
tfarina
2012/12/01 17:24:19
I tried to do this incrementally, but you wanted m
willchan no longer on Chromium
2012/12/01 17:38:45
If I'm being inconsistent, that's bad. Are you sur
not at google - send to devlin
2012/12/03 20:22:01
I'll put this in base.
| |
195 // Returns a new std::set containing the difference of two sets. | |
willchan no longer on Chromium
2012/12/01 17:22:13
It does not necessarily return a new std::set. Ple
| |
196 // A convenient wrapper around std::set_difference. | |
197 template <typename ResultType, typename Arg1, typename Arg2> | |
198 ResultType STLSetDifference(const Arg1& a1, const Arg2& a2) { | |
199 ResultType difference; | |
200 std::set_difference(a1.begin(), a1.end(), | |
willchan no longer on Chromium
2012/12/01 17:22:13
Jeffrey alluded to it earlier, but the part that w
not at google - send to devlin
2012/12/03 20:22:01
Discussing this with willchan a bit, and it's a bi
Jeffrey Yasskin
2012/12/03 20:29:35
template<typename Container>
bool is_sorted(const
not at google - send to devlin
2012/12/03 20:39:10
Dunno, I don't have stl in my veins. But cool, I c
| |
201 a2.begin(), a2.end(), | |
202 std::inserter(difference, difference.end())); | |
203 return difference; | |
204 } | |
205 | |
194 #endif // BASE_STL_UTIL_H_ | 206 #endif // BASE_STL_UTIL_H_ |
OLD | NEW |