OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| 6 #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 namespace pdfium { |
| 11 |
| 12 // To treat a possibly-empty vector as an array, use these functions. |
| 13 // If you know the array will never be empty, you can use &*v.begin() |
| 14 // directly, but that is undefined behaviour if |v| is empty. |
| 15 template <typename T> |
| 16 inline T* vector_as_array(std::vector<T>* v) { |
| 17 return v->empty() ? nullptr : &*v->begin(); |
| 18 } |
| 19 |
| 20 template <typename T> |
| 21 inline const T* vector_as_array(const std::vector<T>* v) { |
| 22 return v->empty() ? nullptr : &*v->begin(); |
| 23 } |
| 24 |
| 25 } // namespace pdfium |
| 26 |
| 27 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
OLD | NEW |