Skip to content

Commit 763f4dc

Browse files
authored
chore(encoder): Simplify to use requires(...) instead of enable_if (#296)
1 parent b8fb0b8 commit 763f4dc

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

components/encoder/include/abi_encoder.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ template <EncoderType T = EncoderType::ROTATIONAL> class AbiEncoder : public Bas
106106
* EncoderType::ROTATIONAL.
107107
* @return Number of revolutions, as a floating point number.
108108
*/
109-
template <EncoderType type = T>
110-
typename std::enable_if<type == EncoderType::ROTATIONAL, float>::type get_revolutions() {
109+
float get_revolutions() requires(T == EncoderType::ROTATIONAL) {
111110
auto raw = get_count();
112111
return (float)raw / (float)counts_per_revolution_;
113112
}
@@ -119,8 +118,7 @@ template <EncoderType T = EncoderType::ROTATIONAL> class AbiEncoder : public Bas
119118
* EncoderType::ROTATIONAL.
120119
* @return Number of radians, as a floating point number.
121120
*/
122-
template <EncoderType type = T>
123-
typename std::enable_if<type == EncoderType::ROTATIONAL, float>::type get_radians() {
121+
float get_radians() requires(T == EncoderType::ROTATIONAL) {
124122
return get_revolutions() * 2.0f * M_PI;
125123
}
126124

@@ -131,10 +129,7 @@ template <EncoderType T = EncoderType::ROTATIONAL> class AbiEncoder : public Bas
131129
* EncoderType::ROTATIONAL.
132130
* @return Number of degrees, as a floating point number.
133131
*/
134-
template <EncoderType type = T>
135-
typename std::enable_if<type == EncoderType::ROTATIONAL, float>::type get_degrees() {
136-
return get_revolutions() * 360.0f;
137-
}
132+
float get_degrees() requires(T == EncoderType::ROTATIONAL) { return get_revolutions() * 360.0f; }
138133

139134
/**
140135
* @brief Start the pulse count hardware.

0 commit comments

Comments
 (0)