diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -1676,6 +1676,14 @@ C.erase(std::remove(C.begin(), C.end(), V), C.end()); } +/// Wrapper function to append a range to a container. +/// +/// C.insert(C.end(), R.begin(), R.end()); +template +inline void append_range(Container &C, Range &&R) { + C.insert(C.end(), R.begin(), R.end()); +} + /// Given a sequence container Cont, replace the range [ContIt, ContEnd) with /// the range [ValIt, ValEnd) (which is not from the same container). template diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp --- a/llvm/unittests/ADT/STLExtrasTest.cpp +++ b/llvm/unittests/ADT/STLExtrasTest.cpp @@ -323,6 +323,15 @@ EXPECT_EQ(7, V[3]); } +TEST(STLExtrasTest, AppendRange) { + auto AppendVals = {3}; + std::vector V = {1, 2}; + append_range(V, AppendVals); + EXPECT_EQ(1, V[0]); + EXPECT_EQ(2, V[1]); + EXPECT_EQ(3, V[2]); +} + namespace some_namespace { struct some_struct { std::vector data;