-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
56 lines (55 loc) · 1.43 KB
/
test.cpp
File metadata and controls
56 lines (55 loc) · 1.43 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
#include <iostream>
#include <initializer_list>
#include <algorithm>
template <typename T, int S = 1>
class FSizeArr {
private:
T* value;
public:
int length;
FSizeArr(std::initializer_list<T> init) {
this->length = S > 1 ? S : 1;
this->value = new T[this->length];
std::copy(init.begin(), init.end(), this->value);
}
FSizeArr() {
this->length = S > 1 ? S : 1;
this->value = new T[this->length];
}
~FSizeArr() {
delete[] this->value;
this->value = nullptr;
}
T& operator[](size_t index) {
return this->value[index];
}
const T& operator[](size_t index) const {
return this->value[index];
}
const T back() const {
return this->value[this->length - 1];
}
const T front() const {
return this->value[0];
}
const T* data() const {
return this->value;
}
};
int _pass = 0;
int _fail = 0;
void _test(int num, int got, int expected) {
bool passed = got == expected;
std::cout << "---------------------\n";
std::cout << "Test " << num << ":\n";
std::cout << (passed ? "Pass\n" : "Fail\n") << "\n";
if (passed) _pass++; else _fail++;
}
int main() {
FSizeArr<int, 3> tester1 = {1, 2, 3};
tester1.~FSizeArr();
_test(1, 1, tester1.data() == nullptr ? 1 : 0);
std::cout << "---------------------\n";
std::cout << _pass << " passed, " << _fail << " failed\n";
return 0;
}