diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-15 10:31:44 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-15 10:31:44 +0100 |
commit | a4cdf9ca10f93181743cb75a4e3c29f23fbe84a5 (patch) | |
tree | ab405baa3970e950b8ae376d2aa2c6cb64631388 /serialize/packbits-write.hpp | |
parent | 8ecfad7829cfa3b4342e41b9c52f9f5557b3cb16 (diff) |
w
Diffstat (limited to 'serialize/packbits-write.hpp')
-rw-r--r-- | serialize/packbits-write.hpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp index 4217d739..060c444f 100644 --- a/serialize/packbits-write.hpp +++ b/serialize/packbits-write.hpp @@ -27,6 +27,7 @@ struct output 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>; @@ -40,7 +41,7 @@ struct output static_assert(N > 0); T value_{value}; if constexpr(CAPACITY != sizeof(T)*8) - value_ <<= CAPACITY; + value_ <<= N; auto x_ = T(x & (T{1}<<N)-T{1}); fm_assert(x_ == x); value_ |= x_; @@ -55,12 +56,28 @@ struct output_field static constexpr size_t Length = LENGTH; }; -template<typename T, size_t Left, size_t F, typename... Fields> -constexpr T write_(output<T, Left> st, output_field<T, F> field, Fields... fields) +template<std::unsigned_integral Type, typename Tuple> struct count_bits; + + +template<std::unsigned_integral Int, size_t N, typename... Ts> struct count_bits<Int, std::tuple<output_field<Int, N>, Ts...>> +{ + static constexpr size_t length = N + count_bits<Int, std::tuple<Ts...>>::length; + static_assert(length <= sizeof(T)*8); +}; + +template<std::unsigned_integral Int> struct count_bits<Int, std::tuple<>> +{ + static constexpr size_t length = 0; +}; + +#if 0 +template<typename T, size_t Left, typename Fields, size_t... Is> +constexpr T write_(output<T, Left> st, std::tuple<Fields..., output_field<T, F>> fields) { - T value = st.set(field.value, output_bits<F>{}); + T value0 = fields.get< std::tuple_size_v<std::tuple<Fields..., output_field<T, F>>>-1 >(fields).value; + T value = st.set(value0, output_bits<F>{}); using next = typename output<T, Left>::template next<F>; - return write_(next{value}, fields...); + return write_(next{value}, ); } template<typename T, size_t Left> @@ -68,5 +85,6 @@ constexpr T write_(output<T, Left> st) { return st.value; } +#endif } // namespace floormat::detail_Pack_output |