OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // STL utility functions. Usually, these replace built-in, but slow(!), | 5 // STL utility functions. Usually, these replace built-in, but slow(!), |
6 // STL functions with more efficient versions. | 6 // STL functions with more efficient versions. |
7 | 7 |
8 #ifndef BASE_STL_UTIL_INL_H_ | 8 #ifndef BASE_STL_UTIL_INL_H_ |
9 #define BASE_STL_UTIL_INL_H_ | 9 #define BASE_STL_UTIL_INL_H_ |
10 | 10 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 440 |
441 // Translates a set into a vector. | 441 // Translates a set into a vector. |
442 template<typename T> | 442 template<typename T> |
443 std::vector<T> SetToVector(const std::set<T>& values) { | 443 std::vector<T> SetToVector(const std::set<T>& values) { |
444 std::vector<T> result; | 444 std::vector<T> result; |
445 result.reserve(values.size()); | 445 result.reserve(values.size()); |
446 result.insert(result.begin(), values.begin(), values.end()); | 446 result.insert(result.begin(), values.begin(), values.end()); |
447 return result; | 447 return result; |
448 } | 448 } |
449 | 449 |
450 // Test to see if a set, map, hash_set or hash_map contains a particular key. | |
451 // Returns true if the key is in the collection. | |
452 template <typename Collection, typename Key> | |
453 bool ContainsKey(const Collection& collection, const Key& key) { | |
454 return collection.find(key) != collection.end(); | |
455 } | |
456 | |
457 #endif // BASE_STL_UTIL_INL_H_ | 450 #endif // BASE_STL_UTIL_INL_H_ |
OLD | NEW |