-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.hh
More file actions
42 lines (33 loc) · 978 Bytes
/
vector.hh
File metadata and controls
42 lines (33 loc) · 978 Bytes
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
#pragma once
#include <algorithm>
#include "iterator/base.hh"
namespace util::vector {
// Clear vector data and releases its memory
template <typename T>
void real_clear (T& vec) {
vec.clear();
vec.shrink_to_fit();
}
// Multi dimension vector
template <typename T, uintmax_t C>
struct multi_st {
using type = std::vector<typename multi_st<T, C - 1>::type>;
};
template <typename T>
struct multi_st<T, 0> { using type = T; };
template <typename T, uintmax_t C>
using multi = typename multi_st<T, C>::type;
// Make a multi dimension vector
template <typename T, typename... ARGS>
multi<T, sizeof...(ARGS) + 1> make_multi (T val, uintmax_t size, ARGS&&... args) {
if constexpr (sizeof...(ARGS) == 0) {
// Last level
return std::vector<T>(size, val);
} else {
// 'Recursive' step
return multi<T, sizeof...(ARGS) + 1>{
size, make_multi(val, std::forward<ARGS>(args)...)
};
}
}
};