Add dynamic_extent constant to third_party/base/span.h
Bring into closer conformance with the spec, but more importantly
avoids a signed/unsigned mismatch in Subspan()'s default count
argument value.
Change-Id: I01fc43cac686f88b264ba9a2ce12c799bedc660d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/89010
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/third_party/base/span.h b/third_party/base/span.h
index e8b8b14..e45dcec 100644
--- a/third_party/base/span.h
+++ b/third_party/base/span.h
@@ -18,6 +18,8 @@
namespace pdfium {
+constexpr size_t dynamic_extent = static_cast<size_t>(-1);
+
template <typename T>
class span;
@@ -149,9 +151,6 @@
// static extent template parameter. Other differences are documented in
// subsections below.
//
-// Differences from [views.constants]:
-// - no dynamic_extent constant
-//
// Differences in constants and types:
// - no element_type type alias
// - no index_type type alias
@@ -230,11 +229,11 @@
return span(data_.Get() + (size_ - count), count);
}
- const span subspan(size_t pos, size_t count = -1) const {
- const auto npos = static_cast<size_t>(-1);
+ const span subspan(size_t pos, size_t count = dynamic_extent) const {
CHECK(pos <= size_);
- CHECK(count == npos || count <= size_ - pos);
- return span(data_.Get() + pos, count == npos ? size_ - pos : count);
+ CHECK(count == dynamic_extent || count <= size_ - pos);
+ return span(data_.Get() + pos,
+ count == dynamic_extent ? size_ - pos : count);
}
// [span.obs], span observers