#include "packbits-read.hpp" #include "compat/assert.hpp" namespace floormat { using namespace floormat::Pack; namespace { template constexpr inline T lowbits = N == sizeof(T)*8 ? (T)-1 : (T{1} << N)-T{1}; static_assert(!input{65535}.check_zero()); static_assert(input{65535}.advance<16>() == 0); static_assert(input::next<16>{ input{65535}.advance<16>() }.check_zero()); static_assert(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 = input{0b10111011}; constexpr auto S1 = input{0b00000101}; constexpr auto S2 = input{0b00000001}; constexpr auto S3 = 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(S0.advance< 0>() == S0.value); static_assert(S0.advance() == S1.value); static_assert(S1.advance() == S2.value); static_assert(S2.advance() == S3.value); static_assert(S0.get() == (S0.value & (1<() == (S1.value & (1<() == (S2.value & (1<{0b1110100110001011}; constexpr auto S1 = input{0b1110}; constexpr auto S2 = input{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()); static_assert(std::is_same_v< make_tuple_type, std::tuple >); constexpr bool test4() { using Tuple_u32 = make_tuple_type; static_assert(std::is_same_v>); using Tuple_u8 = make_tuple_type; { Tuple_u32 tuple{}; static_assert(lowbits == 0x1ffffU); read_(tuple, input{(uint32_t)-1}, std::make_index_sequence<3>{}, make_pack{}); auto [a, b, c] = tuple; fm_assert(a == lowbits); fm_assert(b == lowbits); fm_assert(c & 1); } { Tuple_u8 tuple{}; read_(tuple, input{0b101011}, std::make_index_sequence<3>{}, make_pack{}); auto [a, b, c] = tuple; fm_assert(a == 0b1); fm_assert(b == 0b101); fm_assert(c == 0b10); } { std::tuple<> empty_tuple; read_(empty_tuple, input{0}, std::index_sequence<>{}, make_pack{}); Tuple_u8 tuple{}; (void)tuple; //read_(empty_tuple, input{1}, std::index_sequence<>{}, make_tuple{}); //read_(tuple, input{0b11111}, std::make_index_sequence<3>{}, make_tuple{}); //(void)input{}; //read_(empty_tuple, input{}, std::index_sequence<0>{}, make_tuple{}); //read_(empty_tuple, input{1}, std::index_sequence<>{}, make_tuple{}); } return true; } static_assert(test4()); } // namespace } // namespace floormat