-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_realize.cpp
More file actions
72 lines (60 loc) · 1.85 KB
/
array_realize.cpp
File metadata and controls
72 lines (60 loc) · 1.85 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
60
61
62
63
64
65
66
67
68
69
70
71
// array_realize.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<vector>
//#include<array>
#include<cstdio>
#include<string>
#include<cstddef>
#include<cstdint>
#include"Array.hpp"
template<class __Tp, size_t _N>
void func(Array<__Tp, _N>& __arr) {
//这里可以复用引用的数组的大小
Array < int8_t, std::decay_t<decltype(__arr)>::size()> __arrnew;
//注意用size_t来定义循环体变量来保证循环不崩溃
//且该类型在加arr下标上有天然优势,避免编译器内部执行movezx等操作
//使用循环体测试size功能
for (size_t i = 0; i < __arr.size(); i++) {
__arr.at(i) = i;
}
//迭代器实现,这里注释的语句与size_t* 同理,在Array内部使用using来自定义出iterator
//for (/*Array < uintptr_t, 32>::iterator*/ /*size_t**/ auto it = a.begin(); it != a.end(); ++it) {
// *it = it - a.begin();
//}
/*size_t count = 0;
for (auto& ai : __arr) {
ai = count++;
}*/
}
int main()
{
//Array<class __Tp,size_t _N>
Array<uintptr_t, 3> arr{ 1,2,3 };
try {
size_t count = 0;
for (auto& ai : arr) {
std::cout << ai << " ";
}
std::cout << std::endl;
func(arr);
//arr.fill(10);
arr.swap_two_ele(1,2);
}
catch (const std::runtime_error& errorstatement) {
std::cerr << errorstatement.what() << std::endl;
return 0;
}
/*for (size_t i = 0; i <arr.size(); i++) {
std::cout << arr[i] << std::endl;
}*/
size_t count = 0;
for (auto& ai : arr) {
std::cout << ai << " ";
}
std::cout << std::endl;
//测试front,back函数
std::cout << arr.front() << " " << arr.back() << std::endl;
return 0;
}
//Long 2024.8.2实现Array标准库一