-
Notifications
You must be signed in to change notification settings - Fork 20
/
switch_vector.h
57 lines (47 loc) · 1.48 KB
/
switch_vector.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
#pragma once
#include <vector>
namespace Switch
{
template <class T>
class vector
: public std::vector<T>
{
public:
void RemoveByValue(const T v)
{
const auto e = this->end();
auto it = std::find(this->begin(), e, v);
if (it != e)
{
const auto n = this->size();
this->erase(it);
require(this->size() + 1 == n);
}
}
T Pop()
{
auto last{this->back()};
this->pop_back();
return last;
}
auto values() noexcept
{
return this->data();
}
void pop_front()
{
auto it = this->begin();
this->erase(it);
}
void Append(T *const list, const size_t n)
{
this->reserve(n);
for (size_t i{0}; i != n; ++i)
this->push_back(list[i]);
}
void PopByIndex(const size_t idx)
{
this->erase(this->begin() + idx);
}
};
}