From 6c747d58f85d29987011d9519109928c3438fcef Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 14 Jan 2024 19:48:43 +0100 Subject: a --- serialize/packbits.cpp | 27 +++++++++++++++++- serialize/packbits.hpp | 77 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 92 insertions(+), 12 deletions(-) diff --git a/serialize/packbits.cpp b/serialize/packbits.cpp index 6ed898c7..86c6f605 100644 --- a/serialize/packbits.cpp +++ b/serialize/packbits.cpp @@ -7,6 +7,8 @@ using namespace floormat::detail_Pack; namespace { +template constexpr inline T lowbits = (T{1} << N)-T{1}; + template using us_bits = Bits_; static_assert(!Storage{65535}.check_zero()); @@ -110,7 +112,30 @@ static_assert(std::is_same_v< make_tuple_type, std::tuple(); + using Tuple = std::tuple; + Tuple tuple{}; + assign_tuple2(tuple, Storage{(uint32_t)-1}, std::make_index_sequence<3>{}, + Bits_{}, Bits_{}, Bits_{}); + auto [a, b, c] = tuple; + + static_assert(lowbits != 0); + fm_assert(a == lowbits); + fm_assert(b == lowbits); + fm_assert(c & 1); + + //Assign::do_tuple(tuple, Storage{(uint32_t)-1}); + + return true; +} +static_assert(test4()); + +constexpr bool test5() +{ + auto st = Storage{0xB16B00B5}; + uint32_t a, b, c; + using Tuple = std::tuple; + auto t = Tuple{a, b, c}; + //assign_tuple, Tuple, return true; } diff --git a/serialize/packbits.hpp b/serialize/packbits.hpp index 12c1dd31..527b7676 100644 --- a/serialize/packbits.hpp +++ b/serialize/packbits.hpp @@ -5,7 +5,7 @@ #include "compat/assert.hpp" namespace floormat::Pack { -template struct Bits_; +template struct Bits_; } // namespace floormat::Pack namespace floormat::detail_Pack { @@ -13,7 +13,7 @@ namespace floormat::detail_Pack { using namespace floormat::Pack; template struct check_size_overflow; -template +template struct check_size_overflow, Xs...> { static_assert(std::is_same_v); @@ -95,25 +95,80 @@ struct make_tuple_type_ }; template using make_tuple_type = typename make_tuple_type_::Seq; -template -static void assign_to_tuple(Place&, Storage st, std::index_sequence<>) +template +constexpr void assign_tuple2(Place& p, Storage st, std::index_sequence, Bits_, Sizes... sizes) { - fm_assert(st.check_zero()); + 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...); } -template -static void assign_to_tuple(Place& p, Storage st, std::index_sequence) +template +constexpr void assign_tuple2(Place&, Storage, std::index_sequence<>) { - using std::get; - get(p) = st.template get(st); - assign_to_tuple(p, st.template advance(), std::index_sequence{}); } +#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 + } // namespace floormat::detail_Pack namespace floormat::Pack { -template +template struct Bits_ final { static_assert(std::is_fundamental_v); -- cgit v1.2.3