| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ | 5 #ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| 6 #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ | 6 #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| 7 | 7 |
| 8 #include "third_party/base/numerics/safe_conversions.h" |
| 9 |
| 8 namespace pdfium { | 10 namespace pdfium { |
| 9 | 11 |
| 10 // Test to see if a set, map, hash_set or hash_map contains a particular key. | 12 // Test to see if a set, map, hash_set or hash_map contains a particular key. |
| 11 // Returns true if the key is in the collection. | 13 // Returns true if the key is in the collection. |
| 12 template <typename Collection, typename Key> | 14 template <typename Collection, typename Key> |
| 13 bool ContainsKey(const Collection& collection, const Key& key) { | 15 bool ContainsKey(const Collection& collection, const Key& key) { |
| 14 return collection.find(key) != collection.end(); | 16 return collection.find(key) != collection.end(); |
| 15 } | 17 } |
| 16 | 18 |
| 17 // Test to see if a collection like a vector contains a particular value. | 19 // Test to see if a collection like a vector contains a particular value. |
| 18 // Returns true if the value is in the collection. | 20 // Returns true if the value is in the collection. |
| 19 template <typename Collection, typename Value> | 21 template <typename Collection, typename Value> |
| 20 bool ContainsValue(const Collection& collection, const Value& value) { | 22 bool ContainsValue(const Collection& collection, const Value& value) { |
| 21 return std::find(collection.begin(), collection.end(), value) != | 23 return std::find(collection.begin(), collection.end(), value) != |
| 22 collection.end(); | 24 collection.end(); |
| 23 } | 25 } |
| 24 | 26 |
| 27 // Convenience routine for "int-fected" code, so that the stl collection |
| 28 // size_t size() method return values will be checked. |
| 29 template <typename ResultType, typename Collection> |
| 30 ResultType CollectionSize(const Collection& collection) { |
| 31 return pdfium::base::checked_cast<ResultType, size_t>(collection.size()); |
| 32 } |
| 33 |
| 25 } // namespace pdfium | 34 } // namespace pdfium |
| 26 | 35 |
| 27 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ | 36 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| OLD | NEW |