-
Notifications
You must be signed in to change notification settings - Fork 1
/
evectorhelpers.h
executable file
·57 lines (50 loc) · 1.41 KB
/
evectorhelpers.h
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
51
52
53
54
55
56
57
#ifndef EVECTORHELPERS_H
#define EVECTORHELPERS_H
#include <vector>
#include <algorithm>
namespace eVectorHelpers {
template <typename T>
bool contains(const std::vector<T>& v, const T& t) {
const auto it = std::find(v.begin(), v.end(), t);
return it != v.end();
}
template <typename T>
int index(const std::vector<T>& v, const T& t) {
const auto it = std::find(v.begin(), v.end(), t);
if(it == v.end()) return -1;
return it - v.begin();
}
template <typename T>
bool remove(std::vector<T>& v, const T& t) {
const auto it = std::find(v.begin(), v.end(), t);
if(it != v.end()) {
v.erase(it);
return true;
} else {
return false;
}
}
template <typename T>
int removeAll(std::vector<T>& v, const T& t) {
const bool r = remove(v, t);
if(r) {
return 1 + removeAll(v, t);
}
return 0;
}
template <typename T>
bool same(const std::vector<T>& v1, const std::vector<T>& v2) {
if(v1.size() == v2.size()) {
const int iMax = v1.size();
for(int i = 0; i < iMax; i++) {
const auto& s1 = v1[i];
const auto& s2 = v2[i];
if(s1 != s2) return false;
}
} else {
return false;
}
return true;
}
};
#endif // EVECTORHELPERS_H