abseil-cpp/absl/algorithm/container_test.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/algorithm/container.h"
16 
17 #include <functional>
18 #include <initializer_list>
19 #include <iterator>
20 #include <list>
21 #include <memory>
22 #include <ostream>
23 #include <random>
24 #include <set>
25 #include <unordered_set>
26 #include <utility>
27 #include <valarray>
28 #include <vector>
29 
30 #include "gmock/gmock.h"
31 #include "gtest/gtest.h"
32 #include "absl/base/casts.h"
33 #include "absl/base/macros.h"
34 #include "absl/memory/memory.h"
35 #include "absl/types/span.h"
36 
37 namespace {
38 
47 
48 // Most of these tests just check that the code compiles, not that it
49 // does the right thing. That's fine since the functions just forward
50 // to the STL implementation.
51 class NonMutatingTest : public testing::Test {
52  protected:
53  std::unordered_set<int> container_ = {1, 2, 3};
54  std::list<int> sequence_ = {1, 2, 3};
55  std::vector<int> vector_ = {1, 2, 3};
56  int array_[3] = {1, 2, 3};
57 };
58 
59 struct AccumulateCalls {
60  void operator()(int value) { calls.push_back(value); }
61  std::vector<int> calls;
62 };
63 
64 bool Predicate(int value) { return value < 3; }
65 bool BinPredicate(int v1, int v2) { return v1 < v2; }
66 bool Equals(int v1, int v2) { return v1 == v2; }
67 bool IsOdd(int x) { return x % 2 != 0; }
68 
69 TEST_F(NonMutatingTest, Distance) {
70  EXPECT_EQ(container_.size(), absl::c_distance(container_));
71  EXPECT_EQ(sequence_.size(), absl::c_distance(sequence_));
72  EXPECT_EQ(vector_.size(), absl::c_distance(vector_));
73  EXPECT_EQ(ABSL_ARRAYSIZE(array_), absl::c_distance(array_));
74 
75  // Works with a temporary argument.
76  EXPECT_EQ(vector_.size(), absl::c_distance(std::vector<int>(vector_)));
77 }
78 
79 TEST_F(NonMutatingTest, Distance_OverloadedBeginEnd) {
80  // Works with classes which have custom ADL-selected overloads of std::begin
81  // and std::end.
82  std::initializer_list<int> a = {1, 2, 3};
83  std::valarray<int> b = {1, 2, 3};
86 
87  // It is assumed that other c_* functions use the same mechanism for
88  // ADL-selecting begin/end overloads.
89 }
90 
91 TEST_F(NonMutatingTest, ForEach) {
92  AccumulateCalls c = absl::c_for_each(container_, AccumulateCalls());
93  // Don't rely on the unordered_set's order.
94  std::sort(c.calls.begin(), c.calls.end());
95  EXPECT_EQ(vector_, c.calls);
96 
97  // Works with temporary container, too.
98  AccumulateCalls c2 =
99  absl::c_for_each(std::unordered_set<int>(container_), AccumulateCalls());
100  std::sort(c2.calls.begin(), c2.calls.end());
101  EXPECT_EQ(vector_, c2.calls);
102 }
103 
104 TEST_F(NonMutatingTest, FindReturnsCorrectType) {
105  auto it = absl::c_find(container_, 3);
106  EXPECT_EQ(3, *it);
107  absl::c_find(absl::implicit_cast<const std::list<int>&>(sequence_), 3);
108 }
109 
110 TEST_F(NonMutatingTest, FindIf) { absl::c_find_if(container_, Predicate); }
111 
112 TEST_F(NonMutatingTest, FindIfNot) {
113  absl::c_find_if_not(container_, Predicate);
114 }
115 
116 TEST_F(NonMutatingTest, FindEnd) {
117  absl::c_find_end(sequence_, vector_);
118  absl::c_find_end(vector_, sequence_);
119 }
120 
121 TEST_F(NonMutatingTest, FindEndWithPredicate) {
122  absl::c_find_end(sequence_, vector_, BinPredicate);
123  absl::c_find_end(vector_, sequence_, BinPredicate);
124 }
125 
126 TEST_F(NonMutatingTest, FindFirstOf) {
127  absl::c_find_first_of(container_, sequence_);
128  absl::c_find_first_of(sequence_, container_);
129 }
130 
131 TEST_F(NonMutatingTest, FindFirstOfWithPredicate) {
132  absl::c_find_first_of(container_, sequence_, BinPredicate);
133  absl::c_find_first_of(sequence_, container_, BinPredicate);
134 }
135 
136 TEST_F(NonMutatingTest, AdjacentFind) { absl::c_adjacent_find(sequence_); }
137 
138 TEST_F(NonMutatingTest, AdjacentFindWithPredicate) {
139  absl::c_adjacent_find(sequence_, BinPredicate);
140 }
141 
142 TEST_F(NonMutatingTest, Count) { EXPECT_EQ(1, absl::c_count(container_, 3)); }
143 
144 TEST_F(NonMutatingTest, CountIf) {
145  EXPECT_EQ(2, absl::c_count_if(container_, Predicate));
146  const std::unordered_set<int>& const_container = container_;
147  EXPECT_EQ(2, absl::c_count_if(const_container, Predicate));
148 }
149 
150 TEST_F(NonMutatingTest, Mismatch) {
151  // Testing necessary as absl::c_mismatch executes logic.
152  {
153  auto result = absl::c_mismatch(vector_, sequence_);
154  EXPECT_EQ(result.first, vector_.end());
155  EXPECT_EQ(result.second, sequence_.end());
156  }
157  {
158  auto result = absl::c_mismatch(sequence_, vector_);
159  EXPECT_EQ(result.first, sequence_.end());
160  EXPECT_EQ(result.second, vector_.end());
161  }
162 
163  sequence_.back() = 5;
164  {
165  auto result = absl::c_mismatch(vector_, sequence_);
166  EXPECT_EQ(result.first, std::prev(vector_.end()));
167  EXPECT_EQ(result.second, std::prev(sequence_.end()));
168  }
169  {
170  auto result = absl::c_mismatch(sequence_, vector_);
171  EXPECT_EQ(result.first, std::prev(sequence_.end()));
172  EXPECT_EQ(result.second, std::prev(vector_.end()));
173  }
174 
175  sequence_.pop_back();
176  {
177  auto result = absl::c_mismatch(vector_, sequence_);
178  EXPECT_EQ(result.first, std::prev(vector_.end()));
179  EXPECT_EQ(result.second, sequence_.end());
180  }
181  {
182  auto result = absl::c_mismatch(sequence_, vector_);
183  EXPECT_EQ(result.first, sequence_.end());
184  EXPECT_EQ(result.second, std::prev(vector_.end()));
185  }
186  {
187  struct NoNotEquals {
188  constexpr bool operator==(NoNotEquals) const { return true; }
189  constexpr bool operator!=(NoNotEquals) const = delete;
190  };
191  std::vector<NoNotEquals> first;
192  std::list<NoNotEquals> second;
193 
194  // Check this still compiles.
196  }
197 }
198 
199 TEST_F(NonMutatingTest, MismatchWithPredicate) {
200  // Testing necessary as absl::c_mismatch executes logic.
201  {
202  auto result = absl::c_mismatch(vector_, sequence_, BinPredicate);
203  EXPECT_EQ(result.first, vector_.begin());
204  EXPECT_EQ(result.second, sequence_.begin());
205  }
206  {
207  auto result = absl::c_mismatch(sequence_, vector_, BinPredicate);
208  EXPECT_EQ(result.first, sequence_.begin());
209  EXPECT_EQ(result.second, vector_.begin());
210  }
211 
212  sequence_.front() = 0;
213  {
214  auto result = absl::c_mismatch(vector_, sequence_, BinPredicate);
215  EXPECT_EQ(result.first, vector_.begin());
216  EXPECT_EQ(result.second, sequence_.begin());
217  }
218  {
219  auto result = absl::c_mismatch(sequence_, vector_, BinPredicate);
220  EXPECT_EQ(result.first, std::next(sequence_.begin()));
221  EXPECT_EQ(result.second, std::next(vector_.begin()));
222  }
223 
224  sequence_.clear();
225  {
226  auto result = absl::c_mismatch(vector_, sequence_, BinPredicate);
227  EXPECT_EQ(result.first, vector_.begin());
228  EXPECT_EQ(result.second, sequence_.end());
229  }
230  {
231  auto result = absl::c_mismatch(sequence_, vector_, BinPredicate);
232  EXPECT_EQ(result.first, sequence_.end());
233  EXPECT_EQ(result.second, vector_.begin());
234  }
235 }
236 
237 TEST_F(NonMutatingTest, Equal) {
238  EXPECT_TRUE(absl::c_equal(vector_, sequence_));
239  EXPECT_TRUE(absl::c_equal(sequence_, vector_));
240  EXPECT_TRUE(absl::c_equal(sequence_, array_));
241  EXPECT_TRUE(absl::c_equal(array_, vector_));
242 
243  // Test that behavior appropriately differs from that of equal().
244  std::vector<int> vector_plus = {1, 2, 3};
245  vector_plus.push_back(4);
246  EXPECT_FALSE(absl::c_equal(vector_plus, sequence_));
247  EXPECT_FALSE(absl::c_equal(sequence_, vector_plus));
248  EXPECT_FALSE(absl::c_equal(array_, vector_plus));
249 }
250 
251 TEST_F(NonMutatingTest, EqualWithPredicate) {
252  EXPECT_TRUE(absl::c_equal(vector_, sequence_, Equals));
253  EXPECT_TRUE(absl::c_equal(sequence_, vector_, Equals));
254  EXPECT_TRUE(absl::c_equal(array_, sequence_, Equals));
255  EXPECT_TRUE(absl::c_equal(vector_, array_, Equals));
256 
257  // Test that behavior appropriately differs from that of equal().
258  std::vector<int> vector_plus = {1, 2, 3};
259  vector_plus.push_back(4);
260  EXPECT_FALSE(absl::c_equal(vector_plus, sequence_, Equals));
261  EXPECT_FALSE(absl::c_equal(sequence_, vector_plus, Equals));
262  EXPECT_FALSE(absl::c_equal(vector_plus, array_, Equals));
263 }
264 
265 TEST_F(NonMutatingTest, IsPermutation) {
266  auto vector_permut_ = vector_;
267  std::next_permutation(vector_permut_.begin(), vector_permut_.end());
268  EXPECT_TRUE(absl::c_is_permutation(vector_permut_, sequence_));
269  EXPECT_TRUE(absl::c_is_permutation(sequence_, vector_permut_));
270 
271  // Test that behavior appropriately differs from that of is_permutation().
272  std::vector<int> vector_plus = {1, 2, 3};
273  vector_plus.push_back(4);
274  EXPECT_FALSE(absl::c_is_permutation(vector_plus, sequence_));
275  EXPECT_FALSE(absl::c_is_permutation(sequence_, vector_plus));
276 }
277 
278 TEST_F(NonMutatingTest, IsPermutationWithPredicate) {
279  auto vector_permut_ = vector_;
280  std::next_permutation(vector_permut_.begin(), vector_permut_.end());
281  EXPECT_TRUE(absl::c_is_permutation(vector_permut_, sequence_, Equals));
282  EXPECT_TRUE(absl::c_is_permutation(sequence_, vector_permut_, Equals));
283 
284  // Test that behavior appropriately differs from that of is_permutation().
285  std::vector<int> vector_plus = {1, 2, 3};
286  vector_plus.push_back(4);
287  EXPECT_FALSE(absl::c_is_permutation(vector_plus, sequence_, Equals));
288  EXPECT_FALSE(absl::c_is_permutation(sequence_, vector_plus, Equals));
289 }
290 
291 TEST_F(NonMutatingTest, Search) {
292  absl::c_search(sequence_, vector_);
293  absl::c_search(vector_, sequence_);
294  absl::c_search(array_, sequence_);
295 }
296 
297 TEST_F(NonMutatingTest, SearchWithPredicate) {
298  absl::c_search(sequence_, vector_, BinPredicate);
299  absl::c_search(vector_, sequence_, BinPredicate);
300 }
301 
302 TEST_F(NonMutatingTest, SearchN) { absl::c_search_n(sequence_, 3, 1); }
303 
304 TEST_F(NonMutatingTest, SearchNWithPredicate) {
305  absl::c_search_n(sequence_, 3, 1, BinPredicate);
306 }
307 
308 TEST_F(NonMutatingTest, LowerBound) {
310  ASSERT_TRUE(i != sequence_.end());
311  EXPECT_EQ(2, std::distance(sequence_.begin(), i));
312  EXPECT_EQ(3, *i);
313 }
314 
315 TEST_F(NonMutatingTest, LowerBoundWithPredicate) {
316  std::vector<int> v(vector_);
317  std::sort(v.begin(), v.end(), std::greater<int>());
318  std::vector<int>::iterator i = absl::c_lower_bound(v, 3, std::greater<int>());
319  EXPECT_TRUE(i == v.begin());
320  EXPECT_EQ(3, *i);
321 }
322 
323 TEST_F(NonMutatingTest, UpperBound) {
325  ASSERT_TRUE(i != sequence_.end());
326  EXPECT_EQ(1, std::distance(sequence_.begin(), i));
327  EXPECT_EQ(2, *i);
328 }
329 
330 TEST_F(NonMutatingTest, UpperBoundWithPredicate) {
331  std::vector<int> v(vector_);
332  std::sort(v.begin(), v.end(), std::greater<int>());
333  std::vector<int>::iterator i = absl::c_upper_bound(v, 1, std::greater<int>());
334  EXPECT_EQ(3, i - v.begin());
335  EXPECT_TRUE(i == v.end());
336 }
337 
338 TEST_F(NonMutatingTest, EqualRange) {
340  absl::c_equal_range(sequence_, 2);
341  EXPECT_EQ(1, std::distance(sequence_.begin(), p.first));
342  EXPECT_EQ(2, std::distance(sequence_.begin(), p.second));
343 }
344 
345 TEST_F(NonMutatingTest, EqualRangeArray) {
346  auto p = absl::c_equal_range(array_, 2);
347  EXPECT_EQ(1, std::distance(std::begin(array_), p.first));
348  EXPECT_EQ(2, std::distance(std::begin(array_), p.second));
349 }
350 
351 TEST_F(NonMutatingTest, EqualRangeWithPredicate) {
352  std::vector<int> v(vector_);
353  std::sort(v.begin(), v.end(), std::greater<int>());
355  absl::c_equal_range(v, 2, std::greater<int>());
356  EXPECT_EQ(1, std::distance(v.begin(), p.first));
357  EXPECT_EQ(2, std::distance(v.begin(), p.second));
358 }
359 
360 TEST_F(NonMutatingTest, BinarySearch) {
361  EXPECT_TRUE(absl::c_binary_search(vector_, 2));
362  EXPECT_TRUE(absl::c_binary_search(std::vector<int>(vector_), 2));
363 }
364 
365 TEST_F(NonMutatingTest, BinarySearchWithPredicate) {
366  std::vector<int> v(vector_);
367  std::sort(v.begin(), v.end(), std::greater<int>());
368  EXPECT_TRUE(absl::c_binary_search(v, 2, std::greater<int>()));
369  EXPECT_TRUE(
370  absl::c_binary_search(std::vector<int>(v), 2, std::greater<int>()));
371 }
372 
373 TEST_F(NonMutatingTest, MinElement) {
375  ASSERT_TRUE(i != sequence_.end());
376  EXPECT_EQ(*i, 1);
377 }
378 
379 TEST_F(NonMutatingTest, MinElementWithPredicate) {
381  absl::c_min_element(sequence_, std::greater<int>());
382  ASSERT_TRUE(i != sequence_.end());
383  EXPECT_EQ(*i, 3);
384 }
385 
386 TEST_F(NonMutatingTest, MaxElement) {
388  ASSERT_TRUE(i != sequence_.end());
389  EXPECT_EQ(*i, 3);
390 }
391 
392 TEST_F(NonMutatingTest, MaxElementWithPredicate) {
394  absl::c_max_element(sequence_, std::greater<int>());
395  ASSERT_TRUE(i != sequence_.end());
396  EXPECT_EQ(*i, 1);
397 }
398 
399 TEST_F(NonMutatingTest, LexicographicalCompare) {
400  EXPECT_FALSE(absl::c_lexicographical_compare(sequence_, sequence_));
401 
402  std::vector<int> v;
403  v.push_back(1);
404  v.push_back(2);
405  v.push_back(4);
406 
408  EXPECT_TRUE(absl::c_lexicographical_compare(std::list<int>(sequence_), v));
409 }
410 
411 TEST_F(NonMutatingTest, LexicographicalCopmareWithPredicate) {
412  EXPECT_FALSE(absl::c_lexicographical_compare(sequence_, sequence_,
413  std::greater<int>()));
414 
415  std::vector<int> v;
416  v.push_back(1);
417  v.push_back(2);
418  v.push_back(4);
419 
420  EXPECT_TRUE(
421  absl::c_lexicographical_compare(v, sequence_, std::greater<int>()));
423  std::vector<int>(v), std::list<int>(sequence_), std::greater<int>()));
424 }
425 
426 TEST_F(NonMutatingTest, Includes) {
427  std::set<int> s(vector_.begin(), vector_.end());
428  s.insert(4);
429  EXPECT_TRUE(absl::c_includes(s, vector_));
430 }
431 
432 TEST_F(NonMutatingTest, IncludesWithPredicate) {
433  std::vector<int> v = {3, 2, 1};
434  std::set<int, std::greater<int>> s(v.begin(), v.end());
435  s.insert(4);
436  EXPECT_TRUE(absl::c_includes(s, v, std::greater<int>()));
437 }
438 
439 class NumericMutatingTest : public testing::Test {
440  protected:
441  std::list<int> list_ = {1, 2, 3};
442  std::vector<int> output_;
443 };
444 
445 TEST_F(NumericMutatingTest, Iota) {
446  absl::c_iota(list_, 5);
447  std::list<int> expected{5, 6, 7};
448  EXPECT_EQ(list_, expected);
449 }
450 
451 TEST_F(NonMutatingTest, Accumulate) {
452  EXPECT_EQ(absl::c_accumulate(sequence_, 4), 1 + 2 + 3 + 4);
453 }
454 
455 TEST_F(NonMutatingTest, AccumulateWithBinaryOp) {
456  EXPECT_EQ(absl::c_accumulate(sequence_, 4, std::multiplies<int>()),
457  1 * 2 * 3 * 4);
458 }
459 
460 TEST_F(NonMutatingTest, AccumulateLvalueInit) {
461  int lvalue = 4;
462  EXPECT_EQ(absl::c_accumulate(sequence_, lvalue), 1 + 2 + 3 + 4);
463 }
464 
465 TEST_F(NonMutatingTest, AccumulateWithBinaryOpLvalueInit) {
466  int lvalue = 4;
467  EXPECT_EQ(absl::c_accumulate(sequence_, lvalue, std::multiplies<int>()),
468  1 * 2 * 3 * 4);
469 }
470 
471 TEST_F(NonMutatingTest, InnerProduct) {
472  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, 1000),
473  1000 + 1 * 1 + 2 * 2 + 3 * 3);
474 }
475 
476 TEST_F(NonMutatingTest, InnerProductWithBinaryOps) {
477  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, 10,
478  std::multiplies<int>(), std::plus<int>()),
479  10 * (1 + 1) * (2 + 2) * (3 + 3));
480 }
481 
482 TEST_F(NonMutatingTest, InnerProductLvalueInit) {
483  int lvalue = 1000;
484  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, lvalue),
485  1000 + 1 * 1 + 2 * 2 + 3 * 3);
486 }
487 
488 TEST_F(NonMutatingTest, InnerProductWithBinaryOpsLvalueInit) {
489  int lvalue = 10;
490  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, lvalue,
491  std::multiplies<int>(), std::plus<int>()),
492  10 * (1 + 1) * (2 + 2) * (3 + 3));
493 }
494 
495 TEST_F(NumericMutatingTest, AdjacentDifference) {
496  auto last = absl::c_adjacent_difference(list_, std::back_inserter(output_));
497  *last = 1000;
498  std::vector<int> expected{1, 2 - 1, 3 - 2, 1000};
499  EXPECT_EQ(output_, expected);
500 }
501 
502 TEST_F(NumericMutatingTest, AdjacentDifferenceWithBinaryOp) {
503  auto last = absl::c_adjacent_difference(list_, std::back_inserter(output_),
504  std::multiplies<int>());
505  *last = 1000;
506  std::vector<int> expected{1, 2 * 1, 3 * 2, 1000};
507  EXPECT_EQ(output_, expected);
508 }
509 
510 TEST_F(NumericMutatingTest, PartialSum) {
511  auto last = absl::c_partial_sum(list_, std::back_inserter(output_));
512  *last = 1000;
513  std::vector<int> expected{1, 1 + 2, 1 + 2 + 3, 1000};
514  EXPECT_EQ(output_, expected);
515 }
516 
517 TEST_F(NumericMutatingTest, PartialSumWithBinaryOp) {
518  auto last = absl::c_partial_sum(list_, std::back_inserter(output_),
519  std::multiplies<int>());
520  *last = 1000;
521  std::vector<int> expected{1, 1 * 2, 1 * 2 * 3, 1000};
522  EXPECT_EQ(output_, expected);
523 }
524 
525 TEST_F(NonMutatingTest, LinearSearch) {
526  EXPECT_TRUE(absl::c_linear_search(container_, 3));
527  EXPECT_FALSE(absl::c_linear_search(container_, 4));
528 }
529 
530 TEST_F(NonMutatingTest, AllOf) {
531  const std::vector<int>& v = vector_;
532  EXPECT_FALSE(absl::c_all_of(v, [](int x) { return x > 1; }));
533  EXPECT_TRUE(absl::c_all_of(v, [](int x) { return x > 0; }));
534 }
535 
536 TEST_F(NonMutatingTest, AnyOf) {
537  const std::vector<int>& v = vector_;
538  EXPECT_TRUE(absl::c_any_of(v, [](int x) { return x > 2; }));
539  EXPECT_FALSE(absl::c_any_of(v, [](int x) { return x > 5; }));
540 }
541 
542 TEST_F(NonMutatingTest, NoneOf) {
543  const std::vector<int>& v = vector_;
544  EXPECT_FALSE(absl::c_none_of(v, [](int x) { return x > 2; }));
545  EXPECT_TRUE(absl::c_none_of(v, [](int x) { return x > 5; }));
546 }
547 
548 TEST_F(NonMutatingTest, MinMaxElementLess) {
549  std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
550  p = absl::c_minmax_element(vector_, std::less<int>());
551  EXPECT_TRUE(p.first == vector_.begin());
552  EXPECT_TRUE(p.second == vector_.begin() + 2);
553 }
554 
555 TEST_F(NonMutatingTest, MinMaxElementGreater) {
556  std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
557  p = absl::c_minmax_element(vector_, std::greater<int>());
558  EXPECT_TRUE(p.first == vector_.begin() + 2);
559  EXPECT_TRUE(p.second == vector_.begin());
560 }
561 
562 TEST_F(NonMutatingTest, MinMaxElementNoPredicate) {
563  std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
564  p = absl::c_minmax_element(vector_);
565  EXPECT_TRUE(p.first == vector_.begin());
566  EXPECT_TRUE(p.second == vector_.begin() + 2);
567 }
568 
569 class SortingTest : public testing::Test {
570  protected:
571  std::list<int> sorted_ = {1, 2, 3, 4};
572  std::list<int> unsorted_ = {2, 4, 1, 3};
573  std::list<int> reversed_ = {4, 3, 2, 1};
574 };
575 
576 TEST_F(SortingTest, IsSorted) {
577  EXPECT_TRUE(absl::c_is_sorted(sorted_));
578  EXPECT_FALSE(absl::c_is_sorted(unsorted_));
579  EXPECT_FALSE(absl::c_is_sorted(reversed_));
580 }
581 
582 TEST_F(SortingTest, IsSortedWithPredicate) {
583  EXPECT_FALSE(absl::c_is_sorted(sorted_, std::greater<int>()));
584  EXPECT_FALSE(absl::c_is_sorted(unsorted_, std::greater<int>()));
585  EXPECT_TRUE(absl::c_is_sorted(reversed_, std::greater<int>()));
586 }
587 
588 TEST_F(SortingTest, IsSortedUntil) {
589  EXPECT_EQ(1, *absl::c_is_sorted_until(unsorted_));
590  EXPECT_EQ(4, *absl::c_is_sorted_until(unsorted_, std::greater<int>()));
591 }
592 
593 TEST_F(SortingTest, NthElement) {
594  std::vector<int> unsorted = {2, 4, 1, 3};
595  absl::c_nth_element(unsorted, unsorted.begin() + 2);
596  EXPECT_THAT(unsorted, ElementsAre(Lt(3), Lt(3), 3, Gt(3)));
597  absl::c_nth_element(unsorted, unsorted.begin() + 2, std::greater<int>());
598  EXPECT_THAT(unsorted, ElementsAre(Gt(2), Gt(2), 2, Lt(2)));
599 }
600 
601 TEST(MutatingTest, IsPartitioned) {
602  EXPECT_TRUE(
603  absl::c_is_partitioned(std::vector<int>{1, 3, 5, 2, 4, 6}, IsOdd));
604  EXPECT_FALSE(
605  absl::c_is_partitioned(std::vector<int>{1, 2, 3, 4, 5, 6}, IsOdd));
606  EXPECT_FALSE(
607  absl::c_is_partitioned(std::vector<int>{2, 4, 6, 1, 3, 5}, IsOdd));
608 }
609 
610 TEST(MutatingTest, Partition) {
611  std::vector<int> actual = {1, 2, 3, 4, 5};
612  absl::c_partition(actual, IsOdd);
613  EXPECT_THAT(actual, Truly([](const std::vector<int>& c) {
614  return absl::c_is_partitioned(c, IsOdd);
615  }));
616 }
617 
618 TEST(MutatingTest, StablePartition) {
619  std::vector<int> actual = {1, 2, 3, 4, 5};
620  absl::c_stable_partition(actual, IsOdd);
621  EXPECT_THAT(actual, ElementsAre(1, 3, 5, 2, 4));
622 }
623 
624 TEST(MutatingTest, PartitionCopy) {
625  const std::vector<int> initial = {1, 2, 3, 4, 5};
626  std::vector<int> odds, evens;
627  auto ends = absl::c_partition_copy(initial, back_inserter(odds),
628  back_inserter(evens), IsOdd);
629  *ends.first = 7;
630  *ends.second = 6;
631  EXPECT_THAT(odds, ElementsAre(1, 3, 5, 7));
632  EXPECT_THAT(evens, ElementsAre(2, 4, 6));
633 }
634 
635 TEST(MutatingTest, PartitionPoint) {
636  const std::vector<int> initial = {1, 3, 5, 2, 4};
637  auto middle = absl::c_partition_point(initial, IsOdd);
638  EXPECT_EQ(2, *middle);
639 }
640 
641 TEST(MutatingTest, CopyMiddle) {
642  const std::vector<int> initial = {4, -1, -2, -3, 5};
643  const std::list<int> input = {1, 2, 3};
644  const std::vector<int> expected = {4, 1, 2, 3, 5};
645 
646  std::list<int> test_list(initial.begin(), initial.end());
647  absl::c_copy(input, ++test_list.begin());
648  EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
649 
650  std::vector<int> test_vector = initial;
651  absl::c_copy(input, test_vector.begin() + 1);
652  EXPECT_EQ(expected, test_vector);
653 }
654 
655 TEST(MutatingTest, CopyFrontInserter) {
656  const std::list<int> initial = {4, 5};
657  const std::list<int> input = {1, 2, 3};
658  const std::list<int> expected = {3, 2, 1, 4, 5};
659 
660  std::list<int> test_list = initial;
661  absl::c_copy(input, std::front_inserter(test_list));
662  EXPECT_EQ(expected, test_list);
663 }
664 
665 TEST(MutatingTest, CopyBackInserter) {
666  const std::vector<int> initial = {4, 5};
667  const std::list<int> input = {1, 2, 3};
668  const std::vector<int> expected = {4, 5, 1, 2, 3};
669 
670  std::list<int> test_list(initial.begin(), initial.end());
671  absl::c_copy(input, std::back_inserter(test_list));
672  EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
673 
674  std::vector<int> test_vector = initial;
675  absl::c_copy(input, std::back_inserter(test_vector));
676  EXPECT_EQ(expected, test_vector);
677 }
678 
679 TEST(MutatingTest, CopyN) {
680  const std::vector<int> initial = {1, 2, 3, 4, 5};
681  const std::vector<int> expected = {1, 2};
682  std::vector<int> actual;
683  absl::c_copy_n(initial, 2, back_inserter(actual));
684  EXPECT_EQ(expected, actual);
685 }
686 
687 TEST(MutatingTest, CopyIf) {
688  const std::list<int> input = {1, 2, 3};
689  std::vector<int> output;
690  absl::c_copy_if(input, std::back_inserter(output),
691  [](int i) { return i != 2; });
693 }
694 
695 TEST(MutatingTest, CopyBackward) {
696  std::vector<int> actual = {1, 2, 3, 4, 5};
697  std::vector<int> expected = {1, 2, 1, 2, 3};
698  absl::c_copy_backward(absl::MakeSpan(actual.data(), 3), actual.end());
699  EXPECT_EQ(expected, actual);
700 }
701 
702 TEST(MutatingTest, Move) {
703  std::vector<std::unique_ptr<int>> src;
704  src.emplace_back(absl::make_unique<int>(1));
705  src.emplace_back(absl::make_unique<int>(2));
706  src.emplace_back(absl::make_unique<int>(3));
707  src.emplace_back(absl::make_unique<int>(4));
708  src.emplace_back(absl::make_unique<int>(5));
709 
710  std::vector<std::unique_ptr<int>> dest = {};
711  absl::c_move(src, std::back_inserter(dest));
712  EXPECT_THAT(src, Each(IsNull()));
714  Pointee(5)));
715 }
716 
717 TEST(MutatingTest, MoveBackward) {
718  std::vector<std::unique_ptr<int>> actual;
719  actual.emplace_back(absl::make_unique<int>(1));
720  actual.emplace_back(absl::make_unique<int>(2));
721  actual.emplace_back(absl::make_unique<int>(3));
722  actual.emplace_back(absl::make_unique<int>(4));
723  actual.emplace_back(absl::make_unique<int>(5));
724  auto subrange = absl::MakeSpan(actual.data(), 3);
725  absl::c_move_backward(subrange, actual.end());
726  EXPECT_THAT(actual, ElementsAre(IsNull(), IsNull(), Pointee(1), Pointee(2),
727  Pointee(3)));
728 }
729 
730 TEST(MutatingTest, MoveWithRvalue) {
731  auto MakeRValueSrc = [] {
732  std::vector<std::unique_ptr<int>> src;
733  src.emplace_back(absl::make_unique<int>(1));
734  src.emplace_back(absl::make_unique<int>(2));
735  src.emplace_back(absl::make_unique<int>(3));
736  return src;
737  };
738 
739  std::vector<std::unique_ptr<int>> dest = MakeRValueSrc();
740  absl::c_move(MakeRValueSrc(), std::back_inserter(dest));
742  Pointee(2), Pointee(3)));
743 }
744 
745 TEST(MutatingTest, SwapRanges) {
746  std::vector<int> odds = {2, 4, 6};
747  std::vector<int> evens = {1, 3, 5};
748  absl::c_swap_ranges(odds, evens);
749  EXPECT_THAT(odds, ElementsAre(1, 3, 5));
750  EXPECT_THAT(evens, ElementsAre(2, 4, 6));
751 
752  odds.pop_back();
753  absl::c_swap_ranges(odds, evens);
754  EXPECT_THAT(odds, ElementsAre(2, 4));
755  EXPECT_THAT(evens, ElementsAre(1, 3, 6));
756 
757  absl::c_swap_ranges(evens, odds);
758  EXPECT_THAT(odds, ElementsAre(1, 3));
759  EXPECT_THAT(evens, ElementsAre(2, 4, 6));
760 }
761 
762 TEST_F(NonMutatingTest, Transform) {
763  std::vector<int> x{0, 2, 4}, y, z;
764  auto end = absl::c_transform(x, back_inserter(y), std::negate<int>());
765  EXPECT_EQ(std::vector<int>({0, -2, -4}), y);
766  *end = 7;
767  EXPECT_EQ(std::vector<int>({0, -2, -4, 7}), y);
768 
769  y = {1, 3, 0};
770  end = absl::c_transform(x, y, back_inserter(z), std::plus<int>());
771  EXPECT_EQ(std::vector<int>({1, 5, 4}), z);
772  *end = 7;
773  EXPECT_EQ(std::vector<int>({1, 5, 4, 7}), z);
774 
775  z.clear();
776  y.pop_back();
777  end = absl::c_transform(x, y, std::back_inserter(z), std::plus<int>());
778  EXPECT_EQ(std::vector<int>({1, 5}), z);
779  *end = 7;
780  EXPECT_EQ(std::vector<int>({1, 5, 7}), z);
781 
782  z.clear();
783  std::swap(x, y);
784  end = absl::c_transform(x, y, std::back_inserter(z), std::plus<int>());
785  EXPECT_EQ(std::vector<int>({1, 5}), z);
786  *end = 7;
787  EXPECT_EQ(std::vector<int>({1, 5, 7}), z);
788 }
789 
790 TEST(MutatingTest, Replace) {
791  const std::vector<int> initial = {1, 2, 3, 1, 4, 5};
792  const std::vector<int> expected = {4, 2, 3, 4, 4, 5};
793 
794  std::vector<int> test_vector = initial;
796  EXPECT_EQ(expected, test_vector);
797 
798  std::list<int> test_list(initial.begin(), initial.end());
799  absl::c_replace(test_list, 1, 4);
800  EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
801 }
802 
803 TEST(MutatingTest, ReplaceIf) {
804  std::vector<int> actual = {1, 2, 3, 4, 5};
805  const std::vector<int> expected = {0, 2, 0, 4, 0};
806 
807  absl::c_replace_if(actual, IsOdd, 0);
808  EXPECT_EQ(expected, actual);
809 }
810 
811 TEST(MutatingTest, ReplaceCopy) {
812  const std::vector<int> initial = {1, 2, 3, 1, 4, 5};
813  const std::vector<int> expected = {4, 2, 3, 4, 4, 5};
814 
815  std::vector<int> actual;
816  absl::c_replace_copy(initial, back_inserter(actual), 1, 4);
817  EXPECT_EQ(expected, actual);
818 }
819 
820 TEST(MutatingTest, Sort) {
821  std::vector<int> test_vector = {2, 3, 1, 4};
823  EXPECT_THAT(test_vector, ElementsAre(1, 2, 3, 4));
824 }
825 
826 TEST(MutatingTest, SortWithPredicate) {
827  std::vector<int> test_vector = {2, 3, 1, 4};
828  absl::c_sort(test_vector, std::greater<int>());
829  EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1));
830 }
831 
832 // For absl::c_stable_sort tests. Needs an operator< that does not cover all
833 // fields so that the test can check the sort preserves order of equal elements.
834 struct Element {
835  int key;
836  int value;
837  friend bool operator<(const Element& e1, const Element& e2) {
838  return e1.key < e2.key;
839  }
840  // Make gmock print useful diagnostics.
841  friend std::ostream& operator<<(std::ostream& o, const Element& e) {
842  return o << "{" << e.key << ", " << e.value << "}";
843  }
844 };
845 
846 MATCHER_P2(IsElement, key, value, "") {
847  return arg.key == key && arg.value == value;
848 }
849 
850 TEST(MutatingTest, StableSort) {
851  std::vector<Element> test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}};
854  ElementsAre(IsElement(1, 1), IsElement(1, 0), IsElement(2, 1),
855  IsElement(2, 0), IsElement(2, 2)));
856 }
857 
858 TEST(MutatingTest, StableSortWithPredicate) {
859  std::vector<Element> test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}};
860  absl::c_stable_sort(test_vector, [](const Element& e1, const Element& e2) {
861  return e2 < e1;
862  });
864  ElementsAre(IsElement(2, 1), IsElement(2, 0), IsElement(2, 2),
865  IsElement(1, 1), IsElement(1, 0)));
866 }
867 
868 TEST(MutatingTest, ReplaceCopyIf) {
869  const std::vector<int> initial = {1, 2, 3, 4, 5};
870  const std::vector<int> expected = {0, 2, 0, 4, 0};
871 
872  std::vector<int> actual;
873  absl::c_replace_copy_if(initial, back_inserter(actual), IsOdd, 0);
874  EXPECT_EQ(expected, actual);
875 }
876 
877 TEST(MutatingTest, Fill) {
878  std::vector<int> actual(5);
879  absl::c_fill(actual, 1);
880  EXPECT_THAT(actual, ElementsAre(1, 1, 1, 1, 1));
881 }
882 
883 TEST(MutatingTest, FillN) {
884  std::vector<int> actual(5, 0);
885  absl::c_fill_n(actual, 2, 1);
886  EXPECT_THAT(actual, ElementsAre(1, 1, 0, 0, 0));
887 }
888 
889 TEST(MutatingTest, Generate) {
890  std::vector<int> actual(5);
891  int x = 0;
892  absl::c_generate(actual, [&x]() { return ++x; });
893  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
894 }
895 
896 TEST(MutatingTest, GenerateN) {
897  std::vector<int> actual(5, 0);
898  int x = 0;
899  absl::c_generate_n(actual, 3, [&x]() { return ++x; });
900  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 0, 0));
901 }
902 
903 TEST(MutatingTest, RemoveCopy) {
904  std::vector<int> actual;
905  absl::c_remove_copy(std::vector<int>{1, 2, 3}, back_inserter(actual), 2);
906  EXPECT_THAT(actual, ElementsAre(1, 3));
907 }
908 
909 TEST(MutatingTest, RemoveCopyIf) {
910  std::vector<int> actual;
911  absl::c_remove_copy_if(std::vector<int>{1, 2, 3}, back_inserter(actual),
912  IsOdd);
913  EXPECT_THAT(actual, ElementsAre(2));
914 }
915 
916 TEST(MutatingTest, UniqueCopy) {
917  std::vector<int> actual;
918  absl::c_unique_copy(std::vector<int>{1, 2, 2, 2, 3, 3, 2},
919  back_inserter(actual));
920  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 2));
921 }
922 
923 TEST(MutatingTest, UniqueCopyWithPredicate) {
924  std::vector<int> actual;
925  absl::c_unique_copy(std::vector<int>{1, 2, 3, -1, -2, -3, 1},
926  back_inserter(actual),
927  [](int x, int y) { return (x < 0) == (y < 0); });
928  EXPECT_THAT(actual, ElementsAre(1, -1, 1));
929 }
930 
931 TEST(MutatingTest, Reverse) {
932  std::vector<int> test_vector = {1, 2, 3, 4};
934  EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1));
935 
936  std::list<int> test_list = {1, 2, 3, 4};
938  EXPECT_THAT(test_list, ElementsAre(4, 3, 2, 1));
939 }
940 
941 TEST(MutatingTest, ReverseCopy) {
942  std::vector<int> actual;
943  absl::c_reverse_copy(std::vector<int>{1, 2, 3, 4}, back_inserter(actual));
944  EXPECT_THAT(actual, ElementsAre(4, 3, 2, 1));
945 }
946 
947 TEST(MutatingTest, Rotate) {
948  std::vector<int> actual = {1, 2, 3, 4};
949  auto it = absl::c_rotate(actual, actual.begin() + 2);
950  EXPECT_THAT(actual, testing::ElementsAreArray({3, 4, 1, 2}));
951  EXPECT_EQ(*it, 1);
952 }
953 
954 TEST(MutatingTest, RotateCopy) {
955  std::vector<int> initial = {1, 2, 3, 4};
956  std::vector<int> actual;
957  auto end =
958  absl::c_rotate_copy(initial, initial.begin() + 2, back_inserter(actual));
959  *end = 5;
960  EXPECT_THAT(actual, ElementsAre(3, 4, 1, 2, 5));
961 }
962 
963 TEST(MutatingTest, Shuffle) {
964  std::vector<int> actual = {1, 2, 3, 4, 5};
965  absl::c_shuffle(actual, std::random_device());
966  EXPECT_THAT(actual, UnorderedElementsAre(1, 2, 3, 4, 5));
967 }
968 
969 TEST(MutatingTest, PartialSort) {
970  std::vector<int> sequence{5, 3, 42, 0};
971  absl::c_partial_sort(sequence, sequence.begin() + 2);
972  EXPECT_THAT(absl::MakeSpan(sequence.data(), 2), ElementsAre(0, 3));
973  absl::c_partial_sort(sequence, sequence.begin() + 2, std::greater<int>());
974  EXPECT_THAT(absl::MakeSpan(sequence.data(), 2), ElementsAre(42, 5));
975 }
976 
977 TEST(MutatingTest, PartialSortCopy) {
978  const std::vector<int> initial = {5, 3, 42, 0};
979  std::vector<int> actual(2);
980  absl::c_partial_sort_copy(initial, actual);
981  EXPECT_THAT(actual, ElementsAre(0, 3));
982  absl::c_partial_sort_copy(initial, actual, std::greater<int>());
983  EXPECT_THAT(actual, ElementsAre(42, 5));
984 }
985 
986 TEST(MutatingTest, Merge) {
987  std::vector<int> actual;
988  absl::c_merge(std::vector<int>{1, 3, 5}, std::vector<int>{2, 4},
989  back_inserter(actual));
990  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
991 }
992 
993 TEST(MutatingTest, MergeWithComparator) {
994  std::vector<int> actual;
995  absl::c_merge(std::vector<int>{5, 3, 1}, std::vector<int>{4, 2},
996  back_inserter(actual), std::greater<int>());
997  EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1));
998 }
999 
1000 TEST(MutatingTest, InplaceMerge) {
1001  std::vector<int> actual = {1, 3, 5, 2, 4};
1002  absl::c_inplace_merge(actual, actual.begin() + 3);
1003  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
1004 }
1005 
1006 TEST(MutatingTest, InplaceMergeWithComparator) {
1007  std::vector<int> actual = {5, 3, 1, 4, 2};
1008  absl::c_inplace_merge(actual, actual.begin() + 3, std::greater<int>());
1009  EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1));
1010 }
1011 
1012 class SetOperationsTest : public testing::Test {
1013  protected:
1014  std::vector<int> a_ = {1, 2, 3};
1015  std::vector<int> b_ = {1, 3, 5};
1016 
1017  std::vector<int> a_reversed_ = {3, 2, 1};
1018  std::vector<int> b_reversed_ = {5, 3, 1};
1019 };
1020 
1021 TEST_F(SetOperationsTest, SetUnion) {
1022  std::vector<int> actual;
1023  absl::c_set_union(a_, b_, back_inserter(actual));
1024  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 5));
1025 }
1026 
1027 TEST_F(SetOperationsTest, SetUnionWithComparator) {
1028  std::vector<int> actual;
1029  absl::c_set_union(a_reversed_, b_reversed_, back_inserter(actual),
1030  std::greater<int>());
1031  EXPECT_THAT(actual, ElementsAre(5, 3, 2, 1));
1032 }
1033 
1034 TEST_F(SetOperationsTest, SetIntersection) {
1035  std::vector<int> actual;
1036  absl::c_set_intersection(a_, b_, back_inserter(actual));
1037  EXPECT_THAT(actual, ElementsAre(1, 3));
1038 }
1039 
1040 TEST_F(SetOperationsTest, SetIntersectionWithComparator) {
1041  std::vector<int> actual;
1042  absl::c_set_intersection(a_reversed_, b_reversed_, back_inserter(actual),
1043  std::greater<int>());
1044  EXPECT_THAT(actual, ElementsAre(3, 1));
1045 }
1046 
1047 TEST_F(SetOperationsTest, SetDifference) {
1048  std::vector<int> actual;
1049  absl::c_set_difference(a_, b_, back_inserter(actual));
1050  EXPECT_THAT(actual, ElementsAre(2));
1051 }
1052 
1053 TEST_F(SetOperationsTest, SetDifferenceWithComparator) {
1054  std::vector<int> actual;
1055  absl::c_set_difference(a_reversed_, b_reversed_, back_inserter(actual),
1056  std::greater<int>());
1057  EXPECT_THAT(actual, ElementsAre(2));
1058 }
1059 
1060 TEST_F(SetOperationsTest, SetSymmetricDifference) {
1061  std::vector<int> actual;
1062  absl::c_set_symmetric_difference(a_, b_, back_inserter(actual));
1063  EXPECT_THAT(actual, ElementsAre(2, 5));
1064 }
1065 
1066 TEST_F(SetOperationsTest, SetSymmetricDifferenceWithComparator) {
1067  std::vector<int> actual;
1068  absl::c_set_symmetric_difference(a_reversed_, b_reversed_,
1069  back_inserter(actual), std::greater<int>());
1070  EXPECT_THAT(actual, ElementsAre(5, 2));
1071 }
1072 
1073 TEST(HeapOperationsTest, WithoutComparator) {
1074  std::vector<int> heap = {1, 2, 3};
1078  heap.push_back(4);
1079  EXPECT_EQ(3, absl::c_is_heap_until(heap) - heap.begin());
1081  EXPECT_EQ(4, heap[0]);
1083  EXPECT_EQ(4, heap[3]);
1086  EXPECT_THAT(heap, ElementsAre(1, 2, 3, 4));
1088 }
1089 
1090 TEST(HeapOperationsTest, WithComparator) {
1091  using greater = std::greater<int>;
1092  std::vector<int> heap = {3, 2, 1};
1096  heap.push_back(0);
1097  EXPECT_EQ(3, absl::c_is_heap_until(heap, greater()) - heap.begin());
1099  EXPECT_EQ(0, heap[0]);
1101  EXPECT_EQ(0, heap[3]);
1104  EXPECT_THAT(heap, ElementsAre(3, 2, 1, 0));
1106 }
1107 
1108 TEST(MutatingTest, PermutationOperations) {
1109  std::vector<int> initial = {1, 2, 3, 4};
1110  std::vector<int> permuted = initial;
1111 
1112  absl::c_next_permutation(permuted);
1113  EXPECT_TRUE(absl::c_is_permutation(initial, permuted));
1114  EXPECT_TRUE(absl::c_is_permutation(initial, permuted, std::equal_to<int>()));
1115 
1116  std::vector<int> permuted2 = initial;
1117  absl::c_prev_permutation(permuted2, std::greater<int>());
1118  EXPECT_EQ(permuted, permuted2);
1119 
1120  absl::c_prev_permutation(permuted);
1121  EXPECT_EQ(initial, permuted);
1122 }
1123 
1124 } // namespace
absl::c_is_sorted
bool c_is_sorted(const C &c)
Definition: abseil-cpp/absl/algorithm/container.h:940
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
absl::c_swap_ranges
container_algorithm_internal::ContainerIter< C2 > c_swap_ranges(C1 &c1, C2 &c2)
Definition: abseil-cpp/absl/algorithm/container.h:566
absl::c_move
OutputIterator c_move(C &&src, OutputIterator dest)
Definition: abseil-cpp/absl/algorithm/container.h:545
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
absl::c_all_of
bool c_all_of(const C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:171
absl::compare_internal::ord::greater
@ greater
calls
static fling_call calls[100001]
Definition: test/core/memory_usage/client.cc:57
absl::c_set_union
OutputIterator c_set_union(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: abseil-cpp/absl/algorithm/container.h:1237
regen-readme.it
it
Definition: regen-readme.py:15
testing::Gt
internal::GtMatcher< Rhs > Gt(Rhs x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8591
absl::c_merge
OutputIterator c_merge(const C1 &c1, const C2 &c2, OutputIterator result)
Definition: abseil-cpp/absl/algorithm/container.h:1160
testing::Pointee
internal::PointeeMatcher< InnerMatcher > Pointee(const InnerMatcher &inner_matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8691
grpc_event_engine::experimental::slice_detail::operator==
bool operator==(const BaseSlice &a, const BaseSlice &b)
Definition: include/grpc/event_engine/slice.h:117
absl::c_minmax_element
container_algorithm_internal::ContainerIterPairType< C, C > c_minmax_element(C &c)
Definition: abseil-cpp/absl/algorithm/container.h:1564
testing::Lt
internal::LtMatcher< Rhs > Lt(Rhs x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8603
testing::internal::Equals
constexpr bool Equals(const char(&a)[N], const char(&b)[M])
Definition: googletest/googlemock/include/gmock/gmock-function-mocker.h:83
absl::c_iota
void c_iota(Sequence &sequence, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:1662
testing::internal::IsNull
AssertionResult IsNull(const char *str)
Definition: bloaty/third_party/googletest/googletest/test/gtest-unittest-api_test.cc:139
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
absl::c_partition_copy
std::pair< OutputIterator1, OutputIterator2 > c_partition_copy(const C &c, OutputIterator1 out_true, OutputIterator2 out_false, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:871
EXPECT_THAT
#define EXPECT_THAT(value, matcher)
absl::c_replace
void c_replace(Sequence &sequence, const T &old_value, const T &new_value)
Definition: abseil-cpp/absl/algorithm/container.h:619
absl::c_pop_heap
void c_pop_heap(RandomAccessContainer &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1416
y
const double y
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3611
absl::c_shuffle
void c_shuffle(RandomAccessContainer &c, UniformRandomBitGenerator &&gen)
Definition: abseil-cpp/absl/algorithm/container.h:813
absl::c_is_permutation
bool c_is_permutation(const C1 &c1, const C2 &c2)
Definition: abseil-cpp/absl/algorithm/container.h:427
grpc::testing::BinarySearch
static double BinarySearch(Scenario *scenario, double targeted_cpu_load, double low, double high, const std::map< std::string, std::string > &per_worker_credential_types, bool *success)
Definition: qps_json_driver.cc:180
testing::Truly
PolymorphicMatcher< internal::TrulyMatcher< Predicate > > Truly(Predicate pred)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8935
absl::c_is_partitioned
bool c_is_partitioned(const C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:829
absl::str_format_internal::AllOf
constexpr bool AllOf()
Definition: abseil-cpp/absl/strings/internal/str_format/checker.h:39
arg::value
void * value
Definition: cmdline.cc:44
absl::c_copy_backward
BidirectionalIterator c_copy_backward(const C &src, BidirectionalIterator dest)
Definition: abseil-cpp/absl/algorithm/container.h:534
absl::c_partition
container_algorithm_internal::ContainerIter< C > c_partition(C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:842
absl::FormatConversionChar::s
@ s
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
grpc_core::ForEach
for_each_detail::ForEach< Reader, Action > ForEach(Reader reader, Action action)
For each item acquired by calling Reader::Next, run the promise Action.
Definition: for_each.h:133
absl::c_reverse
void c_reverse(Sequence &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:764
xds_manager.p
p
Definition: xds_manager.py:60
testing::AnyOf
internal::AnyOfResult2< M1, M2 >::type AnyOf(M1 m1, M2 m2)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:13555
second
StrT second
Definition: cxa_demangle.cpp:4885
absl::c_inplace_merge
void c_inplace_merge(C &c, container_algorithm_internal::ContainerIter< C > middle)
Definition: abseil-cpp/absl/algorithm/container.h:1184
ABSL_ARRAYSIZE
#define ABSL_ARRAYSIZE(array)
Definition: abseil-cpp/absl/base/macros.h:44
re2::Search
void Search(int iters, int nbytes, const char *regexp, SearchImpl *search)
Definition: bloaty/third_party/re2/re2/testing/regexp_benchmark.cc:159
z
Uncopyable z
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3612
absl::c_nth_element
void c_nth_element(RandomAccessContainer &sequence, container_algorithm_internal::ContainerIter< RandomAccessContainer > nth)
Definition: abseil-cpp/absl/algorithm/container.h:1037
iterator
const typedef MCPhysReg * iterator
Definition: MCRegisterInfo.h:27
absl::c_is_sorted_until
container_algorithm_internal::ContainerIter< C > c_is_sorted_until(C &c)
Definition: abseil-cpp/absl/algorithm/container.h:1014
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
testing::ElementsAreArray
internal::ElementsAreArrayMatcher< typename ::std::iterator_traits< Iter >::value_type > ElementsAreArray(Iter first, Iter last)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8465
absl::c_adjacent_find
container_algorithm_internal::ContainerIter< Sequence > c_adjacent_find(Sequence &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:300
absl::c_copy_if
OutputIterator c_copy_if(const InputSequence &input, OutputIterator output, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:522
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
testing::ElementsAre
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:13040
absl::c_sort_heap
void c_sort_heap(RandomAccessContainer &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1454
o
UnboundConversion o
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:97
grpc::operator<
bool operator<(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:140
absl::c_copy_n
OutputIterator c_copy_n(const C &input, Size n, OutputIterator output)
Definition: abseil-cpp/absl/algorithm/container.h:513
absl::c_min_element
container_algorithm_internal::ContainerIter< Sequence > c_min_element(Sequence &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1518
absl::FormatConversionChar::e
@ e
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
absl::c_upper_bound
container_algorithm_internal::ContainerIter< Sequence > c_upper_bound(Sequence &sequence, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:1089
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
absl::c_count_if
container_algorithm_internal::ContainerDifferenceType< const C > c_count_if(const C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:333
TEST
#define TEST(name, init_size,...)
Definition: arena_test.cc:75
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
absl::c_fill
void c_fill(C &c, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:670
absl::c_partial_sort_copy
container_algorithm_internal::ContainerIter< RandomAccessContainer > c_partial_sort_copy(const C &sequence, RandomAccessContainer &result)
Definition: abseil-cpp/absl/algorithm/container.h:988
absl::c_any_of
bool c_any_of(const C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:182
test_vector
static void test_vector(const char *raw, size_t raw_length, const char *encoded, size_t encoded_length, grpc_core::PercentEncodingType type)
Definition: percent_encoding_test.cc:37
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
absl::c_find_if
container_algorithm_internal::ContainerIter< C > c_find_if(C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:226
absl::c_find_first_of
container_algorithm_internal::ContainerIter< C1 > c_find_first_of(C1 &container, C2 &options)
Definition: abseil-cpp/absl/algorithm/container.h:275
absl::c_equal_range
container_algorithm_internal::ContainerIterPairType< Sequence, Sequence > c_equal_range(Sequence &sequence, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:1113
grpc_ruby_generator::Replace
std::string Replace(std::string s, const std::string &from, const std::string &to)
Definition: ruby_generator_string-inl.h:52
arg
Definition: cmdline.cc:40
operator!=
bool operator!=(const Bytes &a, const Bytes &b)
Definition: boringssl-with-bazel/src/crypto/test/test_util.h:58
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:1226
absl::c_rotate_copy
OutputIterator c_rotate_copy(const C &sequence, container_algorithm_internal::ContainerIter< const C > middle, OutputIterator result)
Definition: abseil-cpp/absl/algorithm/container.h:798
absl::c_remove_copy
OutputIterator c_remove_copy(const C &c, OutputIterator result, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:719
absl::c_lexicographical_compare
bool c_lexicographical_compare(Sequence1 &&sequence1, Sequence2 &&sequence2)
Definition: abseil-cpp/absl/algorithm/container.h:1591
absl::c_binary_search
bool c_binary_search(Sequence &&sequence, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:1135
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
absl::c_distance
container_algorithm_internal::ContainerDifferenceType< const C > c_distance(const C &c)
Definition: abseil-cpp/absl/algorithm/container.h:156
absl::c_adjacent_difference
OutputIt c_adjacent_difference(const InputSequence &input, OutputIt output_first)
Definition: abseil-cpp/absl/algorithm/container.h:1731
a_
arena< N > & a_
Definition: cxa_demangle.cpp:4778
absl::c_make_heap
void c_make_heap(RandomAccessContainer &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1435
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
absl::c_find
container_algorithm_internal::ContainerIter< C > c_find(C &c, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:215
absl::c_set_intersection
OutputIterator c_set_intersection(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: abseil-cpp/absl/algorithm/container.h:1273
google::protobuf.text_format.Merge
def Merge(text, message, allow_unknown_extension=False, allow_field_number=False, descriptor_pool=None, allow_unknown_field=False)
Definition: bloaty/third_party/protobuf/python/google/protobuf/text_format.py:659
absl::c_generate_n
container_algorithm_internal::ContainerIter< C > c_generate_n(C &c, Size n, Generator &&gen)
Definition: abseil-cpp/absl/algorithm/container.h:702
absl::c_set_symmetric_difference
OutputIterator c_set_symmetric_difference(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: abseil-cpp/absl/algorithm/container.h:1359
tests.qps.qps_worker.dest
dest
Definition: qps_worker.py:45
absl::c_equal
bool c_equal(const C1 &c1, const C2 &c2)
Definition: abseil-cpp/absl/algorithm/container.h:402
absl::implicit_cast
constexpr ABSL_NAMESPACE_BEGIN To implicit_cast(typename absl::internal::identity_t< To > to)
Definition: abseil-cpp/absl/base/casts.h:93
absl::c_rotate
Iterator c_rotate(C &sequence, Iterator middle)
Definition: abseil-cpp/absl/algorithm/container.h:787
absl::c_reverse_copy
OutputIterator c_reverse_copy(const C &sequence, OutputIterator result)
Definition: abseil-cpp/absl/algorithm/container.h:774
absl::synchronization_internal::Sort
static void Sort(const Vec< Node * > &, Vec< int32_t > *delta)
Definition: abseil-cpp/absl/synchronization/internal/graphcycles.cc:603
absl::c_copy
OutputIterator c_copy(const InputSequence &input, OutputIterator output)
Definition: abseil-cpp/absl/algorithm/container.h:503
absl::c_includes
bool c_includes(const C1 &c1, const C2 &c2)
Definition: abseil-cpp/absl/algorithm/container.h:1207
value
const char * value
Definition: hpack_parser_table.cc:165
googletest-output-test.test_list
def test_list
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test.py:250
absl::c_search_n
container_algorithm_internal::ContainerIter< Sequence > c_search_n(Sequence &sequence, Size count, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:475
absl::c_unique_copy
OutputIterator c_unique_copy(const C &c, OutputIterator result)
Definition: abseil-cpp/absl/algorithm/container.h:744
absl::c_remove_copy_if
OutputIterator c_remove_copy_if(const C &c, OutputIterator result, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:731
output_
std::string output_
Definition: json_writer.cc:76
absl::c_linear_search
bool c_linear_search(const C &c, EqualityComparable &&value)
Definition: abseil-cpp/absl/algorithm/container.h:141
absl::c_replace_copy
OutputIterator c_replace_copy(const C &c, OutputIterator result, T &&old_value, T &&new_value)
Definition: abseil-cpp/absl/algorithm/container.h:643
absl::c_is_heap
bool c_is_heap(const RandomAccessContainer &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1473
absl::c_sort
void c_sort(C &c)
Definition: abseil-cpp/absl/algorithm/container.h:901
key
const char * key
Definition: hpack_parser_table.cc:164
absl::c_for_each
decay_t< Function > c_for_each(C &&c, Function &&f)
Definition: abseil-cpp/absl/algorithm/container.h:204
MATCHER_P2
#define MATCHER_P2(name, p0, p1, description)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/gmock-generated-matchers.h:364
testing::internal::Shuffle
void Shuffle(internal::Random *random, std::vector< E > *v)
Definition: gmock-gtest-all.cc:740
absl::c_push_heap
void c_push_heap(RandomAccessContainer &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1397
absl::c_generate
void c_generate(C &c, Generator &&gen)
Definition: abseil-cpp/absl/algorithm/container.h:690
absl::c_inner_product
decay_t< T > c_inner_product(const Sequence1 &factors1, const Sequence2 &factors2, T &&sum)
Definition: abseil-cpp/absl/algorithm/container.h:1703
absl::c_partial_sum
OutputIt c_partial_sum(const InputSequence &input, OutputIt output_first)
Definition: abseil-cpp/absl/algorithm/container.h:1755
absl::c_prev_permutation
bool c_prev_permutation(C &c)
Definition: abseil-cpp/absl/algorithm/container.h:1638
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
first
StrT first
Definition: cxa_demangle.cpp:4884
absl::hash_internal::Rotate
static uint64_t Rotate(uint64_t val, int shift)
Definition: abseil-cpp/absl/hash/internal/city.cc:196
absl::c_next_permutation
bool c_next_permutation(C &c)
Definition: abseil-cpp/absl/algorithm/container.h:1618
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
testing::UnorderedElementsAre
internal::UnorderedElementsAreMatcher< ::testing::tuple<> > UnorderedElementsAre()
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:13255
absl::c_accumulate
decay_t< T > c_accumulate(const Sequence &sequence, T &&init)
Definition: abseil-cpp/absl/algorithm/container.h:1677
google::protobuf::python::repeated_composite_container::Reverse
static PyObject * Reverse(PyObject *pself)
Definition: protobuf/python/google/protobuf/pyext/repeated_composite_container.cc:445
input
std::string input
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc:197
absl::c_max_element
container_algorithm_internal::ContainerIter< Sequence > c_max_element(Sequence &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1540
absl::c_set_difference
OutputIterator c_set_difference(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: abseil-cpp/absl/algorithm/container.h:1321
absl::c_lower_bound
container_algorithm_internal::ContainerIter< Sequence > c_lower_bound(Sequence &sequence, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:1066
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
absl::c_replace_copy_if
OutputIterator c_replace_copy_if(const C &c, OutputIterator result, Pred &&pred, T &&new_value)
Definition: abseil-cpp/absl/algorithm/container.h:657
absl::c_mismatch
container_algorithm_internal::ContainerIterPairType< C1, C2 > c_mismatch(C1 &c1, C2 &c2)
Definition: abseil-cpp/absl/algorithm/container.h:347
b_
const char * b_
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/common_unittest.cc:194
testing::internal::CountIf
int CountIf(const Container &c, Predicate predicate)
Definition: gmock-gtest-all.cc:690
absl::c_replace_if
void c_replace_if(C &c, Pred &&pred, T &&new_value)
Definition: abseil-cpp/absl/algorithm/container.h:631
absl::c_find_if_not
container_algorithm_internal::ContainerIter< C > c_find_if_not(C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:237
absl::c_find_end
container_algorithm_internal::ContainerIter< Sequence1 > c_find_end(Sequence1 &sequence, Sequence2 &subsequence)
Definition: abseil-cpp/absl/algorithm/container.h:249
absl::c_transform
OutputIterator c_transform(const InputSequence &input, OutputIterator output, UnaryOp &&unary_op)
Definition: abseil-cpp/absl/algorithm/container.h:586
testing::Each
internal::EachMatcher< M > Each(M matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:9133
absl::c_stable_sort
void c_stable_sort(C &c)
Definition: abseil-cpp/absl/algorithm/container.h:921
grpc::operator<<
std::ostream & operator<<(std::ostream &out, const string_ref &string)
Definition: grpcpp/impl/codegen/string_ref.h:145
absl::c_partial_sort
void c_partial_sort(RandomAccessContainer &sequence, container_algorithm_internal::ContainerIter< RandomAccessContainer > middle)
Definition: abseil-cpp/absl/algorithm/container.h:960
absl::c_is_heap_until
container_algorithm_internal::ContainerIter< RandomAccessContainer > c_is_heap_until(RandomAccessContainer &sequence)
Definition: abseil-cpp/absl/algorithm/container.h:1493
absl::c_move_backward
BidirectionalIterator c_move_backward(C &&src, BidirectionalIterator dest)
Definition: abseil-cpp/absl/algorithm/container.h:555
google::protobuf::python::descriptor::Count
static PyObject * Count(PyContainer *self, PyObject *item)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.cc:694
absl::c_stable_partition
container_algorithm_internal::ContainerIter< C > c_stable_partition(C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:856
absl::MakeSpan
constexpr Span< T > MakeSpan(T *ptr, size_t size) noexcept
Definition: abseil-cpp/absl/types/span.h:661
absl::c_partition_point
container_algorithm_internal::ContainerIter< C > c_partition_point(C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:885
heap
Definition: heap-inl.h:40
absl::c_none_of
bool c_none_of(const C &c, Pred &&pred)
Definition: abseil-cpp/absl/algorithm/container.h:193
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
absl::c_count
container_algorithm_internal::ContainerDifferenceType< const C > c_count(const C &c, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:321
TEST_F
#define TEST_F(test_fixture, test_name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2367
absl::hash_internal::c2
static const uint32_t c2
Definition: abseil-cpp/absl/hash/internal/city.cc:59
absl::c_fill_n
void c_fill_n(C &c, Size n, T &&value)
Definition: abseil-cpp/absl/algorithm/container.h:680
absl::c_search
container_algorithm_internal::ContainerIter< Sequence1 > c_search(Sequence1 &sequence, Sequence2 &subsequence)
Definition: abseil-cpp/absl/algorithm/container.h:450


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:54