From c26f49ebe40d1900229064db473dd721c991582a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 14 Jan 2024 21:08:43 +0100 Subject: a --- serialize/packbits.cpp | 16 ++++++++-------- serialize/packbits.hpp | 43 ++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/serialize/packbits.cpp b/serialize/packbits.cpp index ffca868f..74b9ff90 100644 --- a/serialize/packbits.cpp +++ b/serialize/packbits.cpp @@ -140,7 +140,7 @@ constexpr bool test4() { Tuple_u32 tuple{}; static_assert(lowbits == 0x1ffffU); - assign_tuple(tuple, Storage{(uint32_t)-1}, std::make_index_sequence<3>{}, Bits{}, Bits{}, Bits{}); + assign_tuple(tuple, Storage{(uint32_t)-1}, std::make_index_sequence<3>{}, make_pack{}); auto [a, b, c] = tuple; fm_assert(a == lowbits); fm_assert(b == lowbits); @@ -148,7 +148,7 @@ constexpr bool test4() } { Tuple_u8 tuple{}; - assign_tuple(tuple, Storage{0b101011}, std::make_index_sequence<3>{}, Bits{}, Bits{}, Bits{}); + assign_tuple(tuple, Storage{0b101011}, std::make_index_sequence<3>{}, make_pack{}); auto [a, b, c] = tuple; fm_assert(a == 0b1); fm_assert(b == 0b101); @@ -156,13 +156,13 @@ constexpr bool test4() } { std::tuple<> empty_tuple; - assign_tuple(empty_tuple, Storage{0}, std::index_sequence<>{}); + assign_tuple(empty_tuple, Storage{0}, std::index_sequence<>{}, make_pack{}); Tuple_u8 tuple{}; (void)tuple; - // assign_tuple(empty_tuple, Storage{1}, std::index_sequence<>{}); - // assign_tuple(tuple, Storage{0b11111}, std::make_index_sequence<3>{}, Bits{}, Bits{}, Bits{}); - // (void)Storage{}; - //assign_tuple(empty_tuple, Storage{}, std::index_sequence<0>{}, Bits{}); - // assign_tuple(empty_tuple, Storage{1}, std::index_sequence<>{}, Bits{}); + //assign_tuple(empty_tuple, Storage{1}, std::index_sequence<>{}, make_tuple{}); + //assign_tuple(tuple, Storage{0b11111}, std::make_index_sequence<3>{}, make_tuple{}); + //(void)Storage{}; + //assign_tuple(empty_tuple, Storage{}, std::index_sequence<0>{}, make_tuple{}); + //assign_tuple(empty_tuple, Storage{1}, std::index_sequence<>{}, make_tuple{}); } return true; diff --git a/serialize/packbits.hpp b/serialize/packbits.hpp index 8a828f94..3fd859d2 100644 --- a/serialize/packbits.hpp +++ b/serialize/packbits.hpp @@ -4,13 +4,18 @@ #include #include "compat/assert.hpp" -namespace floormat::Pack { -template struct Bits; -} // namespace floormat::Pack - namespace floormat::detail_Pack { -using namespace floormat::Pack; +template +struct Bits final +{ + static_assert(std::is_fundamental_v); + static_assert(N > 0); + static_assert(N < sizeof(T)*8); + + using type = T; + static constexpr auto bits = N; +}; template struct Storage @@ -77,8 +82,11 @@ struct make_tuple_type_ }; template using make_tuple_type = typename make_tuple_type_::Seq; -template -constexpr void assign_tuple(Place& p, Storage st, std::index_sequence, Bits, Sizes... sizes) +template struct pack_tuple {}; + +template +requires requires() { sizeof...(Is) == sizeof...(Sizes); } +constexpr void assign_tuple(Place& p, Storage st, std::index_sequence, pack_tuple, Sizes...>) { static_assert(Size <= Left, "too many bits requested"); static_assert(I < std::tuple_size_v, "too few tuple members"); @@ -86,32 +94,25 @@ constexpr void assign_tuple(Place& p, Storage st, std::index_sequence; get(p) = st.template get(); T next_value = st.template advance(); - assign_tuple(p, next_type{next_value}, std::index_sequence{}, sizes...); + assign_tuple(p, next_type{next_value}, std::index_sequence{}, pack_tuple{}); } -template -constexpr void assign_tuple(Place&, Storage st, std::index_sequence<>) +template +constexpr void assign_tuple(Place&, Storage st, std::index_sequence<>, pack_tuple<>) { fm_assert(st.check_zero()); } -template +template requires(sizeof...(Is) != sizeof...(Sizes)) -constexpr void assign_tuple(Place&, Storage, std::index_sequence, Sizes...) = delete; +constexpr void assign_tuple(Place&, Storage, std::index_sequence, pack_tuple) = delete; + +template using make_pack = pack_tuple...>; } // namespace floormat::detail_Pack namespace floormat::Pack { -template -struct Bits final -{ - static_assert(std::is_fundamental_v); - static_assert(N > 0); - static_assert(N < sizeof(T)*8); - using type = T; - static constexpr auto bits = N; -}; } // namespace floormat::Pack -- cgit v1.2.3