-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyVector.hpp
More file actions
52 lines (41 loc) · 906 Bytes
/
MyVector.hpp
File metadata and controls
52 lines (41 loc) · 906 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
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <iostream>
#include <vector>
template<typename T>
struct MyVector {
explicit MyVector(const std::initializer_list<T>& values)
: m_data(values)
{}
MyVector(const MyVector& other)
: m_data{other.m_data}
{}
MyVector(MyVector&& other) noexcept
: m_data{std::move(other.m_data)}
{}
MyVector& operator=(const MyVector& rhs) {
m_data = rhs.m_data;
return *this;
}
MyVector& operator=(MyVector&& rhs) noexcept {
m_data = std::move(rhs.m_data);
return *this;
}
const T& operator[](size_t index) const {
return m_data[index];
}
T& operator[](size_t index) {
return m_data[index];
}
size_t size() const {
return m_data.size();
}
private:
std::vector<T> m_data;
};
template<typename T>
std::ostream& operator<<(std::ostream& os, const MyVector<T>& values) {
for (size_t i = 0; i < values.size(); ++i) {
os << values[i] << ' ';
}
return os;
}