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 66#include < utility>
77template <typename T>
88struct 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)];
1212};
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;
1616void setup () {
1717 Serial.begin (9600 );
1818 std::cout << " 原始数组:" ;
19- for (size_t A : Array)
20- std::cout << A;
2119 // 很多平台并不原生支持uint64_t,但本库仍能输出
2220 for (uint64_t A : Array)
2321 std::cout << A;
@@ -37,7 +35,7 @@ void loop() {
3735 std::cout << " 输入任意字符以生成下一个乱序:" ;
3836 std::cin >> RandomSeed;
3937#endif
40-
38+
4139 // 清除错误标志位。必须紧贴ignore之前,因为不先清除错误状态ignore就不会生效。
4240 std::cin.clear ();
4341
@@ -47,11 +45,16 @@ void loop() {
4745 std::cout << RandomSeed << std::endl;
4846 std::shuffle (std::begin (Array), std::end (Array), Urng);
4947 std::cout << " 随机乱序:" ;
50- for (size_t A : Array)
48+ for (uint64_t A : Array)
5149 std::cout << A;
5250 std::cout << std::endl;
53- # ifdef __cpp_exceptions
51+
5452 // 此段仅用于展示异常处理,对本示例主线逻辑无意义。必须在编译选项中启用-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
5558 try {
5659 throw 0 ;
5760 } catch (...) {
You can’t perform that action at this time.
0 commit comments