回答編集履歴
1
getを工夫
test
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
#include <iostream>
|
8
8
|
|
9
9
|
#include <cstdint>
|
10
|
+
|
11
|
+
#include <type_traits>
|
10
12
|
|
11
13
|
class Direction {
|
12
14
|
|
@@ -62,7 +64,9 @@
|
|
62
64
|
|
63
65
|
}
|
64
66
|
|
67
|
+
template<typename T = value_type, std::enable_if_t<std::is_arithmetic<T>::value, std::nullptr_t> = nullptr>
|
68
|
+
|
65
|
-
constexpr
|
69
|
+
constexpr T get() const noexcept {
|
66
70
|
|
67
71
|
return this->value;
|
68
72
|
|
@@ -76,11 +80,11 @@
|
|
76
80
|
|
77
81
|
Direction a(Direction::front);
|
78
82
|
|
79
|
-
std::cout << a.get() << std::endl;
|
83
|
+
std::cout << a.get<unsigned>() << std::endl;
|
80
84
|
|
81
|
-
a.turn
|
85
|
+
a.turn_left();
|
82
86
|
|
83
|
-
std::cout << a.get() << std::endl;
|
87
|
+
std::cout << a.get<unsigned>() << std::endl;
|
84
88
|
|
85
89
|
return 0;
|
86
90
|
|
@@ -90,4 +94,8 @@
|
|
90
94
|
|
91
95
|
|
92
96
|
|
97
|
+
こんなのかな。
|
98
|
+
|
99
|
+
[動作](http://melpon.org/wandbox/permlink/MlttJTjNsdm9lv94)
|
100
|
+
|
93
|
-
|
101
|
+
sprout使えばコンパイル時に文字列使えるけどそこまでしたくない
|