Skip to content

Commit

Permalink
Make c_find_first_of's options parameter a const reference to all…
Browse files Browse the repository at this point in the history
…ow temporaries.

`c_find_first_of` does not keep or return references into `options` so there's no reason to require an l-value there.

PiperOrigin-RevId: 690696332
Change-Id: Ibbabb69ba72e9506c0406f2124034a944d6899d6
  • Loading branch information
Abseil Team authored and copybara-github committed Oct 28, 2024
1 parent 07fff76 commit fa58881
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions absl/algorithm/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20
template <typename C1, typename C2>
ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20
container_algorithm_internal::ContainerIter<C1>
c_find_first_of(C1& container, C2& options) {
c_find_first_of(C1& container, const C2& options) {
return std::find_first_of(container_algorithm_internal::c_begin(container),
container_algorithm_internal::c_end(container),
container_algorithm_internal::c_begin(options),
Expand All @@ -302,7 +302,7 @@ ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20
template <typename C1, typename C2, typename BinaryPredicate>
ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20
container_algorithm_internal::ContainerIter<C1>
c_find_first_of(C1& container, C2& options, BinaryPredicate&& pred) {
c_find_first_of(C1& container, const C2& options, BinaryPredicate&& pred) {
return std::find_first_of(container_algorithm_internal::c_begin(container),
container_algorithm_internal::c_end(container),
container_algorithm_internal::c_begin(options),
Expand Down
2 changes: 2 additions & 0 deletions absl/algorithm/container_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ TEST_F(NonMutatingTest, FindEndWithPredicate) {
TEST_F(NonMutatingTest, FindFirstOf) {
absl::c_find_first_of(container_, sequence_);
absl::c_find_first_of(sequence_, container_);
absl::c_find_first_of(sequence_, std::array<int, 2>{1, 2});
}

TEST_F(NonMutatingTest, FindFirstOfWithPredicate) {
absl::c_find_first_of(container_, sequence_, BinPredicate);
absl::c_find_first_of(sequence_, container_, BinPredicate);
absl::c_find_first_of(sequence_, std::array<int, 2>{1, 2}, BinPredicate);
}

TEST_F(NonMutatingTest, AdjacentFind) { absl::c_adjacent_find(sequence_); }
Expand Down

0 comments on commit fa58881

Please sign in to comment.