From 193e6ca5e48ee99e620f0e7546f1407ba1a20323 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 14 Mar 2017 15:53:36 -0700 Subject: Add IndexInBounds() convenience routine. Avoid writing |Type| in CollectionSize() so that index type can change without rewriting conditions. Change-Id: I40c94ca39148b379908760ba9b861114b88af7bb Reviewed-on: https://pdfium-review.googlesource.com/3056 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- third_party/base/stl_util.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'third_party') 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(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 +bool IndexInBounds(const Collection& collection, IndexType index) { + return index >= 0 && index < CollectionSize(collection); +} + // Track the addition of an object to a set, removing it automatically when // the ScopedSetInsertion goes out of scope. template -- cgit v1.2.3