From 9b8fb9c6099630e404df5dd976f3f1fa185470cc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 14 Jan 2024 11:35:15 +0100 Subject: a --- serialize/packbits.cpp | 96 +++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 36 deletions(-) (limited to 'serialize') diff --git a/serialize/packbits.cpp b/serialize/packbits.cpp index 83828f66..c908634b 100644 --- a/serialize/packbits.cpp +++ b/serialize/packbits.cpp @@ -7,6 +7,8 @@ using namespace floormat::detail_Pack; namespace { +template using us_bits = Bits_; + static_assert(!Storage{42}.check_zero()); constexpr bool test1() @@ -14,10 +16,10 @@ 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 = Storage{0b10111011}; + constexpr auto S1 = Storage{0b00000101}; + constexpr auto S2 = Storage{0b00000001}; + constexpr auto S3 = Storage{0b00000000}; using P0 = std::decay_t; using P1 = P0::next; @@ -43,38 +45,60 @@ constexpr bool test1() } static_assert(test1()); -namespace test2 { -template using ibits = Bits_; -using foo1 = ibits<2>; -using foo2 = ibits<10>; -using foo3 = ibits<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 = ibits<1>; -using bar4 = check_size_overflow; -static_assert(!bar4::result); -static_assert(bar4::size == 17); - -using foo5 = ibits<20>; -using bar5 = check_size_overflow; -static_assert(!bar5::result); -static_assert(bar5::size == 37); - -using foo6 = ibits<40>; -using bar6 = check_size_overflow; -static_assert(!bar6::result); -static_assert(bar6::size == 57); -} // namespace test2 +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()); + +constexpr bool test3() +{ + constexpr auto S0 = Storage{0b1110100110001011}; + constexpr auto S1 = Storage{0b1110}; + constexpr auto S2 = Storage{0b1}; + + static_assert(S0.get<12>() == 0b100110001011); + static_assert(S0.advance<12>() == S1.value); + + static_assert(S1.get<3>() == 0b110); + static_assert(S1.advance<3>() == S2.value); + + static_assert(S2.get<1>() == 0b1); + static_assert(S2.advance<1>() == 0); + + return true; +} +static_assert(test3()); } // namespace -- cgit v1.2.3