From fe70244f22ad59fa34f08235240ae9c55a6dce1e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jan 2024 01:49:43 +0100 Subject: w --- serialize/packbits-write.cpp | 8 ++++++-- serialize/packbits-write.hpp | 36 ++++++------------------------------ 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/serialize/packbits-write.cpp b/serialize/packbits-write.cpp index 85130c12..416ee718 100644 --- a/serialize/packbits-write.cpp +++ b/serialize/packbits-write.cpp @@ -16,8 +16,12 @@ static_assert(count_bits> == 0); template u32 write_(const std::tuple>&, output, output_bits<32>, std::index_sequence<0>); static_assert(write_(std::tuple>{4242}, output{0}, output_bits<32>{}, std::index_sequence<0>{}) == 4242); -static_assert(output::next<1>::Capacity == 31); -static_assert(output::next<1>::next<2>::Capacity == 29); +static_assert(write_( + std::tuple{f8<3>{7}, f8<2>{3}, f8<1>{1}}, + output{0}, + output_bits<8>{}, + std::make_index_sequence<3>{} +) == (1 << 6) - 1); #if 0 static_assert(write_(output{0}, diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp index a0ebe2ff..a98833ad 100644 --- a/serialize/packbits-write.hpp +++ b/serialize/packbits-write.hpp @@ -23,30 +23,6 @@ struct output static constexpr size_t Capacity = CAPACITY; T value{0}; - - template - struct next_ - { - static_assert(N <= sizeof(T)*8); - 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 - { - static_assert(N <= CAPACITY, "data type too small"); - static_assert(N > 0); - T value_{value}; - if constexpr(CAPACITY != sizeof(T)*8) - value_ <<= N; - auto x_ = T(x & (T{1}< @@ -81,17 +57,17 @@ using make_reverse_index_sequence = decltype(reverse_index_sequence(std::make_in template constexpr T write_(const Tuple& tuple, output st, output_bits, std::index_sequence) { - constexpr size_t N = std::tuple_element_t::Length; static_assert(Capacity <= sizeof(T)*8); static_assert(Left <= Capacity); + constexpr size_t N = std::tuple_element_t::Length; + static_assert(N <= Left); T x = std::get(tuple).value; - T value = st.set(x, output_bits{}); - using next = typename output::template next; - return write_(tuple, next{value}, std::index_sequence{}); + T value = T(T(st.value << N) | x); + return write_(tuple, output{value}, output_bits{}, std::index_sequence{}); } -template -constexpr T write_(const Tuple&, output st, std::index_sequence<>) +template +constexpr T write_(const Tuple&, output st, output_bits, std::index_sequence<>) { return st.value; } -- cgit v1.2.3