From b5f96dda3de339b2db61c531f6f486f9d3d45866 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 14 Jan 2024 20:47:15 +0100 Subject: a --- serialize/packbits.hpp | 70 ++++++++------------------------------------------ 1 file changed, 11 insertions(+), 59 deletions(-) (limited to 'serialize/packbits.hpp') diff --git a/serialize/packbits.hpp b/serialize/packbits.hpp index c94f96d7..8a828f94 100644 --- a/serialize/packbits.hpp +++ b/serialize/packbits.hpp @@ -5,14 +5,13 @@ #include "compat/assert.hpp" namespace floormat::Pack { -template struct Bits_; +template struct Bits; } // namespace floormat::Pack namespace floormat::detail_Pack { using namespace floormat::Pack; - template struct Storage { @@ -79,80 +78,33 @@ struct make_tuple_type_ template using make_tuple_type = typename make_tuple_type_::Seq; template -constexpr void assign_tuple2(Place& p, Storage st, std::index_sequence, Bits_, Sizes... sizes) +constexpr void assign_tuple(Place& p, Storage st, std::index_sequence, Bits, Sizes... sizes) { + static_assert(Size <= Left, "too many bits requested"); + static_assert(I < std::tuple_size_v, "too few tuple members"); using S = Storage; using next_type = typename S::template next; get(p) = st.template get(); T next_value = st.template advance(); - assign_tuple2(p, next_type{next_value}, std::index_sequence{}, sizes...); + assign_tuple(p, next_type{next_value}, std::index_sequence{}, sizes...); } template -constexpr void assign_tuple2(Place&, Storage, std::index_sequence<>) +constexpr void assign_tuple(Place&, Storage st, std::index_sequence<>) { + fm_assert(st.check_zero()); } -#if 0 -template struct assign_tuple; - -template -struct assign_tuple, Bits_, Sizes...> -{ - static_assert(Size <= sizeof(T)*8, "bit count can't be larger than sizeof(T)*8"); - static_assert(Size > 0, "bit count can't be zero"); - - template - static constexpr inline void do_tuple(Place& p, Storage st) - { - static_assert(requires (Place& p) { std::get<0>(p) = T{0}; }); - static_assert(std::tuple_size_v >= sizeof...(Indexes) + 1); - static_assert(Size <= Left, "not enough bits for element"); - - get(p) = st.template get(st.value); - using Next = typename Storage::template next; - assign_tuple, Sizes...>:: - template do_tuple(p, Next{st.template advance()}); - } - - static constexpr bool is_empty = false; -}; - -template -struct assign_tuple> -{ - static_assert(sizeof(T) == (size_t)-1, "too few lhs elements"); - static_assert(sizeof(T) != (size_t)-1); -}; - -template -struct assign_tuple, Bits_, Sizes...> -{ - static_assert(sizeof(T) == (size_t)-1, "too few rhs elements"); - static_assert(sizeof(T) != (size_t)-1); -}; - -template -struct assign_tuple> -{ - template - static constexpr inline void do_tuple(Place&, Storage st) - { - fm_assert(st.check_zero()); - } - - static constexpr bool is_empty = true; - using type = T; -}; - -#endif +template +requires(sizeof...(Is) != sizeof...(Sizes)) +constexpr void assign_tuple(Place&, Storage, std::index_sequence, Sizes...) = delete; } // namespace floormat::detail_Pack namespace floormat::Pack { template -struct Bits_ final +struct Bits final { static_assert(std::is_fundamental_v); static_assert(N > 0); -- cgit v1.2.3