From 8ecfad7829cfa3b4342e41b9c52f9f5557b3cb16 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 15 Jan 2024 09:50:59 +0100 Subject: aw --- serialize/packbits-read.hpp | 21 +++++++++++---------- serialize/packbits-write.cpp | 2 ++ serialize/packbits-write.hpp | 31 ++++++++++++++++--------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/serialize/packbits-read.hpp b/serialize/packbits-read.hpp index ff132913..dc21d7ee 100644 --- a/serialize/packbits-read.hpp +++ b/serialize/packbits-read.hpp @@ -38,15 +38,24 @@ struct input { static_assert(CAPACITY <= sizeof(T)*8); static constexpr size_t Capacity = CAPACITY; + T value; + template + struct next_ + { + static_assert(N <= Capacity); + using type = input; + }; + template using next = typename next_::type; + template constexpr T get() const { static_assert(N > 0); static_assert(N <= sizeof(T)*8); static_assert(N <= Capacity); - return T(value & (T(1) << N) - T(1)); + return T(value & (T{1} << N) - T{1}); } template @@ -58,15 +67,7 @@ struct input } constexpr bool operator==(const input&) const noexcept = default; - [[nodiscard]] constexpr inline bool check_zero() const { return value == T(0); } - - template - struct next_ - { - static_assert(N <= Capacity); - using type = input; - }; - template using next = typename next_::type; + [[nodiscard]] constexpr inline bool check_zero() const { return value == T{0}; } }; template diff --git a/serialize/packbits-write.cpp b/serialize/packbits-write.cpp index 0b4fb4f1..efdf1602 100644 --- a/serialize/packbits-write.cpp +++ b/serialize/packbits-write.cpp @@ -6,6 +6,8 @@ using u32 = uint32_t; using u8 = uint8_t; template u32 write_(output, output_field); + static_assert(output::next<1>::Capacity == 31); +static_assert(output::next<1>::next<2>::Capacity == 29); } // namespace floormat::detail_Pack_output diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp index faa3ff00..4217d739 100644 --- a/serialize/packbits-write.hpp +++ b/serialize/packbits-write.hpp @@ -24,6 +24,15 @@ struct output T value{0}; + template + struct next_ + { + static_assert(N > 0); + static_assert(N <= CAPACITY); + using type = output; + }; + template using next = typename next_::type; + template constexpr T set(T x, output_bits) const { @@ -37,27 +46,19 @@ struct output value_ |= x_; return value_; } - - template - struct next_ - { - static_assert(N > 0); - static_assert(N <= CAPACITY); - using type = output; - }; - - template using next = typename next_::type; }; -template -using output_field = std::pair>; - -template struct empty_pack_tuple {}; // todo copypasta +template +struct output_field +{ + T value; + static constexpr size_t Length = LENGTH; +}; template constexpr T write_(output st, output_field field, Fields... fields) { - T value = st.set(field.first, field.second); + T value = st.set(field.value, output_bits{}); using next = typename output::template next; return write_(next{value}, fields...); } -- cgit v1.2.3