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 
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 
39 using ::testing::Each;
40 using ::testing::ElementsAre;
41 using ::testing::Gt;
42 using ::testing::IsNull;
43 using ::testing::Lt;
44 using ::testing::Pointee;
45 using ::testing::Truly;
46 using ::testing::UnorderedElementsAre;
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) {
61  calls.push_back(value);
62  }
63  std::vector<int> calls;
64 };
65 
66 bool Predicate(int value) { return value < 3; }
67 bool BinPredicate(int v1, int v2) { return v1 < v2; }
68 bool Equals(int v1, int v2) { return v1 == v2; }
69 bool IsOdd(int x) { return x % 2 != 0; }
70 
71 
72 TEST_F(NonMutatingTest, Distance) {
73  EXPECT_EQ(container_.size(), absl::c_distance(container_));
74  EXPECT_EQ(sequence_.size(), absl::c_distance(sequence_));
75  EXPECT_EQ(vector_.size(), absl::c_distance(vector_));
76  EXPECT_EQ(ABSL_ARRAYSIZE(array_), absl::c_distance(array_));
77 
78  // Works with a temporary argument.
79  EXPECT_EQ(vector_.size(), absl::c_distance(std::vector<int>(vector_)));
80 }
81 
82 TEST_F(NonMutatingTest, Distance_OverloadedBeginEnd) {
83  // Works with classes which have custom ADL-selected overloads of std::begin
84  // and std::end.
85  std::initializer_list<int> a = {1, 2, 3};
86  std::valarray<int> b = {1, 2, 3};
87  EXPECT_EQ(3, absl::c_distance(a));
88  EXPECT_EQ(3, absl::c_distance(b));
89 
90  // It is assumed that other c_* functions use the same mechanism for
91  // ADL-selecting begin/end overloads.
92 }
93 
94 TEST_F(NonMutatingTest, ForEach) {
95  AccumulateCalls c = absl::c_for_each(container_, AccumulateCalls());
96  // Don't rely on the unordered_set's order.
97  std::sort(c.calls.begin(), c.calls.end());
98  EXPECT_EQ(vector_, c.calls);
99 
100  // Works with temporary container, too.
101  AccumulateCalls c2 =
102  absl::c_for_each(std::unordered_set<int>(container_), AccumulateCalls());
103  std::sort(c2.calls.begin(), c2.calls.end());
104  EXPECT_EQ(vector_, c2.calls);
105 }
106 
107 TEST_F(NonMutatingTest, FindReturnsCorrectType) {
108  auto it = absl::c_find(container_, 3);
109  EXPECT_EQ(3, *it);
110  absl::c_find(absl::implicit_cast<const std::list<int>&>(sequence_), 3);
111 }
112 
113 TEST_F(NonMutatingTest, FindIf) { absl::c_find_if(container_, Predicate); }
114 
115 TEST_F(NonMutatingTest, FindIfNot) {
116  absl::c_find_if_not(container_, Predicate);
117 }
118 
119 TEST_F(NonMutatingTest, FindEnd) {
120  absl::c_find_end(sequence_, vector_);
121  absl::c_find_end(vector_, sequence_);
122 }
123 
124 TEST_F(NonMutatingTest, FindEndWithPredicate) {
125  absl::c_find_end(sequence_, vector_, BinPredicate);
126  absl::c_find_end(vector_, sequence_, BinPredicate);
127 }
128 
129 TEST_F(NonMutatingTest, FindFirstOf) {
130  absl::c_find_first_of(container_, sequence_);
131  absl::c_find_first_of(sequence_, container_);
132 }
133 
134 TEST_F(NonMutatingTest, FindFirstOfWithPredicate) {
135  absl::c_find_first_of(container_, sequence_, BinPredicate);
136  absl::c_find_first_of(sequence_, container_, BinPredicate);
137 }
138 
139 TEST_F(NonMutatingTest, AdjacentFind) { absl::c_adjacent_find(sequence_); }
140 
141 TEST_F(NonMutatingTest, AdjacentFindWithPredicate) {
142  absl::c_adjacent_find(sequence_, BinPredicate);
143 }
144 
145 TEST_F(NonMutatingTest, Count) { EXPECT_EQ(1, absl::c_count(container_, 3)); }
146 
147 TEST_F(NonMutatingTest, CountIf) {
148  EXPECT_EQ(2, absl::c_count_if(container_, Predicate));
149  const std::unordered_set<int>& const_container = container_;
150  EXPECT_EQ(2, absl::c_count_if(const_container, Predicate));
151 }
152 
153 TEST_F(NonMutatingTest, Mismatch) {
154  absl::c_mismatch(container_, sequence_);
155  absl::c_mismatch(sequence_, container_);
156 }
157 
158 TEST_F(NonMutatingTest, MismatchWithPredicate) {
159  absl::c_mismatch(container_, sequence_, BinPredicate);
160  absl::c_mismatch(sequence_, container_, BinPredicate);
161 }
162 
163 TEST_F(NonMutatingTest, Equal) {
164  EXPECT_TRUE(absl::c_equal(vector_, sequence_));
165  EXPECT_TRUE(absl::c_equal(sequence_, vector_));
166 
167  // Test that behavior appropriately differs from that of equal().
168  std::vector<int> vector_plus = {1, 2, 3};
169  vector_plus.push_back(4);
170  EXPECT_FALSE(absl::c_equal(vector_plus, sequence_));
171  EXPECT_FALSE(absl::c_equal(sequence_, vector_plus));
172 }
173 
174 TEST_F(NonMutatingTest, EqualWithPredicate) {
175  EXPECT_TRUE(absl::c_equal(vector_, sequence_, Equals));
176  EXPECT_TRUE(absl::c_equal(sequence_, vector_, Equals));
177 
178  // Test that behavior appropriately differs from that of equal().
179  std::vector<int> vector_plus = {1, 2, 3};
180  vector_plus.push_back(4);
181  EXPECT_FALSE(absl::c_equal(vector_plus, sequence_, Equals));
182  EXPECT_FALSE(absl::c_equal(sequence_, vector_plus, Equals));
183 }
184 
185 TEST_F(NonMutatingTest, IsPermutation) {
186  auto vector_permut_ = vector_;
187  std::next_permutation(vector_permut_.begin(), vector_permut_.end());
188  EXPECT_TRUE(absl::c_is_permutation(vector_permut_, sequence_));
189  EXPECT_TRUE(absl::c_is_permutation(sequence_, vector_permut_));
190 
191  // Test that behavior appropriately differs from that of is_permutation().
192  std::vector<int> vector_plus = {1, 2, 3};
193  vector_plus.push_back(4);
194  EXPECT_FALSE(absl::c_is_permutation(vector_plus, sequence_));
195  EXPECT_FALSE(absl::c_is_permutation(sequence_, vector_plus));
196 }
197 
198 TEST_F(NonMutatingTest, IsPermutationWithPredicate) {
199  auto vector_permut_ = vector_;
200  std::next_permutation(vector_permut_.begin(), vector_permut_.end());
201  EXPECT_TRUE(absl::c_is_permutation(vector_permut_, sequence_, Equals));
202  EXPECT_TRUE(absl::c_is_permutation(sequence_, vector_permut_, Equals));
203 
204  // Test that behavior appropriately differs from that of is_permutation().
205  std::vector<int> vector_plus = {1, 2, 3};
206  vector_plus.push_back(4);
207  EXPECT_FALSE(absl::c_is_permutation(vector_plus, sequence_, Equals));
208  EXPECT_FALSE(absl::c_is_permutation(sequence_, vector_plus, Equals));
209 }
210 
211 TEST_F(NonMutatingTest, Search) {
212  absl::c_search(sequence_, vector_);
213  absl::c_search(vector_, sequence_);
214  absl::c_search(array_, sequence_);
215 }
216 
217 TEST_F(NonMutatingTest, SearchWithPredicate) {
218  absl::c_search(sequence_, vector_, BinPredicate);
219  absl::c_search(vector_, sequence_, BinPredicate);
220 }
221 
222 TEST_F(NonMutatingTest, SearchN) { absl::c_search_n(sequence_, 3, 1); }
223 
224 TEST_F(NonMutatingTest, SearchNWithPredicate) {
225  absl::c_search_n(sequence_, 3, 1, BinPredicate);
226 }
227 
228 TEST_F(NonMutatingTest, LowerBound) {
229  std::list<int>::iterator i = absl::c_lower_bound(sequence_, 3);
230  ASSERT_TRUE(i != sequence_.end());
231  EXPECT_EQ(2, std::distance(sequence_.begin(), i));
232  EXPECT_EQ(3, *i);
233 }
234 
235 TEST_F(NonMutatingTest, LowerBoundWithPredicate) {
236  std::vector<int> v(vector_);
237  std::sort(v.begin(), v.end(), std::greater<int>());
238  std::vector<int>::iterator i = absl::c_lower_bound(v, 3, std::greater<int>());
239  EXPECT_TRUE(i == v.begin());
240  EXPECT_EQ(3, *i);
241 }
242 
243 TEST_F(NonMutatingTest, UpperBound) {
244  std::list<int>::iterator i = absl::c_upper_bound(sequence_, 1);
245  ASSERT_TRUE(i != sequence_.end());
246  EXPECT_EQ(1, std::distance(sequence_.begin(), i));
247  EXPECT_EQ(2, *i);
248 }
249 
250 TEST_F(NonMutatingTest, UpperBoundWithPredicate) {
251  std::vector<int> v(vector_);
252  std::sort(v.begin(), v.end(), std::greater<int>());
253  std::vector<int>::iterator i = absl::c_upper_bound(v, 1, std::greater<int>());
254  EXPECT_EQ(3, i - v.begin());
255  EXPECT_TRUE(i == v.end());
256 }
257 
258 TEST_F(NonMutatingTest, EqualRange) {
259  std::pair<std::list<int>::iterator, std::list<int>::iterator> p =
260  absl::c_equal_range(sequence_, 2);
261  EXPECT_EQ(1, std::distance(sequence_.begin(), p.first));
262  EXPECT_EQ(2, std::distance(sequence_.begin(), p.second));
263 }
264 
265 TEST_F(NonMutatingTest, EqualRangeArray) {
266  auto p = absl::c_equal_range(array_, 2);
267  EXPECT_EQ(1, std::distance(std::begin(array_), p.first));
268  EXPECT_EQ(2, std::distance(std::begin(array_), p.second));
269 }
270 
271 TEST_F(NonMutatingTest, EqualRangeWithPredicate) {
272  std::vector<int> v(vector_);
273  std::sort(v.begin(), v.end(), std::greater<int>());
274  std::pair<std::vector<int>::iterator, std::vector<int>::iterator> p =
275  absl::c_equal_range(v, 2, std::greater<int>());
276  EXPECT_EQ(1, std::distance(v.begin(), p.first));
277  EXPECT_EQ(2, std::distance(v.begin(), p.second));
278 }
279 
280 TEST_F(NonMutatingTest, BinarySearch) {
281  EXPECT_TRUE(absl::c_binary_search(vector_, 2));
282  EXPECT_TRUE(absl::c_binary_search(std::vector<int>(vector_), 2));
283 }
284 
285 TEST_F(NonMutatingTest, BinarySearchWithPredicate) {
286  std::vector<int> v(vector_);
287  std::sort(v.begin(), v.end(), std::greater<int>());
288  EXPECT_TRUE(absl::c_binary_search(v, 2, std::greater<int>()));
289  EXPECT_TRUE(
290  absl::c_binary_search(std::vector<int>(v), 2, std::greater<int>()));
291 }
292 
293 TEST_F(NonMutatingTest, MinElement) {
294  std::list<int>::iterator i = absl::c_min_element(sequence_);
295  ASSERT_TRUE(i != sequence_.end());
296  EXPECT_EQ(*i, 1);
297 }
298 
299 TEST_F(NonMutatingTest, MinElementWithPredicate) {
300  std::list<int>::iterator i =
301  absl::c_min_element(sequence_, std::greater<int>());
302  ASSERT_TRUE(i != sequence_.end());
303  EXPECT_EQ(*i, 3);
304 }
305 
306 TEST_F(NonMutatingTest, MaxElement) {
307  std::list<int>::iterator i = absl::c_max_element(sequence_);
308  ASSERT_TRUE(i != sequence_.end());
309  EXPECT_EQ(*i, 3);
310 }
311 
312 TEST_F(NonMutatingTest, MaxElementWithPredicate) {
313  std::list<int>::iterator i =
314  absl::c_max_element(sequence_, std::greater<int>());
315  ASSERT_TRUE(i != sequence_.end());
316  EXPECT_EQ(*i, 1);
317 }
318 
319 TEST_F(NonMutatingTest, LexicographicalCompare) {
320  EXPECT_FALSE(absl::c_lexicographical_compare(sequence_, sequence_));
321 
322  std::vector<int> v;
323  v.push_back(1);
324  v.push_back(2);
325  v.push_back(4);
326 
327  EXPECT_TRUE(absl::c_lexicographical_compare(sequence_, v));
328  EXPECT_TRUE(absl::c_lexicographical_compare(std::list<int>(sequence_), v));
329 }
330 
331 TEST_F(NonMutatingTest, LexicographicalCopmareWithPredicate) {
332  EXPECT_FALSE(absl::c_lexicographical_compare(sequence_, sequence_,
333  std::greater<int>()));
334 
335  std::vector<int> v;
336  v.push_back(1);
337  v.push_back(2);
338  v.push_back(4);
339 
340  EXPECT_TRUE(
341  absl::c_lexicographical_compare(v, sequence_, std::greater<int>()));
343  std::vector<int>(v), std::list<int>(sequence_), std::greater<int>()));
344 }
345 
346 TEST_F(NonMutatingTest, Includes) {
347  std::set<int> s(vector_.begin(), vector_.end());
348  s.insert(4);
349  EXPECT_TRUE(absl::c_includes(s, vector_));
350 }
351 
352 TEST_F(NonMutatingTest, IncludesWithPredicate) {
353  std::vector<int> v = {3, 2, 1};
354  std::set<int, std::greater<int>> s(v.begin(), v.end());
355  s.insert(4);
356  EXPECT_TRUE(absl::c_includes(s, v, std::greater<int>()));
357 }
358 
359 class NumericMutatingTest : public testing::Test {
360  protected:
361  std::list<int> list_ = {1, 2, 3};
362  std::vector<int> output_;
363 };
364 
365 TEST_F(NumericMutatingTest, Iota) {
366  absl::c_iota(list_, 5);
367  std::list<int> expected{5, 6, 7};
368  EXPECT_EQ(list_, expected);
369 }
370 
371 TEST_F(NonMutatingTest, Accumulate) {
372  EXPECT_EQ(absl::c_accumulate(sequence_, 4), 1 + 2 + 3 + 4);
373 }
374 
375 TEST_F(NonMutatingTest, AccumulateWithBinaryOp) {
376  EXPECT_EQ(absl::c_accumulate(sequence_, 4, std::multiplies<int>()),
377  1 * 2 * 3 * 4);
378 }
379 
380 TEST_F(NonMutatingTest, AccumulateLvalueInit) {
381  int lvalue = 4;
382  EXPECT_EQ(absl::c_accumulate(sequence_, lvalue), 1 + 2 + 3 + 4);
383 }
384 
385 TEST_F(NonMutatingTest, AccumulateWithBinaryOpLvalueInit) {
386  int lvalue = 4;
387  EXPECT_EQ(absl::c_accumulate(sequence_, lvalue, std::multiplies<int>()),
388  1 * 2 * 3 * 4);
389 }
390 
391 TEST_F(NonMutatingTest, InnerProduct) {
392  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, 1000),
393  1000 + 1 * 1 + 2 * 2 + 3 * 3);
394 }
395 
396 TEST_F(NonMutatingTest, InnerProductWithBinaryOps) {
397  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, 10,
398  std::multiplies<int>(), std::plus<int>()),
399  10 * (1 + 1) * (2 + 2) * (3 + 3));
400 }
401 
402 TEST_F(NonMutatingTest, InnerProductLvalueInit) {
403  int lvalue = 1000;
404  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, lvalue),
405  1000 + 1 * 1 + 2 * 2 + 3 * 3);
406 }
407 
408 TEST_F(NonMutatingTest, InnerProductWithBinaryOpsLvalueInit) {
409  int lvalue = 10;
410  EXPECT_EQ(absl::c_inner_product(sequence_, vector_, lvalue,
411  std::multiplies<int>(), std::plus<int>()),
412  10 * (1 + 1) * (2 + 2) * (3 + 3));
413 }
414 
415 TEST_F(NumericMutatingTest, AdjacentDifference) {
416  auto last = absl::c_adjacent_difference(list_, std::back_inserter(output_));
417  *last = 1000;
418  std::vector<int> expected{1, 2 - 1, 3 - 2, 1000};
419  EXPECT_EQ(output_, expected);
420 }
421 
422 TEST_F(NumericMutatingTest, AdjacentDifferenceWithBinaryOp) {
423  auto last = absl::c_adjacent_difference(list_, std::back_inserter(output_),
424  std::multiplies<int>());
425  *last = 1000;
426  std::vector<int> expected{1, 2 * 1, 3 * 2, 1000};
427  EXPECT_EQ(output_, expected);
428 }
429 
430 TEST_F(NumericMutatingTest, PartialSum) {
431  auto last = absl::c_partial_sum(list_, std::back_inserter(output_));
432  *last = 1000;
433  std::vector<int> expected{1, 1 + 2, 1 + 2 + 3, 1000};
434  EXPECT_EQ(output_, expected);
435 }
436 
437 TEST_F(NumericMutatingTest, PartialSumWithBinaryOp) {
438  auto last = absl::c_partial_sum(list_, std::back_inserter(output_),
439  std::multiplies<int>());
440  *last = 1000;
441  std::vector<int> expected{1, 1 * 2, 1 * 2 * 3, 1000};
442  EXPECT_EQ(output_, expected);
443 }
444 
445 TEST_F(NonMutatingTest, LinearSearch) {
446  EXPECT_TRUE(absl::c_linear_search(container_, 3));
447  EXPECT_FALSE(absl::c_linear_search(container_, 4));
448 }
449 
450 TEST_F(NonMutatingTest, AllOf) {
451  const std::vector<int>& v = vector_;
452  EXPECT_FALSE(absl::c_all_of(v, [](int x) { return x > 1; }));
453  EXPECT_TRUE(absl::c_all_of(v, [](int x) { return x > 0; }));
454 }
455 
456 TEST_F(NonMutatingTest, AnyOf) {
457  const std::vector<int>& v = vector_;
458  EXPECT_TRUE(absl::c_any_of(v, [](int x) { return x > 2; }));
459  EXPECT_FALSE(absl::c_any_of(v, [](int x) { return x > 5; }));
460 }
461 
462 TEST_F(NonMutatingTest, NoneOf) {
463  const std::vector<int>& v = vector_;
464  EXPECT_FALSE(absl::c_none_of(v, [](int x) { return x > 2; }));
465  EXPECT_TRUE(absl::c_none_of(v, [](int x) { return x > 5; }));
466 }
467 
468 TEST_F(NonMutatingTest, MinMaxElementLess) {
469  std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
470  p = absl::c_minmax_element(vector_, std::less<int>());
471  EXPECT_TRUE(p.first == vector_.begin());
472  EXPECT_TRUE(p.second == vector_.begin() + 2);
473 }
474 
475 TEST_F(NonMutatingTest, MinMaxElementGreater) {
476  std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
477  p = absl::c_minmax_element(vector_, std::greater<int>());
478  EXPECT_TRUE(p.first == vector_.begin() + 2);
479  EXPECT_TRUE(p.second == vector_.begin());
480 }
481 
482 TEST_F(NonMutatingTest, MinMaxElementNoPredicate) {
483  std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
484  p = absl::c_minmax_element(vector_);
485  EXPECT_TRUE(p.first == vector_.begin());
486  EXPECT_TRUE(p.second == vector_.begin() + 2);
487 }
488 
489 class SortingTest : public testing::Test {
490  protected:
491  std::list<int> sorted_ = {1, 2, 3, 4};
492  std::list<int> unsorted_ = {2, 4, 1, 3};
493  std::list<int> reversed_ = {4, 3, 2, 1};
494 };
495 
496 TEST_F(SortingTest, IsSorted) {
497  EXPECT_TRUE(absl::c_is_sorted(sorted_));
498  EXPECT_FALSE(absl::c_is_sorted(unsorted_));
499  EXPECT_FALSE(absl::c_is_sorted(reversed_));
500 }
501 
502 TEST_F(SortingTest, IsSortedWithPredicate) {
503  EXPECT_FALSE(absl::c_is_sorted(sorted_, std::greater<int>()));
504  EXPECT_FALSE(absl::c_is_sorted(unsorted_, std::greater<int>()));
505  EXPECT_TRUE(absl::c_is_sorted(reversed_, std::greater<int>()));
506 }
507 
508 TEST_F(SortingTest, IsSortedUntil) {
509  EXPECT_EQ(1, *absl::c_is_sorted_until(unsorted_));
510  EXPECT_EQ(4, *absl::c_is_sorted_until(unsorted_, std::greater<int>()));
511 }
512 
513 TEST_F(SortingTest, NthElement) {
514  std::vector<int> unsorted = {2, 4, 1, 3};
515  absl::c_nth_element(unsorted, unsorted.begin() + 2);
516  EXPECT_THAT(unsorted,
517  ElementsAre(Lt(3), Lt(3), 3, Gt(3)));
518  absl::c_nth_element(unsorted, unsorted.begin() + 2, std::greater<int>());
519  EXPECT_THAT(unsorted,
520  ElementsAre(Gt(2), Gt(2), 2, Lt(2)));
521 }
522 
523 TEST(MutatingTest, IsPartitioned) {
524  EXPECT_TRUE(
525  absl::c_is_partitioned(std::vector<int>{1, 3, 5, 2, 4, 6}, IsOdd));
526  EXPECT_FALSE(
527  absl::c_is_partitioned(std::vector<int>{1, 2, 3, 4, 5, 6}, IsOdd));
528  EXPECT_FALSE(
529  absl::c_is_partitioned(std::vector<int>{2, 4, 6, 1, 3, 5}, IsOdd));
530 }
531 
532 TEST(MutatingTest, Partition) {
533  std::vector<int> actual = {1, 2, 3, 4, 5};
534  absl::c_partition(actual, IsOdd);
535  EXPECT_THAT(actual, Truly([](const std::vector<int>& c) {
536  return absl::c_is_partitioned(c, IsOdd);
537  }));
538 }
539 
540 TEST(MutatingTest, StablePartition) {
541  std::vector<int> actual = {1, 2, 3, 4, 5};
542  absl::c_stable_partition(actual, IsOdd);
543  EXPECT_THAT(actual, ElementsAre(1, 3, 5, 2, 4));
544 }
545 
546 TEST(MutatingTest, PartitionCopy) {
547  const std::vector<int> initial = {1, 2, 3, 4, 5};
548  std::vector<int> odds, evens;
549  auto ends = absl::c_partition_copy(initial, back_inserter(odds),
550  back_inserter(evens), IsOdd);
551  *ends.first = 7;
552  *ends.second = 6;
553  EXPECT_THAT(odds, ElementsAre(1, 3, 5, 7));
554  EXPECT_THAT(evens, ElementsAre(2, 4, 6));
555 }
556 
557 TEST(MutatingTest, PartitionPoint) {
558  const std::vector<int> initial = {1, 3, 5, 2, 4};
559  auto middle = absl::c_partition_point(initial, IsOdd);
560  EXPECT_EQ(2, *middle);
561 }
562 
563 TEST(MutatingTest, CopyMiddle) {
564  const std::vector<int> initial = {4, -1, -2, -3, 5};
565  const std::list<int> input = {1, 2, 3};
566  const std::vector<int> expected = {4, 1, 2, 3, 5};
567 
568  std::list<int> test_list(initial.begin(), initial.end());
569  absl::c_copy(input, ++test_list.begin());
570  EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
571 
572  std::vector<int> test_vector = initial;
573  absl::c_copy(input, test_vector.begin() + 1);
574  EXPECT_EQ(expected, test_vector);
575 }
576 
577 TEST(MutatingTest, CopyFrontInserter) {
578  const std::list<int> initial = {4, 5};
579  const std::list<int> input = {1, 2, 3};
580  const std::list<int> expected = {3, 2, 1, 4, 5};
581 
582  std::list<int> test_list = initial;
583  absl::c_copy(input, std::front_inserter(test_list));
584  EXPECT_EQ(expected, test_list);
585 }
586 
587 TEST(MutatingTest, CopyBackInserter) {
588  const std::vector<int> initial = {4, 5};
589  const std::list<int> input = {1, 2, 3};
590  const std::vector<int> expected = {4, 5, 1, 2, 3};
591 
592  std::list<int> test_list(initial.begin(), initial.end());
593  absl::c_copy(input, std::back_inserter(test_list));
594  EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
595 
596  std::vector<int> test_vector = initial;
597  absl::c_copy(input, std::back_inserter(test_vector));
598  EXPECT_EQ(expected, test_vector);
599 }
600 
601 TEST(MutatingTest, CopyN) {
602  const std::vector<int> initial = {1, 2, 3, 4, 5};
603  const std::vector<int> expected = {1, 2};
604  std::vector<int> actual;
605  absl::c_copy_n(initial, 2, back_inserter(actual));
606  EXPECT_EQ(expected, actual);
607 }
608 
609 TEST(MutatingTest, CopyIf) {
610  const std::list<int> input = {1, 2, 3};
611  std::vector<int> output;
612  absl::c_copy_if(input, std::back_inserter(output),
613  [](int i) { return i != 2; });
614  EXPECT_THAT(output, ElementsAre(1, 3));
615 }
616 
617 TEST(MutatingTest, CopyBackward) {
618  std::vector<int> actual = {1, 2, 3, 4, 5};
619  std::vector<int> expected = {1, 2, 1, 2, 3};
620  absl::c_copy_backward(absl::MakeSpan(actual.data(), 3), actual.end());
621  EXPECT_EQ(expected, actual);
622 }
623 
624 TEST(MutatingTest, Move) {
625  std::vector<std::unique_ptr<int>> src;
626  src.emplace_back(absl::make_unique<int>(1));
627  src.emplace_back(absl::make_unique<int>(2));
628  src.emplace_back(absl::make_unique<int>(3));
629  src.emplace_back(absl::make_unique<int>(4));
630  src.emplace_back(absl::make_unique<int>(5));
631 
632  std::vector<std::unique_ptr<int>> dest = {};
633  absl::c_move(src, std::back_inserter(dest));
634  EXPECT_THAT(src, Each(IsNull()));
635  EXPECT_THAT(dest, ElementsAre(Pointee(1), Pointee(2), Pointee(3), Pointee(4),
636  Pointee(5)));
637 }
638 
639 TEST(MutatingTest, MoveWithRvalue) {
640  auto MakeRValueSrc = [] {
641  std::vector<std::unique_ptr<int>> src;
642  src.emplace_back(absl::make_unique<int>(1));
643  src.emplace_back(absl::make_unique<int>(2));
644  src.emplace_back(absl::make_unique<int>(3));
645  return src;
646  };
647 
648  std::vector<std::unique_ptr<int>> dest = MakeRValueSrc();
649  absl::c_move(MakeRValueSrc(), std::back_inserter(dest));
650  EXPECT_THAT(dest, ElementsAre(Pointee(1), Pointee(2), Pointee(3), Pointee(1),
651  Pointee(2), Pointee(3)));
652 }
653 
654 TEST(MutatingTest, SwapRanges) {
655  std::vector<int> odds = {2, 4, 6};
656  std::vector<int> evens = {1, 3, 5};
657  absl::c_swap_ranges(odds, evens);
658  EXPECT_THAT(odds, ElementsAre(1, 3, 5));
659  EXPECT_THAT(evens, ElementsAre(2, 4, 6));
660 }
661 
662 TEST_F(NonMutatingTest, Transform) {
663  std::vector<int> x{0, 2, 4}, y, z;
664  auto end = absl::c_transform(x, back_inserter(y), std::negate<int>());
665  EXPECT_EQ(std::vector<int>({0, -2, -4}), y);
666  *end = 7;
667  EXPECT_EQ(std::vector<int>({0, -2, -4, 7}), y);
668 
669  y = {1, 3, 0};
670  end = absl::c_transform(x, y, back_inserter(z), std::plus<int>());
671  EXPECT_EQ(std::vector<int>({1, 5, 4}), z);
672  *end = 7;
673  EXPECT_EQ(std::vector<int>({1, 5, 4, 7}), z);
674 }
675 
676 TEST(MutatingTest, Replace) {
677  const std::vector<int> initial = {1, 2, 3, 1, 4, 5};
678  const std::vector<int> expected = {4, 2, 3, 4, 4, 5};
679 
680  std::vector<int> test_vector = initial;
681  absl::c_replace(test_vector, 1, 4);
682  EXPECT_EQ(expected, test_vector);
683 
684  std::list<int> test_list(initial.begin(), initial.end());
685  absl::c_replace(test_list, 1, 4);
686  EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
687 }
688 
689 TEST(MutatingTest, ReplaceIf) {
690  std::vector<int> actual = {1, 2, 3, 4, 5};
691  const std::vector<int> expected = {0, 2, 0, 4, 0};
692 
693  absl::c_replace_if(actual, IsOdd, 0);
694  EXPECT_EQ(expected, actual);
695 }
696 
697 TEST(MutatingTest, ReplaceCopy) {
698  const std::vector<int> initial = {1, 2, 3, 1, 4, 5};
699  const std::vector<int> expected = {4, 2, 3, 4, 4, 5};
700 
701  std::vector<int> actual;
702  absl::c_replace_copy(initial, back_inserter(actual), 1, 4);
703  EXPECT_EQ(expected, actual);
704 }
705 
706 TEST(MutatingTest, Sort) {
707  std::vector<int> test_vector = {2, 3, 1, 4};
708  absl::c_sort(test_vector);
709  EXPECT_THAT(test_vector, ElementsAre(1, 2, 3, 4));
710 }
711 
712 TEST(MutatingTest, SortWithPredicate) {
713  std::vector<int> test_vector = {2, 3, 1, 4};
714  absl::c_sort(test_vector, std::greater<int>());
715  EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1));
716 }
717 
718 // For absl::c_stable_sort tests. Needs an operator< that does not cover all
719 // fields so that the test can check the sort preserves order of equal elements.
720 struct Element {
721  int key;
722  int value;
723  friend bool operator<(const Element& e1, const Element& e2) {
724  return e1.key < e2.key;
725  }
726  // Make gmock print useful diagnostics.
727  friend std::ostream& operator<<(std::ostream& o, const Element& e) {
728  return o << "{" << e.key << ", " << e.value << "}";
729  }
730 };
731 
732 MATCHER_P2(IsElement, key, value, "") {
733  return arg.key == key && arg.value == value;
734 }
735 
736 TEST(MutatingTest, StableSort) {
737  std::vector<Element> test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}};
738  absl::c_stable_sort(test_vector);
739  EXPECT_THAT(
740  test_vector,
741  ElementsAre(IsElement(1, 1), IsElement(1, 0), IsElement(2, 1),
742  IsElement(2, 0), IsElement(2, 2)));
743 }
744 
745 TEST(MutatingTest, StableSortWithPredicate) {
746  std::vector<Element> test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}};
747  absl::c_stable_sort(test_vector, [](const Element& e1, const Element& e2) {
748  return e2 < e1;
749  });
750  EXPECT_THAT(
751  test_vector,
752  ElementsAre(IsElement(2, 1), IsElement(2, 0), IsElement(2, 2),
753  IsElement(1, 1), IsElement(1, 0)));
754 }
755 
756 TEST(MutatingTest, ReplaceCopyIf) {
757  const std::vector<int> initial = {1, 2, 3, 4, 5};
758  const std::vector<int> expected = {0, 2, 0, 4, 0};
759 
760  std::vector<int> actual;
761  absl::c_replace_copy_if(initial, back_inserter(actual), IsOdd, 0);
762  EXPECT_EQ(expected, actual);
763 }
764 
765 TEST(MutatingTest, Fill) {
766  std::vector<int> actual(5);
767  absl::c_fill(actual, 1);
768  EXPECT_THAT(actual, ElementsAre(1, 1, 1, 1, 1));
769 }
770 
771 TEST(MutatingTest, FillN) {
772  std::vector<int> actual(5, 0);
773  absl::c_fill_n(actual, 2, 1);
774  EXPECT_THAT(actual, ElementsAre(1, 1, 0, 0, 0));
775 }
776 
777 TEST(MutatingTest, Generate) {
778  std::vector<int> actual(5);
779  int x = 0;
780  absl::c_generate(actual, [&x]() { return ++x; });
781  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
782 }
783 
784 TEST(MutatingTest, GenerateN) {
785  std::vector<int> actual(5, 0);
786  int x = 0;
787  absl::c_generate_n(actual, 3, [&x]() { return ++x; });
788  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 0, 0));
789 }
790 
791 TEST(MutatingTest, RemoveCopy) {
792  std::vector<int> actual;
793  absl::c_remove_copy(std::vector<int>{1, 2, 3}, back_inserter(actual), 2);
794  EXPECT_THAT(actual, ElementsAre(1, 3));
795 }
796 
797 TEST(MutatingTest, RemoveCopyIf) {
798  std::vector<int> actual;
799  absl::c_remove_copy_if(std::vector<int>{1, 2, 3}, back_inserter(actual),
800  IsOdd);
801  EXPECT_THAT(actual, ElementsAre(2));
802 }
803 
804 TEST(MutatingTest, UniqueCopy) {
805  std::vector<int> actual;
806  absl::c_unique_copy(std::vector<int>{1, 2, 2, 2, 3, 3, 2},
807  back_inserter(actual));
808  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 2));
809 }
810 
811 TEST(MutatingTest, UniqueCopyWithPredicate) {
812  std::vector<int> actual;
813  absl::c_unique_copy(std::vector<int>{1, 2, 3, -1, -2, -3, 1},
814  back_inserter(actual),
815  [](int x, int y) { return (x < 0) == (y < 0); });
816  EXPECT_THAT(actual, ElementsAre(1, -1, 1));
817 }
818 
819 TEST(MutatingTest, Reverse) {
820  std::vector<int> test_vector = {1, 2, 3, 4};
821  absl::c_reverse(test_vector);
822  EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1));
823 
824  std::list<int> test_list = {1, 2, 3, 4};
825  absl::c_reverse(test_list);
826  EXPECT_THAT(test_list, ElementsAre(4, 3, 2, 1));
827 }
828 
829 TEST(MutatingTest, ReverseCopy) {
830  std::vector<int> actual;
831  absl::c_reverse_copy(std::vector<int>{1, 2, 3, 4}, back_inserter(actual));
832  EXPECT_THAT(actual, ElementsAre(4, 3, 2, 1));
833 }
834 
835 TEST(MutatingTest, Rotate) {
836  std::vector<int> actual = {1, 2, 3, 4};
837  auto it = absl::c_rotate(actual, actual.begin() + 2);
838  EXPECT_THAT(actual, testing::ElementsAreArray({3, 4, 1, 2}));
839  EXPECT_EQ(*it, 1);
840 }
841 
842 TEST(MutatingTest, RotateCopy) {
843  std::vector<int> initial = {1, 2, 3, 4};
844  std::vector<int> actual;
845  auto end =
846  absl::c_rotate_copy(initial, initial.begin() + 2, back_inserter(actual));
847  *end = 5;
848  EXPECT_THAT(actual, ElementsAre(3, 4, 1, 2, 5));
849 }
850 
851 TEST(MutatingTest, Shuffle) {
852  std::vector<int> actual = {1, 2, 3, 4, 5};
853  absl::c_shuffle(actual, std::random_device());
854  EXPECT_THAT(actual, UnorderedElementsAre(1, 2, 3, 4, 5));
855 }
856 
857 TEST(MutatingTest, PartialSort) {
858  std::vector<int> sequence{5, 3, 42, 0};
859  absl::c_partial_sort(sequence, sequence.begin() + 2);
860  EXPECT_THAT(absl::MakeSpan(sequence.data(), 2), ElementsAre(0, 3));
861  absl::c_partial_sort(sequence, sequence.begin() + 2, std::greater<int>());
862  EXPECT_THAT(absl::MakeSpan(sequence.data(), 2), ElementsAre(42, 5));
863 }
864 
865 TEST(MutatingTest, PartialSortCopy) {
866  const std::vector<int> initial = {5, 3, 42, 0};
867  std::vector<int> actual(2);
868  absl::c_partial_sort_copy(initial, actual);
869  EXPECT_THAT(actual, ElementsAre(0, 3));
870  absl::c_partial_sort_copy(initial, actual, std::greater<int>());
871  EXPECT_THAT(actual, ElementsAre(42, 5));
872 }
873 
874 TEST(MutatingTest, Merge) {
875  std::vector<int> actual;
876  absl::c_merge(std::vector<int>{1, 3, 5}, std::vector<int>{2, 4},
877  back_inserter(actual));
878  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
879 }
880 
881 TEST(MutatingTest, MergeWithComparator) {
882  std::vector<int> actual;
883  absl::c_merge(std::vector<int>{5, 3, 1}, std::vector<int>{4, 2},
884  back_inserter(actual), std::greater<int>());
885  EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1));
886 }
887 
888 TEST(MutatingTest, InplaceMerge) {
889  std::vector<int> actual = {1, 3, 5, 2, 4};
890  absl::c_inplace_merge(actual, actual.begin() + 3);
891  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
892 }
893 
894 TEST(MutatingTest, InplaceMergeWithComparator) {
895  std::vector<int> actual = {5, 3, 1, 4, 2};
896  absl::c_inplace_merge(actual, actual.begin() + 3, std::greater<int>());
897  EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1));
898 }
899 
900 class SetOperationsTest : public testing::Test {
901  protected:
902  std::vector<int> a_ = {1, 2, 3};
903  std::vector<int> b_ = {1, 3, 5};
904 
905  std::vector<int> a_reversed_ = {3, 2, 1};
906  std::vector<int> b_reversed_ = {5, 3, 1};
907 };
908 
909 TEST_F(SetOperationsTest, SetUnion) {
910  std::vector<int> actual;
911  absl::c_set_union(a_, b_, back_inserter(actual));
912  EXPECT_THAT(actual, ElementsAre(1, 2, 3, 5));
913 }
914 
915 TEST_F(SetOperationsTest, SetUnionWithComparator) {
916  std::vector<int> actual;
917  absl::c_set_union(a_reversed_, b_reversed_, back_inserter(actual),
918  std::greater<int>());
919  EXPECT_THAT(actual, ElementsAre(5, 3, 2, 1));
920 }
921 
922 TEST_F(SetOperationsTest, SetIntersection) {
923  std::vector<int> actual;
924  absl::c_set_intersection(a_, b_, back_inserter(actual));
925  EXPECT_THAT(actual, ElementsAre(1, 3));
926 }
927 
928 TEST_F(SetOperationsTest, SetIntersectionWithComparator) {
929  std::vector<int> actual;
930  absl::c_set_intersection(a_reversed_, b_reversed_, back_inserter(actual),
931  std::greater<int>());
932  EXPECT_THAT(actual, ElementsAre(3, 1));
933 }
934 
935 TEST_F(SetOperationsTest, SetDifference) {
936  std::vector<int> actual;
937  absl::c_set_difference(a_, b_, back_inserter(actual));
938  EXPECT_THAT(actual, ElementsAre(2));
939 }
940 
941 TEST_F(SetOperationsTest, SetDifferenceWithComparator) {
942  std::vector<int> actual;
943  absl::c_set_difference(a_reversed_, b_reversed_, back_inserter(actual),
944  std::greater<int>());
945  EXPECT_THAT(actual, ElementsAre(2));
946 }
947 
948 TEST_F(SetOperationsTest, SetSymmetricDifference) {
949  std::vector<int> actual;
950  absl::c_set_symmetric_difference(a_, b_, back_inserter(actual));
951  EXPECT_THAT(actual, ElementsAre(2, 5));
952 }
953 
954 TEST_F(SetOperationsTest, SetSymmetricDifferenceWithComparator) {
955  std::vector<int> actual;
956  absl::c_set_symmetric_difference(a_reversed_, b_reversed_,
957  back_inserter(actual), std::greater<int>());
958  EXPECT_THAT(actual, ElementsAre(5, 2));
959 }
960 
961 TEST(HeapOperationsTest, WithoutComparator) {
962  std::vector<int> heap = {1, 2, 3};
963  EXPECT_FALSE(absl::c_is_heap(heap));
964  absl::c_make_heap(heap);
965  EXPECT_TRUE(absl::c_is_heap(heap));
966  heap.push_back(4);
967  EXPECT_EQ(3, absl::c_is_heap_until(heap) - heap.begin());
968  absl::c_push_heap(heap);
969  EXPECT_EQ(4, heap[0]);
970  absl::c_pop_heap(heap);
971  EXPECT_EQ(4, heap[3]);
972  absl::c_make_heap(heap);
973  absl::c_sort_heap(heap);
974  EXPECT_THAT(heap, ElementsAre(1, 2, 3, 4));
975  EXPECT_FALSE(absl::c_is_heap(heap));
976 }
977 
978 TEST(HeapOperationsTest, WithComparator) {
979  using greater = std::greater<int>;
980  std::vector<int> heap = {3, 2, 1};
981  EXPECT_FALSE(absl::c_is_heap(heap, greater()));
982  absl::c_make_heap(heap, greater());
983  EXPECT_TRUE(absl::c_is_heap(heap, greater()));
984  heap.push_back(0);
985  EXPECT_EQ(3, absl::c_is_heap_until(heap, greater()) - heap.begin());
986  absl::c_push_heap(heap, greater());
987  EXPECT_EQ(0, heap[0]);
988  absl::c_pop_heap(heap, greater());
989  EXPECT_EQ(0, heap[3]);
990  absl::c_make_heap(heap, greater());
991  absl::c_sort_heap(heap, greater());
992  EXPECT_THAT(heap, ElementsAre(3, 2, 1, 0));
993  EXPECT_FALSE(absl::c_is_heap(heap, greater()));
994 }
995 
996 TEST(MutatingTest, PermutationOperations) {
997  std::vector<int> initial = {1, 2, 3, 4};
998  std::vector<int> permuted = initial;
999 
1000  absl::c_next_permutation(permuted);
1001  EXPECT_TRUE(absl::c_is_permutation(initial, permuted));
1002  EXPECT_TRUE(absl::c_is_permutation(initial, permuted, std::equal_to<int>()));
1003 
1004  std::vector<int> permuted2 = initial;
1005  absl::c_prev_permutation(permuted2, std::greater<int>());
1006  EXPECT_EQ(permuted, permuted2);
1007 
1008  absl::c_prev_permutation(permuted);
1009  EXPECT_EQ(initial, permuted);
1010 }
1011 
1012 } // namespace
int v
Definition: variant_test.cc:81
void c_iota(Sequence &sequence, T &&value)
Definition: container.h:1589
BidirectionalIterator c_copy_backward(const C &src, BidirectionalIterator dest)
Definition: container.h:497
bool c_is_partitioned(const C &c, Pred &&pred)
Definition: container.h:767
container_algorithm_internal::ContainerIter< C1 > c_find_first_of(C1 &container, C2 &options)
Definition: container.h:261
void c_replace(Sequence &sequence, const T &old_value, const T &new_value)
Definition: container.h:557
OutputIterator c_replace_copy_if(const C &c, OutputIterator result, Pred &&pred, T &&new_value)
Definition: container.h:595
char * begin
void c_pop_heap(RandomAccessContainer &sequence)
Definition: container.h:1343
void c_shuffle(RandomAccessContainer &c, UniformRandomBitGenerator &&gen)
Definition: container.h:751
OutputIterator c_merge(const C1 &c1, const C2 &c2, OutputIterator result)
Definition: container.h:1097
container_algorithm_internal::ContainerDifferenceType< const C > c_count(const C &c, T &&value)
Definition: container.h:307
container_algorithm_internal::ContainerIter< RandomAccessContainer > c_partial_sort_copy(const C &sequence, RandomAccessContainer &result)
Definition: container.h:925
bool operator<(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
container_algorithm_internal::ContainerIter< Sequence > c_max_element(Sequence &sequence)
Definition: container.h:1467
OutputIterator c_copy_n(const C &input, Size n, OutputIterator output)
Definition: container.h:476
container_algorithm_internal::ContainerIterPairType< C, C > c_minmax_element(C &c)
Definition: container.h:1491
bool c_any_of(const C &c, Pred &&pred)
Definition: container.h:169
void c_reverse(Sequence &sequence)
Definition: container.h:702
bool c_is_permutation(const C1 &c1, const C2 &c2)
Definition: container.h:390
container_algorithm_internal::ContainerIter< C2 > c_swap_ranges(C1 &c1, C2 &c2)
Definition: container.h:518
Iterator c_rotate(C &sequence, Iterator middle)
Definition: container.h:725
void c_nth_element(RandomAccessContainer &sequence, container_algorithm_internal::ContainerIter< RandomAccessContainer > nth)
Definition: container.h:974
std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
Definition: log_severity.cc:21
bool c_lexicographical_compare(Sequence1 &&sequence1, Sequence2 &&sequence2)
Definition: container.h:1518
container_algorithm_internal::ContainerIter< C > c_partition_point(C &c, Pred &&pred)
Definition: container.h:823
container_algorithm_internal::ContainerIter< Sequence1 > c_search(Sequence1 &sequence, Sequence2 &subsequence)
Definition: container.h:413
container_algorithm_internal::ContainerIter< C > c_find(C &c, T &&value)
Definition: container.h:202
container_algorithm_internal::ContainerIter< C > c_stable_partition(C &c, Pred &&pred)
Definition: container.h:794
container_algorithm_internal::ContainerDifferenceType< const C > c_count_if(const C &c, Pred &&pred)
Definition: container.h:319
void c_fill_n(C &c, Size n, T &&value)
Definition: container.h:618
container_algorithm_internal::ContainerIter< RandomAccessContainer > c_is_heap_until(RandomAccessContainer &sequence)
Definition: container.h:1420
char * end
void c_sort_heap(RandomAccessContainer &sequence)
Definition: container.h:1381
decay_t< Function > c_for_each(C &&c, Function &&f)
Definition: container.h:191
OutputIterator c_remove_copy_if(const C &c, OutputIterator result, Pred &&pred)
Definition: container.h:669
container_algorithm_internal::ContainerIter< C > c_generate_n(C &c, Size n, Generator &&gen)
Definition: container.h:640
container_algorithm_internal::ContainerDifferenceType< const C > c_distance(const C &c)
Definition: container.h:143
OutputIterator c_remove_copy(const C &c, OutputIterator result, T &&value)
Definition: container.h:657
decay_t< T > c_inner_product(const Sequence1 &factors1, const Sequence2 &factors2, T &&sum)
Definition: container.h:1630
bool c_equal(const C1 &c1, const C2 &c2)
Definition: container.h:367
container_algorithm_internal::ContainerIter< Sequence > c_adjacent_find(Sequence &sequence)
Definition: container.h:286
void c_make_heap(RandomAccessContainer &sequence)
Definition: container.h:1362
bool c_prev_permutation(C &c)
Definition: container.h:1565
constexpr To implicit_cast(typename absl::internal::identity_t< To > to)
Definition: casts.h:101
OutputIterator c_rotate_copy(const C &sequence, container_algorithm_internal::ContainerIter< const C > middle, OutputIterator result)
Definition: container.h:736
static void Sort(const Vec< Node * > &, Vec< int32_t > *delta)
Definition: graphcycles.cc:601
OutputIterator c_reverse_copy(const C &sequence, OutputIterator result)
Definition: container.h:712
std::pair< OutputIterator1, OutputIterator2 > c_partition_copy(const C &c, OutputIterator1 out_true, OutputIterator2 out_false, Pred &&pred)
Definition: container.h:809
container_algorithm_internal::ContainerIterPairType< C1, C2 > c_mismatch(C1 &c1, C2 &c2)
Definition: container.h:332
OutputIterator c_copy(const InputSequence &input, OutputIterator output)
Definition: container.h:466
OutputIterator c_set_symmetric_difference(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: container.h:1286
size_t value
OutputIterator c_copy_if(const InputSequence &input, OutputIterator output, Pred &&pred)
Definition: container.h:485
OutputIterator c_unique_copy(const C &c, OutputIterator result)
Definition: container.h:682
TEST_F(GraphCyclesTest, NoCycle)
static uint64_t Rotate(uint64_t val, int shift)
Definition: city.cc:195
bool c_includes(const C1 &c1, const C2 &c2)
Definition: container.h:1144
bool c_binary_search(Sequence &&sequence, T &&value)
Definition: container.h:1072
void c_inplace_merge(C &c, container_algorithm_internal::ContainerIter< C > middle)
Definition: container.h:1121
void c_fill(C &c, T &&value)
Definition: container.h:608
container_algorithm_internal::ContainerIterPairType< Sequence, Sequence > c_equal_range(Sequence &sequence, T &&value)
Definition: container.h:1050
OutputIterator c_move(C &&src, OutputIterator dest)
Definition: container.h:508
bool c_linear_search(const C &c, EqualityComparable &&value)
Definition: container.h:128
bool c_all_of(const C &c, Pred &&pred)
Definition: container.h:158
container_algorithm_internal::ContainerIter< C > c_find_if(C &c, Pred &&pred)
Definition: container.h:213
UnboundConversion o
Definition: parser_test.cc:86
OutputIt c_adjacent_difference(const InputSequence &input, OutputIt output_first)
Definition: container.h:1658
container_algorithm_internal::ContainerIter< Sequence > c_search_n(Sequence &sequence, Size count, T &&value)
Definition: container.h:438
bool c_next_permutation(C &c)
Definition: container.h:1545
container_algorithm_internal::ContainerIter< Sequence > c_min_element(Sequence &sequence)
Definition: container.h:1445
static const uint32_t c2
Definition: city.cc:58
constexpr bool AllOf()
Definition: checker.h:20
OutputIterator c_replace_copy(const C &c, OutputIterator result, T &&old_value, T &&new_value)
Definition: container.h:581
bool c_is_heap(const RandomAccessContainer &sequence)
Definition: container.h:1400
void * arg
Definition: mutex.cc:292
void c_push_heap(RandomAccessContainer &sequence)
Definition: container.h:1324
void c_generate(C &c, Generator &&gen)
Definition: container.h:628
#define ABSL_ARRAYSIZE(array)
Definition: macros.h:42
container_algorithm_internal::ContainerIter< Sequence > c_upper_bound(Sequence &sequence, T &&value)
Definition: container.h:1026
OutputIterator c_set_intersection(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: container.h:1210
OutputIt c_partial_sum(const InputSequence &input, OutputIt output_first)
Definition: container.h:1682
OutputIterator c_transform(const InputSequence &input, OutputIterator output, UnaryOp &&unary_op)
Definition: container.h:531
container_algorithm_internal::ContainerIter< Sequence1 > c_find_end(Sequence1 &sequence, Sequence2 &subsequence)
Definition: container.h:236
decay_t< T > c_accumulate(const Sequence &sequence, T &&init)
Definition: container.h:1604
void c_partial_sort(RandomAccessContainer &sequence, container_algorithm_internal::ContainerIter< RandomAccessContainer > middle)
Definition: container.h:898
OutputIterator c_set_union(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: container.h:1174
TEST(Symbolize, Unimplemented)
void c_stable_sort(C &c)
Definition: container.h:859
bool c_is_sorted(const C &c)
Definition: container.h:878
void c_replace_if(C &c, Pred &&pred, T &&new_value)
Definition: container.h:569
constexpr Span< T > MakeSpan(T *ptr, size_t size) noexcept
Definition: span.h:647
uint64_t b
Definition: layout_test.cc:50
container_algorithm_internal::ContainerIter< C > c_partition(C &c, Pred &&pred)
Definition: container.h:780
container_algorithm_internal::ContainerIter< C > c_find_if_not(C &c, Pred &&pred)
Definition: container.h:224
void c_sort(C &c)
Definition: container.h:839
container_algorithm_internal::ContainerIter< Sequence > c_lower_bound(Sequence &sequence, T &&value)
Definition: container.h:1003
OutputIterator c_set_difference(const C1 &c1, const C2 &c2, OutputIterator output)
Definition: container.h:1248
bool c_none_of(const C &c, Pred &&pred)
Definition: container.h:180
container_algorithm_internal::ContainerIter< C > c_is_sorted_until(C &c)
Definition: container.h:951


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:19:56