Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Unified Diff: third_party/WebKit/Source/wtf/VectorTest.cpp

Issue 2739813003: Allow WTF::Vector::emplace_back accept one or zero arguments (Closed)
Patch Set: Added emplace_back() overload Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/VectorTest.cpp
diff --git a/third_party/WebKit/Source/wtf/VectorTest.cpp b/third_party/WebKit/Source/wtf/VectorTest.cpp
index 1e66770c2d8cde63a592c095fa7865dd79d63976..8cb2c6bb2ac1650206176e05a474cf65aafaa87d 100644
--- a/third_party/WebKit/Source/wtf/VectorTest.cpp
+++ b/third_party/WebKit/Source/wtf/VectorTest.cpp
@@ -674,6 +674,8 @@ TEST(VectorTest, Optional) {
TEST(VectorTest, emplace_back) {
struct Item {
+ Item() = default;
+ explicit Item(int value1) : value1(value1), value2() {}
Item(int value1, int value2) : value1(value1), value2(value2) {}
int value1;
int value2;
@@ -682,12 +684,27 @@ TEST(VectorTest, emplace_back) {
Vector<Item> vector;
vector.emplace_back(1, 2);
vector.emplace_back(3, 4);
+ vector.emplace_back(5);
+ vector.emplace_back();
+
+ EXPECT_EQ(4u, vector.size());
- EXPECT_EQ(2u, vector.size());
EXPECT_EQ(1, vector[0].value1);
EXPECT_EQ(2, vector[0].value2);
+
EXPECT_EQ(3, vector[1].value1);
EXPECT_EQ(4, vector[1].value2);
+
+ EXPECT_EQ(5, vector[2].value1);
+ EXPECT_EQ(0, vector[2].value2);
+
+ EXPECT_EQ(0, vector[3].value1);
+ EXPECT_EQ(0, vector[3].value2);
+
+ // Test returned value.
+ Item& item = vector.emplace_back(6, 7);
+ EXPECT_EQ(6, item.value1);
+ EXPECT_EQ(7, item.value2);
}
static_assert(VectorTraits<int>::canCopyWithMemcpy,
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698