summaryrefslogtreecommitdiffstats
path: root/library/cpp/iterator/ut
diff options
context:
space:
mode:
authorswarmer <[email protected]>2025-12-25 03:21:48 +0300
committerswarmer <[email protected]>2025-12-25 03:42:08 +0300
commit81519b4a5aa5bdfc06e4ff9e80e24919f5f9b96d (patch)
tree447cdc1cd1375f70b78e1970294bcd53ddd6e673 /library/cpp/iterator/ut
parent4dbf62fd2f8cc5ece53cc1446561cf71476bdd12 (diff)
make mapped iterator smaller by using the no_unique_address optimization
commit_hash:42520e745ec2135e405740d2591c55b70b0cba43
Diffstat (limited to 'library/cpp/iterator/ut')
-rw-r--r--library/cpp/iterator/ut/mapped_ut.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/library/cpp/iterator/ut/mapped_ut.cpp b/library/cpp/iterator/ut/mapped_ut.cpp
index 440cd37945a..15a8196eded 100644
--- a/library/cpp/iterator/ut/mapped_ut.cpp
+++ b/library/cpp/iterator/ut/mapped_ut.cpp
@@ -7,12 +7,29 @@
using namespace testing;
+namespace {
+ struct TSelectFirst {
+ const auto& operator()(const auto& pair) const {
+ return pair.first;
+ }
+ };
+}
+
TEST(TIterator, TMappedIteratorTest) {
TVector<int> x = {1, 2, 3, 4, 5};
auto it = MakeMappedIterator(x.begin(), [](int x) { return x + 7; });
EXPECT_EQ(*it, 8);
EXPECT_EQ(it[2], 10);
+
+ TVector<std::pair<int, int>> pairs = {{1, 2}, {3, 4}, {5, 6}};
+ auto firstIt = MakeMappedIterator(pairs.begin(), TSelectFirst{});
+ EXPECT_EQ(*std::next(firstIt, 0), 1);
+ EXPECT_EQ(*std::next(firstIt, 1), 3);
+ EXPECT_EQ(*std::next(firstIt, 2), 5);
+#if defined(_compiler_clang_) && defined(_linux_)
+ static_assert(sizeof(pairs.begin()) == sizeof(firstIt), "empty mapper should not add size overhead"); // this check expected to hold, but not guaranteed to
+#endif
}
TEST(TIterator, TMappedRangeTest) {