summaryrefslogtreecommitdiff
path: root/utils/batched_append.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/batched_append.h')
-rwxr-xr-xutils/batched_append.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/utils/batched_append.h b/utils/batched_append.h
new file mode 100755
index 00000000..14a6d576
--- /dev/null
+++ b/utils/batched_append.h
@@ -0,0 +1,25 @@
+#ifndef BATCHED_APPEND_H
+#define BATCHED_APPEND_H
+
+#include <algorithm> //swap
+#include <cstddef>
+
+template <class SRange,class Vector>
+void batched_append(Vector &v,SRange const& s) {
+ std::size_t news=v.size()+s.size();
+ v.reserve(news);
+ v.insert(v.end(),s.begin(),s.end());
+}
+
+template <class SRange,class Vector>
+void batched_append_swap(Vector &v,SRange & s) {
+ using namespace std; // to find the right swap
+ size_t i=v.size();
+ size_t news=i+s.size();
+ v.resize(news);
+ typename SRange::iterator si=s.begin();
+ for (;i<news;++i,++si)
+ swap(v[i],*si);
+}
+
+#endif