aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/misc/roughtime/roughtime.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lib/misc/roughtime/roughtime.cpp b/src/lib/misc/roughtime/roughtime.cpp
index 671b78cb4..2e4163914 100644
--- a/src/lib/misc/roughtime/roughtime.cpp
+++ b/src/lib/misc/roughtime/roughtime.cpp
@@ -34,10 +34,16 @@ template<class T, std::size_t N>
struct is_array<std::array<T,N>>:std::true_type{};
template<typename T>
-T from_little_endian(const uint8_t* t, size_t N = sizeof(T))
+T impl_from_little_endian(const uint8_t* t, const size_t i)
{
- static_assert(sizeof(T)<=sizeof(int64_t),"");
- return (N == 0) ? T(0) : (T(static_cast<int64_t>(t[N-1]) << ((N-1)*8)) + from_little_endian<T>(t,N-1));
+ static_assert(sizeof(T) <= sizeof(int64_t), "");
+ return T(static_cast<int64_t>(t[i]) << i * 8) + (i == 0 ? T(0) : impl_from_little_endian<T>(t, i - 1));
+ }
+
+template<typename T>
+T from_little_endian(const uint8_t* t)
+ {
+ return impl_from_little_endian<T>(t, sizeof(T) - 1);
}
template<typename T, enable_if_t<is_array<T>::value>* = nullptr>