Skip to content

Commit 4fda744

Browse files
committed
Add test for SmallSet::insert perfect forwarding
1 parent 4974861 commit 4fda744

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

llvm/unittests/ADT/SmallSetTest.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,40 @@ TEST(SmallSetTest, Insert) {
4141
EXPECT_EQ(0u, s1.count(4));
4242
}
4343

44+
TEST(SmallSetTest, InsertPerfectFwd) {
45+
struct Value {
46+
int Key;
47+
bool Moved;
48+
49+
Value(int Key) : Key(Key), Moved(false) {}
50+
Value(const Value &) = default;
51+
Value(Value &&Other) : Key(Other.Key), Moved(false) { Other.Moved = true; }
52+
bool operator==(const Value &Other) const { return Key == Other.Key; }
53+
bool operator<(const Value &Other) const { return Key < Other.Key; }
54+
};
55+
56+
{
57+
SmallSet<Value, 4> S;
58+
Value V1(1), V2(2);
59+
60+
S.insert(V1);
61+
EXPECT_EQ(V1.Moved, false);
62+
63+
S.insert(std::move(V2));
64+
EXPECT_EQ(V2.Moved, true);
65+
}
66+
{
67+
SmallSet<Value, 1> S;
68+
Value V1(1), V2(2);
69+
70+
S.insert(V1);
71+
EXPECT_EQ(V1.Moved, false);
72+
73+
S.insert(std::move(V2));
74+
EXPECT_EQ(V2.Moved, true);
75+
}
76+
}
77+
4478
TEST(SmallSetTest, Grow) {
4579
SmallSet<int, 4> s1;
4680

0 commit comments

Comments
 (0)