Skip to content

Commit

Permalink
[WIP] common_type_t
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed Feb 26, 2024
1 parent bfa7507 commit 32a3125
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions inc/msp/ByteVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,14 @@ class ByteVector : public std::vector<uint8_t> {
typename std::enable_if<std::is_arithmetic<T2>::value,
T2>::type* = nullptr>
bool unpack(T1& val, T2 scale, T2 offset = 0) const {
using cast_type = std::common_type_t<T1, T2>;

bool rc = true;
encoding_T tmp = 0;
rc &= unpack(tmp);
val = static_cast<T1>(tmp) / scale;
val -= offset;
val = static_cast<T1>(static_cast<cast_type>(tmp) /
static_cast<cast_type>(scale) -
static_cast<cast_type>(offset));
return rc;
}

Expand Down

0 comments on commit 32a3125

Please sign in to comment.