From 5b753ed3b632072697bdbf6912ccefcc6a22f4d0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 18 Jan 2024 17:59:14 +0100 Subject: a --- serialize/packbits-read.cpp | 11 ++++++++--- serialize/packbits-read.hpp | 16 ++++++++++++---- serialize/packbits-write.hpp | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/serialize/packbits-read.cpp b/serialize/packbits-read.cpp index d71d06ac..aa5cccfe 100644 --- a/serialize/packbits-read.cpp +++ b/serialize/packbits-read.cpp @@ -84,10 +84,8 @@ constexpr bool test4() { static_assert(lowbits == 0x1ffffU); - f32<17> a; - f32<14> b; - f32< 1> c; //auto tuple = std::tuple&, f32<14>&, f32<1>&>{a, b, c}; + f32<17> a; f32<14> b; f32< 1> c; auto tuple = std::tie(a, b, c); read_(tuple, input{(uint32_t)-1}, std::make_index_sequence<3>{}); fm_assert(a == lowbits); @@ -112,6 +110,13 @@ constexpr bool test4() //read_(std::tie(a), input{3}, std::index_sequence<0>{}); fm_assert(a == 3); //f8<1> d; read_(std::tie(d), input{1}, std::index_sequence<>{}); } + { + f8<1> a; f8<3> b; f8<2> c; + pack_read(std::tie(a, b, c), uint8_t{0b101011}); + fm_assert(a == 0b1); + fm_assert(b == 0b101); + fm_assert(c == 0b10); + } return true; } diff --git a/serialize/packbits-read.hpp b/serialize/packbits-read.hpp index 9e5f0cc8..1d7056c3 100644 --- a/serialize/packbits-read.hpp +++ b/serialize/packbits-read.hpp @@ -38,7 +38,7 @@ struct input template using next = typename next_::type; template - constexpr T get() const + constexpr CORRADE_ALWAYS_INLINE T get() const { static_assert(N > 0); static_assert(N <= sizeof(T)*8); @@ -81,7 +81,7 @@ template struct is_input_field : std::bool_constant {}; template struct is_input_field> : std::bool_constant { static_assert(N > 0); }; template -constexpr void read_(Tuple&& tuple, input st, std::index_sequence) +constexpr CORRADE_ALWAYS_INLINE void read_(Tuple&& tuple, input st, std::index_sequence) { using U = std::decay_t; static_assert(Left <= sizeof(T)*8); @@ -99,7 +99,7 @@ constexpr void read_(Tuple&& tuple, input st, std::index_sequence -constexpr void read_(Tuple&&, input st, std::index_sequence<>) +constexpr CORRADE_ALWAYS_INLINE void read_(Tuple&&, input st, std::index_sequence<>) { if (!st.check_zero()) [[unlikely]] throw_on_read_nonzero(); @@ -109,6 +109,14 @@ constexpr void read_(Tuple&&, input st, std::index_sequence<>) namespace floormat { - +template +constexpr void pack_read(Tuple&& tuple, T value) +{ + constexpr size_t nbits = sizeof(T)*8, + tuple_size = std::tuple_size_v>; + Pack_impl::read_(std::forward(tuple), + Pack_impl::input{value}, + std::make_index_sequence{}); +} } // namespace floormat diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp index 234b1632..12e202ac 100644 --- a/serialize/packbits-write.hpp +++ b/serialize/packbits-write.hpp @@ -62,7 +62,7 @@ constexpr CORRADE_ALWAYS_INLINE T write_(const Tuple&, output namespace floormat { template -constexpr T pack_write(const std::tuple...>& tuple) +[[nodiscard]] constexpr T pack_write(const std::tuple...>& tuple) { constexpr size_t nbits = sizeof(T)*8; return Pack_impl::write_(tuple, Pack_impl::output{T{0}}, make_reverse_index_sequence{}); -- cgit v1.2.3