Skip to content

Commit 398e24a

Browse files
lwolfsonkincopybara-github
authored andcommitted
[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
1 parent 8ce0c88 commit 398e24a

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

absl/strings/string_view.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class ABSL_ATTRIBUTE_VIEW string_view {
398398
if (ABSL_PREDICT_FALSE(pos > length_)) {
399399
base_internal::ThrowStdOutOfRange("absl::string_view::substr");
400400
}
401-
return string_view(ptr_ + pos, Min(n, length_ - pos));
401+
return string_view(ptr_ + pos, (std::min)(n, length_ - pos));
402402
}
403403

404404
// string_view::compare()
@@ -409,10 +409,10 @@ class ABSL_ATTRIBUTE_VIEW string_view {
409409
// is greater than `x`.
410410
constexpr int compare(string_view x) const noexcept {
411411
return CompareImpl(length_, x.length_,
412-
Min(length_, x.length_) == 0
412+
(std::min)(length_, x.length_) == 0
413413
? 0
414414
: ABSL_INTERNAL_STRING_VIEW_MEMCMP(
415-
ptr_, x.ptr_, Min(length_, x.length_)));
415+
ptr_, x.ptr_, (std::min)(length_, x.length_)));
416416
}
417417

418418
// Overload of `string_view::compare()` for comparing a substring of the
@@ -689,10 +689,6 @@ class ABSL_ATTRIBUTE_VIEW string_view {
689689
#endif
690690
}
691691

692-
static constexpr size_t Min(size_type length_a, size_type length_b) {
693-
return length_a < length_b ? length_a : length_b;
694-
}
695-
696692
static constexpr int CompareImpl(size_type length_a, size_type length_b,
697693
int compare_result) {
698694
return compare_result == 0 ? static_cast<int>(length_a > length_b) -

0 commit comments

Comments
 (0)