-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector3.h
More file actions
59 lines (45 loc) · 1.42 KB
/
vector3.h
File metadata and controls
59 lines (45 loc) · 1.42 KB
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
58
59
#include <initializer_list>
#include <string>
#include <algorithm>
#include <memory>
#include <stdexcept>
struct Range_error : std::out_of_range {
int index;
Range_error(int i) : std::out_of_range("Range error"), index{ i } {};
};
template<typename T, typename A> struct vector_base
{
A alloc;
T* elem;
int sz;
int space;
vector_base() :sz{ 0 }, elem{ alloc.allocate(0) }, space{ 0 } {}
vector_base(int n) : elem(alloc.allocate(n)), sz(n), space(n) {}
vector_base(const A& a, int n) :alloc{ a }, elem{ alloc.allocate(n) }, sz{ 0 }, space{ n } {}
vector_base(const vector_base& arg);
vector_base(std::initializer_list<T> lst);
vector_base(vector_base&& arg);
~vector_base() { alloc.deallocate(elem, space); }
};
template<typename T, typename A = std::allocator<T>>
class vector3 : private vector_base<T, A>
{
public:
vector3();
vector3(int);
vector3(std::initializer_list<T> lst);
vector3(const vector3& arg);
vector3& operator=(const vector3& a);
vector3(vector3&& a);
vector3& operator=(vector3&& a);
~vector3() {}
T& at(int n);
const T& at(int n) const;
T& operator[] (int n) { return this->elem[n]; }
const T& operator[] (int n) const { return this->elem[n]; }
int capacity() const { return this->space; }
int size() const { return this->sz; };
void resize(int newsize, T val = T());
void push_back(const T& val);
void reserve(int newalloc);
};