aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers
diff options
context:
space:
mode:
authortobo <tobo@yandex-team.com>2022-11-22 07:03:30 +0300
committertobo <tobo@yandex-team.com>2022-11-22 07:03:30 +0300
commit2f3767ccf0d30d61d8ecb7f40b06d2d41ee01a93 (patch)
tree3d5721968c52b76f0baafa446bd20e2576231558 /library/cpp/containers
parent1060914f94b4c25e526e41adaa68518a8932e583 (diff)
downloadydb-2f3767ccf0d30d61d8ecb7f40b06d2d41ee01a93.tar.gz
add copy assignment operator
Diffstat (limited to 'library/cpp/containers')
-rw-r--r--library/cpp/containers/compact_vector/compact_vector.h8
-rw-r--r--library/cpp/containers/compact_vector/compact_vector_ut.cpp21
2 files changed, 29 insertions, 0 deletions
diff --git a/library/cpp/containers/compact_vector/compact_vector.h b/library/cpp/containers/compact_vector/compact_vector.h
index ff1e94e024..0c6c563d71 100644
--- a/library/cpp/containers/compact_vector/compact_vector.h
+++ b/library/cpp/containers/compact_vector/compact_vector.h
@@ -98,6 +98,14 @@ public:
return *this;
}
+ TThis& operator = (const TThis& that) {
+ if (Y_LIKELY(this != &that)) {
+ TThis tmp(that);
+ Swap(tmp);
+ }
+ return *this;
+ }
+
TThis& operator = (std::initializer_list<T> init) {
TThis data(init);
Swap(data);
diff --git a/library/cpp/containers/compact_vector/compact_vector_ut.cpp b/library/cpp/containers/compact_vector/compact_vector_ut.cpp
index ed2936fb9e..4dba7b2f49 100644
--- a/library/cpp/containers/compact_vector/compact_vector_ut.cpp
+++ b/library/cpp/containers/compact_vector/compact_vector_ut.cpp
@@ -125,4 +125,25 @@ Y_UNIT_TEST_SUITE(TCompactVectorTest) {
UNIT_ASSERT_VALUES_EQUAL("мыла", vector[1]);
UNIT_ASSERT_VALUES_EQUAL("раму", vector[2]);
}
+
+ Y_UNIT_TEST(TestCopyAssignmentOperator) {
+ TCompactVector<std::string> vector;
+ const TCompactVector<std::string> vector2 = {
+ "мама",
+ "мыла",
+ "раму"
+ };
+
+ vector = vector2;
+
+ UNIT_ASSERT_VALUES_EQUAL(3u, vector.Size());
+
+ UNIT_ASSERT_VALUES_EQUAL("мама", vector[0]);
+ UNIT_ASSERT_VALUES_EQUAL("мыла", vector[1]);
+ UNIT_ASSERT_VALUES_EQUAL("раму", vector[2]);
+
+ UNIT_ASSERT_VALUES_EQUAL(vector[0], vector2[0]);
+ UNIT_ASSERT_VALUES_EQUAL(vector[1], vector2[1]);
+ UNIT_ASSERT_VALUES_EQUAL(vector[2], vector2[2]);
+ }
}