From 9b957f519620a07597fa28f796c09bdbef2e8fab Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 14 Jan 2024 14:55:25 +0100 Subject: aa --- serialize/packbits.cpp | 18 +++++++++++++++++- serialize/packbits.hpp | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/serialize/packbits.cpp b/serialize/packbits.cpp index c908634b..6ed898c7 100644 --- a/serialize/packbits.cpp +++ b/serialize/packbits.cpp @@ -9,7 +9,13 @@ namespace { template using us_bits = Bits_; -static_assert(!Storage{42}.check_zero()); +static_assert(!Storage{65535}.check_zero()); +static_assert(Storage{65535}.advance<16>() == 0); + +static_assert(Storage::next<16>{ + Storage{65535}.advance<16>() +}.check_zero()); +static_assert(Storage::next<16>{}.Capacity == 14); constexpr bool test1() { @@ -100,6 +106,16 @@ constexpr bool test3() } static_assert(test3()); +static_assert(std::is_same_v< make_tuple_type, std::tuple >); + +constexpr bool test4() +{ + auto t = std::tuple(); + + return true; +} +static_assert(test4()); + } // namespace } // namespace floormat diff --git a/serialize/packbits.hpp b/serialize/packbits.hpp index cb91602f..12c1dd31 100644 --- a/serialize/packbits.hpp +++ b/serialize/packbits.hpp @@ -1,6 +1,8 @@ #pragma once #include #include +#include +#include "compat/assert.hpp" namespace floormat::Pack { template struct Bits_; @@ -55,7 +57,7 @@ struct Storage } constexpr bool operator==(const Storage&) const noexcept = default; - constexpr bool check_zero() const = delete; + [[nodiscard]] constexpr inline bool check_zero() const { return value == T(0); } template using next = Storage; }; @@ -70,11 +72,7 @@ struct Storage template [[maybe_unused]] constexpr T get() const = delete; template [[maybe_unused]] constexpr T advance() const = delete; constexpr bool operator==(const Storage&) const noexcept = default; - - [[nodiscard]] constexpr inline bool check_zero() const - { - return value == T(0); - } + [[nodiscard]] constexpr inline bool check_zero() const { return true; } template struct next { @@ -83,6 +81,34 @@ struct Storage }; }; +template +struct make_tuple_type_ +{ + template using index_to_type = T; + template struct aux; + template struct aux> + { + static_assert(sizeof...(Is) > 0); + using type = std::tuple...>; + }; + using Seq = typename aux>::type; +}; +template using make_tuple_type = typename make_tuple_type_::Seq; + +template +static void assign_to_tuple(Place&, Storage st, std::index_sequence<>) +{ + fm_assert(st.check_zero()); +} + +template +static void assign_to_tuple(Place& p, Storage st, std::index_sequence) +{ + using std::get; + get(p) = st.template get(st); + assign_to_tuple(p, st.template advance(), std::index_sequence{}); +} + } // namespace floormat::detail_Pack namespace floormat::Pack { -- cgit v1.2.3