diff --git a/quicktex/Vec.h b/quicktex/Vec.h index 28fce4d..16fd03c 100644 --- a/quicktex/Vec.h +++ b/quicktex/Vec.h @@ -29,6 +29,7 @@ namespace quicktex { +#pragma pack(push, 1) template class Vec { public: typedef T value_type; @@ -52,6 +53,7 @@ template class Vec { * @param rvalue Source vector to copy from */ template Vec(std::enable_if_t, const Vec> &rvalue) { + static_assert(sizeof(Vec) == N * sizeof(T)); for (unsigned i = 0; i < N; i++) { at(i) = static_cast(rvalue[i]); } } @@ -218,5 +220,6 @@ template class BatchVec return val; } }; +#pragma pack(pop) } // namespace quicktex \ No newline at end of file diff --git a/quicktex/util/bitbash.h b/quicktex/util/bitbash.h index 1103c21..258441a 100644 --- a/quicktex/util/bitbash.h +++ b/quicktex/util/bitbash.h @@ -84,8 +84,8 @@ size_t unpack_into(P packed, OI begin, OI end, WI widths, bool little_endian = t auto w = *(widths++); assert(w <= std::numeric_limits::digits); - auto mask = ((1 << w) - 1); - *(begin++) = (packed >> offset) & mask; + auto mask = ((1 << w) - 1); // least significant w bits all 1 + *(begin++) = (packed >> offset) & mask; // write to output offset += w; // increment offset } @@ -103,11 +103,11 @@ size_t unpack_into(P packed, OI begin, OI end, WI widths, bool little_endian = t unsigned offset = total_offset; while (begin < end) { auto w = *(widths++); - offset -= w; // decrement offset - assert(w < std::numeric_limits::digits); + offset -= w; // decrement offset + assert(w < std::numeric_limits::digits); // detect an overflow condition - auto mask = ((1 << w) - 1); - *(begin++) = (packed >> offset) & mask; + auto mask = ((1 << w) - 1); // least significant w bits all 1 + *(begin++) = (packed >> offset) & mask; // write to output } return total_offset; @@ -199,9 +199,9 @@ std::array unpack(P packed, const std::array &widths, bool litt * @return an array of unpacked values */ template - requires std::unsigned_integral

&& sized_range + requires std::unsigned_integral

&& range std::array unpack(P packed, const WR &widths, bool little_endian = true) { - assert(widths.size() >= N); + assert(distance(widths) == N); return unpack(packed, widths.begin(), little_endian); } diff --git a/quicktex/util/types.h b/quicktex/util/types.h index 3598f90..6100831 100644 --- a/quicktex/util/types.h +++ b/quicktex/util/types.h @@ -23,13 +23,27 @@ namespace quicktex::util { template struct next_size; template using next_size_t = typename next_size::type; -template struct next_size_tag { using type = T; }; +template struct type_tag { using type = T; }; -template <> struct next_size : next_size_tag {}; -template <> struct next_size : next_size_tag {}; -template <> struct next_size : next_size_tag {}; +template <> struct next_size : type_tag {}; +template <> struct next_size : type_tag {}; +template <> struct next_size : type_tag {}; -template <> struct next_size : next_size_tag {}; -template <> struct next_size : next_size_tag {}; -template <> struct next_size : next_size_tag {}; +template <> struct next_size : type_tag {}; +template <> struct next_size : type_tag {}; +template <> struct next_size : type_tag {}; + +template +using unsigned_bits = + std::conditional_t>>>; + +template +using signed_bits = + std::conditional_t>>>; } // namespace quicktex::util \ No newline at end of file