From d168b52140c9eb08b6fdbb68665e1b07a6fda7a9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 15 Jan 2024 05:59:18 +0100 Subject: a --- serialize/packbits.cpp | 107 +++++++++++-------------------------------------- 1 file changed, 24 insertions(+), 83 deletions(-) (limited to 'serialize/packbits.cpp') diff --git a/serialize/packbits.cpp b/serialize/packbits.cpp index 74b9ff90..c22c621e 100644 --- a/serialize/packbits.cpp +++ b/serialize/packbits.cpp @@ -7,57 +7,36 @@ using namespace floormat::detail_Pack; namespace { -#if 0 -template struct check_size_overflow; - -template -struct check_size_overflow, Xs...> -{ - static_assert(std::is_same_v); - static constexpr auto acc = Sum + size_t{N}; - using next_check = check_size_overflow; - static constexpr auto size = next_check::size; - static constexpr bool result = next_check::result; -}; - -template -struct check_size_overflow -{ - static constexpr size_t size = Sum; - static constexpr bool result = Sum <= sizeof(T)*8; -}; -#endif - template constexpr inline T lowbits = (T{1} << N)-T{1}; template using us_bits = Bits; -static_assert(!Storage{65535}.check_zero()); -static_assert(Storage{65535}.advance<16>() == 0); +static_assert(!pack_input{65535}.check_zero()); +static_assert(pack_input{65535}.advance<16>() == 0); -static_assert(Storage::next<16>{ - Storage{65535}.advance<16>() +static_assert(pack_input::next<16>{ + pack_input{65535}.advance<16>() }.check_zero()); -static_assert(Storage::next<16>{}.Capacity == 14); +static_assert(pack_input::next<16>{}.Capacity == 14); constexpr bool test1() { constexpr size_t bits[] = { 5, 2, 1 }; constexpr size_t vals[] = { 8, 3, 1, 0 }; - constexpr auto S0 = Storage{0b10111011}; - constexpr auto S1 = Storage{0b00000101}; - constexpr auto S2 = Storage{0b00000001}; - constexpr auto S3 = Storage{0b00000000}; + constexpr auto S0 = pack_input{0b10111011}; + constexpr auto S1 = pack_input{0b00000101}; + constexpr auto S2 = pack_input{0b00000001}; + constexpr auto S3 = pack_input{0b00000000}; using P0 = std::decay_t; using P1 = P0::next; using P2 = P1::next; using P3 = P2::next; - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); static_assert(S0.advance< 0>() == S0.value); static_assert(S0.advance() == S1.value); @@ -73,49 +52,11 @@ constexpr bool test1() } static_assert(test1()); -#if 0 -constexpr bool test2() -{ - using foo1 = us_bits<2>; - using foo2 = us_bits<10>; - using foo3 = us_bits<4>; - using bar1 = check_size_overflow; - static_assert(bar1::result); - static_assert(bar1::size == 12); - - using bar2 = check_size_overflow; - static_assert(bar2::result); - static_assert(bar2::size == 10); - - using bar3 = check_size_overflow; - static_assert(bar3::result); - static_assert(bar3::size == 16); - - using foo4 = us_bits<1>; - using bar4 = check_size_overflow; - static_assert(!bar4::result); - static_assert(bar4::size == 17); - - using foo5 = us_bits<20>; - using bar5 = check_size_overflow; - static_assert(!bar5::result); - static_assert(bar5::size == 37); - - using foo6 = us_bits<40>; - using bar6 = check_size_overflow; - static_assert(!bar6::result); - static_assert(bar6::size == 57); - - return true; -} -static_assert(test2()); -#endif - constexpr bool test3() { - constexpr auto S0 = Storage{0b1110100110001011}; - constexpr auto S1 = Storage{0b1110}; - constexpr auto S2 = Storage{0b1}; + constexpr auto S0 = pack_input{0b1110100110001011}; + constexpr auto S1 = pack_input{0b1110}; + constexpr auto S2 = pack_input{0b1}; static_assert(S0.get<12>() == 0b100110001011); static_assert(S0.advance<12>() == S1.value); @@ -140,7 +81,7 @@ constexpr bool test4() { Tuple_u32 tuple{}; static_assert(lowbits == 0x1ffffU); - assign_tuple(tuple, Storage{(uint32_t)-1}, std::make_index_sequence<3>{}, make_pack{}); + read_pack(tuple, pack_input{(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 +89,7 @@ constexpr bool test4() } { Tuple_u8 tuple{}; - assign_tuple(tuple, Storage{0b101011}, std::make_index_sequence<3>{}, make_pack{}); + read_pack(tuple, pack_input{0b101011}, std::make_index_sequence<3>{}, make_pack{}); auto [a, b, c] = tuple; fm_assert(a == 0b1); fm_assert(b == 0b101); @@ -156,13 +97,13 @@ constexpr bool test4() } { std::tuple<> empty_tuple; - assign_tuple(empty_tuple, Storage{0}, std::index_sequence<>{}, make_pack{}); + read_pack(empty_tuple, pack_input{0}, std::index_sequence<>{}, make_pack{}); Tuple_u8 tuple{}; (void)tuple; - //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{}); + //read_pack(empty_tuple, pack_input{1}, std::index_sequence<>{}, make_tuple{}); + //read_pack(tuple, pack_input{0b11111}, std::make_index_sequence<3>{}, make_tuple{}); + //(void)pack_input{}; + //read_pack(empty_tuple, pack_input{}, std::index_sequence<0>{}, make_tuple{}); + //read_pack(empty_tuple, pack_input{1}, std::index_sequence<>{}, make_tuple{}); } return true; -- cgit v1.2.3