-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyvector.cpp
48 lines (40 loc) · 925 Bytes
/
myvector.cpp
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
//
// Created by neko on 03.03.2017.
//
#include "myvector.h"
using namespace test;
double& Vector::operator[] (int i) {
if (i < 0 || i > sz) {
throw std::invalid_argument("out of bounds");
}
return elem[i];
}
int Vector::size(){
return sz;
}
double* Vector::begin(){
return &elem[0];
}
double* Vector::end() {
return &elem[sz];
}
std::ostream& test::operator<<(std::ostream &os, const Vector &vector) {
os << "elem: " << vector.elem << " sz: " << vector.sz;
return os;
}
bool Vector::operator<(const Vector &rhs) const {
if (elem < rhs.elem)
return true;
if (rhs.elem < elem)
return false;
return sz < rhs.sz;
}
bool Vector::operator>(const Vector &rhs) const {
return rhs < *this;
}
bool Vector::operator<=(const Vector &rhs) const {
return !(rhs < *this);
}
bool Vector::operator>=(const Vector &rhs) const {
return !(*this < rhs);
}