Index: llvm/include/llvm/ADT/SmallPtrSet.h =================================================================== --- llvm/include/llvm/ADT/SmallPtrSet.h +++ llvm/include/llvm/ADT/SmallPtrSet.h @@ -366,6 +366,13 @@ return std::make_pair(makeIterator(p.first), p.second); } + /// Insert the given pointer with an iterator hint that is ignored. This is + /// identical to calling insert(Ptr), but allows SmallPtrSet to be used by + /// std::insert_iterator and std::inserter(). + iterator insert(iterator, PtrType Ptr) { + return insert(Ptr).first; + } + /// erase - If the set contains the specified pointer, remove it and return /// true, otherwise return false. bool erase(PtrType Ptr) { Index: llvm/unittests/ADT/SmallPtrSetTest.cpp =================================================================== --- llvm/unittests/ADT/SmallPtrSetTest.cpp +++ llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -14,6 +14,8 @@ #include "llvm/ADT/PointerIntPair.h" #include "llvm/Support/PointerLikeTypeTraits.h" #include "gtest/gtest.h" +#include +#include using namespace llvm; @@ -395,3 +397,16 @@ EXPECT_TRUE(Set.contains(&buf[1])); EXPECT_TRUE(Set.contains(&buf[2])); } + +TEST(SmallPtrSetTest, InsertIterator) { + SmallPtrSet Set; + int Vals[5] = {11, 22, 33, 44, 55}; + int *Buf[5] = {&Vals[0], &Vals[1], &Vals[2], &Vals[3], &Vals[4]}; + + // Ensure that we can use SmallPtrSet with std::inserter(). + std::copy(std::begin(Buf), std::end(Buf), std::inserter(Set, Set.begin())); + + // Ensure that all of the values were copied into the set. + for (const auto *Ptr : Buf) + EXPECT_TRUE(Set.contains(Ptr)); +}