================
@@ -153,23 +153,27 @@ class SetVector {
}
/// Insert a new element into the SetVector.
- /// \returns true if the element was inserted into the SetVector.
- bool insert(const value_type &X) {
+ /// \returns a pair, whose first member is the iterator pointed to the
+ /// element, and the second member indicates if the element was inserted.
----------------
eugeneepshteyn wrote:
(This comment was generated with the help of AI)
The new return value has no test in `llvm/unittests/ADT/SetVectorTest.cpp`.
Something like this covers both modes and the small-to-big transition (it
passes with this PR, under ASan too):
```cpp
TEST(SetVector, InsertReturnsIterator) {
SmallSetVector<int, 2> S;
auto [It1, New1] = S.insert(1);
EXPECT_TRUE(New1);
EXPECT_EQ(*It1, 1);
auto [It2, New2] = S.insert(1); // small-mode duplicate
EXPECT_FALSE(New2);
EXPECT_EQ(It2, It1);
S.insert(2);
auto [It3, New3] = S.insert(3); // small -> big transition
EXPECT_TRUE(New3);
EXPECT_EQ(It3, std::prev(S.end()));
auto [It4, New4] = S.insert(2); // big-mode duplicate
EXPECT_FALSE(New4);
EXPECT_EQ(*It4, 2);
}
```
Each iterator is checked before the next insert, since an insert can reallocate.
https://github.com/llvm/llvm-project/pull/232372
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits