blob: 842f32092579bc2663cd9cfd1442166ff15b166b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 via ADL
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
|