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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/Vector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 TEST(VectorTest, Optional) { 667 TEST(VectorTest, Optional) {
668 Optional<Vector<int>> vector; 668 Optional<Vector<int>> vector;
669 EXPECT_FALSE(vector); 669 EXPECT_FALSE(vector);
670 vector.emplace(3); 670 vector.emplace(3);
671 EXPECT_TRUE(vector); 671 EXPECT_TRUE(vector);
672 EXPECT_EQ(3u, vector->size()); 672 EXPECT_EQ(3u, vector->size());
673 } 673 }
674 674
675 TEST(VectorTest, emplace_back) { 675 TEST(VectorTest, emplace_back) {
676 struct Item { 676 struct Item {
677 Item() = default;
678 explicit Item(int value1) : value1(value1), value2() {}
677 Item(int value1, int value2) : value1(value1), value2(value2) {} 679 Item(int value1, int value2) : value1(value1), value2(value2) {}
678 int value1; 680 int value1;
679 int value2; 681 int value2;
680 }; 682 };
681 683
682 Vector<Item> vector; 684 Vector<Item> vector;
683 vector.emplace_back(1, 2); 685 vector.emplace_back(1, 2);
684 vector.emplace_back(3, 4); 686 vector.emplace_back(3, 4);
687 vector.emplace_back(5);
688 vector.emplace_back();
685 689
686 EXPECT_EQ(2u, vector.size()); 690 EXPECT_EQ(4u, vector.size());
691
687 EXPECT_EQ(1, vector[0].value1); 692 EXPECT_EQ(1, vector[0].value1);
688 EXPECT_EQ(2, vector[0].value2); 693 EXPECT_EQ(2, vector[0].value2);
694
689 EXPECT_EQ(3, vector[1].value1); 695 EXPECT_EQ(3, vector[1].value1);
690 EXPECT_EQ(4, vector[1].value2); 696 EXPECT_EQ(4, vector[1].value2);
697
698 EXPECT_EQ(5, vector[2].value1);
699 EXPECT_EQ(0, vector[2].value2);
700
701 EXPECT_EQ(0, vector[3].value1);
702 EXPECT_EQ(0, vector[3].value2);
703
704 // Test returned value.
705 Item& item = vector.emplace_back(6, 7);
706 EXPECT_EQ(6, item.value1);
707 EXPECT_EQ(7, item.value2);
691 } 708 }
692 709
693 static_assert(VectorTraits<int>::canCopyWithMemcpy, 710 static_assert(VectorTraits<int>::canCopyWithMemcpy,
694 "int should be copied with memcopy."); 711 "int should be copied with memcopy.");
695 static_assert(VectorTraits<char>::canCopyWithMemcpy, 712 static_assert(VectorTraits<char>::canCopyWithMemcpy,
696 "char should be copied with memcpy."); 713 "char should be copied with memcpy.");
697 static_assert(VectorTraits<LChar>::canCopyWithMemcpy, 714 static_assert(VectorTraits<LChar>::canCopyWithMemcpy,
698 "LChar should be copied with memcpy."); 715 "LChar should be copied with memcpy.");
699 static_assert(VectorTraits<UChar>::canCopyWithMemcpy, 716 static_assert(VectorTraits<UChar>::canCopyWithMemcpy,
700 "UChar should be copied with memcpy."); 717 "UChar should be copied with memcpy.");
701 718
702 class UnknownType; 719 class UnknownType;
703 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy, 720 static_assert(VectorTraits<UnknownType*>::canCopyWithMemcpy,
704 "Pointers should be copied with memcpy."); 721 "Pointers should be copied with memcpy.");
705 722
706 } // anonymous namespace 723 } // anonymous namespace
707 724
708 } // namespace WTF 725 } // namespace WTF
OLDNEW
« 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