diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-16 01:49:43 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-16 01:59:00 +0100 |
| commit | fe70244f22ad59fa34f08235240ae9c55a6dce1e (patch) | |
| tree | 0062662ac32338b68b89473ab6d9817744e86dc3 /serialize/packbits-write.hpp | |
| parent | dc228530bcd523d574408446ce93d98093205e7d (diff) | |
w
Diffstat (limited to 'serialize/packbits-write.hpp')
| -rw-r--r-- | serialize/packbits-write.hpp | 36 |
1 files changed, 6 insertions, 30 deletions
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<size_t N> - struct next_ - { - static_assert(N <= sizeof(T)*8); - static_assert(N > 0); - static_assert(N <= CAPACITY); - using type = output<T, CAPACITY - N>; - }; - template<size_t N> using next = typename next_<N>::type; - - template<size_t N> - constexpr T set(T x, output_bits<N>) 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}<<N)-T{1}); - fm_assert(x_ == x); - value_ |= x_; - return value_; - } }; template<typename T, size_t LENGTH> @@ -81,17 +57,17 @@ using make_reverse_index_sequence = decltype(reverse_index_sequence(std::make_in template<typename T, size_t Capacity, size_t Left, size_t I, size_t... Is, typename Tuple> constexpr T write_(const Tuple& tuple, output<T, Left> st, output_bits<Capacity>, std::index_sequence<I, Is...>) { - constexpr size_t N = std::tuple_element_t<I, Tuple>::Length; static_assert(Capacity <= sizeof(T)*8); static_assert(Left <= Capacity); + constexpr size_t N = std::tuple_element_t<I, Tuple>::Length; + static_assert(N <= Left); T x = std::get<I>(tuple).value; - T value = st.set(x, output_bits<N>{}); - using next = typename output<T, Left>::template next<N>; - return write_(tuple, next{value}, std::index_sequence<Is...>{}); + T value = T(T(st.value << N) | x); + return write_(tuple, output<T, Left - N>{value}, output_bits<Capacity>{}, std::index_sequence<Is...>{}); } -template<typename T, size_t Left, typename Tuple> -constexpr T write_(const Tuple&, output<T, Left> st, std::index_sequence<>) +template<typename T, size_t Capacity, size_t Left, typename Tuple> +constexpr T write_(const Tuple&, output<T, Left> st, output_bits<Capacity>, std::index_sequence<>) { return st.value; } |
