diff options
author | Nuno Goncalves <[email protected]> | 2019-10-18 20:05:27 +0200 |
---|---|---|
committer | Nuno Goncalves <[email protected]> | 2019-10-20 09:43:10 +0200 |
commit | a79c2781066785a27f2e92c154d27a1c4f6efc5d (patch) | |
tree | 86c8f4caee77c08d2d437229474aed7f12734649 /src/lib/misc/roughtime | |
parent | 7b3453963dac1a8f45354343b0af26535aea21ae (diff) |
split public interface and recursive implementation
Signed-off-by: Nuno Goncalves <[email protected]>
Diffstat (limited to 'src/lib/misc/roughtime')
-rw-r--r-- | src/lib/misc/roughtime/roughtime.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/misc/roughtime/roughtime.cpp b/src/lib/misc/roughtime/roughtime.cpp index 435308cd0..6d3542160 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, 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)); + return (i == 0) ? T(0) : (T(static_cast<int64_t>(t[i-1]) << ((i-1)*8)) + 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)); } template<typename T, enable_if_t<is_array<T>::value>* = nullptr> |