summaryrefslogtreecommitdiff
path: root/third_party
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-14 15:53:36 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-15 00:03:38 +0000
commit193e6ca5e48ee99e620f0e7546f1407ba1a20323 (patch)
tree11d920c59a89247d28fe590d77ab6d6a9ce37a0c /third_party
parentcd5139a291113f177d3494990efbcaf388d1f3bf (diff)
downloadpdfium-193e6ca5e48ee99e620f0e7546f1407ba1a20323.tar.xz
Add IndexInBounds() convenience routine.
Avoid writing |Type| in CollectionSize<Type>() so that index type can change without rewriting conditions. Change-Id: I40c94ca39148b379908760ba9b861114b88af7bb Reviewed-on: https://pdfium-review.googlesource.com/3056 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'third_party')
-rw-r--r--third_party/base/stl_util.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h
index 795414b59f..96947f5e53 100644
--- a/third_party/base/stl_util.h
+++ b/third_party/base/stl_util.h
@@ -44,6 +44,13 @@ ResultType CollectionSize(const Collection& collection) {
return pdfium::base::checked_cast<ResultType>(collection.size());
}
+// Convenience routine for "int-fected" code, to handle signed indicies. The
+// compiler can deduce the type, making this more convenient than the above.
+template <typename IndexType, typename Collection>
+bool IndexInBounds(const Collection& collection, IndexType index) {
+ return index >= 0 && index < CollectionSize<IndexType>(collection);
+}
+
// Track the addition of an object to a set, removing it automatically when
// the ScopedSetInsertion goes out of scope.
template <typename T>