-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparsegen_std_vector.hpp
50 lines (40 loc) · 1.04 KB
/
parsegen_std_vector.hpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include <vector>
#include <cassert>
namespace parsegen {
/* just some wrappers over std::vector to let us
do all indexing with int */
template <typename T>
inline int isize(std::vector<T> const& v) {
return int(v.size());
}
template <typename T>
inline typename std::vector<T>::reference at(std::vector<T>& v, int i) {
assert(0 <= i);
#if !(defined(__GNUC__) && __GNUC__ < 5)
assert(i < int(v.size()));
#endif
return v[std::size_t(i)];
}
template <typename T>
inline typename std::vector<T>::const_reference at(
std::vector<T> const& v, int i) {
assert(0 <= i);
assert(i < int(v.size()));
return v[std::size_t(i)];
}
template <typename T>
inline void resize(std::vector<T>& v, int n) {
assert(0 <= n);
v.resize(std::size_t(n));
}
template <typename T>
inline void reserve(std::vector<T>& v, int n) {
assert(0 <= n);
v.reserve(std::size_t(n));
}
template <typename T>
inline std::vector<T> make_vector(int n, T const& init_val = T()) {
return std::vector<T>(std::size_t(n), init_val);
}
} // namespace parsegen