-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
57 lines (51 loc) · 1.38 KB
/
test.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
49
50
51
52
53
54
55
56
57
//
// Created by Brekcel on 7.10.2018.
//
#define RTARRAY_COPY
#include "RTArray.h"
#include <iostream>
struct Test {
int x;
Test(Test&& move) : x(move.x) {
move.x = -1;
std::cout << "Moving test x: " << x << std::endl;
}
Test(const Test& copy) :x(copy.x) {
std::cout << "Copying test x: " << x << std::endl;
}
Test(int x) : x(x) {
std::cout << "Creating test x: " << x << std::endl;
}
Test& operator =(const Test& eq) {
this->x = eq.x;
std::cout << "Assigning test x: " << x << std::endl;
return *this;
}
~Test() {
std::cout << "Destroying test x:" << x << std::endl;
}
};
#include <array>
int main(int argc, char* argv[]) {
//std::array
//std::vector
std::cout << "RTArraySize: " << sizeof(RTArray<Test>) << std::endl;
std::array<Test, 6> arr4 = {Test(3), Test(4), Test(5), Test(6), Test(7), Test(8)};
RTArray<Test> arrIter(arr4.begin(), arr4.end());
int j = 0;
RTArray<int> arr(5, [&j](size_t idx) {
j += 2;
return static_cast<int>(j * idx);
});
RTArray<int> arr2 = arr;
RTArray<int> arr3 = std::move(arr);
int i = arr3[3]; //i == 24
std::cout << "arr[3]: " << i << std::endl;
for (const auto& t : arrIter) {
std::cout << "Iter item with value " << t.x << std::endl;
}
for (RTArray<Test>::reverse_iterator begin = arrIter.rbegin(); begin != arrIter.rend(); ++begin) {
std::cout << "Reverse Iter item with value " << begin->x << std::endl;
}
return 0;
}