diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-14 19:49:15 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-14 19:49:15 +0100 |
commit | 97fc4fcd50272dab1d2c6e94019502d42deb4a2c (patch) | |
tree | cec5e6b6621ee5ad64dbb058bd1be3daca65e4b9 /serialize/packbits.cpp | |
parent | 6c747d58f85d29987011d9519109928c3438fcef (diff) |
a
Diffstat (limited to 'serialize/packbits.cpp')
-rw-r--r-- | serialize/packbits.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/serialize/packbits.cpp b/serialize/packbits.cpp index 86c6f605..634191fc 100644 --- a/serialize/packbits.cpp +++ b/serialize/packbits.cpp @@ -7,6 +7,25 @@ using namespace floormat::detail_Pack; namespace { +template<std::unsigned_integral T, size_t Sum, typename... Xs> struct check_size_overflow; + +template<std::unsigned_integral T, std::unsigned_integral U, size_t Sum, size_t N, typename... Xs> +struct check_size_overflow<T, Sum, Bits_<U, N>, Xs...> +{ + static_assert(std::is_same_v<T, U>); + static constexpr auto acc = Sum + size_t{N}; + using next_check = check_size_overflow<T, acc, Xs...>; + static constexpr auto size = next_check::size; + static constexpr bool result = next_check::result; +}; + +template<std::unsigned_integral T, size_t Sum> +struct check_size_overflow<T, Sum> +{ + static constexpr size_t size = Sum; + static constexpr bool result = Sum <= sizeof(T)*8; +}; + template<std::unsigned_integral T, size_t N> constexpr inline T lowbits = (T{1} << N)-T{1}; template<size_t Val> using us_bits = Bits_<uint16_t, Val>; |