summaryrefslogtreecommitdiff
path: root/decoder/batched_append.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 02:46:13 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 02:46:13 +0000
commitb22b4fb953987d6a19716af8c3f8af73826bcfca (patch)
tree6db7e6872417c34127db03181ed62b63841e6c8e /decoder/batched_append.h
parent1db7d5bdc95db9515e3c3ce41cefd4e98fc69298 (diff)
merge
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@511 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/batched_append.h')
-rwxr-xr-xdecoder/batched_append.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/decoder/batched_append.h b/decoder/batched_append.h
new file mode 100755
index 00000000..745f567f
--- /dev/null
+++ b/decoder/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_type si=s.begin();
+ for (;i<news;++i,++si)
+ swap(v[i],*si);
+}
+
+#endif