15 #include "absl/container/inlined_vector.h"
18 #include <forward_list>
21 #include <scoped_allocator>
27 #include "gmock/gmock.h"
28 #include "gtest/gtest.h"
29 #include "absl/base/attributes.h"
30 #include "absl/base/internal/exception_testing.h"
31 #include "absl/base/internal/raw_logging.h"
32 #include "absl/base/macros.h"
33 #include "absl/base/options.h"
34 #include "absl/container/internal/counting_allocator.h"
35 #include "absl/container/internal/test_instance_tracker.h"
36 #include "absl/hash/hash_testing.h"
37 #include "absl/memory/memory.h"
38 #include "absl/strings/str_cat.h"
91 friend void swap(RefCounted&
a, RefCounted&
b) {
97 RefCounted& operator=(RefCounted
v) {
122 virtual ~Dynamic() {}
128 template <
typename Container>
129 static void Fill(Container*
v,
int len,
int offset = 0) {
130 for (
int i = 0;
i <
len;
i++) {
135 static IntVec Fill(
int len,
int offset = 0) {
141 TEST(IntVec, SimpleOps) {
144 const IntVec&
cv =
v;
150 for (
int i = 0;
i <
len;
i++) {
165 for (IntVec::const_iterator
iter =
v.begin();
iter !=
v.end(); ++
iter) {
172 for (IntVec::const_iterator
iter =
v.cbegin();
iter !=
v.cend(); ++
iter) {
183 for (
int i = 0;
i <
v.size(); ++
i) {
191 TEST(IntVec, PopBackNoOverflow) {
197 TEST(IntVec, AtThrows) {
198 IntVec
v = {1, 2, 3};
201 "failed bounds check");
210 for (IntVec::reverse_iterator
iter =
v.rbegin();
iter !=
v.rend(); ++
iter) {
217 for (IntVec::const_reverse_iterator
iter =
v.rbegin();
iter !=
v.rend();
225 for (IntVec::const_reverse_iterator
iter =
v.crbegin();
iter !=
v.crend();
234 TEST(IntVec, Erase) {
236 for (
int i = 0;
i <
len; ++
i) {
239 v.erase(
v.begin() +
i);
241 for (
int j = 0;
j <
i; ++
j) {
244 for (
int j =
i;
j <
len - 1; ++
j) {
251 TEST(IntVec, Hardened) {
255 #if !defined(NDEBUG) || ABSL_OPTION_HARDENED
264 TEST(RefCountedVec, EraseBeginEnd) {
266 for (
int erase_begin = 0; erase_begin <
len; ++erase_begin) {
267 for (
int erase_end = erase_begin; erase_end <=
len; ++erase_end) {
268 std::vector<int> counts(
len, 0);
270 for (
int i = 0;
i <
len; ++
i) {
271 v.push_back(RefCounted(
i, &counts[
i]));
274 int erase_len = erase_end - erase_begin;
276 v.erase(
v.begin() + erase_begin,
v.begin() + erase_end);
281 for (
int i = 0;
i < erase_begin; ++
i) {
286 for (
int i = erase_begin;
i <
v.size(); ++
i) {
291 for (
int i = 0;
i < erase_begin; ++
i) {
296 for (
int i = erase_begin;
i < erase_end; ++
i) {
301 for (
int i = erase_end;
i <
len; ++
i) {
309 struct NoDefaultCtor {
310 explicit NoDefaultCtor(
int) {}
314 NoCopy(
const NoCopy&) =
delete;
318 NoAssign& operator=(
const NoAssign&) =
delete;
322 MoveOnly(MoveOnly&&) =
default;
323 MoveOnly& operator=(MoveOnly&&) =
default;
325 TEST(InlinedVectorTest, NoDefaultCtor) {
329 TEST(InlinedVectorTest, NoCopy) {
333 TEST(InlinedVectorTest, NoAssign) {
337 TEST(InlinedVectorTest, MoveOnly) {
339 v.push_back(MoveOnly{});
340 v.push_back(MoveOnly{});
341 v.push_back(MoveOnly{});
343 v.push_back(MoveOnly{});
344 v.erase(
v.begin(),
v.begin() + 1);
345 v.insert(
v.begin(), MoveOnly{});
346 v.emplace(
v.begin());
347 v.emplace(
v.begin(), MoveOnly{});
349 TEST(InlinedVectorTest, Noexcept) {
354 struct MoveCanThrow {
355 MoveCanThrow(MoveCanThrow&&) {}
358 (std::is_nothrow_move_constructible<
362 TEST(InlinedVectorTest, EmplaceBack) {
365 auto& inlined_element =
v.emplace_back(
"answer", 42);
367 EXPECT_EQ(inlined_element.first,
"answer");
370 auto& allocated_element =
v.emplace_back(
"taxicab", 1729);
372 EXPECT_EQ(allocated_element.first,
"taxicab");
373 EXPECT_EQ(allocated_element.second, 1729);
376 TEST(InlinedVectorTest, ShrinkToFitGrowingVector) {
382 v.emplace_back(
"answer", 42);
386 v.emplace_back(
"taxicab", 1729);
397 TEST(InlinedVectorTest, ShrinkToFitEdgeCases) {
400 v.emplace_back(
"answer", 42);
401 v.emplace_back(
"taxicab", 1729);
444 std::vector<int> std_v;
449 std_v.insert(std_v.begin() +
pos, 9999);
456 std::vector<int> std_v;
461 IntVec::size_type
n = 5;
462 std_v.insert(std_v.begin() +
pos,
n, 9999);
469 std::vector<int> std_v;
474 const std::vector<int>
input = {9999, 8888, 7777};
475 std_v.insert(std_v.begin() +
pos,
input.cbegin(),
input.cend());
483 std::vector<int> std_v;
488 const std::forward_list<int>
input = {9999, 8888, 7777};
489 std_v.insert(std_v.begin() +
pos,
input.cbegin(),
input.cend());
497 std::vector<int> std_v;
502 std_v.insert(std_v.begin() +
pos, {9999, 8888, 7777});
503 std::istringstream
input(
"9999 8888 7777");
505 v.insert(
v.cbegin() +
pos, std::istream_iterator<int>(
input),
506 std::istream_iterator<int>());
512 std::vector<int> std_v;
517 std_v.insert(std_v.begin() +
pos, {9999, 8888});
526 TEST(RefCountedVec, InsertConstructorDestructor) {
533 std::vector<int> counts(
len, 0);
534 int inserted_count = 0;
536 for (
int i = 0;
i <
len; ++
i) {
538 v.push_back(RefCounted(
i, &counts[
i]));
543 RefCounted insert_element(9999, &inserted_count);
545 v.insert(
v.begin() +
pos, insert_element);
554 TEST(IntVec, Resize) {
560 static const int kResizeElem = 1000000;
561 for (
int k = 0;
k < 10;
k++) {
563 v.resize(
len +
k, kResizeElem);
566 for (
int i = 0;
i <
len +
k;
i++) {
575 v.resize(
len, kResizeElem);
578 for (
int i = 0;
i <
len;
i++) {
585 TEST(IntVec, InitWithLength) {
590 for (
int i = 0;
i <
len;
i++) {
596 TEST(IntVec, CopyConstructorAndAssignment) {
606 for (
int start_len = 0; start_len < 20; start_len++) {
608 Fill(&v3, start_len, 99);
615 TEST(IntVec, AliasingCopyAssignment) {
618 Fill(&original,
len);
619 IntVec dup = original;
625 TEST(IntVec, MoveConstructorAndAssignment) {
628 const int inlined_capacity = v_in.capacity();
635 auto* old_data = v_temp.data();
638 if (v_in.size() > inlined_capacity) {
645 for (
int start_len = 0; start_len < 20; start_len++) {
647 Fill(&v_out, start_len, 99);
649 auto* old_data = v_temp.data();
652 if (v_in.size() > inlined_capacity) {
662 class NotTriviallyDestructible {
664 NotTriviallyDestructible() :
p_(
new int(1)) {}
665 explicit NotTriviallyDestructible(
int i) :
p_(
new int(
i)) {}
667 NotTriviallyDestructible(
const NotTriviallyDestructible& other)
670 NotTriviallyDestructible& operator=(
const NotTriviallyDestructible& other) {
671 p_ = absl::make_unique<int>(*other.p_);
675 bool operator==(
const NotTriviallyDestructible& other)
const {
676 return *
p_ == *other.p_;
680 std::unique_ptr<int>
p_;
683 TEST(AliasingTest, Emplace) {
684 for (
int i = 2;
i < 20; ++
i) {
686 for (
int j = 0;
j <
i; ++
j) {
687 vec.
push_back(NotTriviallyDestructible(j));
698 TEST(AliasingTest, InsertWithCount) {
699 for (
int i = 1;
i < 20; ++
i) {
701 for (
int j = 0;
j <
i; ++
j) {
702 vec.
push_back(NotTriviallyDestructible(j));
704 for (
int n = 0;
n < 5; ++
n) {
709 std::all_of(
b,
b +
n, [&vec](
const NotTriviallyDestructible&
x) {
710 return x == vec.
back();
713 auto m_idx = vec.
size() / 2;
715 auto m = vec.
begin() + m_idx;
717 std::all_of(
m,
m +
n, [&vec](
const NotTriviallyDestructible&
x) {
718 return x == vec.
back();
723 auto old_e = vec.
size() - 1;
724 auto val = vec[old_e];
726 auto e = vec.
begin() + old_e;
729 [&val](
const NotTriviallyDestructible&
x) {
return x == val; }));
734 TEST(OverheadTest, Storage) {
740 struct T {
void* val; };
741 size_t expected_overhead =
sizeof(
T);
772 TEST(IntVec, Reserve) {
777 for (
int newlen = 0; newlen < 100; newlen++) {
778 const int* start_rep =
v.data();
780 const int* final_rep =
v.data();
787 while (
v.size() < newlen) {
795 TEST(StringVec, SelfRefPushBack) {
796 std::vector<std::string> std_v;
798 const std::string s =
"A quite long string to ensure heap.";
801 for (
int i = 0;
i < 20; ++
i) {
804 v.push_back(
v.back());
805 std_v.push_back(std_v.back());
810 TEST(StringVec, SelfRefPushBackWithMove) {
811 std::vector<std::string> std_v;
813 const std::string s =
"A quite long string to ensure heap.";
816 for (
int i = 0;
i < 20; ++
i) {
820 std_v.push_back(
std::move(std_v.back()));
825 TEST(StringVec, SelfMove) {
826 const std::string s =
"A quite long string to ensure heap.";
830 for (
int i = 0;
i <
len; ++
i) {
839 std::vector<std::string>
copy(
v.begin(),
v.end());
844 for (
int l1 = 0; l1 < 20; l1++) {
846 for (
int l2 = 0; l2 < 20; l2++) {
848 IntVec
a = Fill(l1, 0);
849 IntVec
b = Fill(l2, 100);
856 for (
int i = 0;
i < l1;
i++) {
860 for (
int i = 0;
i < l2;
i++) {
869 using Instance = TypeParam;
871 for (
int l1 = 0; l1 < 20; l1++) {
873 for (
int l2 = 0; l2 < 20; l2++) {
877 const size_t inlined_capacity =
a.capacity();
880 for (
int i = 0;
i < l1;
i++)
a.push_back(Instance(
i));
881 for (
int i = 0;
i < l2;
i++)
b.push_back(Instance(100 +
i));
883 tracker.ResetCopiesMovesSwaps();
889 if (
a.size() > inlined_capacity &&
b.size() > inlined_capacity) {
892 }
else if (
a.size() <= inlined_capacity &&
b.size() <= inlined_capacity) {
906 for (
int i = 0;
i < l1;
i++) {
909 for (
int i = 0;
i < l2;
i++) {
916 TEST(IntVec, EqualAndNotEqual) {
939 for (
int i = 0;
i < 100;
i++) {
955 TEST(IntVec, RelationalOps) {
976 TYPED_TEST_P(InstanceTest, CountConstructorsDestructors) {
977 using Instance = TypeParam;
982 tracker.ResetCopiesMovesSwaps();
985 const size_t inlined_capacity =
v.capacity();
986 for (
int i = 0;
i <
len;
i++) {
987 v.push_back(Instance(
i));
992 tracker.ResetCopiesMovesSwaps();
995 tracker.ResetCopiesMovesSwaps();
996 v.resize(
len + 10, Instance(100));
998 if (len <= inlined_capacity && len + 10 > inlined_capacity) {
1008 tracker.ResetCopiesMovesSwaps();
1009 v.resize(
len, Instance(100));
1016 v.reserve(
len + 1000);
1022 tracker.ResetCopiesMovesSwaps();
1029 tracker.ResetCopiesMovesSwaps();
1036 tracker.ResetCopiesMovesSwaps();
1037 int instances_before_empty_erase =
tracker.instances();
1038 v.erase(
v.begin(),
v.begin());
1044 TYPED_TEST_P(InstanceTest, CountConstructorsDestructorsOnCopyConstruction) {
1045 using Instance = TypeParam;
1050 tracker.ResetCopiesMovesSwaps();
1053 for (
int i = 0;
i <
len;
i++) {
1054 v.push_back(Instance(
i));
1059 tracker.ResetCopiesMovesSwaps();
1061 InstanceVec v_copy(
v);
1070 TYPED_TEST_P(InstanceTest, CountConstructorsDestructorsOnMoveConstruction) {
1071 using Instance = TypeParam;
1076 tracker.ResetCopiesMovesSwaps();
1079 const size_t inlined_capacity =
v.capacity();
1080 for (
int i = 0;
i <
len;
i++) {
1081 v.push_back(Instance(
i));
1086 tracker.ResetCopiesMovesSwaps();
1089 if (
len > inlined_capacity) {
1099 if (Instance::supports_move()) {
1114 TYPED_TEST_P(InstanceTest, CountConstructorsDestructorsOnAssignment) {
1115 using Instance = TypeParam;
1120 for (
int longorshort = 0; longorshort <= 1; ++longorshort) {
1122 tracker.ResetCopiesMovesSwaps();
1124 InstanceVec longer, shorter;
1125 for (
int i = 0;
i <
len;
i++) {
1126 longer.push_back(Instance(
i));
1127 shorter.push_back(Instance(
i));
1129 longer.push_back(Instance(
len));
1134 tracker.ResetCopiesMovesSwaps();
1149 TYPED_TEST_P(InstanceTest, CountConstructorsDestructorsOnMoveAssignment) {
1150 using Instance = TypeParam;
1155 for (
int longorshort = 0; longorshort <= 1; ++longorshort) {
1157 tracker.ResetCopiesMovesSwaps();
1159 InstanceVec longer, shorter;
1160 const int inlined_capacity = longer.capacity();
1161 for (
int i = 0;
i <
len;
i++) {
1162 longer.push_back(Instance(
i));
1163 shorter.push_back(Instance(
i));
1165 longer.push_back(Instance(
len));
1170 tracker.ResetCopiesMovesSwaps();
1179 if (src_len > inlined_capacity) {
1188 if (Instance::supports_move()) {
1203 TEST(CountElemAssign, SimpleTypeWithInlineBacking) {
1204 for (
size_t original_size = 0; original_size <= 5; ++original_size) {
1207 std::vector<int> original_contents(original_size, 12345);
1210 original_contents.end());
1213 if (original_size <= 2) {
1220 TEST(CountElemAssign, SimpleTypeWithAllocation) {
1221 for (
size_t original_size = 0; original_size <= 5; ++original_size) {
1224 std::vector<int> original_contents(original_size, 12345);
1227 original_contents.end());
1234 TYPED_TEST_P(InstanceTest, CountElemAssignInlineBacking) {
1235 using Instance = TypeParam;
1236 for (
size_t original_size = 0; original_size <= 5; ++original_size) {
1239 std::vector<Instance> original_contents(original_size, Instance(12345));
1242 original_contents.end());
1243 v.assign(2, Instance(123));
1245 if (original_size <= 2) {
1252 template <
typename Instance>
1253 void InstanceCountElemAssignWithAllocationTest() {
1254 for (
size_t original_size = 0; original_size <= 5; ++original_size) {
1257 std::vector<Instance> original_contents(original_size, Instance(12345));
1260 original_contents.end());
1261 v.assign(3, Instance(123));
1267 TEST(CountElemAssign, WithAllocationCopyableInstance) {
1268 InstanceCountElemAssignWithAllocationTest<CopyableOnlyInstance>();
1270 TEST(CountElemAssign, WithAllocationCopyableMovableInstance) {
1271 InstanceCountElemAssignWithAllocationTest<CopyableMovableInstance>();
1274 TEST(RangedConstructor, SimpleType) {
1275 std::vector<int> source_v = {4, 5, 6};
1295 template <
typename Instance,
typename SourceContainer,
int inlined_capacity>
1296 void InstanceRangedConstructorTestForContainer() {
1298 SourceContainer source_v = {Instance(0), Instance(1)};
1299 tracker.ResetCopiesMovesSwaps();
1310 template <
typename Instance,
int inlined_capacity>
1311 void InstanceRangedConstructorTestWithCapacity() {
1316 InstanceRangedConstructorTestForContainer<Instance, std::list<Instance>,
1317 inlined_capacity>();
1320 InstanceRangedConstructorTestForContainer<
1321 Instance,
const std::list<Instance>, inlined_capacity>();
1325 InstanceRangedConstructorTestForContainer<Instance, std::vector<Instance>,
1326 inlined_capacity>();
1330 InstanceRangedConstructorTestForContainer<
1331 Instance,
const std::vector<Instance>, inlined_capacity>();
1337 using Instance = TypeParam;
1339 InstanceRangedConstructorTestWithCapacity<Instance, 1>();
1341 InstanceRangedConstructorTestWithCapacity<Instance, 2>();
1344 TEST(RangedConstructor, ElementsAreConstructed) {
1345 std::vector<std::string> source_v = {
"cat",
"dog"};
1354 TEST(RangedAssign, SimpleType) {
1357 for (
size_t original_size = 0; original_size <= 5; ++original_size) {
1360 std::vector<int> original_contents(original_size, 12345);
1362 for (
size_t target_size = 0; target_size <= 5; ++target_size) {
1366 std::vector<int> new_contents;
1367 for (
size_t i = 0;
i < target_size; ++
i) {
1368 new_contents.push_back(
i + 3);
1372 original_contents.end());
1373 v.assign(new_contents.begin(), new_contents.end());
1376 EXPECT_LE(new_contents.size(),
v.capacity());
1377 if (target_size <= 3 && original_size <= 3) {
1387 template <
typename Instance>
1388 static bool InstanceValuesEqual(
const Instance& lhs,
const Instance& rhs) {
1389 return lhs.value() == rhs.value();
1394 template <
typename Instance,
typename SourceContainer>
1395 void InstanceRangedAssignTestForContainer() {
1398 for (
size_t original_size = 0; original_size <= 5; ++original_size) {
1401 std::vector<Instance> original_contents(original_size, Instance(12345));
1403 for (
size_t target_size = 0; target_size <= 5; ++target_size) {
1410 std::vector<Instance> new_contents_in;
1411 for (
size_t i = 0;
i < target_size; ++
i) {
1412 new_contents_in.push_back(Instance(
i + 3));
1414 SourceContainer new_contents(new_contents_in.begin(),
1415 new_contents_in.end());
1418 original_contents.end());
1419 v.assign(new_contents.begin(), new_contents.end());
1422 EXPECT_LE(new_contents.size(),
v.capacity());
1423 if (target_size <= 3 && original_size <= 3) {
1427 EXPECT_TRUE(std::equal(
v.begin(),
v.end(), new_contents.begin(),
1428 InstanceValuesEqual<Instance>));
1434 using Instance = TypeParam;
1438 InstanceRangedAssignTestForContainer<Instance, std::list<Instance>>();
1440 InstanceRangedAssignTestForContainer<Instance, const std::list<Instance>>();
1442 InstanceRangedAssignTestForContainer<Instance, std::vector<Instance>>();
1444 InstanceRangedAssignTestForContainer<Instance, const std::vector<Instance>>();
1447 TEST(InitializerListConstructor, SimpleTypeWithInlineBacking) {
1452 TEST(InitializerListConstructor, SimpleTypeWithReallocationRequired) {
1457 TEST(InitializerListConstructor, DisparateTypesInList) {
1464 TEST(InitializerListConstructor, ComplexTypeWithInlineBacking) {
1466 CopyableMovableInstance(0)}),
1470 TEST(InitializerListConstructor, ComplexTypeWithReallocationRequired) {
1473 CopyableMovableInstance(0), CopyableMovableInstance(1)}),
1477 TEST(InitializerListAssign, SimpleTypeFitsInlineBacking) {
1478 for (
size_t original_size = 0; original_size <= 4; ++original_size) {
1482 const size_t original_capacity_v1 = v1.capacity();
1488 const size_t original_capacity_v2 = v2.capacity();
1495 TEST(InitializerListAssign, SimpleTypeDoesNotFitInlineBacking) {
1496 for (
size_t original_size = 0; original_size <= 4; ++original_size) {
1499 v1.assign({3, 4, 5});
1510 TEST(InitializerListAssign, DisparateTypesInList) {
1516 v_int2 = {-7, 8
ULL};
1529 using Instance = TypeParam;
1530 for (
size_t original_size = 0; original_size <= 4; ++original_size) {
1533 const size_t original_capacity =
v.capacity();
1534 v.assign({Instance(3)});
1538 for (
size_t original_size = 0; original_size <= 4; ++original_size) {
1541 v.assign({Instance(3), Instance(4), Instance(5)});
1549 CountConstructorsDestructorsOnCopyConstruction,
1550 CountConstructorsDestructorsOnMoveConstruction,
1551 CountConstructorsDestructorsOnAssignment,
1552 CountConstructorsDestructorsOnMoveAssignment,
1553 CountElemAssignInlineBacking, RangedConstructor,
1554 RangedAssign, InitializerListAssign);
1556 using InstanceTypes =
1561 TEST(DynamicVec, DynamicVecCompiles) {
1566 TEST(AllocatorSupportTest, Constructors) {
1567 using MyAlloc = CountingAllocator<int>;
1569 const int ia[] = {0, 1, 2, 3, 4, 5, 6, 7};
1571 MyAlloc
alloc(&allocated);
1582 TEST(AllocatorSupportTest, CountAllocations) {
1583 using MyAlloc = CountingAllocator<int>;
1585 const int ia[] = {0, 1, 2, 3, 4, 5, 6, 7};
1587 MyAlloc
alloc(&allocated);
1603 MyAlloc alloc2(&allocated2);
1604 AllocVec v2(
v, alloc2);
1608 MyAlloc alloc3(&allocated3);
1618 MyAlloc alloc2(&allocated2);
1619 AllocVec v2(
v, alloc2);
1623 MyAlloc alloc3(&allocated3);
1643 TEST(AllocatorSupportTest, SwapBothAllocated) {
1644 using MyAlloc = CountingAllocator<int>;
1649 const int ia1[] = {0, 1, 2, 3, 4, 5, 6, 7};
1650 const int ia2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1651 MyAlloc
a1(&allocated1);
1652 MyAlloc
a2(&allocated2);
1655 EXPECT_LT(v1.capacity(), v2.capacity());
1656 EXPECT_THAT(allocated1, v1.capacity() *
sizeof(
int));
1657 EXPECT_THAT(allocated2, v2.capacity() *
sizeof(
int));
1661 EXPECT_THAT(allocated1, v2.capacity() *
sizeof(
int));
1662 EXPECT_THAT(allocated2, v1.capacity() *
sizeof(
int));
1668 TEST(AllocatorSupportTest, SwapOneAllocated) {
1669 using MyAlloc = CountingAllocator<int>;
1674 const int ia1[] = {0, 1, 2, 3, 4, 5, 6, 7};
1675 const int ia2[] = {0, 1, 2, 3};
1676 MyAlloc
a1(&allocated1);
1677 MyAlloc
a2(&allocated2);
1680 EXPECT_THAT(allocated1, v1.capacity() *
sizeof(
int));
1685 EXPECT_THAT(allocated1, v2.capacity() *
sizeof(
int));
1694 TEST(AllocatorSupportTest, ScopedAllocatorWorksInlined) {
1695 using StdVector = std::vector<int, CountingAllocator<int>>;
1696 using Alloc = CountingAllocator<StdVector>;
1697 using ScopedAlloc = std::scoped_allocator_adaptor<Alloc>;
1700 int64_t total_allocated_byte_count = 0;
1702 AllocVec inlined_case(ScopedAlloc(
Alloc(+&total_allocated_byte_count)));
1705 inlined_case.emplace_back();
1707 int64_t absl_responsible_for_count = total_allocated_byte_count;
1710 #if !defined(_MSC_VER)
1711 EXPECT_EQ(absl_responsible_for_count, 0);
1712 #endif // !defined(_MSC_VER)
1714 inlined_case[0].emplace_back();
1715 EXPECT_GT(total_allocated_byte_count, absl_responsible_for_count);
1717 inlined_case.clear();
1718 inlined_case.shrink_to_fit();
1719 EXPECT_EQ(total_allocated_byte_count, 0);
1722 TEST(AllocatorSupportTest, ScopedAllocatorWorksAllocated) {
1723 using StdVector = std::vector<int, CountingAllocator<int>>;
1724 using Alloc = CountingAllocator<StdVector>;
1725 using ScopedAlloc = std::scoped_allocator_adaptor<Alloc>;
1728 int64_t total_allocated_byte_count = 0;
1730 AllocVec allocated_case(ScopedAlloc(
Alloc(+&total_allocated_byte_count)));
1733 allocated_case.emplace_back();
1734 allocated_case.emplace_back();
1736 int64_t absl_responsible_for_count = total_allocated_byte_count;
1737 EXPECT_GT(absl_responsible_for_count, 0);
1739 allocated_case[1].emplace_back();
1740 EXPECT_GT(total_allocated_byte_count, absl_responsible_for_count);
1742 allocated_case.clear();
1743 allocated_case.shrink_to_fit();
1744 EXPECT_EQ(total_allocated_byte_count, 0);
1747 TEST(AllocatorSupportTest, SizeAllocConstructor) {
1748 constexpr
int inlined_size = 4;
1749 using Alloc = CountingAllocator<int>;
1753 auto len = inlined_size / 2;
1755 auto v = AllocVec(
len,
Alloc(&allocated));
1763 auto len = inlined_size * 2;
1765 auto v = AllocVec(
len,
Alloc(&allocated));
1773 TEST(InlinedVectorTest, MinimumAllocatorCompilesUsingTraits) {
1775 using A = std::allocator<T>;
1778 struct MinimumAllocator {
1783 return ATraits::allocate(
a,
n);
1788 ATraits::deallocate(
a,
p,
n);
1797 TEST(InlinedVectorTest, AbslHashValueWorks) {
1799 std::vector<V> cases;
1803 for (
int i = 0;
i < 10; ++
i) {
1805 for (
int j = 0;
j <
i; ++
j) {