[PATCH] D90894: [STLExtras] Add append_range helper.
Sean Silva via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 5 16:20:34 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9e2e3107d6b: [STLExtras] Add append_range helper. (authored by silvas).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90894/new/
https://reviews.llvm.org/D90894
Files:
llvm/include/llvm/ADT/STLExtras.h
llvm/unittests/ADT/STLExtrasTest.cpp
Index: llvm/unittests/ADT/STLExtrasTest.cpp
===================================================================
--- llvm/unittests/ADT/STLExtrasTest.cpp
+++ llvm/unittests/ADT/STLExtrasTest.cpp
@@ -323,6 +323,15 @@
EXPECT_EQ(7, V[3]);
}
+TEST(STLExtrasTest, AppendRange) {
+ auto AppendVals = {3};
+ std::vector<int> 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<int> data;
Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ 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 <typename Container, typename Range>
+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<typename Container, typename RandomAccessIterator>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90894.303295.patch
Type: text/x-patch
Size: 1252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201106/d0289c77/attachment.bin>
More information about the llvm-commits
mailing list