mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
[absl] Use std::min in constexpr contexts in absl::string_view
* [As of C++14, `std::min` is defined `constexpr`](https://en.cppreference.com/w/cpp/algorithm/min), so we don't need to roll our own version * Since [C++14 is Abseil's minimum supported C++ version](https://abseil.io/docs/cpp/quickstart-cmake.html#prerequisites), that makes this sufficient PiperOrigin-RevId: 729563815 Change-Id: I80f0d7c352a880818c60642f296f9f06e1f62500
This commit is contained in:
committed by
Copybara-Service
parent
8ce0c88d6a
commit
398e24a0b1
@@ -398,7 +398,7 @@ class ABSL_ATTRIBUTE_VIEW string_view {
|
||||
if (ABSL_PREDICT_FALSE(pos > length_)) {
|
||||
base_internal::ThrowStdOutOfRange("absl::string_view::substr");
|
||||
}
|
||||
return string_view(ptr_ + pos, Min(n, length_ - pos));
|
||||
return string_view(ptr_ + pos, (std::min)(n, length_ - pos));
|
||||
}
|
||||
|
||||
// string_view::compare()
|
||||
@@ -409,10 +409,10 @@ class ABSL_ATTRIBUTE_VIEW string_view {
|
||||
// is greater than `x`.
|
||||
constexpr int compare(string_view x) const noexcept {
|
||||
return CompareImpl(length_, x.length_,
|
||||
Min(length_, x.length_) == 0
|
||||
(std::min)(length_, x.length_) == 0
|
||||
? 0
|
||||
: ABSL_INTERNAL_STRING_VIEW_MEMCMP(
|
||||
ptr_, x.ptr_, Min(length_, x.length_)));
|
||||
ptr_, x.ptr_, (std::min)(length_, x.length_)));
|
||||
}
|
||||
|
||||
// Overload of `string_view::compare()` for comparing a substring of the
|
||||
@@ -689,10 +689,6 @@ class ABSL_ATTRIBUTE_VIEW string_view {
|
||||
#endif
|
||||
}
|
||||
|
||||
static constexpr size_t Min(size_type length_a, size_type length_b) {
|
||||
return length_a < length_b ? length_a : length_b;
|
||||
}
|
||||
|
||||
static constexpr int CompareImpl(size_type length_a, size_type length_b,
|
||||
int compare_result) {
|
||||
return compare_result == 0 ? static_cast<int>(length_a > length_b) -
|
||||
|
||||
Reference in New Issue
Block a user