File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 6
6
#include < utility>
7
7
template <typename T>
8
8
struct MakeArray {};
9
- template <size_t ... V>
10
- struct MakeArray <std::integer_sequence<size_t , V...>> {
11
- static size_t value[sizeof ...(V)];
9
+ template <uint64_t ... V>
10
+ struct MakeArray <std::integer_sequence<uint64_t , V...>> {
11
+ static uint64_t value[sizeof ...(V)];
12
12
};
13
- template <size_t ... V>
14
- size_t MakeArray<std::integer_sequence<size_t , V...>>::value[sizeof ...(V)] = { V... };
15
- size_t (&Array)[10 ] = MakeArray<std::make_index_sequence< 10 >>::value;
13
+ template <uint64_t ... V>
14
+ uint64_t MakeArray<std::integer_sequence<uint64_t , V...>>::value[sizeof ...(V)] = { V... };
15
+ uint64_t (&Array)[10 ] = MakeArray<std::make_integer_sequence< uint64_t , 10 >>::value;
16
16
void setup () {
17
17
Serial.begin (9600 );
18
18
std::cout << " 原始数组:" ;
19
- for (size_t A : Array)
20
- std::cout << A;
21
19
// 很多平台并不原生支持uint64_t,但本库仍能输出
22
20
for (uint64_t A : Array)
23
21
std::cout << A;
@@ -37,7 +35,7 @@ void loop() {
37
35
std::cout << " 输入任意字符以生成下一个乱序:" ;
38
36
std::cin >> RandomSeed;
39
37
#endif
40
-
38
+
41
39
// 清除错误标志位。必须紧贴ignore之前,因为不先清除错误状态ignore就不会生效。
42
40
std::cin.clear ();
43
41
@@ -47,11 +45,16 @@ void loop() {
47
45
std::cout << RandomSeed << std::endl;
48
46
std::shuffle (std::begin (Array), std::end (Array), Urng);
49
47
std::cout << " 随机乱序:" ;
50
- for (size_t A : Array)
48
+ for (uint64_t A : Array)
51
49
std::cout << A;
52
50
std::cout << std::endl;
53
- # ifdef __cpp_exceptions
51
+
54
52
// 此段仅用于展示异常处理,对本示例主线逻辑无意义。必须在编译选项中启用-fexceptions并禁用-fno-rtti才能使本段生效。AVR不支持异常处理。
53
+ #ifdef ARDUINO_ARCH_SAM
54
+ // SAM架构不会自动定义此宏。如果在SAM的编译选项中启用了-fexceptions,还需要手动定义__cpp_exceptions。
55
+ #define __cpp_exceptions
56
+ #endif
57
+ #ifdef __cpp_exceptions
55
58
try {
56
59
throw 0 ;
57
60
} catch (...) {
You can’t perform that action at this time.
0 commit comments